index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. // pages/queueCar/index.js
  2. const app = getApp()
  3. import Dialog from '@vant/weapp/dialog/dialog';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. str:' ',
  10. payStatus : false,
  11. isClose: true, //判断当前页面是打开还是返回页还是切换页面 true是切换页面 false是返回
  12. loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
  13. roleCodeList: wx.getStorageSync('roleCodeList') ? wx.getStorageSync('roleCodeList') : '',
  14. accountType: '',
  15. appointmentClassifyArray: [
  16. { label:'充电预约',value:'1' },
  17. { label:'管桩预约',value:'2' },
  18. { label:'其他预约',value:'3' },
  19. ], //预约类型
  20. searchVal: '',
  21. codeNum:0,
  22. //分页
  23. limit: 10,
  24. requestStatu: '加载中...',
  25. page: 1,
  26. totalPages: 1,
  27. more: false,
  28. nomore: '',
  29. },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow() {
  34. const roleCodeList = wx.getStorageSync('roleCodeList')
  35. let loginStatus = wx.getStorageSync('loginStatus')
  36. this.setData({
  37. searchVal: '',
  38. roleCodeList: roleCodeList ? roleCodeList : '',
  39. loginStatus: loginStatus ? loginStatus : false
  40. })
  41. //动态tabbar
  42. // if (roleCodeList == 'bizAdmin') {
  43. // this.getTabBar().setData({
  44. // list: app.globalData.allList[0].list2,
  45. // })
  46. // } else if(roleCodeList == 'send') {
  47. // this.getTabBar().setData({
  48. // list: app.globalData.allList[0].list3,
  49. // })
  50. // } else if(roleCodeList == 'sale') {
  51. // this.getTabBar().setData({
  52. // list: app.globalData.allList[0].list4,
  53. // })
  54. // } else if(roleCodeList == 'customer') {
  55. // this.getTabBar().setData({
  56. // list: app.globalData.allList[0].list5,
  57. // })
  58. // } else if (roleCodeList=='driver'||roleCodeList==''){
  59. // this.getTabBar().setData({
  60. // list: app.globalData.allList[0].list1,
  61. // })
  62. // }
  63. // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  64. // this.getTabBar().setData({
  65. // selected: 0
  66. // })
  67. // }
  68. if(wx.getStorageSync('loginStatus')){
  69. this.getListFun();
  70. }
  71. },
  72. //获取排队信息
  73. getInfoFun: function () {
  74. //详情
  75. app.request.requestGetApi(app.API.appletQueueLicense, {}, this, function (res, _that) {
  76. let data = res.data.data;
  77. wx.stopPullDownRefresh();
  78. _that.setData({
  79. info: data
  80. })
  81. })
  82. },
  83. //取消排队
  84. cancelPd: function (e) {
  85. let _this = this;
  86. let { id,licenseNumber } = e.currentTarget.dataset
  87. if (this.data.loginStatus) {
  88. wx.showModal({
  89. title: '提示',
  90. content: `确定取消车辆【${licenseNumber}】排队?`,
  91. success: function (res) {
  92. if (res.confirm) {
  93. app.request.POST({
  94. url: app.API.lineUpCancel,
  95. params: {
  96. id: id
  97. },
  98. page: _this,
  99. isLoadingTxt: '取消中...',
  100. successFun: true
  101. }).then(res => {
  102. wx.showToast({
  103. title: '取消成功',
  104. icon: 'success',
  105. duration: 1000,
  106. mask: true
  107. })
  108. _this.getListFun(); //刷新列表
  109. })
  110. }
  111. }
  112. })
  113. } else {
  114. wx.showToast({
  115. icon: 'none',
  116. title: '登录后可操作',
  117. duration: 1500
  118. })
  119. }
  120. },
  121. //车辆调度
  122. adjustOrder: function (e) {
  123. let _this = this;
  124. let { id, orderId, licenseNumber } = e.currentTarget.dataset
  125. if (this.data.loginStatus) {
  126. wx.showModal({
  127. title: '提示',
  128. content: `确定对车辆【${licenseNumber}】进行调度?`,
  129. success: function (res) {
  130. if (res.confirm) {
  131. app.request.POST({
  132. url: app.API.lineUpAdjust,
  133. params: {
  134. id: id,
  135. orderId:orderId
  136. },
  137. page: _this,
  138. isLoadingTxt: '调度中...',
  139. successFun: true
  140. }).then(res => {
  141. wx.showToast({
  142. title: '调度成功',
  143. icon: 'success',
  144. duration: 1000,
  145. mask: true
  146. })
  147. _this.getListFun(); //刷新列表
  148. })
  149. }
  150. }
  151. })
  152. } else {
  153. wx.showToast({
  154. icon: 'none',
  155. title: '登录后可操作',
  156. duration: 1500
  157. })
  158. }
  159. },
  160. //登录
  161. toLogin: function () {
  162. wx.redirectTo({
  163. url: '../login/index?page=index',
  164. })
  165. },
  166. //页面跳转
  167. toLink: function (e) {
  168. let { url } = e.currentTarget.dataset
  169. wx.navigateTo({
  170. url: url
  171. })
  172. },
  173. //授权手机号登录
  174. getPhoneNumber: function (e) {
  175. let _this = this;
  176. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  177. app.request.requestPostApi(app.API.wxlogin + '?code=' + e.detail.code, {
  178. 'code': e.detail.code
  179. }, _this, function (res, sourceObj) {
  180. // 登录成功保存token和登录状态在缓存中
  181. let getData = res.data.data;
  182. wx.setStorageSync('loginStatus', true); //登录状态
  183. wx.setStorageSync('Authorization', getData.token); //token
  184. wx.setStorageSync('phone', getData.phone); //手机号码
  185. wx.setStorageSync('accountType', getData.accountType); //账号类型
  186. wx.setStorageSync('name', getData.name); //名称
  187. wx.setStorageSync('account', getData.account); //账号
  188. wx.setStorageSync('id', getData.id); //账号
  189. _this.onShow()
  190. //重新设置底部tabbar
  191. const accountType = wx.getStorageSync('accountType')
  192. if (accountType != 1) {
  193. sourceObj.getTabBar().setData({
  194. list: app.globalData.list,
  195. })
  196. } else {
  197. sourceObj.getTabBar().setData({
  198. list: app.globalData.list2,
  199. })
  200. }
  201. wx.showModal({
  202. title: '温馨提示',
  203. content: '为更好的促进与您的交流,服务号需要向您发送消息',
  204. confirmText: "同意",
  205. cancelText: "拒绝",
  206. success(res) {
  207. if (res.confirm) {
  208. wx.requestSubscribeMessage({
  209. tmplIds: ["kJHrL39stnuaPO4ruYcNb7_1Wxc-JGlllaM79iDk9zE"], //所选模板的模板ID,可以有多个
  210. success: function (res) {
  211. wx.switchTab({
  212. url: '/pages/index/index',
  213. })
  214. wx.getSetting({
  215. withSubscriptions: true,
  216. success(res) {
  217. console.log(res, res.subscriptionsSetting)
  218. }
  219. })
  220. },
  221. fail: function (err) {
  222. console.log("获取消息推送授权失败", err);
  223. wx.switchTab({
  224. url: '/pages/index/index',
  225. })
  226. }
  227. })
  228. } else if (res.cancel) {
  229. console.log('用户点击取消')
  230. }
  231. }
  232. })
  233. });
  234. }
  235. },
  236. //搜索框请求S
  237. onChange(e) {
  238. this.setData({
  239. searchVal: e.detail,
  240. });
  241. },
  242. onSearch: function (event) {
  243. this.setData({
  244. searchVal: event.detail
  245. })
  246. this.getListFun();
  247. },
  248. onCancel: function () {
  249. this.setData({})
  250. },
  251. toSearch: function (event) {
  252. this.getListFun();
  253. },
  254. //列表
  255. getListFun: function () {
  256. this.setData({
  257. page: 1
  258. })
  259. let params = {
  260. current: this.data.page,
  261. size: this.data.limit,
  262. licenseNumber:this.data.searchVal,
  263. appointmentFlag:'1'
  264. }
  265. app.request.pageFirst({
  266. url: app.API.lineUpList,
  267. page: this,
  268. params: params
  269. })
  270. },
  271. // 支付
  272. paySubmit: function (e) {
  273. // this.setData({
  274. // payStatus : true,
  275. // })
  276. let _this = this
  277. let clearId = null
  278. if(e.currentTarget.dataset.warnType=='1'||this.data.codeNum > 0){
  279. return false
  280. }
  281. //60秒倒计时
  282. this.setData({
  283. codeNum : 60,
  284. })
  285. wx.showLoading({
  286. title: '等待支付...',
  287. mask: true
  288. })
  289. wx.login({
  290. success: (res) => {
  291. let formData = {
  292. id: e.currentTarget.dataset.id,
  293. code: res.code,
  294. //money: e.currentTarget.dataset.money //e.currentTarget.dataset.money //支付金额
  295. };
  296. wx.request({
  297. url: app.API.appointmentPay,
  298. method: 'POST',
  299. data: formData,
  300. header: {
  301. //'content-type': 'application/json',
  302. 'Authorization': wx.getStorageSync('Authorization') ? 'Bearer ' + wx.getStorageSync('Authorization') : '' //'Bearer ' +
  303. },
  304. success: function (res) {
  305. let obj = res.data;
  306. wx.hideLoading()
  307. wx.requestPayment({
  308. 'timeStamp': obj.timeStamp,
  309. 'nonceStr': obj.nonceStr,
  310. 'package': obj.package,
  311. 'signType': obj.signType,
  312. 'paySign': obj.paySign,
  313. 'success': function (payres) {
  314. _this.getInfoFun()
  315. // _this.setData({
  316. // payStatus : false
  317. // })
  318. //支付成功后查询订单
  319. app.request.requestPostApi(app.API.payorder, {
  320. id: e.currentTarget.dataset.id,
  321. code: '123',
  322. }, _this, function (payorderRes, that) {
  323. let payorderData = payorderRes.data.data;
  324. console.log(payorderData)
  325. })
  326. if(clearId) clearInterval(clearId)
  327. clearId = setInterval(() => {
  328. let getNumber = _this.data.codeNum - 1
  329. _this.setData({
  330. codeNum : getNumber
  331. })
  332. if (_this.data.codeNum == 0) {
  333. clearInterval(clearId);
  334. }
  335. }, 1000);
  336. },
  337. 'fail': function (res) {
  338. console.log('支付失败',res)
  339. if(clearId) clearInterval(clearId)
  340. clearId = setInterval(() => {
  341. let getNumber = _this.data.codeNum - 1
  342. _this.setData({
  343. codeNum : getNumber
  344. })
  345. if (_this.data.codeNum == 0) {
  346. clearInterval(clearId);
  347. }
  348. }, 1000);
  349. // _this.setData({
  350. // payStatus : false
  351. // })
  352. // Notify({ type: 'danger', message: '您已取消支付,可在订单中完成支付' });
  353. console.log("申请支付,支付失败! res:" + res);
  354. Dialog.alert({
  355. title: '提示',
  356. message: '支付失败或已取消支付',
  357. }).then(() => {})
  358. }
  359. })
  360. },
  361. fail:function(res){
  362. //倒计时
  363. if(clearId) clearInterval(clearId)
  364. clearId = setInterval(() => {
  365. let getNumber = _this.data.codeNum - 1
  366. _this.setData({
  367. codeNum : getNumber
  368. })
  369. if (_this.data.codeNum == 0) {
  370. clearInterval(clearId);
  371. }
  372. }, 1000);
  373. }
  374. })
  375. },
  376. })
  377. },
  378. //完成装载
  379. toCompleteLoading: function (e) {
  380. let _this = this;
  381. if (this.data.loginStatus) {
  382. wx.showModal({
  383. title: '提示',
  384. content: '确定完成装货?',
  385. success: function (res) {
  386. if (res.confirm) {
  387. app.request.requestPostApi(app.API.completeLoading, {id:e.currentTarget.dataset.id}, _this, function (res, that) {
  388. if (res.data.code == '200') { //退出登录
  389. that.getListFun()
  390. wx.showToast({
  391. title: '操作成功',
  392. icon: 'success',
  393. duration: 2000,
  394. complete: function () {
  395. setTimeout(function () {}, 1500) //延迟时间
  396. }
  397. })
  398. } else {
  399. wx.showToast({
  400. title: res.data.msg ? res.data.msg : '出错了',
  401. icon: 'none',
  402. duration: 1500,
  403. mask: true
  404. })
  405. }
  406. });
  407. }
  408. }
  409. })
  410. } else {
  411. wx.showToast({
  412. icon: 'none',
  413. title: '登录后可操作',
  414. duration: 1500
  415. })
  416. }
  417. },
  418. /**
  419. * 页面相关事件处理函数--监听用户下拉动作
  420. */
  421. onPullDownRefresh: function () {
  422. this.setData({
  423. searchVal: ''
  424. })
  425. if (wx.getStorageSync('loginStatus')) {
  426. this.getListFun();
  427. } else {
  428. wx.stopPullDownRefresh();
  429. }
  430. },
  431. /**
  432. * 页面上拉触底事件的处理函数
  433. */
  434. onReachBottom: function () {
  435. this.data.page++;
  436. let params = {
  437. current: this.data.page,
  438. size: this.data.limit,
  439. licenseNumber:this.data.searchVal,
  440. appointmentFlag:'1'
  441. }
  442. app.request.pageOther({
  443. url: app.API.lineUpList,
  444. page: this,
  445. params: params,
  446. loadType: true //加载类型,是否是下拉加载
  447. });
  448. },
  449. /**
  450. * 用户点击右上角分享
  451. */
  452. onShareAppMessage() {
  453. }
  454. })