add.js 5.8 KB

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