index.js 18 KB

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