allocation.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. // pages/loadAppoint/allocation.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 : '1'
  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' : '1'},
  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. })
  95. }
  96. },
  97. //装卸时间
  98. loadUserData:function(loadUserId){
  99. app.request.GET({
  100. url: app.API.roleUser,
  101. params: {
  102. roleName : '起卸员',
  103. },
  104. page: this,
  105. successFun: true
  106. }).then(res => {
  107. this.setData({
  108. loadUserArray : res.data.data,
  109. loadUserIndex : loadUserId?app.util.getDicIndex(res.data.data, loadUserId, 'id'):''
  110. })
  111. })
  112. },
  113. //下拉选择
  114. bindPickerChange: function (e) { //下拉菜单
  115. let { pickername } = e.target.dataset
  116. let getIndex = pickername + 'Index'
  117. app.util.getPickerIndex(this, getIndex, e);
  118. switch (pickername) {
  119. case 'loadPoint': //客户
  120. this.loadTimeData('', '') //获取起卸时段
  121. break;
  122. }
  123. },
  124. //删除
  125. delFun: function (e) {
  126. let _this = this
  127. let { id, loadPoint } = e.currentTarget.dataset
  128. wx.showModal({
  129. title: '提示!',
  130. content: `删除【${loadPoint}】后不可恢复。确定要删除吗?`,
  131. confirmColor: '#FF5B5B',
  132. success: function (res) {
  133. if (res.confirm) {
  134. app.request.POST({
  135. url: app.API.appointDelete,
  136. params: [{
  137. id: id
  138. }],
  139. page: _this,
  140. isLoadingTxt: '删除中...',
  141. successFun: true
  142. }).then(res => {
  143. wx.showToast({
  144. title: '删除成功',
  145. icon: 'success',
  146. duration: 1000,
  147. mask: true
  148. })
  149. _this.getAllocationListFun(); //刷新列表
  150. })
  151. } else if (res.cancel) {
  152. }
  153. }
  154. })
  155. },
  156. // 添加S
  157. showPopup(e) {
  158. let { id, loadPoint, loadTime, loadUser} = e.currentTarget.dataset
  159. this.setData({
  160. show : true,
  161. id : id ? id : '',
  162. loadPointId : loadPoint,//起卸地点
  163. loadTimeId : loadTime,//起卸时段
  164. userId : loadUser
  165. });
  166. this.loadPointData(loadPoint);
  167. this.loadUserData(loadUser);
  168. if(loadPoint){
  169. this.loadTimeData(loadPoint, loadTime);
  170. }
  171. },
  172. onClose() {
  173. this.setData({
  174. show: false,
  175. id: '',
  176. loadPointId:'',//起卸地点
  177. loadTimeId:'',//起卸时段
  178. userId:'',//执行员
  179. loadPointArray:'',
  180. loadTimeArray:'',
  181. loadUserArray:''
  182. });
  183. },
  184. /**
  185. * 生命周期函数--监听页面初次渲染完成
  186. */
  187. onReady() {
  188. },
  189. /**
  190. * 生命周期函数--监听页面显示
  191. */
  192. onShow() {
  193. },
  194. //页面跳转
  195. toLink: function (e) {
  196. let { url } = e.currentTarget.dataset
  197. wx.navigateTo({
  198. url: url
  199. })
  200. },
  201. //表单提交 carTaskAdd
  202. formSubmitAllocation: function ({detail:{value}}) {
  203. let _this = this
  204. var warn = ""; //弹框时提示的内容
  205. if (value.loadPointId == '') {
  206. warn = "请选择装卸点位!";
  207. } else if(value.loadTimeId == ''){
  208. warn = "请选择装卸时间!";
  209. } else if(value.userId == ''){
  210. warn = "请选择执行员!";
  211. }
  212. if (warn != '') {
  213. app.util.checkForm(warn);
  214. } else {
  215. app.request.POST({
  216. url: value.id=='' ? app.API.appointAdd : app.API.appointReplace,
  217. params: value,
  218. page: this,
  219. isLoadingTxt: '提交中...',
  220. isSubmitting: true,
  221. successFun: true
  222. }).then(res => {
  223. wx.showToast({
  224. title: value.id=='' ? '新增成功' : '更换成功',
  225. icon: 'success',
  226. duration: 1000,
  227. mask: true
  228. })
  229. _this.onClose()
  230. _this.getAllocationListFun(); //刷新列表
  231. })
  232. }
  233. },
  234. /**
  235. * 生命周期函数--监听页面隐藏
  236. */
  237. onHide() {
  238. },
  239. /**
  240. * 生命周期函数--监听页面卸载
  241. */
  242. onUnload() {
  243. },
  244. /**
  245. * 页面相关事件处理函数--监听用户下拉动作
  246. */
  247. onPullDownRefresh: function () {
  248. this.setData({
  249. searchVal: ''
  250. })
  251. if (wx.getStorageSync('loginStatus')) {
  252. this.getAllocationListFun();
  253. } else {
  254. wx.stopPullDownRefresh();
  255. }
  256. },
  257. /**
  258. * 页面上拉触底事件的处理函数
  259. */
  260. onReachBottom: function () {
  261. this.data.page++;
  262. let params = {
  263. current : this.data.page,
  264. size : this.data.limit,
  265. appointId : this.data.appointId,
  266. appointType : '1'
  267. }
  268. app.request.pageFirst({
  269. url: app.API.bizloaddispatchPage,
  270. page: this,
  271. params: params,
  272. loadType: true //加载类型,是否是下拉加载
  273. });
  274. },
  275. /**
  276. * 用户点击右上角分享
  277. */
  278. onShareAppMessage() {
  279. }
  280. })