dispatch.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. // pages/loadAppoint/dispatch.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showModal: false,
  9. defaultText: '请选择',
  10. isSubmitting: false,
  11. str:' ',
  12. loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
  13. roleCodeList: wx.getStorageSync('roleCodeList') ? wx.getStorageSync('roleCodeList') : '',
  14. searchVal: '',
  15. //分页
  16. limit: 10,
  17. requestStatu: '加载中...',
  18. page: 1,
  19. totalPages: 1,
  20. more: false,
  21. nomore: '',
  22. resData:[],
  23. show: false,
  24. loadPointId:'',//装货地点
  25. loadTimeId:'',//装货时段
  26. loadPointArray:[],//装卸点位
  27. loadPointIndex:null,
  28. loadTimeArray:[], //装卸时间
  29. loadTimeIndex:null,
  30. // loadUserArray:[], //执行员
  31. // loadUserIndex:null,
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad(options) {
  37. this.setData({
  38. appointId : options.appointId,
  39. })
  40. //装货点位
  41. this.getAllocationListFun()
  42. },
  43. //列表
  44. getAllocationListFun: function () {
  45. this.setData({
  46. page: 1
  47. })
  48. let params = {
  49. current : this.data.page,
  50. size : this.data.limit,
  51. appointId : this.data.appointId,
  52. appointType : '2'
  53. }
  54. app.request.pageFirst({
  55. url: app.API.bizloaddispatchPage,
  56. page: this,
  57. params: params,
  58. })
  59. },
  60. //装卸点位
  61. loadPointData:function(loadPointId){
  62. app.request.GET({
  63. url: app.API.loadPoint,
  64. params: {'appointType' : '2'},
  65. page: this,
  66. successFun: true
  67. }).then(res => {
  68. this.setData({
  69. loadPointArray : res.data.data,
  70. loadPointIndex : loadPointId?app.util.getDicIndex(res.data.data, loadPointId, 'id'):''
  71. })
  72. })
  73. },
  74. //装卸时间
  75. loadTimeData:function(loadPointId, loadTimeId){
  76. let pointId = loadPointId? loadPointId : this.data.loadPointArray[this.data.loadPointIndex].id;
  77. if(pointId && pointId != ''){
  78. app.request.GET({
  79. url: app.API.loadTimeNow,
  80. params: {
  81. pointId : pointId,
  82. },
  83. page: this,
  84. successFun: true
  85. }).then(res => {
  86. let timeList = res.data.data
  87. timeList.forEach((element,index) => {
  88. timeList[index].time = element.beginTime + '~' + element.endTime
  89. });
  90. this.setData({
  91. loadTimeArray : timeList,
  92. loadTimeIndex : loadTimeId != ''?app.util.getDicIndex(res.data.data, loadTimeId, 'id'):'',
  93. })
  94. if(loadTimeId!=''){
  95. this.setData({
  96. availableNumber : loadTimeId != ''?this.data.loadTimeArray[this.data.loadTimeIndex].availableNumber:'',
  97. alreadyNumber : loadTimeId != ''?this.data.loadTimeArray[this.data.loadTimeIndex].alreadyNumber:'',
  98. })
  99. }
  100. })
  101. }
  102. },
  103. //装货员
  104. // loadUserData:function(loadUserId){
  105. // app.request.GET({
  106. // url: app.API.roleUser,
  107. // params: {
  108. // roleName : '装货员',
  109. // },
  110. // page: this,
  111. // successFun: true
  112. // }).then(res => {
  113. // this.setData({
  114. // loadUserArray : res.data.data,
  115. // loadUserIndex : loadUserId?app.util.getDicIndex(res.data.data, loadUserId, 'id'):''
  116. // })
  117. // })
  118. // },
  119. //下拉选择
  120. bindPickerChange: function (e) { //下拉菜单
  121. let { pickername } = e.target.dataset
  122. let getIndex = pickername + 'Index'
  123. app.util.getPickerIndex(this, getIndex, e);
  124. switch (pickername) {
  125. case 'loadPoint': //点位
  126. this.loadTimeData('', '') //获取装货时段
  127. break;
  128. case 'loadTime': //点位
  129. this.setData({
  130. availableNumber : this.data.loadTimeArray[this.data.loadTimeIndex].availableNumber,
  131. alreadyNumber : this.data.loadTimeArray[this.data.loadTimeIndex].alreadyNumber,
  132. })
  133. break;
  134. }
  135. },
  136. //删除
  137. delFun: function (e) {
  138. let _this = this
  139. let { id, loadPoint } = e.currentTarget.dataset
  140. wx.showModal({
  141. title: '提示!',
  142. content: `删除【${loadPoint}】后不可恢复。确定要删除吗?`,
  143. confirmColor: '#FF5B5B',
  144. success: function (res) {
  145. if (res.confirm) {
  146. app.request.POST({
  147. url: app.API.appointDelete,
  148. params: [{
  149. id: id
  150. }],
  151. page: _this,
  152. isLoadingTxt: '删除中...',
  153. successFun: true
  154. }).then(res => {
  155. wx.showToast({
  156. title: '删除成功',
  157. icon: 'success',
  158. duration: 1000,
  159. mask: true
  160. })
  161. _this.getAllocationListFun(); //刷新列表
  162. })
  163. } else if (res.cancel) {
  164. }
  165. }
  166. })
  167. },
  168. // 添加S
  169. showPopup(e) {
  170. let { id, loadPoint, loadTime} = e.currentTarget.dataset
  171. this.setData({
  172. show : true,
  173. id : id ? id : '',
  174. loadPointId : loadPoint,//装货地点
  175. loadTimeId : loadTime,//装货时段
  176. // userId : loadUser
  177. });
  178. this.loadPointData(loadPoint);
  179. // this.loadUserData(loadUser);
  180. if(loadPoint){
  181. this.loadTimeData(loadPoint, loadTime);
  182. }
  183. },
  184. onClose() {
  185. this.setData({
  186. show: false,
  187. id: '',
  188. loadPointId:'',//装货地点
  189. loadTimeId:'',//装货时段
  190. // userId:'',//执行员
  191. loadPointArray:'',
  192. loadTimeArray:'',
  193. // loadUserArray:''
  194. });
  195. },
  196. /**
  197. * 生命周期函数--监听页面初次渲染完成
  198. */
  199. onReady() {
  200. },
  201. /**
  202. * 生命周期函数--监听页面显示
  203. */
  204. onShow() {
  205. },
  206. //页面跳转
  207. toLink: function (e) {
  208. let { url } = e.currentTarget.dataset
  209. wx.navigateTo({
  210. url: url
  211. })
  212. },
  213. //表单提交 carTaskAdd
  214. formSubmitAllocation: function ({detail:{value}}) {
  215. let _this = this
  216. var warn = ""; //弹框时提示的内容
  217. if (value.loadPointId == '') {
  218. warn = "请选择装卸点位!";
  219. } else if(value.loadTimeId == ''){
  220. warn = "请选择装卸时间!";
  221. // } else if(value.userId == ''){
  222. // warn = "请选择执行员!";
  223. }
  224. if (warn != '') {
  225. app.util.checkForm(warn);
  226. } else {
  227. app.request.POST({
  228. url: value.id=='' ? app.API.dispatchAdd : app.API.dispatchReplace,
  229. params: value,
  230. page: this,
  231. isLoadingTxt: '提交中...',
  232. isSubmitting: true,
  233. successFun: true
  234. }).then(res => {
  235. wx.showToast({
  236. title: value.id=='' ? '新增成功' : '更换成功',
  237. icon: 'success',
  238. duration: 1000,
  239. mask: true
  240. })
  241. _this.onClose()
  242. _this.getAllocationListFun(); //刷新列表
  243. })
  244. }
  245. },
  246. /**
  247. * 生命周期函数--监听页面隐藏
  248. */
  249. onHide() {
  250. },
  251. /**
  252. * 生命周期函数--监听页面卸载
  253. */
  254. onUnload() {
  255. },
  256. /**
  257. * 页面相关事件处理函数--监听用户下拉动作
  258. */
  259. onPullDownRefresh: function () {
  260. this.setData({
  261. searchVal: ''
  262. })
  263. if (wx.getStorageSync('loginStatus')) {
  264. this.getAllocationListFun();
  265. } else {
  266. wx.stopPullDownRefresh();
  267. }
  268. },
  269. /**
  270. * 页面上拉触底事件的处理函数
  271. */
  272. onReachBottom: function () {
  273. this.data.page++;
  274. let params = {
  275. current : this.data.page,
  276. size : this.data.limit,
  277. appointId : this.data.appointId,
  278. appointType : '2'
  279. }
  280. app.request.pageFirst({
  281. url: app.API.bizloaddispatchPage,
  282. page: this,
  283. params: params,
  284. loadType: true //加载类型,是否是下拉加载
  285. });
  286. },
  287. /**
  288. * 用户点击右上角分享
  289. */
  290. onShareAppMessage() {
  291. }
  292. })