抖音c端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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