抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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