抖音c端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1275 строки
35 KiB

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