抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1366 lines
38 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  2. let config = require("../../../config/config.js");
  3. let util = require("../../../utils/util");
  4. let Http = require("../../../utils/HttpBasics");
  5. let app = getApp();
  6. const imgurl = require("../../../utils/imgurl");
  7. const QR = require("../../../utils/memberqrcode.js");
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. curHtml: '',
  14. showIdFalg: false,
  15. outOrderNo: '', //支付2.0继续支付id
  16. payOrderNo: "", //评价订单id
  17. evaluateFlag: false, //控制评价显隐藏
  18. serviceUrl: '', //客服外部链接
  19. dynamicRq: "",
  20. expiredSeconds: 0,
  21. couponTenantId: '',
  22. showhieRq: false,
  23. mouldType: 0,
  24. showFlag: false,
  25. navigationBarHeight,
  26. upDataRqUrlF: imgurl.upDataRqF.url,
  27. succUrl: imgurl.succ.url,
  28. spcodeUrl: imgurl.spcode.url,
  29. chevronUrl: imgurl.chevron.url,
  30. teljpgUrl: imgurl.teljpg.url,
  31. newUrl: imgurl.new1.url,
  32. weixinTitle: imgurl.weixinTitle.url,
  33. lineUrl: imgurl.line.url,
  34. wm01Url: imgurl.wm01.url,
  35. wm02Url: imgurl.wm02.url,
  36. wm03Url: imgurl.wm03.url,
  37. wm04Url: imgurl.wm04.url,
  38. wm05Url: imgurl.wm05.url,
  39. showModalStatus: false,
  40. flag: 0,
  41. order: null,
  42. orderId: null,
  43. //存储计时器
  44. setInter: "",
  45. mystatus: '',
  46. staticGamedata: {},
  47. showIf: false,
  48. showPage: false,
  49. showButton: false,
  50. cardDetail: null,
  51. supportTransfer: '',
  52. cardIf: false,
  53. contentType: 0,
  54. orderFlag: false, //判断是不是线上配送
  55. tenantId: '',
  56. mallList: [],
  57. imId: "",
  58. orderStatus: 1,
  59. tenantId: "",
  60. IMorderId: "",
  61. outOrderId: "",
  62. outRefundOrderId: "",
  63. canIUseRefund: false,
  64. isAppointment: false,
  65. appointStart: "",
  66. appointEnd: "",
  67. appointmentId: "",
  68. appointmentStatus: "",
  69. use_num_per_consume: ""
  70. },
  71. imCallback(e) {
  72. console.log("跳转IM客服成功", e);
  73. },
  74. onimError(e) {
  75. console.log("拉起IM客服失败", e.detail);
  76. },
  77. handleRefund(event) {
  78. const {
  79. status,
  80. result
  81. } = event.detail;
  82. if (status === 'success') {
  83. const {
  84. refundId,
  85. outRefundNo
  86. } = result;
  87. console.log(refundId, outRefundNo, 'handleRefund');
  88. } else {
  89. const {
  90. errMsg
  91. } = result;
  92. console.log(errMsg);
  93. }
  94. },
  95. applyRefund(event) {
  96. console.log('applyRefund');
  97. const {
  98. orderId
  99. } = event.detail;
  100. const extra = {
  101. tenantId: this.data.tenantId
  102. }; // 开发者需要透传的参数,可自定义内容
  103. return new Promise(resolve => {
  104. console.log(extra, 'extra');
  105. console.log(this.data.outOrderId, 'outOrderId');
  106. resolve(extra);
  107. });
  108. },
  109. handleError(event) {
  110. const {
  111. errMsg,
  112. errNo
  113. } = event.detail;
  114. console.log(event, 'err');
  115. },
  116. showId() {
  117. let this_ = this;
  118. if (!this_.data.showIdFalg) {
  119. tt.showModal({
  120. // title: "查看券码",
  121. content: "是否查看完整券码",
  122. success(res) {
  123. if (res.confirm) {
  124. console.log("confirm, continued");
  125. this_.setData({
  126. showIdFalg: true
  127. })
  128. } else if (res.cancel) {
  129. //取消
  130. console.log("cancel, cold");
  131. } else {
  132. // what happend?
  133. }
  134. },
  135. fail(err) {
  136. console.log(`showModal 调用失败`, err);
  137. },
  138. });
  139. } else {
  140. this.setData({
  141. showIdFalg: false
  142. })
  143. }
  144. },
  145. copeCode(e) {
  146. let code = e.currentTarget.dataset.text
  147. tt.setClipboardData({
  148. data: code,
  149. success: function () {
  150. tt.showToast({
  151. title: '复制成功',
  152. icon: "none"
  153. })
  154. }
  155. })
  156. },
  157. gokuaidi(e) {
  158. let nu = e.currentTarget.dataset.nu
  159. tt.navigateToMiniProgram({
  160. appId: 'wx6885acbedba59c14',
  161. path: `pages/result/result?nu=${nu}&com=&querysource=third_xcx`
  162. })
  163. },
  164. setShow() {
  165. this.setData({
  166. showFlag: true
  167. })
  168. },
  169. hieShow() {
  170. this.setData({
  171. showFlag: false
  172. })
  173. },
  174. goAppointment(e) {
  175. const that = this
  176. const orderId = e.currentTarget.dataset.id
  177. const id = this.data.appointmentId
  178. const startTime = that.data.order.validStartDATE
  179. const endTime = that.data.order.validEndDate
  180. const mallList = JSON.stringify(that.data.mallList)
  181. console.log(startTime, endTime, mallList);
  182. tt.navigateTo({
  183. url: `/package2/pages/appointment/appointment?id=${id}&orderId=${orderId}&startTime=${startTime}&endTime=${endTime}&mallList=${mallList}`,
  184. });
  185. },
  186. getUserReservation(couponOrderId) {
  187. const that = this
  188. Http.get({
  189. url: config.api.getUserReservation,
  190. data: {
  191. couponOrderId,
  192. mallTenantId: this.data.mallTenantId || ''
  193. }
  194. }).then(res => {
  195. console.log(res, 'getUserReservation');
  196. if (res.data) {
  197. const appointStart = util.timestampToTime(res.data.startDate, 'YYYY-MM-DD hh:mm:ss')
  198. const appointEnd = util.timestampToTime(res.data.endDate, 'hh:mm:ss')
  199. console.log(appointStart, appointEnd);
  200. const appointmentId = res.data.id
  201. const appointmentStatus = res.data.status
  202. that.setData({
  203. appointStart,
  204. appointEnd,
  205. appointmentId,
  206. appointmentStatus,
  207. isAppointment: true
  208. })
  209. }
  210. }).catch(err => {
  211. console.log(err, 'getUserReservation');
  212. })
  213. },
  214. getOrderStatus(orderId) {
  215. const that = this
  216. Http.get({
  217. url: config.api.getRefundStatus,
  218. data: {
  219. orderId,
  220. mallTenantId: this.data.mallTenantId || ''
  221. }
  222. }).then(res => {
  223. console.log(res, 'res');
  224. const orderStatus = res.data.orderStatus
  225. const outOrderId = res.data.outOrderId
  226. const refundOrderStatus = res.data.refundOrderStatus
  227. const outRefundOrderId = res.data.outRefundOrderId
  228. let status = ''
  229. if (orderStatus == 1) { // 申请退款
  230. status = 1
  231. } else if (orderStatus == 3 || orderStatus == 4 || orderStatus == 5) {
  232. if (refundOrderStatus == 1 || refundOrderStatus == 11) { // 退款中
  233. status = 2
  234. } else if (refundOrderStatus == 3) { //退款成功
  235. status = 3
  236. } else if (refundOrderStatus == 4) { //退款失败
  237. status = 4
  238. } else { // 退款处理中
  239. status = 0
  240. }
  241. that.setData({
  242. outRefundOrderId: outRefundOrderId
  243. })
  244. } else if (orderStatus == 2) {
  245. status = 'orderCancel'
  246. } else {
  247. status = 'noRefund'
  248. }
  249. that.setData({
  250. orderStatus: status,
  251. outOrderId: outOrderId
  252. })
  253. }).catch(err => {
  254. console.log(err, 'err');
  255. })
  256. },
  257. getIm() { //获取im客服id
  258. const that = this
  259. Http.get({
  260. url: config.api.getIm,
  261. data: {
  262. mallTenantId: this.data.mallTenantId || ''
  263. }
  264. }).then(res => {
  265. console.log(res, 'getIm');
  266. const imId = res.data.imId || ''
  267. that.setData({
  268. imId: imId
  269. })
  270. }).catch(err => {
  271. console.log(err, 'err');
  272. })
  273. },
  274. getCouponMerchant() { //获取适用门店
  275. const that = this
  276. Http.get({
  277. url: config.api.orderDetail,
  278. data: {
  279. orderId: this.data.orderId,
  280. mallTenantId: this.data.mallTenantId || ''
  281. }
  282. }).then(res => {
  283. const couponChannelId = res.data.orders[0].couponChannelId
  284. const orderID = res.data.orders[0].id
  285. const cOrderID = res.data.orders[0].couponOrderId
  286. that.getOrderStatus(orderID)
  287. that.getUserReservation(cOrderID)
  288. that.getIm()
  289. const extParam = res.data.extParam || null
  290. if (extParam) {
  291. const obj = JSON.parse(extParam)
  292. that.setData({
  293. IMorderId: obj.order_id,
  294. tenantId: res.data.tenantId,
  295. })
  296. }
  297. Http.get({
  298. url: config.api.couponMerchant,
  299. data: {
  300. couponChannelId: couponChannelId,
  301. mallTenantId: this.data.mallTenantId || ''
  302. }
  303. }).then(res => {
  304. const keys = Object.keys(res.data)
  305. const mallList = []
  306. let i = 0
  307. keys.forEach(item => {
  308. const arr = item.split('|')
  309. const obj = {
  310. tenantId: arr[0],
  311. mallName: arr[1],
  312. merchantVoList: res.data[item],
  313. expand: false
  314. }
  315. if (i == 0) {
  316. obj.expand = true
  317. }
  318. mallList.push(obj)
  319. i++
  320. })
  321. this.setData({
  322. mallList: mallList
  323. })
  324. })
  325. }).catch(err => {
  326. })
  327. },
  328. goDetail(e) {
  329. if (e.target.id == "payBtn") return
  330. tt.navigateTo({
  331. url: `/pages/coupon/detail/index?couponChannelId=${this.data.order.couponChannelId}&mallTenantId=${this.data.mallTenantId}`,
  332. success: (res) => {
  333. },
  334. fail: (res) => {
  335. },
  336. });
  337. },
  338. refund() { //退款
  339. Http.post({
  340. url: config.api.refund,
  341. data: {
  342. orderId: this.data.order.id,
  343. mallTenantId: this.data.mallTenantId || ''
  344. }
  345. }).then(res => {
  346. tt.navigateTo({
  347. url: `/pages/refund/refund?id=${this.data.order.id}&mallTenantId=${this.data.mallTenantId}`,
  348. success: (res) => {
  349. },
  350. fail: (res) => {
  351. },
  352. });
  353. }).catch(err => {
  354. tt.showToast({
  355. title: err.message ? err.message : err.data, // 内容
  356. icon: "none"
  357. });
  358. })
  359. },
  360. goRefund(e) {
  361. let this_ = this
  362. if (this_.data.order.couponOrderStatus == 0) {
  363. tt.showModal({
  364. title: "申请退款",
  365. content: "提交申请退款",
  366. confirmText: "确定",
  367. success(res) {
  368. if (res.confirm) {
  369. this_.refund()
  370. console.log("confirm, continued");
  371. } else if (res.cancel) {
  372. console.log("cancel, cold");
  373. } else {
  374. // what happend?
  375. }
  376. },
  377. fail(res) {
  378. console.log(`showModal调用失败`);
  379. },
  380. });
  381. } else if (this_.data.order.couponOrderStatus == 3) { //退款中
  382. tt.navigateTo({
  383. url: `/pages/refund/refund?id=${this.data.order.id}&mallTenantId=${this.data.mallTenantId}`,
  384. success: (res) => {
  385. },
  386. fail: (res) => {
  387. },
  388. });
  389. }
  390. },
  391. //刷新订单
  392. updetail() {
  393. let that = this
  394. let url = config.api.orderDetail
  395. Http.get({
  396. url: url,
  397. data: {
  398. orderId: this.data.orderId,
  399. mallTenantId: this.data.mallTenantId || ''
  400. }
  401. }).then(res => {
  402. tt.hideLoading();
  403. if (res.data.tenantId) {
  404. that.setData({
  405. tenantId: res.data.tenantId
  406. })
  407. }
  408. var createDate = util.timestampToTime(res.data.orders[0].createDate, "YYYY-MM-DD");
  409. let tempData = res.data.orders[0]
  410. tempData.deliveryInfo = tempData.deliveryInfo ? JSON.parse(tempData.deliveryInfo) : ""
  411. tempData.itemGroup = tempData.itemGroup ? JSON.parse(tempData.itemGroup) : ""
  412. tempData.soldStartTime = util.timestampToTime(tempData.soldStartTime, "YYYY-MM-DD") || null,
  413. tempData.soldEndTime = util.timestampToTime(tempData.soldEndTime, "YYYY-MM-DD") || null,
  414. tempData.validStartDATE = tempData.validStartDate
  415. tempData.validEndDATE = tempData.validEndDate
  416. tempData.validStartDate = util.timestampToTime(tempData.validStartDate, "YYYY-MM-DD")
  417. tempData.validEndDate = util.timestampToTime(tempData.validEndDate, "YYYY-MM-DD")
  418. tempData.couponOrderIdS = tempData.couponOrderId ? tempData.couponOrderId.slice(0, 4) + `******` + tempData.couponOrderId.slice(14) : ''
  419. if (tempData.productAttrs && tempData.skuAttrs) {
  420. tempData.productAttrs = JSON.parse(tempData.productAttrs)
  421. tempData.skuAttrs = JSON.parse(tempData.skuAttrs)
  422. console.log(tempData.productAttrs);
  423. console.log(tempData.skuAttrs);
  424. console.log('****');
  425. tempData.productAttrs.map(item => {
  426. if (item.key == "appointment") {
  427. let tempAppoinObj = JSON.parse(item.data)
  428. if (tempAppoinObj.need_appointment) {
  429. let subscribeSing = "";
  430. if (tempAppoinObj.ahead_time_type == 1) {
  431. subscribeSing = `需提前${tempAppoinObj.ahead_day_num}天预约`
  432. } else if (tempAppoinObj.ahead_time_type == 2) {
  433. subscribeSing = `需提前${tempAppoinObj.ahead_hour_num}小时预约`
  434. } else if (tempAppoinObj.ahead_time_type == 3) {
  435. subscribeSing = `需提前${tempAppoinObj.ahead_minute_num}分钟预约`
  436. }
  437. tempData.subscribeSing = subscribeSing
  438. }
  439. }
  440. if (item.key == "limit_use_rule") {
  441. if (item.data != '') {
  442. let tempAppoinObj = JSON.parse(item.data)
  443. that.setData({
  444. use_num_per_consume: tempAppoinObj.use_num_per_consume || ""
  445. })
  446. }
  447. }
  448. if (item.key == "Notification") {
  449. if (item.data != '') {
  450. tempData.curLsit = JSON.parse(item.data)
  451. }
  452. }
  453. if (item.key == "bring_out_meal") {
  454. tempData.besides = item.data
  455. }
  456. if (item.key == "free_pack") {
  457. tempData.pack = item.data
  458. }
  459. if (item.key == "superimposed_discounts") {
  460. tempData.superimposed_discounts = item.data
  461. }
  462. if (item.key == "private_room") {
  463. tempData.private_room = item.data
  464. }
  465. if (item.key == "rec_person_num_max") {
  466. tempData.rec_person_num_max = item.data
  467. }
  468. if (item.key == 'Description' && item.isRequired) {
  469. tempData.Description = JSON.parse(item.data)
  470. }
  471. if (item.key == "can_no_use_date") {
  472. tempData.can_no_use_date = JSON.parse(item.data)
  473. }
  474. })
  475. tempData.skuAttrs.map(item => {
  476. if (item.key == "commodity") {
  477. if (item.data != '') {
  478. tempData.itemGroup = JSON.parse(item.data)
  479. }
  480. }
  481. })
  482. }
  483. that.setData({
  484. outOrderNo: res.data.id,
  485. order: tempData,
  486. showPage: true,
  487. createDate: createDate,
  488. composeOrderType: tempData.composeOrderType,
  489. contentType: tempData.contentType ? tempData.contentType : 0,
  490. orderFlag: tempData.type == 11 ? true : false, //判断是不是线上配送
  491. })
  492. if (tempData.couponOrderId) { //0未付款 1已支付 2已取消 3退款中 4已退款
  493. that.setRq()
  494. // that.upStatus()
  495. let setInter = setInterval(() => {
  496. if (tempData.couponOrderStatus == 0) {
  497. Http.get({
  498. url: config.api.getStatus,
  499. data: {
  500. couponOrderId: tempData.couponOrderId,
  501. mallTenantId: this.data.mallTenantId || ''
  502. }
  503. }).then(res => {
  504. console.log(res);
  505. that.setData({
  506. couponOrderStatus: res.data.CouponOrderStatus
  507. });
  508. if (res.data.CouponOrderStatus == 1 || res.data.CouponOrderStatus == 3) {
  509. /**
  510. * 动态改变上一级页面的核销状态
  511. */
  512. // that.getStaticGame()
  513. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  514. clearInterval(that.data.setInter);
  515. clearInterval(that.data.templTiem);
  516. that.updetail()
  517. that.setData({
  518. mystatus: res.data.CouponOrderStatus
  519. });
  520. }
  521. })
  522. .catch(err => {
  523. tt.showToast({
  524. title: err.errMsg,
  525. icon: 'none',
  526. duration: 2000,
  527. mask: false
  528. });
  529. })
  530. } else {
  531. Http.get({
  532. url: config.api.getStatus,
  533. data: {
  534. couponOrderId: tempData.couponOrderId,
  535. mallTenantId: this.data.mallTenantId || ''
  536. }
  537. }).then(res => {
  538. console.log(res, 'getStatus');
  539. that.setData({
  540. couponOrderStatus: res.data.CouponOrderStatus
  541. });
  542. if (res.data.CouponOrderStatus == 1 || res.data.CouponOrderStatus == 3) {
  543. /**
  544. * 动态改变上一级页面的核销状态
  545. */
  546. // that.getStaticGame()
  547. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  548. clearInterval(that.data.setInter);
  549. clearInterval(that.data.templTiem);
  550. that.updetail()
  551. that.setData({
  552. mystatus: res.data.CouponOrderStatus
  553. });
  554. }
  555. })
  556. .catch(err => {
  557. console.log(err);
  558. })
  559. }
  560. }, 2000);
  561. that.setData({
  562. setInter: setInter
  563. })
  564. }
  565. if (tempData.couponOrderStatus && tempData.couponOrderStatus == 1) { //核销后
  566. that.goIfEvaluate() //判断订单是否能评价
  567. }
  568. }).catch(error => {
  569. console.log(error, "error");
  570. tt.hideLoading();
  571. tt.showModal({
  572. title: '提示',
  573. content: error.errMsg,
  574. showCancel: false
  575. })
  576. })
  577. },
  578. //确认收货
  579. verify() {
  580. Http.post({
  581. url: config.api.verify,
  582. data: {
  583. couponOrderId: this.data.order.couponOrderId
  584. }
  585. }).then(res => {
  586. tt.showToast({
  587. title: '签收成功',
  588. icon: "none"
  589. })
  590. this.updetail()
  591. }).catch(err => {
  592. tt.showModal({
  593. title: '提示',
  594. content: err.message ? err.message : err.data,
  595. showCancel: false
  596. })
  597. })
  598. },
  599. phone: function (e) {
  600. let that = this;
  601. console.log(e);
  602. tt.makePhoneCall({
  603. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  604. });
  605. },
  606. /**
  607. * 跳转到门店列表的详情页面
  608. */
  609. gotoDetail(e) {
  610. tt.navigateTo({
  611. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  612. })
  613. },
  614. getUserInfo: function () {
  615. let that = this;
  616. // 获取用户信息
  617. Http.get({
  618. url: config.api.getScore,
  619. data: {}
  620. })
  621. .then(res => {
  622. console.log(res)
  623. that.setData({
  624. userName: res.data.nickName,
  625. avatarUrl: res.data.avatarUrl
  626. })
  627. })
  628. },
  629. onShareAppMessage: function (res) {
  630. app.globalData.previewFlag = true
  631. if (res.from === 'button') {
  632. console.log(res, 3333333333333333333333)
  633. // 来自页面内转发按钮
  634. let _this = this;
  635. return {
  636. title: _this.data.userName + '赠送您一张' + _this.data.order.title,
  637. path: '/pages/index/index?couponChannelId=' + this.data.order.couponChannelId + '&cuserId=' + this.data.order.cuserId + '&couponId=' + this.data.order.productId + '&coverImg=' + this.data.order.coverImg + '&userName=' + this.data.userName + '&avatarUrl=' + this.data.avatarUrl + '&couponOrderId=' + this.data.order.couponOrderId + '&updateDate=' + this.data.order.updateDate,
  638. imageUrl: this.data.order.coverImg,
  639. success: function (res) {
  640. // 转发成功
  641. },
  642. fail: function (res) {
  643. // 转发失败
  644. }
  645. }
  646. } else {
  647. console.log(res, 444444444444444444)
  648. }
  649. },
  650. createQrCode: function (url, canvasId, cavW, cavH) {
  651. //调用插件中的draw方法,绘制二维码图片
  652. let that = this;
  653. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  654. that.setData({
  655. tempFilePath: res
  656. })
  657. });
  658. },
  659. setRq() {
  660. let _this = this
  661. _this.setData({
  662. showhieRq: false,
  663. })
  664. Http.get({ //获取动态二维码
  665. url: config.api.dynamicId,
  666. data: {
  667. couponOrderId: _this.data.order.couponOrderId,
  668. couponTenantId: _this.data.tenantId || ''
  669. }
  670. }).then(res => {
  671. console.log(res, "res")
  672. _this.setData({
  673. dynamicRq: res.data.dynamicId,
  674. expiredSeconds: res.data.expiredSeconds,
  675. couponTenantId: res.data.couponTenantId
  676. })
  677. let url = JSON.stringify({
  678. END: "C",
  679. TYPE: "couponorder",
  680. ID: _this.data.dynamicRq,
  681. couponTenantId: _this.data.couponTenantId
  682. })
  683. if (res.data.expiredSeconds == 0) {
  684. //倒计时为零直接显示券码
  685. } else {
  686. let inre = setInterval(() => {
  687. if (_this.data.expiredSeconds > 1) {
  688. _this.setData({
  689. expiredSeconds: _this.data.expiredSeconds - 1
  690. })
  691. // console.log("有效", _this.data.expiredSeconds)
  692. } else {
  693. // console.log("无效", _this.data.expiredSeconds)
  694. clearInterval(_this.data.templTiem)
  695. _this.setData({
  696. showhieRq: true
  697. })
  698. }
  699. _this.setData({
  700. templTiem: inre
  701. })
  702. }, 1000)
  703. }
  704. _this.createQrCode(url, "qrcode", 350, 350);
  705. }).catch(err => {
  706. tt.showToast({
  707. title: err.message,
  708. icon: 'none',
  709. duration: 2000,
  710. mask: false
  711. });
  712. })
  713. },
  714. goPaySnapshoot(e) {
  715. let id = e.currentTarget.dataset.id;
  716. tt.navigateTo({
  717. url: `/pages/paySnapshoot/paySnapshoot?id=${id}`,
  718. success: (res) => {
  719. },
  720. fail: (res) => {
  721. },
  722. });
  723. },
  724. powerDrawer: function (e) {
  725. let that = this;
  726. console.log(e)
  727. // couponOrderStatus
  728. // 0 未使用
  729. // 1 已使用
  730. // 2 已过期
  731. // 3 已经退款
  732. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  733. tt.navigateTo({
  734. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  735. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  736. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  737. &contentType=${that.data.contentType}`
  738. });
  739. } else {
  740. tt.navigateTo({
  741. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  742. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  743. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  744. &contentType=${that.data.contentType}`
  745. });
  746. }
  747. },
  748. gotogame: function () {
  749. let that = this;
  750. tt.redirectTo({
  751. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  752. })
  753. },
  754. // 买完卡跳转到立即使用页面
  755. gotoUse: function () {
  756. tt.navigateTo({
  757. url: '/pages/cardorder/index/index'
  758. })
  759. },
  760. // 获取游戏
  761. getStaticGame(token) {
  762. let _this = this;
  763. Http.get({
  764. url: config.api.getGame,
  765. data: {
  766. triggleAction: 3 // 购买触发
  767. }
  768. }).then(res => {
  769. if (res.data.id) {
  770. _this.setData({
  771. showIf: true
  772. })
  773. }
  774. _this.setData({
  775. staticGamedata: res.data
  776. })
  777. })
  778. .catch(err => {
  779. console.log(err);
  780. })
  781. },
  782. goEvaluate() {
  783. let _this = this
  784. tt.rateAwemeOrder({
  785. orderId: _this.data.payOrderNo,
  786. success({
  787. result
  788. }) {
  789. console.log(result);
  790. if (result) {
  791. tt.navigateBack({
  792. delta: 1,
  793. success: (res) => {
  794. },
  795. fail: (res) => {
  796. },
  797. });
  798. // 用户已经评价的逻辑
  799. } else {
  800. // 用户没有评价的逻辑
  801. }
  802. },
  803. fail(err) {
  804. console.log(err);
  805. },
  806. });
  807. },
  808. goIfEvaluate() {
  809. let _this = this
  810. Http.get({
  811. url: config.api.getchanId,
  812. data: {
  813. id: _this.data.order.couponOrderId,
  814. mallTenantId: this.data.mallTenantId || ''
  815. }
  816. }).then(res => {
  817. tt.canRateAwemeOrders({
  818. orderIds: [res.data.payOrderNo],
  819. success({
  820. result
  821. }) {
  822. console.log("result", result);
  823. _this.setData({
  824. evaluateFlag: result[0],
  825. payOrderNo: res.data.payOrderNo
  826. })
  827. },
  828. fail(err) {
  829. console.log(err);
  830. },
  831. });
  832. }).catch(err => {
  833. tt.showToast({
  834. title: err.message ? err.message : err.data, // 内容
  835. icon: "none"
  836. });
  837. })
  838. },
  839. /**
  840. * 生命周期函数--监听页面加载
  841. */
  842. onLoad: function (option) {
  843. let options = null
  844. if (option.params) {
  845. options = JSON.parse(option.params)
  846. } else {
  847. options = option
  848. }
  849. // this.getSeUrl()
  850. if (options.mallTenantId) {
  851. this.setData({
  852. mallTenantId: options.mallTenantId,
  853. })
  854. }
  855. this.setData({
  856. mouldType: app.globalData.mouldType
  857. })
  858. let that = this;
  859. // if (options.dingdan && options.dingdan == "order") {
  860. // }
  861. that.setData({
  862. orderId: options.orderId,
  863. });
  864. tt.hideShareMenu()
  865. if (options.cardIf) { //转赠 展示不需
  866. that.setData({
  867. cardIf: true
  868. })
  869. }
  870. tt.showLoading({
  871. title: "加载中"
  872. });
  873. this.getCouponMerchant() //获取可用商户
  874. },
  875. onShow: function () {
  876. let that = this;
  877. that.setData({
  878. showButton: false
  879. })
  880. that.updetail()
  881. this.getCouponMerchant() //获取可用商户
  882. if (tt.canIUse("microapp-trade-plugin")) {
  883. that.setData({
  884. canIUseRefund: true
  885. })
  886. console.log(that.data.canIUseRefund, 'canIUseRefund');
  887. }
  888. },
  889. getSeUrl() { //获取客服链接
  890. const openId = tt.getStorageSync('openId');
  891. Http.post({
  892. url: config.api.getServiceUrl,
  893. data: {
  894. appid: app.globalData.appId,
  895. openid: openId
  896. }
  897. }).then(res => {
  898. this.setData({
  899. serviceUrl: res.data ? res.data : ''
  900. })
  901. if (res.data) {
  902. tt.setStorageSync('serviceData', res.data);
  903. }
  904. })
  905. },
  906. goWebView() {
  907. let _this = this
  908. tt.navigateTo({
  909. url: `/pages/serviceWebView/serviceWebView`,
  910. success: (res) => {
  911. },
  912. fail: (res) => {
  913. },
  914. });
  915. },
  916. /**
  917. * 去拼团
  918. */
  919. goToOrderGroup(orderId, orderGroupId, _this) {
  920. let that = this;
  921. // 支付成功
  922. Http.post({
  923. url: config.api.toOrderGroup,
  924. data: {
  925. id: orderGroupId,
  926. orderId,
  927. couponId: _this.data.order.productId
  928. }
  929. })
  930. .then(res => {
  931. tt.redirectTo({
  932. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}&mallTenantId=${this.data.mallTenantId}`
  933. });
  934. })
  935. .catch(err => {
  936. console.log(err);
  937. })
  938. // return;
  939. },
  940. /**
  941. * 发起支付
  942. */
  943. orderFunc(e) {
  944. var that = this;
  945. const orderId = "" + that.data.orderId;
  946. that.setData({
  947. showButton: true
  948. })
  949. tt.showLoading({
  950. title: "加载中..."
  951. });
  952. // if (true) {//兼容不支持支付2.0 js-api !tt.canIUse('createOrder')
  953. if (that.data.order.payment > 0) {
  954. if (tt.canIUse('createOrder')) { //支付2.0 js-api
  955. const outOrderNo = that.data.outOrderNo
  956. console.log(outOrderNo, "outOrderNo");
  957. Http.post({
  958. url: config.api.payOrderCreate_2,
  959. data: {
  960. // composeOrderId: outOrderNo
  961. orderId: outOrderNo,
  962. composeOrderType: that.data.composeOrderType,
  963. mallTenantId: this.data.mallTenantId || ''
  964. }
  965. }).then(res => {
  966. if (res.data.createPay) {
  967. let tempCallbackData = res.data.callbackData
  968. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  969. let options = {
  970. callbackData: tempCallbackData,
  971. goodsList: res.data.goodsList,
  972. payment: res.data.payment,
  973. success: res => {
  974. tt.hideLoading();
  975. that.setData({
  976. showbutton: false,
  977. })
  978. const {
  979. orderId,
  980. outOrderNo
  981. } = res;
  982. // that.setData({
  983. // orderId,
  984. // outOrderNo
  985. // });
  986. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  987. },
  988. fail: res => {
  989. const {
  990. orderId,
  991. outOrderNo,
  992. errNo,
  993. errMsg,
  994. errLogId
  995. } = res;
  996. if (errLogId) {
  997. tt.hideLoading();
  998. that.setData({
  999. showbutton: false,
  1000. })
  1001. console.log('预下单失败', errNo, errMsg, errLogId);
  1002. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  1003. tt.showToast({
  1004. title: tempErrmsg[tempErrmsg.length - 1],
  1005. icon: 'none',
  1006. duration: 2000,
  1007. mask: false
  1008. });
  1009. }
  1010. if (orderId || outOrderNo) {
  1011. tt.hideLoading();
  1012. that.setData({
  1013. showbutton: false,
  1014. })
  1015. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1016. console.log(that.payOrderUpdate, "payOrderUpdate");
  1017. tt.showToast({
  1018. title: "取消支付",
  1019. icon: 'none',
  1020. duration: 2000,
  1021. mask: false
  1022. });
  1023. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  1024. }
  1025. },
  1026. }
  1027. console.log(options, "options");
  1028. tt.createOrder(options)
  1029. } else {
  1030. tt.continueToPay({
  1031. outOrderNo: res.data.outOrderNo, // 外部订单号 2个订单号必填一个
  1032. success: res => {
  1033. // const { orderId, outOrderNo } = res;
  1034. // console.log('success res', res);
  1035. // console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  1036. that.setData({
  1037. showButton: false
  1038. })
  1039. tt.hideLoading();
  1040. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that); // 支付成功
  1041. },
  1042. fail: res => {
  1043. const {
  1044. orderId,
  1045. outOrderNo,
  1046. errNo,
  1047. errMsg,
  1048. errLogId
  1049. } = res;
  1050. if (errLogId) {
  1051. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  1052. that.setData({
  1053. showButton: false
  1054. })
  1055. tt.showToast({
  1056. title: errMsg,
  1057. icon: 'none',
  1058. duration: 2000,
  1059. mask: false
  1060. });
  1061. tt.hideLoading();
  1062. }
  1063. if (orderId || outOrderNo) {
  1064. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1065. tt.showToast({
  1066. title: errMsg,
  1067. icon: 'none',
  1068. duration: 2000,
  1069. mask: false
  1070. });
  1071. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail', that);
  1072. that.setData({
  1073. showButton: false
  1074. })
  1075. tt.hideLoading();
  1076. }
  1077. },
  1078. });
  1079. }
  1080. }).catch(err => {
  1081. tt.showToast({
  1082. title: err.message ? err.message : err.data, // 内容
  1083. icon: "none"
  1084. });
  1085. })
  1086. } else { //不支持支付2.0 js-api
  1087. tt.showToast({
  1088. title: '请升级抖音', // 内容
  1089. icon: "none"
  1090. });
  1091. return
  1092. // 支付金额不为0
  1093. Http.post({
  1094. url: config.api.payOrderCreate,
  1095. data: {
  1096. orderId: orderId,
  1097. composeOrderType: that.data.composeOrderType
  1098. }
  1099. }).then(res => {
  1100. var payOrderId = "" + res.data.outOrderNo;
  1101. tt.hideLoading();
  1102. tt.pay({
  1103. service: 5,
  1104. orderInfo: {
  1105. order_id: res.data.payOrderId,
  1106. order_token: res.data.payOrderToken,
  1107. },
  1108. success: res => {
  1109. tt.showLoading({
  1110. title: '订单正在处理中...',
  1111. })
  1112. if (res.code == 0) {
  1113. setTimeout(function () {
  1114. tt.hideLoading()
  1115. }, 5000)
  1116. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  1117. if (res.errMsg == "requestPayment:ok") {
  1118. if (that.data.order.type == 100) {
  1119. tt.setStorage({
  1120. key: 'couponNum2',
  1121. data: "couponNum2"
  1122. })
  1123. } else if (that.data.order.type != 5) {
  1124. tt.setStorage({
  1125. key: 'couponNum',
  1126. data: "couponNum"
  1127. })
  1128. }
  1129. }
  1130. } else if (res.code === 1) {
  1131. that.setData({
  1132. showButton: false
  1133. })
  1134. tt.hideLoading();
  1135. tt.showToast({
  1136. title: '支付超时', // 内容
  1137. icon: "none"
  1138. });
  1139. } else if (res.code === 2) {
  1140. that.setData({
  1141. showButton: false
  1142. })
  1143. tt.hideLoading();
  1144. tt.showToast({
  1145. title: '支付失败', // 内容
  1146. icon: "none"
  1147. });
  1148. } else if (res.code === 3) {
  1149. that.setData({
  1150. showButton: false
  1151. })
  1152. tt.hideLoading();
  1153. tt.showToast({
  1154. title: '支付关闭', // 内容
  1155. icon: "none"
  1156. });
  1157. } else if (res.code === 4) {
  1158. that.setData({
  1159. showButton: false
  1160. })
  1161. tt.hideLoading();
  1162. tt.showToast({
  1163. title: '支付取消', // 内容
  1164. icon: "none"
  1165. });
  1166. } else if (res.code === 9) {
  1167. that.setData({
  1168. showButton: false
  1169. })
  1170. tt.hideLoading();
  1171. tt.showToast({
  1172. title: '订单状态开发者自行获取', // 内容
  1173. icon: "none"
  1174. });
  1175. }
  1176. },
  1177. fail: res => {
  1178. that.setData({
  1179. showButton: false
  1180. })
  1181. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  1182. return;
  1183. },
  1184. });
  1185. }).catch(err => {
  1186. tt.hideLoading();
  1187. that.setData({
  1188. showButton: false
  1189. })
  1190. tt.showModal({
  1191. title: "抱歉",
  1192. content: err.message,
  1193. showCancel: false
  1194. })
  1195. });
  1196. }
  1197. } else {
  1198. // 免费券
  1199. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  1200. if (that.data.order.type == 100) {
  1201. tt.setStorage({
  1202. key: 'couponNum2',
  1203. data: "couponNum2"
  1204. })
  1205. } else if (that.data.order.type != "5") {
  1206. tt.setStorage({
  1207. key: 'couponNum',
  1208. data: "couponNum"
  1209. })
  1210. }
  1211. tt.showToast({
  1212. title: "支付成功",
  1213. duration: 2000,
  1214. image: imgurl.success.url,
  1215. });
  1216. }
  1217. // } else {//支持 支付2.0 js-api
  1218. // }
  1219. },
  1220. /**
  1221. * 支付订单更新
  1222. */
  1223. payOrderUpdate(orderId, payOrderId, status, reason, type, _this) {
  1224. // 支付成功
  1225. Http.post({
  1226. url: config.api.payOrderUpdate,
  1227. data: {
  1228. payOrderId: payOrderId,
  1229. composeOrderId: orderId,
  1230. status: status,
  1231. reason: reason,
  1232. mallTenantId: this.data.mallTenantId || ''
  1233. }
  1234. })
  1235. .then(res => {
  1236. tt.hideLoading();
  1237. _this.setData({
  1238. showButton: false
  1239. })
  1240. if (!type && type != 'free') {
  1241. tt.showToast({
  1242. title: "购买成功",
  1243. duration: 2000,
  1244. image: imgurl.success.url,
  1245. mask: false,
  1246. success: function () {
  1247. tt.showLoading({
  1248. title: "加载中..."
  1249. });
  1250. setTimeout(function () {
  1251. tt.hideLoading();
  1252. }, 1600);
  1253. setTimeout(() => {
  1254. console.log('Here1');
  1255. let url = ""
  1256. if (_this.data.orderFlag) {
  1257. tt.redirectTo({
  1258. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order}&mallTenantId=${that.data.mallTenantId}`
  1259. });
  1260. } else {
  1261. tt.redirectTo({
  1262. url: `/pages/order/detail/index?orderId=${orderId}}&mallTenantId=${that.data.mallTenantId}`
  1263. });
  1264. }
  1265. }, 1600);
  1266. }
  1267. });
  1268. } else if (type == 'free') {
  1269. console.log('Here2');
  1270. tt.redirectTo({
  1271. url: `/pages/order/detail/index?orderId=${orderId}}&mallTenantId=${that.data.mallTenantId}`
  1272. });
  1273. }
  1274. })
  1275. .catch(err => {
  1276. console.log(err)
  1277. if (!type) {
  1278. setTimeout(function () {
  1279. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  1280. }, 1500)
  1281. }
  1282. });
  1283. },
  1284. onUnload: function () {
  1285. let that = this;
  1286. clearInterval(that.data.setInter);
  1287. clearInterval(that.data.templTiem);
  1288. },
  1289. onHide: function () {
  1290. let that = this;
  1291. clearInterval(that.data.setInter);
  1292. clearInterval(that.data.templTiem);
  1293. },
  1294. });