index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. // pages/reservationMan/index.js
  2. const app = getApp();
  3. var startPoint
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. str:' ',
  10. loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
  11. roleCodeList: wx.getStorageSync('roleCodeList') ? wx.getStorageSync('roleCodeList') : '',
  12. filterWidth: 0, //获取顶部筛选宽度
  13. filterHeight: 0, //获取顶部筛选高度
  14. safeAreaHeight: 0, //底部安全区域的高度
  15. //按钮位置参数
  16. buttonTop: 0,
  17. buttonLeft: 0,
  18. windowHeight: '',
  19. windowWidth: '',
  20. searchVal: '', //筛选条件
  21. type:'',//预约类型
  22. appointmentClassifyArray: [
  23. { label:'充电预约',value:'1' },
  24. { label:'管桩预约',value:'2' },
  25. { label:'其他预约',value:'3' },
  26. ], //预约类型
  27. appointmentTypeArray: [{
  28. dictValue: "",
  29. dictLabel: "全部状态"
  30. }],
  31. appointmentTypeIndex: 0,
  32. appointmentStatusArray: [{
  33. dictValue: "",
  34. dictLabel: "全部状态"
  35. }],
  36. appointmentStatusIndex: 0,
  37. appointmentType: '', //切换显示
  38. appointmentTypeSha: '', //砂石
  39. appointmentTypeQi: '', //起卸
  40. appointmentTypeGuan: '', //管桩
  41. appointmentTypeChong: '', //充电桩
  42. appointmentTypeOther: '', //其他
  43. //分页
  44. limit: 10,
  45. requestStatu: '加载中...',
  46. page: 1,
  47. totalPages: 1,
  48. more: false,
  49. nomore: '',
  50. //筛选E
  51. setIndex: 0,
  52. resData: [],
  53. show:false,
  54. auditFlag:'false',
  55. appointmentReason:'',//审核备注
  56. showQrcode:false,
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad(options) {
  62. this.setData({
  63. safeAreaHeight: app.globalData.windowInfo.screenHeight - app.globalData.systemInfo.safeArea.bottom
  64. })
  65. // 使用选择器选择节点
  66. this.getFilterHeight()
  67. //获取页面高度设置新增按钮的初始位置
  68. var that = this;
  69. wx.getSystemInfo({
  70. success: function (res) {
  71. // 高度,宽度 单位为px
  72. that.setData({
  73. windowHeight: res.windowHeight, //屏幕宽度、高度
  74. windowWidth: res.windowWidth,
  75. buttonTop: res.windowHeight * 0.8 - that.data.safeAreaHeight-60, //这里定义按钮的初始位置
  76. buttonLeft: res.windowWidth * 0.80, //这里定义按钮的初始位置
  77. })
  78. }
  79. })
  80. },
  81. //获取顶部筛选区域的高度
  82. getFilterHeight:function(){
  83. let that = this;
  84. // 使用顶部筛选高度选择器选择节点的高度
  85. const query = wx.createSelectorQuery();
  86. query.select('.topFilter').boundingClientRect(function (rect) {
  87. if(rect){
  88. that.setData({
  89. filterWidth: rect.width,
  90. filterHeight: rect.height,
  91. });
  92. }
  93. }).exec();
  94. },
  95. /**
  96. * 生命周期函数--监听页面初次渲染完成
  97. */
  98. onReady() {
  99. },
  100. /**
  101. * 生命周期函数--监听页面显示
  102. */
  103. onShow() {
  104. const roleCodeList = wx.getStorageSync('roleCodeList')
  105. let loginStatus = wx.getStorageSync('loginStatus')
  106. this.setData({
  107. searchVal: '',
  108. roleCodeList: roleCodeList ? roleCodeList : '',
  109. loginStatus: loginStatus ? loginStatus : false
  110. })
  111. //动态tabbar
  112. // if (roleCodeList == 'bizAdmin') {
  113. // this.getTabBar().setData({
  114. // list: app.globalData.allList[0].list2,
  115. // })
  116. // } else if(roleCodeList == 'send') {
  117. // this.getTabBar().setData({
  118. // list: app.globalData.allList[0].list3,
  119. // })
  120. // } else if(roleCodeList == 'sale') {
  121. // this.getTabBar().setData({
  122. // list: app.globalData.allList[0].list4,
  123. // })
  124. // }else if(roleCodeList == 'customer') {
  125. // this.getTabBar().setData({
  126. // list: app.globalData.allList[0].list5,
  127. // })
  128. // } else if (roleCodeList=='driver'||roleCodeList==''){
  129. // this.getTabBar().setData({
  130. // list: app.globalData.allList[0].list1,
  131. // })
  132. // }
  133. // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  134. // this.getTabBar().setData({
  135. // selected: 2
  136. // })
  137. // }
  138. if(wx.getStorageSync('loginStatus')){
  139. this.getListFun();
  140. }
  141. if(this.data.appointmentStatusArray.length==1 || this.data.appointmentTypeArray.length==1){
  142. this.getTree()
  143. }
  144. },
  145. //获取字典数据
  146. getTree:function(){
  147. app.request.GET({
  148. url:app.API.getTree,
  149. page:this,
  150. successFun:true
  151. }).then(res=>{
  152. if(this.data.appointmentStatusArray.length==1){
  153. let treeData = res.data.data
  154. for (const element of treeData) {
  155. let arrStr;
  156. switch (element.dictValue) {
  157. case 'appointment_status':
  158. arrStr = "appointmentStatusArray";
  159. break;
  160. }
  161. let getArray = this.data.appointmentStatusArray
  162. this.setData({
  163. [arrStr]: getArray.concat(element.children)
  164. })
  165. }
  166. }
  167. if(this.data.appointmentTypeArray.length==1){
  168. let treeData = res.data.data
  169. for (const element of treeData) {
  170. let arrStr;
  171. switch (element.dictValue) {
  172. case 'appointment_type':
  173. arrStr = "appointmentTypeArray";
  174. break;
  175. }
  176. let getArray = this.data.appointmentTypeArray
  177. this.setData({
  178. [arrStr]: getArray.concat(element.children)
  179. })
  180. }
  181. }
  182. })
  183. },
  184. //搜索框请求S
  185. onChange(e) {
  186. this.setData({
  187. searchVal: e.detail,
  188. });
  189. },
  190. onSearch: function (event) {
  191. this.setData({
  192. searchVal: event.detail
  193. })
  194. this.getListFun();
  195. },
  196. typeFun: function (e) {
  197. this.setData({
  198. appointmentType : e.currentTarget.dataset.type
  199. })
  200. this.getListFun()
  201. },
  202. onCancel: function () {
  203. this.setData({})
  204. },
  205. toSearch: function (event) {
  206. this.getListFun();
  207. },
  208. //列表
  209. getListFun: function () {
  210. this.setData({
  211. page: 1
  212. })
  213. let params = {
  214. current : this.data.page,
  215. size : this.data.limit,
  216. licenseNumber : this.data.searchVal,
  217. type : this.data.appointmentType
  218. //status:1
  219. }
  220. app.request.pageFirst({
  221. url: app.API.appointmentPage,
  222. page: this,
  223. params: params,
  224. })
  225. },
  226. //取消预约
  227. cancelFun: function (e) {
  228. let _this = this
  229. let { id, licenseNumber } = e.currentTarget.dataset
  230. wx.showModal({
  231. title: '提示!',
  232. content: `取消【${licenseNumber}】后不可恢复。确定要取消吗?`,
  233. confirmColor: '#FF5B5B',
  234. success: function (res) {
  235. if (res.confirm) {
  236. app.request.POST({
  237. url: app.API.appointmentCancel,
  238. params: {
  239. id: id
  240. },
  241. page: _this,
  242. isLoadingTxt: '取消中...',
  243. successFun: true
  244. }).then(res => {
  245. wx.showToast({
  246. title: '取消成功',
  247. icon: 'success',
  248. duration: 1000,
  249. mask: true
  250. })
  251. _this.getListFun(); //刷新列表
  252. })
  253. } else if (res.cancel) {
  254. }
  255. }
  256. })
  257. },
  258. //完成装货 管桩预约
  259. completePipeFun: function (e) {
  260. let _this = this
  261. let { id, licenseNumber } = e.currentTarget.dataset
  262. wx.showModal({
  263. title: '提示!',
  264. content: `确定【${licenseNumber}】完成装货?`,
  265. confirmColor: '#FF5B5B',
  266. success: function (res) {
  267. if (res.confirm) {
  268. app.request.POST({
  269. url: app.API.completePipeAppoint,
  270. params: {
  271. id: id
  272. },
  273. page: _this,
  274. isLoadingTxt: '取消中...',
  275. successFun: true
  276. }).then(res => {
  277. wx.showToast({
  278. title: '取消成功',
  279. icon: 'success',
  280. duration: 1000,
  281. mask: true
  282. })
  283. _this.getListFun(); //刷新列表
  284. })
  285. } else if (res.cancel) {
  286. }
  287. }
  288. })
  289. },
  290. //完成装货 其他预约
  291. completeOtherFun: function (e) {
  292. let _this = this
  293. let { id, licenseNumber } = e.currentTarget.dataset
  294. wx.showModal({
  295. title: '提示!',
  296. content: `确定【${licenseNumber}】完成装货?`,
  297. confirmColor: '#FF5B5B',
  298. success: function (res) {
  299. if (res.confirm) {
  300. app.request.POST({
  301. url: app.API.completeOtherAppoint,
  302. params: {
  303. id: id
  304. },
  305. page: _this,
  306. isLoadingTxt: '取消中...',
  307. successFun: true
  308. }).then(res => {
  309. wx.showToast({
  310. title: '取消成功',
  311. icon: 'success',
  312. duration: 1000,
  313. mask: true
  314. })
  315. _this.getListFun(); //刷新列表
  316. })
  317. } else if (res.cancel) {
  318. }
  319. }
  320. })
  321. },
  322. // 授权出场:其他预约
  323. exitFun: function (e) {
  324. let _this = this
  325. let { id, licenseNumber } = e.currentTarget.dataset
  326. wx.showModal({
  327. title: '提示!',
  328. content: `确定授权【${licenseNumber}】出场,操作后无法撤回,请确认?`,
  329. confirmColor: '#FF5B5B',
  330. success: function (res) {
  331. if (res.confirm) {
  332. app.request.POST({
  333. url: app.API.otherAuthorize,
  334. params: {
  335. id: id
  336. },
  337. page: _this,
  338. isLoadingTxt: '授权中...',
  339. successFun: true
  340. }).then(res => {
  341. wx.showToast({
  342. title: '授权成功',
  343. icon: 'success',
  344. duration: 1000,
  345. mask: true
  346. })
  347. _this.getListFun(); //刷新列表
  348. })
  349. } else if (res.cancel) {
  350. }
  351. }
  352. })
  353. },
  354. // 强制结束
  355. overFun: function (e) {
  356. let _this = this
  357. let { id, licenseNumber } = e.currentTarget.dataset
  358. wx.showModal({
  359. title: '提示!',
  360. content: `确定强制结束【${licenseNumber}】预约信息,操作后无法撤回,请确认?`,
  361. confirmColor: '#FF5B5B',
  362. success: function (res) {
  363. if (res.confirm) {
  364. app.request.POST({
  365. url: app.API.appointmentExit,
  366. params: {
  367. id: id
  368. },
  369. page: _this,
  370. isLoadingTxt: '授权中...',
  371. successFun: true
  372. }).then(res => {
  373. wx.showToast({
  374. title: '授权成功',
  375. icon: 'success',
  376. duration: 1000,
  377. mask: true
  378. })
  379. _this.getListFun(); //刷新列表
  380. })
  381. } else if (res.cancel) {
  382. }
  383. }
  384. })
  385. },
  386. // 强制结束 其他预约
  387. overOtherFun: function (e) {
  388. let _this = this
  389. let { id, licenseNumber } = e.currentTarget.dataset
  390. wx.showModal({
  391. title: '提示!',
  392. content: `确定强制结束【${licenseNumber}】预约信息,操作后无法撤回,请确认?`,
  393. confirmColor: '#FF5B5B',
  394. success: function (res) {
  395. if (res.confirm) {
  396. app.request.POST({
  397. url: app.API.otherExit,
  398. params: {
  399. id: id
  400. },
  401. page: _this,
  402. isLoadingTxt: '授权中...',
  403. successFun: true
  404. }).then(res => {
  405. wx.showToast({
  406. title: '授权成功',
  407. icon: 'success',
  408. duration: 1000,
  409. mask: true
  410. })
  411. _this.getListFun(); //刷新列表
  412. })
  413. } else if (res.cancel) {
  414. }
  415. }
  416. })
  417. },
  418. // 审核S
  419. showPopup(e) {
  420. let { id,type } = e.currentTarget.dataset
  421. this.setData({
  422. show: true,
  423. appointmentReason: '',
  424. type:type,
  425. id: id
  426. });
  427. },
  428. onClose() {
  429. this.setData({
  430. show: false,
  431. auditFlag:'false',
  432. appointmentReason:'',
  433. id: ''
  434. });
  435. },
  436. // 单选
  437. dangerStatusChange: function (e) {
  438. this.setData({
  439. [e.currentTarget.dataset.radiotype]: e.detail.value
  440. })
  441. },
  442. //审核
  443. formSubmit: function (e) {
  444. let formData = e.detail.value;
  445. var warn = ""; //弹框时提示的内容
  446. if (formData.auditFlag == '') {
  447. warn = "选择审核结果!";
  448. } else if (formData.auditFlag == 'false' && formData.appointmentReason == '') {
  449. warn = "审核不通过时备注不能为空!";
  450. }
  451. formData.auditFlag = formData.auditFlag=='true'
  452. if (warn != '') {
  453. app.util.checkForm(warn);
  454. } else {
  455. let url = app.API.appointmentAudit
  456. if(this.data.type == '2'){
  457. url = app.API.tempAudit
  458. }
  459. app.request.POST({
  460. url: url,
  461. params: formData,
  462. page: this,
  463. isLoadingTxt: '审核中...',
  464. successFun: true
  465. }).then(res => {
  466. wx.showToast({
  467. title: '审核成功',
  468. icon: 'success',
  469. duration: 1000,
  470. mask: true
  471. })
  472. this.onClose()
  473. this.getListFun(); //刷新列表
  474. })
  475. }
  476. },
  477. // 审核E
  478. //申请
  479. changeAdd() {
  480. wx.navigateTo({
  481. url: '/pages/reservationOther/add'
  482. })
  483. },
  484. //删除
  485. delFun: function (e) {
  486. let _this = this
  487. let { id, licenseNumber } = e.currentTarget.dataset
  488. wx.showModal({
  489. title: '提示!',
  490. content: `删除【${licenseNumber}】其他预约后不可恢复。确定要删除吗?`,
  491. confirmColor: '#FF5B5B',
  492. success: function (res) {
  493. if (res.confirm) {
  494. app.request.POST({
  495. url: app.API.otherDelete,
  496. params: [{
  497. id: id
  498. }],
  499. page: _this,
  500. isLoadingTxt: '删除中...',
  501. successFun: true
  502. }).then(res => {
  503. wx.showToast({
  504. title: '删除成功',
  505. icon: 'success',
  506. duration: 1000,
  507. mask: true
  508. })
  509. _this.getListFun(); //刷新列表
  510. })
  511. } else if (res.cancel) {
  512. }
  513. }
  514. })
  515. },
  516. //修改
  517. toUpdate: function (e) {
  518. let { id, index } = e.currentTarget.dataset
  519. wx.navigateTo({
  520. url: '/pages/reservationOther/edit?id=' + id + '&index=' + index,
  521. })
  522. },
  523. //页面跳转
  524. toLink: function (e) {
  525. let { url } = e.currentTarget.dataset
  526. wx.navigateTo({
  527. url: url
  528. })
  529. },
  530. /**
  531. * 生命周期函数--监听页面隐藏
  532. */
  533. onHide: function () {
  534. },
  535. /**
  536. * 生命周期函数--监听页面卸载
  537. */
  538. onUnload: function () {
  539. },
  540. /**
  541. * 页面相关事件处理函数--监听用户下拉动作
  542. */
  543. onPullDownRefresh: function () {
  544. this.setData({
  545. searchVal: ''
  546. })
  547. if (wx.getStorageSync('loginStatus')) {
  548. this.getListFun();
  549. } else {
  550. wx.stopPullDownRefresh();
  551. }
  552. },
  553. /**
  554. * 页面上拉触底事件的处理函数
  555. */
  556. onReachBottom: function () {
  557. this.data.page++;
  558. let params = {
  559. current : this.data.page,
  560. size : this.data.limit,
  561. licenseNumber : this.data.searchVal,
  562. // reservationStatus: this.data.applyData[this.data.setIndex].value,,
  563. type : this.data.appointmentType
  564. }
  565. app.request.pageOther({
  566. url: app.API.appointmentPage,
  567. page: this,
  568. params: params,
  569. loadType: true, //加载类型,是否是下拉加载
  570. });
  571. //this.getTypeCount()
  572. },
  573. //以下是按钮拖动事件
  574. buttonStart: function (e) {
  575. startPoint = e.touches[0] //获取拖动开始点
  576. },
  577. buttonMove: function (e) {
  578. var endPoint = e.touches[e.touches.length - 1] //获取拖动结束点
  579. //计算在X轴上拖动的距离和在Y轴上拖动的距离
  580. var translateX = endPoint.clientX - startPoint.clientX
  581. var translateY = endPoint.clientY - startPoint.clientY
  582. startPoint = endPoint //重置开始位置
  583. var buttonTop = this.data.buttonTop + translateY
  584. var buttonLeft = this.data.buttonLeft + translateX
  585. //判断是移动否超出屏幕
  586. if (buttonLeft + 60 >= this.data.windowWidth) {
  587. buttonLeft = this.data.windowWidth - 60;
  588. }
  589. if (buttonLeft <= 0) {
  590. buttonLeft = 0;
  591. }
  592. if (buttonTop <= this.data.filterHeight) {
  593. buttonTop = this.data.filterHeight
  594. }
  595. if (buttonTop + 60 + 48 + this.data.safeAreaHeight >= this.data.windowHeight) {
  596. buttonTop = this.data.windowHeight - 60 - 48 - this.data.safeAreaHeight;
  597. }
  598. this.setData({
  599. buttonTop: buttonTop,
  600. buttonLeft: buttonLeft
  601. })
  602. },
  603. buttonEnd: function (e) {},
  604. /**
  605. * 用户点击右上角分享
  606. */
  607. onShareAppMessage: function () {
  608. }
  609. })