抖音c端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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