抖音c端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1145 行
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. }
  628. }).then(res => {
  629. tt.canRateAwemeOrders({
  630. orderIds: [res.data.payOrderNo],
  631. success({
  632. result
  633. }) {
  634. console.log("result", result);
  635. _this.setData({
  636. evaluateFlag: result[0],
  637. payOrderNo: res.data.payOrderNo
  638. })
  639. },
  640. fail(err) {
  641. console.log(err);
  642. },
  643. });
  644. }).catch(err => {
  645. tt.showToast({
  646. title: err.message ? err.message : err.data, // 内容
  647. icon: "none"
  648. });
  649. })
  650. },
  651. /**
  652. * 生命周期函数--监听页面加载
  653. */
  654. onLoad: function (options) {
  655. this.getSeUrl()
  656. if (options.mallTenantId) {
  657. this.setData({
  658. mallTenantId: options.mallTenantId,
  659. })
  660. }
  661. this.setData({
  662. mouldType: app.globalData.mouldType
  663. })
  664. let that = this;
  665. // if (options.dingdan && options.dingdan == "order") {
  666. // }
  667. that.setData({
  668. orderId: options.orderId,
  669. });
  670. tt.hideShareMenu()
  671. if (options.cardIf) { //转赠 展示不需
  672. that.setData({
  673. cardIf: true
  674. })
  675. }
  676. tt.showLoading({
  677. title: "加载中"
  678. });
  679. this.getCouponMerchant() //获取可用商户
  680. },
  681. onShow: function () {
  682. let that = this;
  683. that.setData({
  684. showButton: false
  685. })
  686. that.updetail()
  687. },
  688. getSeUrl() { //获取客服链接
  689. const openId = tt.getStorageSync('openId');
  690. Http.post({
  691. url: config.api.getServiceUrl,
  692. data: {
  693. appid: app.globalData.appId,
  694. openid: openId
  695. }
  696. }).then(res => {
  697. this.setData({
  698. serviceUrl: res.data ? res.data : ''
  699. })
  700. if (res.data) {
  701. tt.setStorageSync('serviceData', res.data);
  702. }
  703. })
  704. },
  705. goWebView() {
  706. let _this = this
  707. tt.navigateTo({
  708. url: `/pages/serviceWebView/serviceWebView`,
  709. success: (res) => {
  710. },
  711. fail: (res) => {
  712. },
  713. });
  714. },
  715. /**
  716. * 去拼团
  717. */
  718. goToOrderGroup(orderId, orderGroupId, _this) {
  719. let that = this;
  720. // 支付成功
  721. Http.post({
  722. url: config.api.toOrderGroup,
  723. data: {
  724. id: orderGroupId,
  725. orderId,
  726. couponId: _this.data.order.productId
  727. }
  728. })
  729. .then(res => {
  730. tt.redirectTo({
  731. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}&mallTenantId=${this.data.mallTenantId}`
  732. });
  733. })
  734. .catch(err => {
  735. console.log(err);
  736. })
  737. // return;
  738. },
  739. /**
  740. * 发起支付
  741. */
  742. orderFunc(e) {
  743. var that = this;
  744. const orderId = "" + that.data.orderId;
  745. that.setData({
  746. showButton: true
  747. })
  748. tt.showLoading({
  749. title: "加载中..."
  750. });
  751. // if (true) {//兼容不支持支付2.0 js-api !tt.canIUse('createOrder')
  752. if (that.data.order.payment > 0) {
  753. if (tt.canIUse('createOrder')) { //支付2.0 js-api
  754. const outOrderNo = that.data.outOrderNo
  755. console.log(outOrderNo, "outOrderNo");
  756. Http.post({
  757. url: config.api.payOrderCreate_2,
  758. data: {
  759. // composeOrderId: outOrderNo
  760. orderId: outOrderNo,
  761. composeOrderType: that.data.composeOrderType,
  762. mallTenantId: this.data.mallTenantId || ''
  763. }
  764. }).then(res => {
  765. if (res.data.createPay) {
  766. let tempCallbackData = res.data.callbackData
  767. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  768. let options = {
  769. callbackData: tempCallbackData,
  770. goodsList: res.data.goodsList,
  771. payment: res.data.payment,
  772. success: res => {
  773. tt.hideLoading();
  774. that.setData({
  775. showbutton: false,
  776. })
  777. const {
  778. orderId,
  779. outOrderNo
  780. } = res;
  781. // that.setData({
  782. // orderId,
  783. // outOrderNo
  784. // });
  785. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  786. },
  787. fail: res => {
  788. const {
  789. orderId,
  790. outOrderNo,
  791. errNo,
  792. errMsg,
  793. errLogId
  794. } = res;
  795. if (errLogId) {
  796. tt.hideLoading();
  797. that.setData({
  798. showbutton: false,
  799. })
  800. console.log('预下单失败', errNo, errMsg, errLogId);
  801. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  802. tt.showToast({
  803. title: tempErrmsg[tempErrmsg.length - 1],
  804. icon: 'none',
  805. duration: 2000,
  806. mask: false
  807. });
  808. }
  809. if (orderId || outOrderNo) {
  810. tt.hideLoading();
  811. that.setData({
  812. showbutton: false,
  813. })
  814. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  815. console.log(that.payOrderUpdate, "payOrderUpdate");
  816. tt.showToast({
  817. title: "取消支付",
  818. icon: 'none',
  819. duration: 2000,
  820. mask: false
  821. });
  822. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  823. }
  824. },
  825. }
  826. console.log(options, "options");
  827. tt.createOrder(options)
  828. } else {
  829. tt.continueToPay({
  830. outOrderNo: res.data.outOrderNo, // 外部订单号 2个订单号必填一个
  831. success: res => {
  832. // const { orderId, outOrderNo } = res;
  833. // console.log('success res', res);
  834. // console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  835. that.setData({
  836. showButton: false
  837. })
  838. tt.hideLoading();
  839. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that); // 支付成功
  840. },
  841. fail: res => {
  842. const {
  843. orderId,
  844. outOrderNo,
  845. errNo,
  846. errMsg,
  847. errLogId
  848. } = res;
  849. if (errLogId) {
  850. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  851. that.setData({
  852. showButton: false
  853. })
  854. tt.showToast({
  855. title: errMsg,
  856. icon: 'none',
  857. duration: 2000,
  858. mask: false
  859. });
  860. tt.hideLoading();
  861. }
  862. if (orderId || outOrderNo) {
  863. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  864. tt.showToast({
  865. title: errMsg,
  866. icon: 'none',
  867. duration: 2000,
  868. mask: false
  869. });
  870. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail', that);
  871. that.setData({
  872. showButton: false
  873. })
  874. tt.hideLoading();
  875. }
  876. },
  877. });
  878. }
  879. }).catch(err => {
  880. tt.showToast({
  881. title: err.message ? err.message : err.data, // 内容
  882. icon: "none"
  883. });
  884. })
  885. } else { //不支持支付2.0 js-api
  886. tt.showToast({
  887. title: '请升级抖音', // 内容
  888. icon: "none"
  889. });
  890. return
  891. // 支付金额不为0
  892. Http.post({
  893. url: config.api.payOrderCreate,
  894. data: {
  895. orderId: orderId,
  896. composeOrderType: that.data.composeOrderType
  897. }
  898. }).then(res => {
  899. var payOrderId = "" + res.data.outOrderNo;
  900. tt.hideLoading();
  901. tt.pay({
  902. service: 5,
  903. orderInfo: {
  904. order_id: res.data.payOrderId,
  905. order_token: res.data.payOrderToken,
  906. },
  907. success: res => {
  908. tt.showLoading({
  909. title: '订单正在处理中...',
  910. })
  911. if (res.code == 0) {
  912. setTimeout(function () {
  913. tt.hideLoading()
  914. }, 5000)
  915. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  916. if (res.errMsg == "requestPayment:ok") {
  917. if (that.data.order.type == 100) {
  918. tt.setStorage({
  919. key: 'couponNum2',
  920. data: "couponNum2"
  921. })
  922. } else if (that.data.order.type != 5) {
  923. tt.setStorage({
  924. key: 'couponNum',
  925. data: "couponNum"
  926. })
  927. }
  928. }
  929. } else if (res.code === 1) {
  930. that.setData({
  931. showButton: false
  932. })
  933. tt.hideLoading();
  934. tt.showToast({
  935. title: '支付超时', // 内容
  936. icon: "none"
  937. });
  938. } else if (res.code === 2) {
  939. that.setData({
  940. showButton: false
  941. })
  942. tt.hideLoading();
  943. tt.showToast({
  944. title: '支付失败', // 内容
  945. icon: "none"
  946. });
  947. } else if (res.code === 3) {
  948. that.setData({
  949. showButton: false
  950. })
  951. tt.hideLoading();
  952. tt.showToast({
  953. title: '支付关闭', // 内容
  954. icon: "none"
  955. });
  956. } else if (res.code === 4) {
  957. that.setData({
  958. showButton: false
  959. })
  960. tt.hideLoading();
  961. tt.showToast({
  962. title: '支付取消', // 内容
  963. icon: "none"
  964. });
  965. } else if (res.code === 9) {
  966. that.setData({
  967. showButton: false
  968. })
  969. tt.hideLoading();
  970. tt.showToast({
  971. title: '订单状态开发者自行获取', // 内容
  972. icon: "none"
  973. });
  974. }
  975. },
  976. fail: res => {
  977. that.setData({
  978. showButton: false
  979. })
  980. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  981. return;
  982. },
  983. });
  984. }).catch(err => {
  985. tt.hideLoading();
  986. that.setData({
  987. showButton: false
  988. })
  989. tt.showModal({
  990. title: "抱歉",
  991. content: err.message,
  992. showCancel: false
  993. })
  994. });
  995. }
  996. } else {
  997. // 免费券
  998. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  999. if (that.data.order.type == 100) {
  1000. tt.setStorage({
  1001. key: 'couponNum2',
  1002. data: "couponNum2"
  1003. })
  1004. } else if (that.data.order.type != "5") {
  1005. tt.setStorage({
  1006. key: 'couponNum',
  1007. data: "couponNum"
  1008. })
  1009. }
  1010. tt.showToast({
  1011. title: "支付成功",
  1012. duration: 2000,
  1013. image: imgurl.success.url,
  1014. });
  1015. }
  1016. // } else {//支持 支付2.0 js-api
  1017. // }
  1018. },
  1019. /**
  1020. * 支付订单更新
  1021. */
  1022. payOrderUpdate(orderId, payOrderId, status, reason, type, _this) {
  1023. // 支付成功
  1024. Http.post({
  1025. url: config.api.payOrderUpdate,
  1026. data: {
  1027. payOrderId: payOrderId,
  1028. composeOrderId: orderId,
  1029. status: status,
  1030. reason: reason,
  1031. mallTenantId: this.data.mallTenantId || ''
  1032. }
  1033. })
  1034. .then(res => {
  1035. tt.hideLoading();
  1036. _this.setData({
  1037. showButton: false
  1038. })
  1039. if (!type && type != 'free') {
  1040. tt.showToast({
  1041. title: "购买成功",
  1042. duration: 2000,
  1043. image: imgurl.success.url,
  1044. mask: false,
  1045. success: function () {
  1046. tt.showLoading({
  1047. title: "加载中..."
  1048. });
  1049. setTimeout(function () {
  1050. tt.hideLoading();
  1051. }, 1600);
  1052. setTimeout(() => {
  1053. console.log('Here1');
  1054. let url = ""
  1055. if (_this.data.orderFlag) {
  1056. tt.redirectTo({
  1057. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order}&mallTenantId=${that.data.mallTenantId}`
  1058. });
  1059. } else {
  1060. tt.redirectTo({
  1061. url: `/pages/order/detail/index?orderId=${orderId}}&mallTenantId=${that.data.mallTenantId}`
  1062. });
  1063. }
  1064. }, 1600);
  1065. }
  1066. });
  1067. } else if (type == 'free') {
  1068. console.log('Here2');
  1069. tt.redirectTo({
  1070. url: `/pages/order/detail/index?orderId=${orderId}}&mallTenantId=${that.data.mallTenantId}`
  1071. });
  1072. }
  1073. })
  1074. .catch(err => {
  1075. console.log(err)
  1076. if (!type) {
  1077. setTimeout(function () {
  1078. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  1079. }, 1500)
  1080. }
  1081. });
  1082. },
  1083. onUnload: function () {
  1084. let that = this;
  1085. clearInterval(that.data.setInter);
  1086. clearInterval(that.data.templTiem);
  1087. },
  1088. onHide: function () {
  1089. let that = this;
  1090. clearInterval(that.data.setInter);
  1091. clearInterval(that.data.templTiem);
  1092. },
  1093. });