index.js 20 KB

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