allocation.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. // pages/loadAppoint/allocation.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 : '1'
  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' : '1'},
  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. })
  134. }
  135. },
  136. //装卸员
  137. loadUserData:function(loadUserId){
  138. app.request.GET({
  139. url: app.API.roleUser,
  140. params: {
  141. roleName : '起卸员',
  142. },
  143. page: this,
  144. successFun: true
  145. }).then(res => {
  146. this.setData({
  147. loadUserArray : res.data.data,
  148. loadUserIndex : loadUserId?app.util.getDicIndex(res.data.data, loadUserId, 'id'):''
  149. })
  150. })
  151. },
  152. //下拉选择
  153. bindPickerChange: function (e) { //下拉菜单
  154. let { pickername } = e.target.dataset
  155. let getIndex = pickername + 'Index'
  156. app.util.getPickerIndex(this, getIndex, e);
  157. switch (pickername) {
  158. case 'loadPoint': //客户
  159. this.loadTimeData('', '') //获取起卸时段
  160. break;
  161. }
  162. },
  163. //删除
  164. delFun: function (e) {
  165. let _this = this
  166. let { id, loadPoint } = e.currentTarget.dataset
  167. wx.showModal({
  168. title: '提示!',
  169. content: `删除【${loadPoint}】后不可恢复。确定要删除吗?`,
  170. confirmColor: '#FF5B5B',
  171. success: function (res) {
  172. if (res.confirm) {
  173. app.request.POST({
  174. url: app.API.appointDelete,
  175. params: [{
  176. id: id
  177. }],
  178. page: _this,
  179. isLoadingTxt: '删除中...',
  180. successFun: true
  181. }).then(res => {
  182. wx.showToast({
  183. title: '删除成功',
  184. icon: 'success',
  185. duration: 1000,
  186. mask: true
  187. })
  188. _this.getAllocationListFun(); //刷新列表
  189. })
  190. } else if (res.cancel) {
  191. }
  192. }
  193. })
  194. },
  195. // 添加S
  196. showPopup(e) {
  197. let { id, loadPoint, loadTime, loadUser} = e.currentTarget.dataset
  198. this.setData({
  199. show : true,
  200. id : id ? id : '',
  201. loadPointId : loadPoint,//起卸地点
  202. loadTimeId : loadTime,//起卸时段
  203. userId : loadUser
  204. });
  205. this.loadPointData(loadPoint);
  206. this.loadUserData(loadUser);
  207. if(loadPoint){
  208. this.loadTimeData(loadPoint, loadTime);
  209. }
  210. },
  211. onClose() {
  212. this.setData({
  213. show: false,
  214. id: '',
  215. loadPointId:'',//起卸地点
  216. loadTimeId:'',//起卸时段
  217. userId:'',//执行员
  218. loadPointArray:'',
  219. loadTimeArray:'',
  220. loadUserArray:''
  221. });
  222. },
  223. /**
  224. * 生命周期函数--监听页面初次渲染完成
  225. */
  226. onReady() {
  227. },
  228. /**
  229. * 生命周期函数--监听页面显示
  230. */
  231. onShow() {
  232. },
  233. //页面跳转
  234. toLink: function (e) {
  235. let { url } = e.currentTarget.dataset
  236. wx.navigateTo({
  237. url: url
  238. })
  239. },
  240. //表单提交 carTaskAdd
  241. formSubmitAllocation: function ({detail:{value}}) {
  242. let _this = this
  243. var warn = ""; //弹框时提示的内容
  244. if (value.loadPointId == '') {
  245. warn = "请选择装卸点位!";
  246. } else if(value.loadTimeId == ''){
  247. warn = "请选择装卸时间!";
  248. } else if(value.userId == ''){
  249. warn = "请选择执行员!";
  250. }
  251. if (warn != '') {
  252. app.util.checkForm(warn);
  253. } else {
  254. app.request.POST({
  255. url: value.id=='' ? app.API.appointAdd : app.API.appointReplace,
  256. params: value,
  257. page: this,
  258. isLoadingTxt: '提交中...',
  259. isSubmitting: true,
  260. successFun: true
  261. }).then(res => {
  262. wx.showToast({
  263. title: value.id=='' ? '新增成功' : '调度成功',
  264. icon: 'success',
  265. duration: 1000,
  266. mask: true
  267. })
  268. _this.onClose()
  269. _this.getAllocationListFun(); //刷新列表
  270. })
  271. }
  272. },
  273. /**
  274. * 生命周期函数--监听页面隐藏
  275. */
  276. onHide() {
  277. },
  278. /**
  279. * 生命周期函数--监听页面卸载
  280. */
  281. onUnload() {
  282. },
  283. /**
  284. * 页面相关事件处理函数--监听用户下拉动作
  285. */
  286. onPullDownRefresh: function () {
  287. this.setData({
  288. searchVal: ''
  289. })
  290. if (wx.getStorageSync('loginStatus')) {
  291. this.getAllocationListFun();
  292. } else {
  293. wx.stopPullDownRefresh();
  294. }
  295. },
  296. /**
  297. * 页面上拉触底事件的处理函数
  298. * appointType 1起卸点位 2装货点位
  299. */
  300. onReachBottom: function () {
  301. this.data.page++;
  302. let params = {
  303. current : this.data.page,
  304. size : this.data.limit,
  305. appointId : this.data.appointId,
  306. appointType : '1'
  307. }
  308. app.request.pageFirst({
  309. url: app.API.bizloaddispatchPage,
  310. page: this,
  311. params: params,
  312. loadType: true //加载类型,是否是下拉加载
  313. });
  314. },
  315. //以下是按钮拖动事件
  316. buttonStart: function (e) {
  317. startPoint = e.touches[0] //获取拖动开始点
  318. },
  319. buttonMove: function (e) {
  320. var endPoint = e.touches[e.touches.length - 1] //获取拖动结束点
  321. //计算在X轴上拖动的距离和在Y轴上拖动的距离
  322. var translateX = endPoint.clientX - startPoint.clientX
  323. var translateY = endPoint.clientY - startPoint.clientY
  324. startPoint = endPoint //重置开始位置
  325. var buttonTop = this.data.buttonTop + translateY
  326. var buttonLeft = this.data.buttonLeft + translateX
  327. //判断是移动否超出屏幕
  328. if (buttonLeft + 60 >= this.data.windowWidth) {
  329. buttonLeft = this.data.windowWidth - 60;
  330. }
  331. if (buttonLeft <= 0) {
  332. buttonLeft = 0;
  333. }
  334. if (buttonTop <= this.data.filterHeight) {
  335. buttonTop = this.data.filterHeight
  336. }
  337. if (buttonTop + 60 + 48 + this.data.safeAreaHeight >= this.data.windowHeight) {
  338. buttonTop = this.data.windowHeight - 60 - 48 - this.data.safeAreaHeight;
  339. }
  340. this.setData({
  341. buttonTop: buttonTop,
  342. buttonLeft: buttonLeft
  343. })
  344. },
  345. buttonEnd: function (e) {},
  346. /**
  347. * 用户点击右上角分享
  348. */
  349. onShareAppMessage: function () {
  350. }
  351. })