抖音c端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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