抖音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.

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