抖音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.

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