index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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(info)
  390. //console.log(JSON.parse(info)) //{id: "1712651156370632706", projectCode: "D456"}
  391. if(info.type=='1'){
  392. wx.navigateTo({
  393. url: 'add?orderId=' + info.id + '&orderName='+ info.orderName+'&orderNumber='+ info.orderNumber
  394. })
  395. }else if(info.type=='2'){
  396. wx.navigateTo({
  397. url: '/pages/temporary/add?orderId=' + info.id + '&orderName='+ info.orderName+'&orderNumber='+ info.orderNumber
  398. })
  399. }
  400. },
  401. fail: (res) => {
  402. wx.showToast({
  403. title: '请重试!',
  404. icon: 'error',
  405. duration: 2000
  406. })
  407. }
  408. })
  409. },
  410. //删除
  411. delFun: function (e) {
  412. let _this = this
  413. let { id, licenseNumber } = e.currentTarget.dataset
  414. wx.showModal({
  415. title: '提示!',
  416. content: `删除【${licenseNumber}】后不可恢复。确定要删除吗?`,
  417. confirmColor: '#FF5B5B',
  418. success: function (res) {
  419. if (res.confirm) {
  420. app.request.POST({
  421. url: app.API.appointmentDelete,
  422. params: [{
  423. id: id
  424. }],
  425. page: _this,
  426. isLoadingTxt: '删除中...',
  427. successFun: true
  428. }).then(res => {
  429. wx.showToast({
  430. title: '删除成功',
  431. icon: 'success',
  432. duration: 1000,
  433. mask: true
  434. })
  435. _this.getListFun(); //刷新列表
  436. })
  437. } else if (res.cancel) {
  438. }
  439. }
  440. })
  441. },
  442. //取消预约
  443. cancelFun: function (e) {
  444. let _this = this
  445. let { id, licenseNumber } = e.currentTarget.dataset
  446. wx.showModal({
  447. title: '提示!',
  448. content: `取消【${licenseNumber}】后不可恢复。确定要取消吗?`,
  449. confirmColor: '#FF5B5B',
  450. success: function (res) {
  451. if (res.confirm) {
  452. app.request.POST({
  453. url: app.API.appointmentCancel,
  454. params: {
  455. id: id
  456. },
  457. page: _this,
  458. isLoadingTxt: '取消中...',
  459. successFun: true
  460. }).then(res => {
  461. wx.showToast({
  462. title: '取消成功',
  463. icon: 'success',
  464. duration: 1000,
  465. mask: true
  466. })
  467. _this.getListFun(); //刷新列表
  468. })
  469. } else if (res.cancel) {
  470. }
  471. }
  472. })
  473. },
  474. //修改
  475. toUpdate: function (e) {
  476. let { id, index, type } = e.currentTarget.dataset
  477. if(type=='1'){
  478. wx.navigateTo({
  479. url: 'edit?id=' + id + '&index=' + index,
  480. })
  481. }else if(type=='2'){
  482. wx.navigateTo({
  483. url: '/pages/temporary/edit?id=' + id + '&index=' + index,
  484. })
  485. }
  486. },
  487. //页面跳转
  488. toLink: function (e) {
  489. let { url } = e.currentTarget.dataset
  490. wx.navigateTo({
  491. url: url
  492. })
  493. },
  494. // 审核S
  495. showPopup(e) {
  496. let { id } = e.currentTarget.dataset
  497. this.setData({
  498. show: true,
  499. id: id
  500. });
  501. },
  502. onClose() {
  503. this.setData({
  504. show: false,
  505. auditFlag:'false',
  506. id: ''
  507. });
  508. },
  509. // 单选
  510. dangerStatusChange: function (e) {
  511. this.setData({
  512. [e.currentTarget.dataset.radiotype]: e.detail.value
  513. })
  514. },
  515. //审核
  516. formSubmit: function (e) {
  517. let formData = e.detail.value;
  518. var warn = ""; //弹框时提示的内容
  519. // if (formData.auditFlag == '') {
  520. // warn = "选择审核结果!";
  521. // } else if (formData.auditFlag == '2' && formData.appointmentReason == '') {
  522. // warn = "审核不通过时备注不能为空!";
  523. // }
  524. formData.auditFlag = formData.auditFlag=='true'
  525. if (warn != '') {
  526. app.util.checkForm(warn);
  527. } else {
  528. app.request.POST({
  529. url: app.API.appointmentAudit,
  530. params: formData,
  531. page: this,
  532. isLoadingTxt: '审核中...',
  533. successFun: true
  534. }).then(res => {
  535. wx.showToast({
  536. title: '审核成功',
  537. icon: 'success',
  538. duration: 1000,
  539. mask: true
  540. })
  541. this.onClose()
  542. this.getListFun(); //刷新列表
  543. })
  544. }
  545. },
  546. // 审核E
  547. //提交申请
  548. sendFun: function (e) {
  549. let _this = this;
  550. if (this.data.loginStatus) {
  551. wx.showModal({
  552. title: '提示',
  553. content: '确定立即提交申请?',
  554. success: function (res) {
  555. if (res.confirm) {
  556. app.request.requestGetApi(app.API.api.appointmentSend, {
  557. id: e.currentTarget.dataset.id
  558. }, _this, function (res, that) {
  559. if (res.statusCode == '200') { //退出登录
  560. wx.showToast({
  561. title: '提交成功',
  562. icon: 'success',
  563. duration: 2000,
  564. complete: function () {
  565. setTimeout(function () {
  566. that.getListFun();
  567. }, 1500) //延迟时间
  568. }
  569. })
  570. } else {
  571. wx.showToast({
  572. title: res.data.msg ? res.data.msg : '出错了',
  573. icon: 'none',
  574. duration: 1500,
  575. mask: true
  576. })
  577. }
  578. });
  579. }
  580. }
  581. })
  582. } else {
  583. wx.showToast({
  584. title: '您还未登录,无需退出哦!',
  585. icon: 'none',
  586. duration: 1500,
  587. mask: true
  588. })
  589. }
  590. },
  591. /**
  592. * 生命周期函数--监听页面隐藏
  593. */
  594. onHide: function () {
  595. },
  596. /**
  597. * 生命周期函数--监听页面卸载
  598. */
  599. onUnload: function () {
  600. },
  601. /**
  602. * 页面相关事件处理函数--监听用户下拉动作
  603. */
  604. onPullDownRefresh: function () {
  605. this.setData({
  606. searchVal: ''
  607. })
  608. if (wx.getStorageSync('loginStatus')) {
  609. this.getListFun();
  610. } else {
  611. wx.stopPullDownRefresh();
  612. }
  613. },
  614. /**
  615. * 页面上拉触底事件的处理函数
  616. */
  617. onReachBottom: function () {
  618. this.data.page++;
  619. let params = {
  620. current: this.data.page,
  621. size: this.data.limit,
  622. licenseNumber: this.data.searchVal,
  623. // reservationStatus: this.data.applyData[this.data.setIndex].value,
  624. // reservationType: this.data.typeArray[this.data.typeIndex].code,
  625. }
  626. app.request.pageOther({
  627. url: app.API.appointmentList,
  628. page: this,
  629. params: params,
  630. loadType: true, //加载类型,是否是下拉加载
  631. });
  632. //this.getTypeCount()
  633. },
  634. //以下是按钮拖动事件
  635. buttonStart: function (e) {
  636. startPoint = e.touches[0] //获取拖动开始点
  637. },
  638. buttonMove: function (e) {
  639. var endPoint = e.touches[e.touches.length - 1] //获取拖动结束点
  640. //计算在X轴上拖动的距离和在Y轴上拖动的距离
  641. var translateX = endPoint.clientX - startPoint.clientX
  642. var translateY = endPoint.clientY - startPoint.clientY
  643. startPoint = endPoint //重置开始位置
  644. var buttonTop = this.data.buttonTop + translateY
  645. var buttonLeft = this.data.buttonLeft + translateX
  646. //判断是移动否超出屏幕
  647. if (buttonLeft + 60 >= this.data.windowWidth) {
  648. buttonLeft = this.data.windowWidth - 60;
  649. }
  650. if (buttonLeft <= 0) {
  651. buttonLeft = 0;
  652. }
  653. if (buttonTop <= this.data.filterHeight) {
  654. buttonTop = this.data.filterHeight
  655. }
  656. if (buttonTop + 60 + 48 + this.data.safeAreaHeight >= this.data.windowHeight) {
  657. buttonTop = this.data.windowHeight - 60 - 48 - this.data.safeAreaHeight;
  658. }
  659. this.setData({
  660. buttonTop: buttonTop,
  661. buttonLeft: buttonLeft
  662. })
  663. },
  664. buttonEnd: function (e) {},
  665. /**
  666. * 用户点击右上角分享
  667. */
  668. onShareAppMessage: function () {
  669. }
  670. })