edit.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // pages/salesOrderMan/edit.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showModal: false,
  9. defaultText: '请选择',
  10. isSubmitting: false,
  11. orderTypeArray:[],//订单类型
  12. saleOrderType:'',
  13. customerArray:[], //客户
  14. customerIndex:null,
  15. saleOrderArray:[], //销售订单
  16. saleOrderIndex:null,
  17. confTimeArray:[], //提货时间
  18. confTimeIndex:null,
  19. supplierArray:[],//供应商
  20. supplierIndex:null,
  21. freightPrice:'',//运费单价
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. var pages = getCurrentPages();
  28. var prevPage = pages[pages.length - 2];
  29. let getInfo = prevPage.data.resData[options.index]
  30. this.setData({
  31. info: getInfo,
  32. saleOrderWeight:getInfo.orderWeight,
  33. saleOrderType:getInfo.orderType,
  34. freightPrice:getInfo.freightPrice
  35. })
  36. //订单类型
  37. let treeData = app.globalData.treeArr
  38. for (const element of treeData) {
  39. let arrStr;
  40. switch (element.dictValue) {
  41. case 'order_type':
  42. arrStr = "orderTypeArray";
  43. break;
  44. }
  45. this.setData({
  46. [arrStr]: element.children
  47. })
  48. }
  49. //获取客户列表接口
  50. this.getCustomerData()
  51. //供应商
  52. this.getsupplierData()
  53. },
  54. //选择客户
  55. getCustomerData:function(){
  56. //收货单位列表接口
  57. app.request.GET({
  58. url: app.API.getCustomerList,
  59. params: {},
  60. page: this,
  61. successFun: true
  62. }).then(res => {
  63. this.setData({
  64. customerArray:res.data.data,
  65. customerIndex: app.util.getDicIndex(res.data.data, this.data.info.customerId, 'id')
  66. })
  67. this.getSaleOrderData('info')
  68. })
  69. },
  70. //选择供应商
  71. getsupplierData:function(){
  72. //收货单位列表接口
  73. app.request.GET({
  74. url: app.API.supplierPage,
  75. params: {},
  76. page: this,
  77. successFun: true
  78. }).then(res => {
  79. this.setData({
  80. supplierArray:res.data.data,
  81. supplierIndex: app.util.getDicIndex(res.data.data, this.data.info.supplierId, 'id')
  82. })
  83. })
  84. },
  85. //下拉选择
  86. bindPickerChange: function (e) { //下拉菜单
  87. let { pickername } = e.target.dataset
  88. let getIndex = pickername + 'Index'
  89. app.util.getPickerIndex(this, getIndex, e);
  90. switch (pickername) {
  91. case 'customer': //客户
  92. this.setData({
  93. confTimeArray:[],
  94. confTimeIndex:null,
  95. saleOrderArray:[],
  96. saleOrderIndex:null,
  97. orderType:''
  98. })
  99. this.getSaleOrderData() //获取销售订单
  100. break;
  101. case 'saleOrder': //销售订单
  102. this.setData({
  103. saleOrderType:this.data.saleOrderArray[this.data.saleOrderIndex].saleOrderType,
  104. confTimeArray:[],
  105. confTimeIndex:null,
  106. saleOrderWeight:this.data.saleOrderArray[this.data.saleOrderIndex].saleOrderWeight
  107. })
  108. this.getConfTimeData() //获取提货时间段
  109. break;
  110. }
  111. },
  112. //选择销售订单
  113. getSaleOrderData:function(type){
  114. app.request.GET({
  115. url: app.API.getOrderByCustomerId,
  116. params: {
  117. id:this.data.customerArray[this.data.customerIndex].id
  118. },
  119. page: this,
  120. successFun: true
  121. }).then(res => {
  122. let orderList = res.data.data
  123. orderList.forEach((element,index) => {
  124. orderList[index].name = element.saleGoodsName + '-' + element.saleOrderNumber
  125. });
  126. this.setData({
  127. saleOrderArray:orderList,
  128. saleOrderIndex: type?app.util.getDicIndex(orderList, this.data.info.saleOrderInfo, 'id'):null
  129. })
  130. if(type){
  131. this.getConfTimeData('info')
  132. }
  133. })
  134. },
  135. //提货时间
  136. getConfTimeData:function(type){
  137. app.request.GET({
  138. url: app.API.getTakeList,
  139. params: {
  140. goodsName:this.data.saleOrderArray[this.data.saleOrderIndex].saleGoodsName,
  141. needWeight:this.data.saleOrderArray[this.data.saleOrderIndex].saleOrderWeight,
  142. goodsCode:this.data.saleOrderArray[this.data.saleOrderIndex].saleGoodsCode
  143. },
  144. page: this,
  145. successFun: true
  146. }).then(res => {
  147. let resData = res.data.data
  148. resData.forEach((element,index) => {
  149. resData[index].timeRange = element.confStartTime + '至' + element.confEndTime
  150. });
  151. this.setData({
  152. confTimeArray:resData,
  153. confTimeIndex: type?app.util.getDicIndex(resData, this.data.info.deliveryTimeId, 'id'):null
  154. })
  155. })
  156. },
  157. // 单选
  158. dangerStatusChange: function (e) {
  159. this.setData({
  160. [e.currentTarget.dataset.radiotype]: e.detail.value
  161. })
  162. },
  163. //多选
  164. checkboxChange: function (e) {
  165. this.setData({
  166. [e.currentTarget.dataset.checkboxtype]: e.detail
  167. })
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. bindscrolltolowerFun() {
  173. },
  174. //表单提交 carTaskAdd
  175. formSubmit: function ({detail:{value}}) {
  176. var warn = ""; //弹框时提示的内容
  177. if (value.customerId == '') {
  178. warn = "请选择客户!";
  179. } else if(value.orderName == ''){
  180. warn = "请选择销售订单!";
  181. } else if(value.deliveryTimeId == ''){
  182. warn = "请选择提货时间!";
  183. } else if(value.supplierId == ''){
  184. warn = "请选择供应商!";
  185. } else if(value.freightPrice == ''){
  186. warn = "请输入运费单价!";
  187. }
  188. if (warn != '') {
  189. app.util.checkForm(warn);
  190. } else {
  191. app.request.POST({
  192. url: app.API.orderEdit,
  193. params: value,
  194. page: this,
  195. isLoadingTxt: '提交中...',
  196. isSubmitting: true,
  197. successFun: true
  198. }).then(res => {
  199. wx.showToast({
  200. title: '修改成功',
  201. icon: 'success',
  202. duration: 2000,
  203. mask:true,
  204. complete: function () {
  205. setTimeout(() => {
  206. wx.navigateBack()
  207. }, 1500) //延迟时间
  208. }
  209. })
  210. })
  211. }
  212. },
  213. /**
  214. * 生命周期函数--监听页面初次渲染完成
  215. */
  216. onReady: function () {
  217. },
  218. /**
  219. * 生命周期函数--监听页面显示
  220. */
  221. onShow: function () {
  222. },
  223. /**
  224. * 生命周期函数--监听页面隐藏
  225. */
  226. onHide: function () {
  227. },
  228. /**
  229. * 生命周期函数--监听页面卸载
  230. */
  231. onUnload: function () {
  232. },
  233. /**
  234. * 页面相关事件处理函数--监听用户下拉动作
  235. */
  236. onPullDownRefresh: function () {
  237. },
  238. /**
  239. * 页面上拉触底事件的处理函数
  240. */
  241. onReachBottom: function () {
  242. },
  243. /**
  244. * 用户点击右上角分享
  245. */
  246. onShareAppMessage: function () {
  247. }
  248. })