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

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