抖音c端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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