index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. exitFun: 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.otherAuthorize,
  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. overFun: 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.appointmentExit,
  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. // 审核S
  323. showPopup(e) {
  324. let { id,type } = e.currentTarget.dataset
  325. this.setData({
  326. show: true,
  327. appointmentReason: '',
  328. type:type,
  329. id: id
  330. });
  331. },
  332. onClose() {
  333. this.setData({
  334. show: false,
  335. auditFlag:'false',
  336. appointmentReason:'',
  337. id: ''
  338. });
  339. },
  340. // 单选
  341. dangerStatusChange: function (e) {
  342. this.setData({
  343. [e.currentTarget.dataset.radiotype]: e.detail.value
  344. })
  345. },
  346. //审核
  347. formSubmit: function (e) {
  348. let formData = e.detail.value;
  349. var warn = ""; //弹框时提示的内容
  350. if (formData.auditFlag=='true' && formData.appointmentReason == '') {
  351. warn = "审核不通过时备注不能为空!";
  352. }
  353. formData.auditFlag = formData.auditFlag=='true'
  354. if (warn != '') {
  355. app.util.checkForm(warn);
  356. } else {
  357. let url = app.API.appointmentAudit
  358. if(this.data.type == '2'){
  359. url = app.API.tempAudit
  360. }
  361. app.request.POST({
  362. url: url,
  363. params: formData,
  364. page: this,
  365. isLoadingTxt: '审核中...',
  366. successFun: true
  367. }).then(res => {
  368. wx.showToast({
  369. title: '审核成功',
  370. icon: 'success',
  371. duration: 1000,
  372. mask: true
  373. })
  374. this.onClose()
  375. this.getListFun(); //刷新列表
  376. })
  377. }
  378. },
  379. // 审核E
  380. //申请
  381. changeAdd() {
  382. wx.navigateTo({
  383. url: '/pages/reservationOther/add'
  384. })
  385. },
  386. //删除
  387. delFun: 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.otherDelete,
  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. //修改
  419. toUpdate: function (e) {
  420. let { id, index } = e.currentTarget.dataset
  421. wx.navigateTo({
  422. url: '/pages/reservationOther/edit?id=' + id + '&index=' + index,
  423. })
  424. },
  425. //页面跳转
  426. toLink: function (e) {
  427. let { url } = e.currentTarget.dataset
  428. wx.navigateTo({
  429. url: url
  430. })
  431. },
  432. /**
  433. * 生命周期函数--监听页面隐藏
  434. */
  435. onHide: function () {
  436. },
  437. /**
  438. * 生命周期函数--监听页面卸载
  439. */
  440. onUnload: function () {
  441. },
  442. /**
  443. * 页面相关事件处理函数--监听用户下拉动作
  444. */
  445. onPullDownRefresh: function () {
  446. this.setData({
  447. searchVal: ''
  448. })
  449. if (wx.getStorageSync('loginStatus')) {
  450. this.getListFun();
  451. } else {
  452. wx.stopPullDownRefresh();
  453. }
  454. },
  455. /**
  456. * 页面上拉触底事件的处理函数
  457. */
  458. onReachBottom: function () {
  459. this.data.page++;
  460. let params = {
  461. current : this.data.page,
  462. size : this.data.limit,
  463. licenseNumber : this.data.searchVal,
  464. // reservationStatus: this.data.applyData[this.data.setIndex].value,
  465. type : this.data.type,
  466. }
  467. app.request.pageOther({
  468. url: app.API.appointmentPage,
  469. page: this,
  470. params: params,
  471. loadType: true, //加载类型,是否是下拉加载
  472. });
  473. //this.getTypeCount()
  474. },
  475. //以下是按钮拖动事件
  476. buttonStart: function (e) {
  477. startPoint = e.touches[0] //获取拖动开始点
  478. },
  479. buttonMove: function (e) {
  480. var endPoint = e.touches[e.touches.length - 1] //获取拖动结束点
  481. //计算在X轴上拖动的距离和在Y轴上拖动的距离
  482. var translateX = endPoint.clientX - startPoint.clientX
  483. var translateY = endPoint.clientY - startPoint.clientY
  484. startPoint = endPoint //重置开始位置
  485. var buttonTop = this.data.buttonTop + translateY
  486. var buttonLeft = this.data.buttonLeft + translateX
  487. //判断是移动否超出屏幕
  488. if (buttonLeft + 60 >= this.data.windowWidth) {
  489. buttonLeft = this.data.windowWidth - 60;
  490. }
  491. if (buttonLeft <= 0) {
  492. buttonLeft = 0;
  493. }
  494. if (buttonTop <= this.data.filterHeight) {
  495. buttonTop = this.data.filterHeight
  496. }
  497. if (buttonTop + 60 + 48 + this.data.safeAreaHeight >= this.data.windowHeight) {
  498. buttonTop = this.data.windowHeight - 60 - 48 - this.data.safeAreaHeight;
  499. }
  500. this.setData({
  501. buttonTop: buttonTop,
  502. buttonLeft: buttonLeft
  503. })
  504. },
  505. buttonEnd: function (e) {},
  506. /**
  507. * 用户点击右上角分享
  508. */
  509. onShareAppMessage: function () {
  510. }
  511. })