order.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. timer: '',
  7. orderList: [],
  8. showType: 2,
  9. page: 1,
  10. limit: 10,
  11. totalPages: 1,
  12. myqr_show: false,
  13. //我的分享二维码
  14. myqr_url: null,
  15. myqr_blur: 0,
  16. //背景模糊值
  17. myqr_width: 0,
  18. hasLogin: false,
  19. goodsId: '',
  20. tipsList:[],
  21. refundTipShow:false,
  22. refundId:'',
  23. serModifyList:[],
  24. serviceId:'',
  25. appointOrderId:'',
  26. appointDiaType:'',//1修改预约 2取消预约
  27. appointDiaShow:false,
  28. cancelShow:false,
  29. cancelList: [{
  30. id: 19,
  31. value: '【个人原因】临时有事暂时不预约'
  32. },
  33. {
  34. id: 20,
  35. value: '【个人原因】先囤着以后再约'
  36. },
  37. {
  38. id: 22,
  39. value: '【个人原因】计划有变不需要了'
  40. },
  41. {
  42. id: 21,
  43. value: '【商家原因】保洁师无法上门服务'
  44. },
  45. {
  46. id: 23,
  47. value: ' 其他'
  48. }
  49. ],
  50. cancelReason: '',
  51. cancelFirstShow:false,
  52. },
  53. onLoad: function (options) {
  54. // 页面初始化 options为页面跳转所带来的参数
  55. if (options.tab) {
  56. this.setData({
  57. showType: options.tab
  58. });
  59. }
  60. },
  61. getOrderList() {
  62. wx.showLoading({
  63. title: '加载中'
  64. });
  65. let that = this;
  66. util.request(api.OrderList, {
  67. showType: that.data.showType,
  68. page: that.data.page,
  69. limit: that.data.limit
  70. }).then(res => {
  71. wx.hideLoading();
  72. if (res.errno === 0) {
  73. console.log(res.data);
  74. that.setData({
  75. orderList: that.data.orderList.concat(res.data.data),
  76. totalPages: res.data.pages
  77. });
  78. clearInterval(this.data.timer);
  79. // 如果有未支付订单,倒计时定时器
  80. let isHasOver = this.data.orderList.some(item => {
  81. return item.payOverTime > 0;
  82. });
  83. console.log(isHasOver);
  84. if (isHasOver) {
  85. let timer = setInterval(() => {
  86. let list = this.data.orderList;
  87. let newList = [];
  88. list.forEach(item => {
  89. let obj = item;
  90. if (item.payOverTime > 0) {
  91. obj.payOverTime = item.payOverTime - 1;
  92. }
  93. newList.push(obj);
  94. });
  95. this.setData({
  96. orderList: newList
  97. });
  98. }, 1000);
  99. this.setData({
  100. timer: timer
  101. });
  102. }
  103. }
  104. });
  105. },
  106. onHide: function () {
  107. console.log('onHide');
  108. clearInterval(this.data.timer);
  109. },
  110. onUnload: function () {
  111. console.log('onunload');
  112. clearInterval(this.data.timer);
  113. },
  114. onReachBottom() {
  115. if (this.data.totalPages > this.data.page) {
  116. this.setData({
  117. page: this.data.page + 1
  118. });
  119. this.getOrderList();
  120. } else if (this.data.orderList.length > 0) {
  121. wx.showToast({
  122. title: '没有更多订单了',
  123. icon: 'none',
  124. duration: 2000
  125. });
  126. return false;
  127. }
  128. },
  129. orderDetail(e) {
  130. let id = e.currentTarget.dataset.id;
  131. wx.navigateTo({
  132. url: '/pages/ucenter/orderDetail/orderDetail?id=' + id
  133. });
  134. },
  135. switchTab: function (event) {
  136. let showType = event.currentTarget.dataset.index;
  137. this.setData({
  138. orderList: [],
  139. showType: showType,
  140. page: 1,
  141. // limit: 10,
  142. totalPages: 1
  143. });
  144. this.getOrderList();
  145. },
  146. onTabChange(e) {
  147. // let showType = e.detail.name;
  148. let showType = e.currentTarget.dataset.tab;
  149. this.setData({
  150. orderList: [],
  151. showType: showType,
  152. page: 1,
  153. // limit: 10,
  154. totalPages: 1
  155. });
  156. this.getOrderList();
  157. },
  158. appointServiceOld(e) {
  159. let id = e.currentTarget.dataset.id;
  160. let addressId = e.currentTarget.dataset.aid;
  161. let type = e.currentTarget.dataset.type;
  162. if (type && type == 5) {
  163. wx.navigateTo({
  164. url: "/pages/ucenter/coupon/couponGoods?id=1"
  165. });
  166. return;
  167. }
  168. if (addressId == null || addressId == 0)
  169. wx.navigateTo({
  170. url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + id
  171. });
  172. else //买约分离 没有地址的预约
  173. wx.navigateTo({
  174. url: '/pages/ucenter/serviceDetail/serviceDetail?orderId=' + id
  175. });
  176. },
  177. appointService(e) {
  178. let id = e.currentTarget.dataset.id;
  179. let addressId = e.currentTarget.dataset.aid;
  180. let type = e.currentTarget.dataset.type;
  181. let detailId = e.currentTarget.dataset.detail;
  182. wx.navigateTo({
  183. url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + id + '&serviceId=' + detailId
  184. });
  185. },
  186. qrtouchstart: function () {
  187. this.setData({
  188. myqr_blur: 0,
  189. myqr_show: false
  190. });
  191. },
  192. shareFriendOrCircle: function (e) {
  193. // let that = this;
  194. // if (!app.globalData.hasLogin) {
  195. // wx.navigateTo({
  196. // url: "/pages/auth/login/login"
  197. // });
  198. // return;
  199. // }
  200. // //获取分享id 用来追踪链接
  201. // //引荐人和非引荐人的 链接不同
  202. // let imgUrl = that.data.goods.shareWxUrl ? that.data.goods.shareWxUrl : that.data.goods.gallery[0];
  203. // var path = '/pages/goods/goods?id=' + that.data.id + '&rId=' + that.data.userInfo.id;
  204. // if (that.data.userInfo.isDis) { //是引荐人
  205. // path = '/pages/goods/goods?id=' + that.data.id + '&shareId=' + that.data.wxShareId;
  206. // }
  207. // this.hidePoster();
  208. // return {
  209. // title: that.data.goods.name,
  210. // desc: that.data.myqr_ads,
  211. // path: path,
  212. // imageUrl: imgUrl
  213. // }
  214. },
  215. // 保存分享图
  216. saveShare: function () {
  217. let that = this;
  218. wx.showLoading({
  219. title: '图片保存中'
  220. });
  221. console.log(that.data);
  222. wx.downloadFile({
  223. url: that.data.myqr_url,
  224. success: function (res) {
  225. console.log(res);
  226. wx.saveImageToPhotosAlbum({
  227. filePath: res.tempFilePath,
  228. success: function (res) {
  229. wx.hideLoading();
  230. wx.showModal({
  231. title: '存图成功',
  232. content: '图片成功保存到相册了,可以分享到朋友圈了',
  233. showCancel: false,
  234. confirmText: '好的',
  235. confirmColor: '#a78845',
  236. success: function (res) {
  237. if (res.confirm) {
  238. console.log('用户点击确定');
  239. that.setData({
  240. myqr_show: false,
  241. myqr_blur: 0
  242. });
  243. }
  244. }
  245. });
  246. },
  247. fail: function (res) {
  248. wx.hideLoading();
  249. wx.showModal({
  250. title: '警告',
  251. content: '不授权无法保存',
  252. showCancel: false
  253. });
  254. that.setData({
  255. myqr_show: false,
  256. myqr_blur: 0
  257. });
  258. }
  259. });
  260. },
  261. fail: function (res) {
  262. wx.hideLoading();
  263. console.log(res);
  264. }
  265. });
  266. },
  267. // “去付款”按钮点击效果
  268. payOrder: function (e) {
  269. let that = this;
  270. let id = e.currentTarget.dataset.id;
  271. let ordern = e.currentTarget.dataset.sn;
  272. util.request(api.OrderPayCheck, {
  273. orderId: id
  274. }, 'POST').then(function (res) {
  275. if (res.errno === 0) {
  276. const outOrderNo = res.data;
  277. console.log(res);
  278. wx.continueToPay({
  279. // orderId: this.data.orderId, // 内部订单号
  280. outOrderNo: outOrderNo, // 外部订单号 2个订单号必填一个
  281. success: res => {
  282. console.log(res);
  283. const {
  284. orderId,
  285. outOrderNo
  286. } = res;
  287. console.log('success res', res);
  288. console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  289. wx.redirectTo({
  290. url: '/pages/ucenter/order/order'
  291. });
  292. },
  293. fail: res => {
  294. console.log(res);
  295. const {
  296. orderId,
  297. outOrderNo,
  298. errNo,
  299. errMsg,
  300. errLogId
  301. } = res;
  302. if (errLogId) {
  303. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  304. }
  305. if (orderId || outOrderNo) {
  306. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  307. console.log('订单号' + outOrderNo);
  308. // wx.navigateTo({
  309. // url: '/pages/ucenter/orderDetail/orderDetail?id='+outOrderNo
  310. // });
  311. }
  312. util.showErrorToast('支付失败');
  313. },
  314. });
  315. }
  316. });
  317. },
  318. payOrder(e) {
  319. let that = this;
  320. let id = e.currentTarget.dataset.id;
  321. util.request(api.OrderPrepay, {
  322. orderId: id
  323. }, 'POST').then(function (res) {
  324. if (res.errno === 0) {
  325. const payParam = res.data;
  326. console.log("支付过程开始")
  327. wx.requestPayment({
  328. 'timeStamp': payParam.timeStamp,
  329. 'nonceStr': payParam.nonceStr,
  330. 'package': payParam.packageValue,
  331. 'signType': payParam.signType,
  332. 'paySign': payParam.paySign,
  333. 'success': function (res) {
  334. console.log("支付过程成功")
  335. wx.redirectTo({
  336. url: '/pages/ucenter/order/order'
  337. });
  338. },
  339. 'fail': function (res) {
  340. console.log("支付过程失败")
  341. util.showErrorToast('支付失败');
  342. },
  343. 'complete': function (res) {
  344. console.log("支付过程结束")
  345. }
  346. });
  347. }else{
  348. wx.showToast({
  349. title: res.errmsg,
  350. icon: 'none'
  351. });
  352. }
  353. });
  354. },
  355. // “删除”点击效果
  356. deleteOrder: function (e) {
  357. let that = this;
  358. let id = e.currentTarget.dataset.id;
  359. wx.showModal({
  360. title: '',
  361. content: '确定要删除此订单?',
  362. success: function (res) {
  363. if (res.confirm) {
  364. util.request(api.OrderDelete, {
  365. orderId: id
  366. }, 'POST').then(function (res) {
  367. if (res.errno === 0) {
  368. wx.showToast({
  369. title: '删除订单成功'
  370. });
  371. util.redirect('/pages/ucenter/order/order');
  372. } else {
  373. util.showErrorToast(res.errmsg);
  374. }
  375. });
  376. }
  377. }
  378. });
  379. },
  380. // “取消订单”点击效果
  381. cancelOrder: function (e) {
  382. let that = this;
  383. let id = e.currentTarget.dataset.id;
  384. wx.showModal({
  385. title: '',
  386. content: '确定要取消此订单?',
  387. success: function (res) {
  388. if (res.confirm) {
  389. util.request(api.OrderCancel, {
  390. orderId: id
  391. }, 'POST').then(function (res) {
  392. if (res.errno === 0) {
  393. wx.showToast({
  394. title: '取消订单成功'
  395. });
  396. util.redirect('/pages/ucenter/order/order');
  397. } else {
  398. util.showErrorToast(res.errmsg);
  399. }
  400. });
  401. }
  402. }
  403. });
  404. },
  405. // “待上门”点击效果
  406. confirmOrder: function (e) {
  407. let that = this;
  408. let id = e.currentTarget.dataset.id;
  409. wx.showModal({
  410. title: '',
  411. content: '确认上门服务?',
  412. success: function (res) {
  413. if (res.confirm) {
  414. util.request(api.OrderConfirm, {
  415. orderId: id
  416. }, 'POST').then(function (res) {
  417. if (res.errno === 0) {
  418. wx.showToast({
  419. title: '确认上门成功!'
  420. });
  421. util.redirect('/pages/ucenter/order/order');
  422. } else {
  423. util.showErrorToast(res.errmsg);
  424. }
  425. });
  426. }
  427. }
  428. });
  429. },
  430. // “取消订单并退款”点击效果
  431. refundOrderOld: function (e) {
  432. let that = this;
  433. let id = e.currentTarget.dataset.id;
  434. wx.showModal({
  435. title: '',
  436. content: '确定要取消此订单?',
  437. success: function (res) {
  438. if (res.confirm) {
  439. util.request(api.OrderRefund, {
  440. orderId: id
  441. }, 'POST').then(function (res) {
  442. if (res.errno === 0) {
  443. wx.showToast({
  444. title: '取消订单成功'
  445. });
  446. util.redirect('/pages/ucenter/order/order');
  447. } else {
  448. util.showErrorToast(res.errmsg);
  449. }
  450. });
  451. }
  452. }
  453. });
  454. },
  455. refundOrderOld: function (e) {
  456. let id = e.currentTarget.dataset.id;
  457. },
  458. refundOrder: function (e) {
  459. let id = e.currentTarget.dataset.id;
  460. wx.navigateTo({
  461. url: '/pages/ucenter/applyRefund/applyRefund?id=' + id,
  462. });
  463. },
  464. onReady: function () {
  465. // 页面渲染完成
  466. },
  467. onShow: function () {
  468. // 页面显示
  469. this.setData({
  470. orderList: [],
  471. page: 1,
  472. });
  473. // wx.pageScrollTo({
  474. // scrollTop: 0,
  475. // duration: 1000,
  476. // });
  477. this.getOrderList();
  478. },
  479. buyAgain(e) {
  480. let id = e.currentTarget.dataset.id;
  481. wx.navigateTo({
  482. url: '/pages/goods/goods?id=' + id,
  483. });
  484. },
  485. goCheck(e) {
  486. let id = e.currentTarget.dataset.id;
  487. wx.navigateTo({
  488. url: '/pages/ucenter/orderDetail/orderDetail?id=' + id
  489. });
  490. },
  491. handleInit(event) {
  492. const {
  493. status
  494. } = event.detail;
  495. console.log(status);
  496. },
  497. handleSuccess(event) {
  498. const {
  499. result
  500. } = event.detail;
  501. // 团购订单不支持查看评价,此时可决定按钮是否展示
  502. console.log(result);
  503. },
  504. handleError(event) {
  505. const {
  506. errMsg,
  507. errNo
  508. } = event.detail;
  509. // errNo(错误码,对应某种具体报错原因)
  510. // errMsg(报错信息)
  511. console.log(errMsg, errNo);
  512. },
  513. goAppoint(e) {
  514. let id = e.currentTarget.dataset.id;
  515. let detailId = e.currentTarget.dataset.detail;
  516. wx.navigateTo({
  517. url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + id + '&serviceId=' + detailId
  518. });
  519. },
  520. switchSer(e){
  521. let serid = e.currentTarget.dataset.serid;
  522. this.setData({
  523. serviceId:serid
  524. });
  525. },
  526. appointModifyConf(){
  527. if(this.data.serviceId==''||this.data.serviceId==null){
  528. wx.showToast({
  529. title: '请选择要修改的服务',
  530. icon:'none'
  531. });
  532. return false;
  533. }else{
  534. this.setData({
  535. appointDiaShow:false
  536. });
  537. wx.navigateTo({
  538. url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + this.data.appointOrderId + '&serviceId=' +
  539. this.data.serviceId
  540. });
  541. }
  542. },
  543. closeModify(){
  544. this.setData({
  545. appointDiaShow:false
  546. });
  547. },
  548. modifyAppoint(e){
  549. let id = e.currentTarget.dataset.id;
  550. let serid = e.currentTarget.dataset.serid;
  551. let times = e.currentTarget.dataset.times;
  552. this.setData({
  553. appointOrderId:id
  554. });
  555. if(times>1){
  556. this.setData({
  557. appointDiaShow:true,
  558. serviceId:''
  559. });
  560. util.request(
  561. api.getBooked,
  562. {orderId: id},
  563. 'GET'
  564. ).then(res=> {
  565. if (res.errno === 0) {
  566. this.setData({
  567. serModifyList:res.data
  568. })
  569. }
  570. });
  571. }else{
  572. wx.navigateTo({
  573. url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + id + '&serviceId=' +serid
  574. });
  575. }
  576. },
  577. onCancelClick() {
  578. },
  579. cancelAppoint(e){
  580. let id = e.currentTarget.dataset.id;
  581. let serid = e.currentTarget.dataset.serid;
  582. let times = e.currentTarget.dataset.times;
  583. this.setData({
  584. appointOrderId:id
  585. });
  586. if(times>1){
  587. this.setData({
  588. cancelFirstShow:true,
  589. serviceId:''
  590. });
  591. util.request(
  592. api.getBooked,
  593. {orderId: id},
  594. 'GET'
  595. ).then(res=> {
  596. if (res.errno === 0) {
  597. this.setData({
  598. serModifyList:res.data
  599. })
  600. }
  601. });
  602. }else{
  603. this.setData({
  604. cancelShow:true,
  605. serviceId:serid
  606. });
  607. }
  608. },
  609. cancelItemSelect(e) {
  610. this.setData({
  611. cancelReason: e.currentTarget.dataset.id
  612. });
  613. },
  614. onCancelPopupClose() {
  615. this.setData({
  616. cancelShow: false
  617. });
  618. },
  619. onCancelPopupCloseFir(){
  620. this.setData({
  621. cancelFirstShow: false
  622. });
  623. },
  624. cancelFirstConfirm(){
  625. if(this.data.serviceId==''||this.data.serviceId==null){
  626. wx.showToast({
  627. title: '请选择要取消的服务',
  628. icon:'none'
  629. });
  630. return false;
  631. }
  632. this.setData({
  633. cancelFirstShow: false,
  634. cancelShow: true
  635. });
  636. },
  637. cancelItemConfirm() {
  638. let that = this;
  639. if (that.data.cancelReason == '') {
  640. util.showErrorToast('请选择取消原因');
  641. return;
  642. }
  643. wx.showLoading({
  644. title: '提交中'
  645. });
  646. util.request(
  647. api.OrderBookCancel, {
  648. detailId: this.data.serviceId,
  649. cancelReason: this.data.cancelReason
  650. },
  651. 'POST'
  652. ).then((res) => {
  653. wx.hideLoading();
  654. if (res.errno === 0) {
  655. wx.showToast({
  656. title: '提交成功'
  657. });
  658. this.setData({
  659. cancelShow: false,
  660. orderList: [],
  661. page: 1
  662. });
  663. this.getOrderList();
  664. }else{
  665. util.showErrorToast(res.errmsg);
  666. }
  667. });
  668. },
  669. });