dispatch.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. // pages/loadAppoint/dispatch.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. str:' ',
  9. str2: ' ',
  10. loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
  11. roleCodeList: wx.getStorageSync('roleCodeList') ? wx.getStorageSync('roleCodeList') : '',
  12. //按钮位置参数
  13. safeAreaHeight: 0, //底部安全区域的高度
  14. buttonTop: 0,
  15. buttonLeft: 0,
  16. windowHeight: '',
  17. windowWidth: '',
  18. showModal: false,
  19. defaultText: '请选择',
  20. isSubmitting: false,
  21. //分页
  22. limit: 10,
  23. requestStatu: '加载中...',
  24. page: 1,
  25. totalPages: 1,
  26. more: false,
  27. nomore: '',
  28. resData:[],
  29. searchVal: '',
  30. show: false,
  31. loadPointId:'',//装货地点
  32. loadTimeId:'',//装货时段
  33. loadPointArray:[],//装卸点位
  34. loadPointIndex:null,
  35. loadTimeArray:[], //装卸时间
  36. loadTimeIndex:null,
  37. // loadUserArray:[], //执行员
  38. // loadUserIndex:null,
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad(options) {
  44. this.setData({
  45. safeAreaHeight: app.globalData.windowInfo.screenHeight - app.globalData.systemInfo.safeArea.bottom
  46. })
  47. // 使用选择器选择节点
  48. this.getFilterHeight()
  49. //获取页面高度设置新增按钮的初始位置
  50. var that = this;
  51. wx.getSystemInfo({
  52. success: function (res) {
  53. // 高度,宽度 单位为px
  54. that.setData({
  55. windowHeight: res.windowHeight, //屏幕宽度、高度
  56. windowWidth: res.windowWidth,
  57. buttonTop: res.windowHeight * 0.8 - that.data.safeAreaHeight-60, //这里定义按钮的初始位置
  58. buttonLeft: res.windowWidth * 0.80, //这里定义按钮的初始位置
  59. })
  60. }
  61. })
  62. this.setData({
  63. appointId : options.appointId,
  64. })
  65. //装货点位
  66. this.getAllocationListFun()
  67. },
  68. //获取顶部筛选区域的高度
  69. getFilterHeight:function(){
  70. let that = this;
  71. // 使用顶部筛选高度选择器选择节点的高度
  72. const query = wx.createSelectorQuery();
  73. query.select('.topFilter').boundingClientRect(function (rect) {
  74. if(rect){
  75. that.setData({
  76. filterWidth: rect.width,
  77. filterHeight: rect.height,
  78. });
  79. }
  80. }).exec();
  81. },
  82. //列表 appointType 1起卸点位 2装货点位
  83. getAllocationListFun: function () {
  84. this.setData({
  85. page: 1
  86. })
  87. let params = {
  88. current : this.data.page,
  89. size : this.data.limit,
  90. appointId : this.data.appointId,
  91. appointType : '2'
  92. }
  93. app.request.pageFirst({
  94. url: app.API.bizloaddispatchPage,
  95. page: this,
  96. params: params,
  97. })
  98. },
  99. //装卸点位 appointType 1起卸点位 2装货点位
  100. loadPointData:function(loadPointId){
  101. app.request.GET({
  102. url: app.API.loadPoint,
  103. params: {'appointType' : '2'},
  104. page: this,
  105. successFun: true
  106. }).then(res => {
  107. this.setData({
  108. loadPointArray : res.data.data,
  109. loadPointIndex : loadPointId?app.util.getDicIndex(res.data.data, loadPointId, 'id'):''
  110. })
  111. })
  112. },
  113. //装卸时间
  114. loadTimeData:function(loadPointId, loadTimeId){
  115. let pointId = loadPointId? loadPointId : this.data.loadPointArray[this.data.loadPointIndex].id;
  116. if(pointId && pointId != ''){
  117. app.request.GET({
  118. url: app.API.loadTimeNow,
  119. params: {
  120. pointId : pointId,
  121. },
  122. page: this,
  123. successFun: true
  124. }).then(res => {
  125. let timeList = res.data.data
  126. timeList.forEach((element,index) => {
  127. timeList[index].time = element.beginTime + '~' + element.endTime
  128. });
  129. this.setData({
  130. loadTimeArray : timeList,
  131. loadTimeIndex : loadTimeId != ''?app.util.getDicIndex(res.data.data, loadTimeId, 'id'):'',
  132. })
  133. if(loadTimeId!=''){
  134. this.setData({
  135. availableNumber : loadTimeId != ''?this.data.loadTimeArray[this.data.loadTimeIndex].availableNumber:'',
  136. alreadyNumber : loadTimeId != ''?this.data.loadTimeArray[this.data.loadTimeIndex].alreadyNumber:'',
  137. })
  138. }
  139. })
  140. }
  141. },
  142. //装货员
  143. // loadUserData:function(loadUserId){
  144. // app.request.GET({
  145. // url: app.API.roleUser,
  146. // params: {
  147. // roleName : '装货员',
  148. // },
  149. // page: this,
  150. // successFun: true
  151. // }).then(res => {
  152. // this.setData({
  153. // loadUserArray : res.data.data,
  154. // loadUserIndex : loadUserId?app.util.getDicIndex(res.data.data, loadUserId, 'id'):''
  155. // })
  156. // })
  157. // },
  158. //下拉选择
  159. bindPickerChange: function (e) { //下拉菜单
  160. let { pickername } = e.target.dataset
  161. let getIndex = pickername + 'Index'
  162. app.util.getPickerIndex(this, getIndex, e);
  163. switch (pickername) {
  164. case 'loadPoint': //点位
  165. this.loadTimeData('', '') //获取装货时段
  166. break;
  167. case 'loadTime': //点位
  168. this.setData({
  169. availableNumber : this.data.loadTimeArray[this.data.loadTimeIndex].availableNumber,
  170. alreadyNumber : this.data.loadTimeArray[this.data.loadTimeIndex].alreadyNumber,
  171. })
  172. break;
  173. }
  174. },
  175. //删除
  176. delFun: function (e) {
  177. let _this = this
  178. let { id, loadPoint } = e.currentTarget.dataset
  179. wx.showModal({
  180. title: '提示!',
  181. content: `删除【${loadPoint}】后不可恢复。确定要删除吗?`,
  182. confirmColor: '#FF5B5B',
  183. success: function (res) {
  184. if (res.confirm) {
  185. app.request.POST({
  186. url: app.API.appointDelete,
  187. params: [{
  188. id: id
  189. }],
  190. page: _this,
  191. isLoadingTxt: '删除中...',
  192. successFun: true
  193. }).then(res => {
  194. wx.showToast({
  195. title: '删除成功',
  196. icon: 'success',
  197. duration: 1000,
  198. mask: true
  199. })
  200. _this.getAllocationListFun(); //刷新列表
  201. })
  202. } else if (res.cancel) {
  203. }
  204. }
  205. })
  206. },
  207. // 添加S
  208. showPopup(e) {
  209. let { id, loadPoint, loadTime} = e.currentTarget.dataset
  210. this.setData({
  211. show : true,
  212. id : id ? id : '',
  213. loadPointId : loadPoint,//装货地点
  214. loadTimeId : loadTime,//装货时段
  215. // userId : loadUser
  216. });
  217. this.loadPointData(loadPoint);
  218. // this.loadUserData(loadUser);
  219. if(loadPoint){
  220. this.loadTimeData(loadPoint, loadTime);
  221. }
  222. },
  223. onClose() {
  224. this.setData({
  225. show: false,
  226. id: '',
  227. loadPointId:'',//装货地点
  228. loadTimeId:'',//装货时段
  229. // userId:'',//执行员
  230. loadPointArray:'',
  231. loadTimeArray:'',
  232. // loadUserArray:''
  233. });
  234. },
  235. /**
  236. * 生命周期函数--监听页面初次渲染完成
  237. */
  238. onReady() {
  239. },
  240. /**
  241. * 生命周期函数--监听页面显示
  242. */
  243. onShow() {
  244. },
  245. //页面跳转
  246. toLink: function (e) {
  247. let { url } = e.currentTarget.dataset
  248. wx.navigateTo({
  249. url: url
  250. })
  251. },
  252. //表单提交 carTaskAdd
  253. formSubmitAllocation: function ({detail:{value}}) {
  254. let _this = this
  255. var warn = ""; //弹框时提示的内容
  256. if (value.loadPointId == '') {
  257. warn = "请选择装卸点位!";
  258. } else if(value.loadTimeId == ''){
  259. warn = "请选择装卸时间!";
  260. // } else if(value.userId == ''){
  261. // warn = "请选择执行员!";
  262. }
  263. if (warn != '') {
  264. app.util.checkForm(warn);
  265. } else {
  266. app.request.POST({
  267. url: value.id=='' ? app.API.dispatchAdd : app.API.dispatchReplace,
  268. params: value,
  269. page: this,
  270. isLoadingTxt: '提交中...',
  271. isSubmitting: true,
  272. successFun: true
  273. }).then(res => {
  274. wx.showToast({
  275. title: value.id=='' ? '新增成功' : '更换成功',
  276. icon: 'success',
  277. duration: 1000,
  278. mask: true
  279. })
  280. _this.onClose()
  281. _this.getAllocationListFun(); //刷新列表
  282. })
  283. }
  284. },
  285. /**
  286. * 生命周期函数--监听页面隐藏
  287. */
  288. onHide() {
  289. },
  290. /**
  291. * 生命周期函数--监听页面卸载
  292. */
  293. onUnload() {
  294. },
  295. /**
  296. * 页面相关事件处理函数--监听用户下拉动作
  297. */
  298. onPullDownRefresh: function () {
  299. this.setData({
  300. searchVal: ''
  301. })
  302. if (wx.getStorageSync('loginStatus')) {
  303. this.getAllocationListFun();
  304. } else {
  305. wx.stopPullDownRefresh();
  306. }
  307. },
  308. /**
  309. * 页面上拉触底事件的处理函数
  310. * appointType 1起卸点位 2装货点位
  311. */
  312. onReachBottom: function () {
  313. this.data.page++;
  314. let params = {
  315. current : this.data.page,
  316. size : this.data.limit,
  317. appointId : this.data.appointId,
  318. appointType : '2'
  319. }
  320. app.request.pageFirst({
  321. url: app.API.bizloaddispatchPage,
  322. page: this,
  323. params: params,
  324. loadType: true //加载类型,是否是下拉加载
  325. });
  326. },
  327. //以下是按钮拖动事件
  328. buttonStart: function (e) {
  329. startPoint = e.touches[0] //获取拖动开始点
  330. },
  331. buttonMove: function (e) {
  332. var endPoint = e.touches[e.touches.length - 1] //获取拖动结束点
  333. //计算在X轴上拖动的距离和在Y轴上拖动的距离
  334. var translateX = endPoint.clientX - startPoint.clientX
  335. var translateY = endPoint.clientY - startPoint.clientY
  336. startPoint = endPoint //重置开始位置
  337. var buttonTop = this.data.buttonTop + translateY
  338. var buttonLeft = this.data.buttonLeft + translateX
  339. //判断是移动否超出屏幕
  340. if (buttonLeft + 60 >= this.data.windowWidth) {
  341. buttonLeft = this.data.windowWidth - 60;
  342. }
  343. if (buttonLeft <= 0) {
  344. buttonLeft = 0;
  345. }
  346. if (buttonTop <= this.data.filterHeight) {
  347. buttonTop = this.data.filterHeight
  348. }
  349. if (buttonTop + 60 + 48 + this.data.safeAreaHeight >= this.data.windowHeight) {
  350. buttonTop = this.data.windowHeight - 60 - 48 - this.data.safeAreaHeight;
  351. }
  352. this.setData({
  353. buttonTop: buttonTop,
  354. buttonLeft: buttonLeft
  355. })
  356. },
  357. buttonEnd: function (e) {},
  358. /**
  359. * 用户点击右上角分享
  360. */
  361. onShareAppMessage: function () {
  362. }
  363. })