index.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. // pages/index/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. content: '',
  13. filterWidth: 0, //获取顶部筛选宽度
  14. filterHeight: 0, //获取顶部筛选高度
  15. safeAreaHeight: 0, //底部安全区域的高度
  16. //按钮位置参数
  17. buttonTop: 0,
  18. buttonLeft: 0,
  19. windowHeight: '',
  20. windowWidth: '',
  21. //分页
  22. requestStatu: '', //加载中...
  23. limit: 10,
  24. page: 1,
  25. totalPages: 1,
  26. more: false,
  27. nomore: '',
  28. searchVal: '', //筛选条件
  29. appointmentClassifyArray: [
  30. { label:'充电预约',value:'1' },
  31. { label:'管桩预约',value:'2' },
  32. { label:'其他预约',value:'3' },
  33. ], //预约类型
  34. appointmentStatusArray: [{
  35. dictValue: "",
  36. dictLabel: "全部状态"
  37. }],
  38. appointmentStatusIndex: 0,
  39. registStatus: '', //状态
  40. registStatusdrc: '', //显示状态数值
  41. registStatusdgb: '', //显示状态数值
  42. registStatusgbz: '', //显示状态数值
  43. registStatusdcc: '', //显示状态数值
  44. registStatusycc: '', //显示状态数值
  45. //筛选E
  46. setIndex: 0,
  47. resData: [],
  48. show:false,
  49. auditFlag:'false'
  50. },
  51. //下拉选择
  52. bindPickerChange: function (e) { //下拉菜单
  53. //方法一动态的
  54. let getIndex = e.target.dataset.pickername + 'Index'
  55. app.util.getPickerIndex(this, getIndex, e);
  56. this.getListFun()
  57. },
  58. //去登录页面
  59. toLogin(e) {
  60. wx.navigateTo({
  61. url: '../login/index',
  62. })
  63. },
  64. //拨打电话
  65. call: function (e) {
  66. e.currentTarget.dataset.phone && wx.makePhoneCall({
  67. phoneNumber: e.currentTarget.dataset.phone
  68. })
  69. },
  70. //变动筛选条件时
  71. changeFilter: function (e) {
  72. let getFilterType = e.currentTarget.dataset.filtertype + 'Value'
  73. this.setData({
  74. [getFilterType]: e.detail
  75. })
  76. //重新请求
  77. this.getListFun();
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad: function (options) {
  83. //订单状态
  84. if(wx.getStorageSync('loginStatus')){
  85. this.getTree()
  86. }
  87. this.setData({
  88. safeAreaHeight: app.globalData.windowInfo.screenHeight - app.globalData.systemInfo.safeArea.bottom
  89. })
  90. // 使用选择器选择节点
  91. this.getFilterHeight()
  92. //获取页面高度设置新增按钮的初始位置
  93. var that = this;
  94. wx.getSystemInfo({
  95. success: function (res) {
  96. // 高度,宽度 单位为px
  97. that.setData({
  98. windowHeight: res.windowHeight, //屏幕宽度、高度
  99. windowWidth: res.windowWidth,
  100. buttonTop: res.windowHeight * 0.8 - that.data.safeAreaHeight-60, //这里定义按钮的初始位置
  101. buttonLeft: res.windowWidth * 0.80, //这里定义按钮的初始位置
  102. })
  103. }
  104. })
  105. },
  106. //获取顶部筛选区域的高度
  107. getFilterHeight:function(){
  108. let that = this;
  109. // 使用顶部筛选高度选择器选择节点的高度
  110. const query = wx.createSelectorQuery();
  111. query.select('.topFilter').boundingClientRect(function (rect) {
  112. if(rect){
  113. that.setData({
  114. filterWidth: rect.width,
  115. filterHeight: rect.height,
  116. });
  117. }
  118. }).exec();
  119. },
  120. /**
  121. * 生命周期函数--监听页面初次渲染完成
  122. */
  123. onReady: function () {
  124. },
  125. //绑定微信
  126. bindingWX: function () {
  127. let _this = this;
  128. if (this.data.loginStatus) {
  129. wx.showModal({
  130. title: '提示',
  131. content: '确定绑定该微信账号?',
  132. success: function (res) {
  133. if (res.confirm) {
  134. wx.login({
  135. success: (res) => {
  136. //console.log(res.code)
  137. app.request.requestPostApi(app.API.api.bindingWX, {
  138. id: wx.getStorageSync('id'),
  139. appCode: res.code
  140. }, _this, function (res, that) {
  141. if (res.code == '200') { //退出登录
  142. wx.showToast({
  143. title: '绑定成功',
  144. icon: 'none',
  145. duration: 1500,
  146. mask: true
  147. })
  148. } else {
  149. wx.showToast({
  150. title: res.data.msg ? res.data.msg : '出错了',
  151. icon: 'none',
  152. duration: 1500,
  153. mask: true
  154. })
  155. }
  156. });
  157. },
  158. })
  159. }
  160. }
  161. })
  162. } else {
  163. wx.showToast({
  164. title: '您还未登录!',
  165. icon: 'none',
  166. duration: 1500,
  167. mask: true
  168. })
  169. }
  170. },
  171. /**
  172. * 生命周期函数--监听页面显示
  173. */
  174. onShow: function () {
  175. let that = this
  176. const roleCodeList = wx.getStorageSync('roleCodeList')
  177. let loginStatus = wx.getStorageSync('loginStatus')
  178. this.setData({
  179. searchVal: '',
  180. roleCodeList: roleCodeList ? roleCodeList : '',
  181. loginStatus: loginStatus ? loginStatus : false
  182. })
  183. //动态tabbar
  184. // if (roleCodeList == 'bizAdmin') {
  185. // this.getTabBar().setData({
  186. // list: app.globalData.allList[0].list2,
  187. // })
  188. // } else if(roleCodeList == 'send') {
  189. // this.getTabBar().setData({
  190. // list: app.globalData.allList[0].list3,
  191. // })
  192. // } else if(roleCodeList == 'sale') {
  193. // this.getTabBar().setData({
  194. // list: app.globalData.allList[0].list4,
  195. // })
  196. // } else if(roleCodeList == 'customer') {
  197. // this.getTabBar().setData({
  198. // list: app.globalData.allList[0].list5,
  199. // })
  200. // } else if (roleCodeList=='driver'||roleCodeList==''){
  201. // this.getTabBar().setData({
  202. // list: app.globalData.allList[0].list1,
  203. // })
  204. // }
  205. // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  206. // this.getTabBar().setData({
  207. // selected: 0
  208. // })
  209. // }
  210. if (wx.getStorageSync('loginStatus')) {
  211. // if (roleCodeList=='bizAdmin') {
  212. // wx.switchTab({
  213. // url: '/pages/queueCar/index',
  214. // })
  215. // } else if (roleCodeList=='send') {
  216. // wx.switchTab({
  217. // url: '/pages/deliveryConfirm/index',
  218. // })
  219. // } else if (roleCodeList=='sale') {
  220. // wx.switchTab({
  221. // url: '/pages/salesOrderMan/index',
  222. // })
  223. // }
  224. if(this.data.filterHeight){
  225. const query = wx.createSelectorQuery();
  226. query.select('.topFilter').boundingClientRect(function (rect) {
  227. that.setData({
  228. filterWidth: rect.width,
  229. filterHeight: rect.height,
  230. });
  231. }).exec();
  232. }
  233. if(roleCodeList=='driver'||roleCodeList=='customer'){
  234. this.getListFun();
  235. }
  236. if(this.data.appointmentStatusArray.length==1){
  237. this.getTree()
  238. }
  239. }
  240. },
  241. //获取字典数据
  242. getTree:function(){
  243. app.request.GET({
  244. url:app.API.getTree,
  245. page:this,
  246. successFun:true
  247. }).then(res=>{
  248. if(this.data.appointmentStatusArray.length==1){
  249. let treeData = res.data.data
  250. for (const element of treeData) {
  251. let arrStr;
  252. switch (element.dictValue) {
  253. case 'appointment_status':
  254. arrStr = "appointmentStatusArray";
  255. break;
  256. }
  257. let getArray = this.data.appointmentStatusArray
  258. this.setData({
  259. [arrStr]: getArray.concat(element.children)
  260. })
  261. }
  262. }
  263. })
  264. },
  265. //获取通知消息
  266. getContent: function () {
  267. app.request.GET({
  268. url: app.API.getContent,
  269. params: {},
  270. page: this,
  271. successFun: true
  272. }).then(res => {
  273. //console.log(res.data.data)
  274. this.setData({
  275. content: res.data.data.content
  276. })
  277. })
  278. },
  279. //预约列表页面审核状态汇总页面接口
  280. getReservationCount: function () {
  281. app.request.GET({
  282. url: app.API.reservationCount,
  283. params: {},
  284. page: this,
  285. successFun: true
  286. }).then(res => {
  287. let resData = res.data.data
  288. let getApplyData = this.data.applyData
  289. resData.forEach(element => {
  290. //console.log(element)
  291. switch (Number(element.reservationStatus)) {
  292. case 0:
  293. getApplyData[1].label = '待审核' + "(" + element.recordCount + ")辆"
  294. break;
  295. case 1:
  296. getApplyData[2].label = '审核通过' + "(" + element.recordCount + ")辆"
  297. break;
  298. case 2:
  299. getApplyData[3].label = '过磅中' + "(" + element.recordCount + ")辆"
  300. break;
  301. }
  302. });
  303. this.setData({
  304. applyData: getApplyData
  305. })
  306. })
  307. },
  308. //搜索框请求S
  309. onChange(e) {
  310. this.setData({
  311. searchVal: e.detail,
  312. });
  313. },
  314. onSearch: function (event) {
  315. this.setData({
  316. searchVal: event.detail
  317. })
  318. this.getListFun();
  319. },
  320. onCancel: function () {
  321. this.setData({})
  322. },
  323. toSearch: function (event) {
  324. this.getListFun();
  325. },
  326. statusFun: function (e) {
  327. this.setData({
  328. registStatus: e.currentTarget.dataset.status
  329. })
  330. this.getListFun()
  331. },
  332. //状态筛选
  333. clickScroll: function (e) {
  334. this.setData({
  335. setIndex: e.detail.index
  336. })
  337. this.getListFun()
  338. },
  339. //预约类型
  340. onClick() {
  341. this.getListFun()
  342. },
  343. //列表
  344. getListFun: function () {
  345. this.setData({
  346. page: 1
  347. })
  348. let params = {
  349. current: this.data.page,
  350. size: this.data.limit,
  351. status: this.data.appointmentStatusArray[this.data.appointmentStatusIndex].dictValue,
  352. licenseNumber: this.data.searchVal
  353. }
  354. app.request.pageFirst({
  355. url: app.API.appointmentList,
  356. page: this,
  357. params: params,
  358. })
  359. // if (this.data.roleCodeList != '0') {
  360. // this.getReservationCount()
  361. // }
  362. },
  363. //分类统计数据获取
  364. getTypeCount: function () {
  365. app.request.GET({
  366. url: app.API.typeCount,
  367. page: this,
  368. params: {
  369. dataStatus: this.data.registStatus,
  370. searchKey: this.data.searchVal
  371. },
  372. successFun: true
  373. }).then(res => {
  374. let getCount = res.data.data
  375. for (let key in getCount) {
  376. let setStr = 'registStatus' + key
  377. this.setData({
  378. [setStr]: getCount[key]
  379. })
  380. }
  381. })
  382. },
  383. //扫码预约申请
  384. changeAdd() {
  385. wx.scanCode({
  386. success: (res) => {
  387. let info = JSON.parse(res.result.trim())
  388. console.log(info)
  389. //console.log(JSON.parse(info)) //{id: "1712651156370632706", projectCode: "D456"}
  390. if(info.type=='1'){
  391. // 砂石预约
  392. wx.navigateTo({
  393. url: 'add?orderId=' + info.id + '&orderName='+ info.orderName+'&orderNumber='+ info.orderNumber
  394. })
  395. }else if(info.type=='2'){
  396. // 临时预约
  397. wx.navigateTo({
  398. url: '/pages/reservationTemp/add?orderId=' + info.id + '&orderName='+ info.orderName+'&orderNumber='+ info.orderNumber
  399. })
  400. }else if(info.type=='3'){
  401. // 起卸预约
  402. wx.navigateTo({
  403. url: '/pages/reservationLoadAppoint/add?orderId=' + info.id + '&orderName='+ info.orderName+'&orderNumber='+ info.orderNumber
  404. })
  405. }else if(info.type=='4'){
  406. // 充电桩预约
  407. wx.navigateTo({
  408. url: '/pages/reservationChargestation/add?orderId=' + info.id + '&orderName='+ info.orderName+'&orderNumber='+ info.orderNumber
  409. })
  410. }else if(info.type=='5'){
  411. // 管桩预约
  412. wx.navigateTo({
  413. url: '/pages/reservationPipe/add?orderId=' + info.id + '&orderName='+ info.orderName+'&orderNumber='+ info.orderNumber
  414. })
  415. }
  416. },
  417. fail: (res) => {
  418. wx.showToast({
  419. title: '请重试!',
  420. icon: 'error',
  421. duration: 2000
  422. })
  423. }
  424. })
  425. },
  426. //删除
  427. delFun: function (e) {
  428. let _this = this
  429. let { id, licenseNumber } = e.currentTarget.dataset
  430. wx.showModal({
  431. title: '提示!',
  432. content: `删除【${licenseNumber}】后不可恢复。确定要删除吗?`,
  433. confirmColor: '#FF5B5B',
  434. success: function (res) {
  435. if (res.confirm) {
  436. app.request.POST({
  437. url: app.API.appointmentDelete,
  438. params: [{
  439. id: id
  440. }],
  441. page: _this,
  442. isLoadingTxt: '删除中...',
  443. successFun: true
  444. }).then(res => {
  445. wx.showToast({
  446. title: '删除成功',
  447. icon: 'success',
  448. duration: 1000,
  449. mask: true
  450. })
  451. _this.getListFun(); //刷新列表
  452. })
  453. } else if (res.cancel) {
  454. }
  455. }
  456. })
  457. },
  458. //取消预约
  459. cancelFun: function (e) {
  460. let _this = this
  461. let { id, licenseNumber } = e.currentTarget.dataset
  462. wx.showModal({
  463. title: '提示!',
  464. content: `取消【${licenseNumber}】后不可恢复。确定要取消吗?`,
  465. confirmColor: '#FF5B5B',
  466. success: function (res) {
  467. if (res.confirm) {
  468. app.request.POST({
  469. url: app.API.appointmentCancel,
  470. params: {
  471. id: id
  472. },
  473. page: _this,
  474. isLoadingTxt: '取消中...',
  475. successFun: true
  476. }).then(res => {
  477. wx.showToast({
  478. title: '取消成功',
  479. icon: 'success',
  480. duration: 1000,
  481. mask: true
  482. })
  483. _this.getListFun(); //刷新列表
  484. })
  485. } else if (res.cancel) {
  486. }
  487. }
  488. })
  489. },
  490. //修改
  491. toUpdate: function (e) {
  492. let { id, index, type } = e.currentTarget.dataset
  493. if(type=='1'){
  494. wx.navigateTo({
  495. url: 'edit?id=' + id + '&index=' + index,
  496. })
  497. }else if(type=='2'){
  498. wx.navigateTo({
  499. url: '/pages/reservationTemp/edit?id=' + id + '&index=' + index,
  500. })
  501. }
  502. },
  503. //页面跳转
  504. toLink: function (e) {
  505. let { url } = e.currentTarget.dataset
  506. wx.navigateTo({
  507. url: url
  508. })
  509. },
  510. // 审核S
  511. showPopup(e) {
  512. let { id } = e.currentTarget.dataset
  513. this.setData({
  514. show: true,
  515. id: id
  516. });
  517. },
  518. onClose() {
  519. this.setData({
  520. show: false,
  521. auditFlag:'false',
  522. id: ''
  523. });
  524. },
  525. // 单选
  526. dangerStatusChange: function (e) {
  527. this.setData({
  528. [e.currentTarget.dataset.radiotype]: e.detail.value
  529. })
  530. },
  531. //审核
  532. formSubmit: function (e) {
  533. let formData = e.detail.value;
  534. var warn = ""; //弹框时提示的内容
  535. // if (formData.auditFlag == '') {
  536. // warn = "选择审核结果!";
  537. // } else if (formData.auditFlag == '2' && formData.appointmentReason == '') {
  538. // warn = "审核不通过时备注不能为空!";
  539. // }
  540. formData.auditFlag = formData.auditFlag=='true'
  541. if (warn != '') {
  542. app.util.checkForm(warn);
  543. } else {
  544. app.request.POST({
  545. url: app.API.appointmentAudit,
  546. params: formData,
  547. page: this,
  548. isLoadingTxt: '审核中...',
  549. successFun: true
  550. }).then(res => {
  551. wx.showToast({
  552. title: '审核成功',
  553. icon: 'success',
  554. duration: 1000,
  555. mask: true
  556. })
  557. this.onClose()
  558. this.getListFun(); //刷新列表
  559. })
  560. }
  561. },
  562. // 审核E
  563. //提交申请
  564. sendFun: function (e) {
  565. let _this = this;
  566. if (this.data.loginStatus) {
  567. wx.showModal({
  568. title: '提示',
  569. content: '确定立即提交申请?',
  570. success: function (res) {
  571. if (res.confirm) {
  572. app.request.requestGetApi(app.API.api.appointmentSend, {
  573. id: e.currentTarget.dataset.id
  574. }, _this, function (res, that) {
  575. if (res.statusCode == '200') { //退出登录
  576. wx.showToast({
  577. title: '提交成功',
  578. icon: 'success',
  579. duration: 2000,
  580. complete: function () {
  581. setTimeout(function () {
  582. that.getListFun();
  583. }, 1500) //延迟时间
  584. }
  585. })
  586. } else {
  587. wx.showToast({
  588. title: res.data.msg ? res.data.msg : '出错了',
  589. icon: 'none',
  590. duration: 1500,
  591. mask: true
  592. })
  593. }
  594. });
  595. }
  596. }
  597. })
  598. } else {
  599. wx.showToast({
  600. title: '您还未登录,无需退出哦!',
  601. icon: 'none',
  602. duration: 1500,
  603. mask: true
  604. })
  605. }
  606. },
  607. /**
  608. * 生命周期函数--监听页面隐藏
  609. */
  610. onHide: function () {
  611. },
  612. /**
  613. * 生命周期函数--监听页面卸载
  614. */
  615. onUnload: function () {
  616. },
  617. /**
  618. * 页面相关事件处理函数--监听用户下拉动作
  619. */
  620. onPullDownRefresh: function () {
  621. this.setData({
  622. searchVal: ''
  623. })
  624. if (wx.getStorageSync('loginStatus')) {
  625. this.getListFun();
  626. } else {
  627. wx.stopPullDownRefresh();
  628. }
  629. },
  630. /**
  631. * 页面上拉触底事件的处理函数
  632. */
  633. onReachBottom: function () {
  634. this.data.page++;
  635. let params = {
  636. current: this.data.page,
  637. size: this.data.limit,
  638. licenseNumber: this.data.searchVal,
  639. // reservationStatus: this.data.applyData[this.data.setIndex].value,
  640. // reservationType: this.data.typeArray[this.data.typeIndex].code,
  641. }
  642. app.request.pageOther({
  643. url: app.API.appointmentList,
  644. page: this,
  645. params: params,
  646. loadType: true, //加载类型,是否是下拉加载
  647. });
  648. //this.getTypeCount()
  649. },
  650. //以下是按钮拖动事件
  651. buttonStart: function (e) {
  652. startPoint = e.touches[0] //获取拖动开始点
  653. },
  654. buttonMove: function (e) {
  655. var endPoint = e.touches[e.touches.length - 1] //获取拖动结束点
  656. //计算在X轴上拖动的距离和在Y轴上拖动的距离
  657. var translateX = endPoint.clientX - startPoint.clientX
  658. var translateY = endPoint.clientY - startPoint.clientY
  659. startPoint = endPoint //重置开始位置
  660. var buttonTop = this.data.buttonTop + translateY
  661. var buttonLeft = this.data.buttonLeft + translateX
  662. //判断是移动否超出屏幕
  663. if (buttonLeft + 60 >= this.data.windowWidth) {
  664. buttonLeft = this.data.windowWidth - 60;
  665. }
  666. if (buttonLeft <= 0) {
  667. buttonLeft = 0;
  668. }
  669. if (buttonTop <= this.data.filterHeight) {
  670. buttonTop = this.data.filterHeight
  671. }
  672. if (buttonTop + 60 + 48 + this.data.safeAreaHeight >= this.data.windowHeight) {
  673. buttonTop = this.data.windowHeight - 60 - 48 - this.data.safeAreaHeight;
  674. }
  675. this.setData({
  676. buttonTop: buttonTop,
  677. buttonLeft: buttonLeft
  678. })
  679. },
  680. buttonEnd: function (e) {},
  681. /**
  682. * 用户点击右上角分享
  683. */
  684. onShareAppMessage: function () {
  685. }
  686. })