serviceSupply.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. const app = getApp()
  2. const util = require("../../utils/jmsUtil.js");
  3. const api = require('../../api/jms.js');
  4. import moment from 'moment'
  5. Page({
  6. data: {
  7. bookno:'',
  8. showPicker:false,
  9. currentItem:'',
  10. supplyList:[{itemName:'',number:1,price:0,difTotalPrice:0}],
  11. columns:[],
  12. typeList:[],
  13. totalAmount:0,
  14. diffId:0,
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. if(options.bookno){
  21. this.setData({
  22. bookno:options.bookno
  23. });
  24. this.getSupplyTypeList();
  25. }
  26. if(options.id){
  27. this.setData({
  28. diffId:options.id
  29. });
  30. this.getDiffOrderDetail();
  31. }
  32. },
  33. getDiffOrderDetail(){
  34. wx.showLoading({
  35. title: '加载中...',
  36. });
  37. util.request(api.getDiffDetail, {
  38. diffOrderId:this.data.diffId
  39. }, 'GET').then(res => {
  40. wx.hideLoading();
  41. if (res.errno === 0) {
  42. this.setData({
  43. orderInfo:res.data,
  44. supplyList:res.data.itemList,
  45. totalAmount:res.data.difTotalPrice,
  46. bookno:res.data.bookDetailId
  47. });
  48. this.getSupplyTypeList();
  49. }
  50. }).catch(err => {
  51. wx.hideLoading();
  52. });
  53. },
  54. getSupplyTypeList(){
  55. wx.showLoading({
  56. title: '加载中...',
  57. });
  58. util.request(api.getDiffTypeList, {
  59. bookDetailId:this.data.bookno
  60. }, 'GET').then(res => {
  61. wx.hideLoading();
  62. if (res.errno === 0) {
  63. let list=res.data;
  64. list=list.map(item=>{return item.itemName});
  65. this.setData({
  66. typeList:res.data,
  67. columns:list
  68. });
  69. }
  70. }).catch(err => {
  71. wx.hideLoading();
  72. });
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. },
  79. minusNum(e){
  80. let index=e.currentTarget.dataset.index;
  81. let num=e.currentTarget.dataset.num;
  82. let price=e.currentTarget.dataset.price;
  83. if(num<=1){
  84. wx.showToast({
  85. title: '数量不能再少了',
  86. icon: 'none',
  87. duration: 3000
  88. });
  89. return false;
  90. }else{
  91. let item1='supplyList['+index+']'+'.number';
  92. let item2='supplyList['+index+']'+'.difTotalPrice';
  93. this.setData({
  94. [item1]:num-1,
  95. [item2]:Number((num-1)*price).toFixed(2)
  96. });
  97. }
  98. let total=0;
  99. this.data.supplyList.forEach(item=>{
  100. total+=Number(item.difTotalPrice);
  101. });
  102. total=Number(total).toFixed(2);
  103. this.setData({
  104. totalAmount:total
  105. });
  106. },
  107. addNum(e){
  108. let index=e.currentTarget.dataset.index;
  109. let num=e.currentTarget.dataset.num;
  110. let price=e.currentTarget.dataset.price;
  111. let item1='supplyList['+index+']'+'.number';
  112. let item2='supplyList['+index+']'+'.difTotalPrice';
  113. this.setData({
  114. [item1]:num+1,
  115. [item2]:Number((num+1)*price).toFixed(2)
  116. });
  117. let total=0;
  118. this.data.supplyList.forEach(item=>{
  119. total+=Number(item.difTotalPrice);
  120. });
  121. total=total.toFixed(2);
  122. this.setData({
  123. totalAmount:total
  124. });
  125. },
  126. delItem(e){
  127. let index=e.currentTarget.dataset.index;
  128. let supplyList=this.data.supplyList;
  129. supplyList.splice(index, 1);
  130. this.setData({
  131. supplyList: supplyList
  132. });
  133. },
  134. addItem(){
  135. this.setData({
  136. supplyList: this.data.supplyList.concat({itemName:'',number:1,price:0,difTotalPrice:0}),
  137. })
  138. },
  139. pickerCancel(){
  140. this.setData({
  141. showPicker:false
  142. });
  143. },
  144. showTypePicker(e){
  145. let index=e.currentTarget.dataset.index;
  146. this.setData({
  147. currentItem:index,
  148. showPicker:true
  149. })
  150. },
  151. pickerConfirm(e){
  152. let value=e.detail.value;
  153. let index=e.detail.index;
  154. let item='supplyList['+this.data.currentItem+']';
  155. let item1='supplyList['+this.data.currentItem+']'+'.itemName';
  156. let item2='supplyList['+this.data.currentItem+']'+'.price';
  157. let item3='supplyList['+this.data.currentItem+']'+'.difTotalPrice';
  158. this.setData({
  159. // [item]:{itemName:this.data.typeList[index].itemName,
  160. // },
  161. [item1]:value,
  162. [item2]:this.data.typeList[index].price,
  163. [item3]:Number((this.data.typeList[index].price)*(this.data.supplyList[this.data.currentItem].number)).toFixed(2),
  164. showPicker:false,
  165. });
  166. let total=0;
  167. this.data.supplyList.forEach(item=>{
  168. total+=Number(item.difTotalPrice);
  169. console.log(total);
  170. });
  171. total=total.toFixed(2);
  172. this.setData({
  173. totalAmount:total
  174. });
  175. },
  176. createOrder(){
  177. let isValid=this.data.supplyList.every(item=>{return item.itemName!=''});
  178. if(isValid){
  179. wx.showLoading({
  180. title: '加载中...',
  181. });
  182. util.request(api.createDiffOrder, {
  183. bookDetailId:this.data.bookno,
  184. diffId:this.data.diffId,
  185. diffList:this.data.supplyList
  186. }, 'POST').then(res => {
  187. wx.hideLoading();
  188. if (res.errno === 0) {
  189. app.globalData.diffId=res.data.diffOrder.id;
  190. app.globalData.diffOrder=res.data.diffOrder;
  191. app.globalData.diffItem=res.data.diffItem;
  192. wx.navigateTo({
  193. url: '/pages/supplyOrder/supplyOrder',
  194. });
  195. }else{
  196. wx.showToast({
  197. title: res.errmsg,
  198. icon: 'none',
  199. });
  200. }
  201. }).catch(err => {
  202. wx.hideLoading();
  203. });
  204. }else{
  205. wx.showToast({
  206. title: '补差项内容不能为空',
  207. icon:'none'
  208. })
  209. }
  210. },
  211. /**
  212. * 生命周期函数--监听页面显示
  213. */
  214. onShow: function () {
  215. this.setData({
  216. diffId:app.globalData.diffId
  217. });
  218. },
  219. onHide: function () {
  220. },
  221. onUnload: function () {
  222. },
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh: function () {
  227. },
  228. /**
  229. * 页面上拉触底事件的处理函数
  230. */
  231. onReachBottom: function () {
  232. },
  233. /**
  234. * 用户点击右上角分享
  235. */
  236. onShareAppMessage: function () {
  237. },
  238. })