抖音小程序C端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

802 lines
21 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. payOrderNo:"",//评价订单id
  14. evaluateFlag:false,//控制评价显隐藏
  15. serviceUrl:'',//客服外部链接
  16. dynamicRq: "",
  17. expiredSeconds: 0,
  18. showhieRq: false,
  19. mouldType: 0,
  20. showFlag: false,
  21. navigationBarHeight,
  22. upDataRqUrlF: imgurl.upDataRqF.url,
  23. succUrl: imgurl.succ.url,
  24. spcodeUrl: imgurl.spcode.url,
  25. chevronUrl: imgurl.chevron.url,
  26. teljpgUrl: imgurl.teljpg.url,
  27. newUrl: imgurl.new1.url,
  28. weixinTitle: imgurl.weixinTitle.url,
  29. lineUrl: imgurl.line.url,
  30. wm01Url: imgurl.wm01.url,
  31. wm02Url: imgurl.wm02.url,
  32. wm03Url: imgurl.wm03.url,
  33. wm04Url: imgurl.wm04.url,
  34. showModalStatus: false,
  35. flag: 0,
  36. order: null,
  37. orderId: null,
  38. //存储计时器
  39. setInter: "",
  40. mystatus: '',
  41. staticGamedata: {},
  42. showIf: false,
  43. showPage: false,
  44. showButton: false,
  45. cardDetail: null,
  46. supportTransfer: '',
  47. cardIf: false,
  48. contentType: 0,
  49. orderFlag: false, //判断是不是线上配送
  50. },
  51. copeCode(e) {
  52. let code = e.currentTarget.dataset.text
  53. tt.setClipboardData({
  54. data: code,
  55. success: function () {
  56. tt.showToast({
  57. title: '复制成功',
  58. icon: "none"
  59. })
  60. }
  61. })
  62. },
  63. gokuaidi(e) {
  64. let nu = e.currentTarget.dataset.nu
  65. tt.navigateToMiniProgram({
  66. appId: 'wx6885acbedba59c14',
  67. path: `pages/result/result?nu=${nu}&com=&querysource=third_xcx`
  68. })
  69. },
  70. setShow() {
  71. this.setData({
  72. showFlag: true
  73. })
  74. },
  75. hieShow() {
  76. this.setData({
  77. showFlag: false
  78. })
  79. },
  80. goDetail() {
  81. tt.navigateTo({
  82. url: `/pages/coupon/detail/index?couponChannelId=${this.data.order.couponChannelId}`,
  83. success: (res) => {
  84. },
  85. fail: (res) => {
  86. },
  87. });
  88. },
  89. refund(){//退款
  90. Http.post({
  91. url:config.api.refund,
  92. data:{
  93. orderId:this.data.order.id
  94. }
  95. }).then(res=>{
  96. tt.navigateTo({
  97. url: `/pages/refund/refund?id=${this.data.order.id}`,
  98. success: (res) => {
  99. },
  100. fail: (res) => {
  101. },
  102. });
  103. }).catch(err=>{
  104. tt.showToast({
  105. title: err.message ? err.message : err.data, // 内容
  106. icon: "none"
  107. });
  108. })
  109. },
  110. goRefund(e) {
  111. let this_ = this
  112. if(this_.data.order.couponOrderStatus==0){
  113. tt.showModal({
  114. title: "申请退款",
  115. content: "提交申请退款",
  116. confirmText: "确定",
  117. success(res) {
  118. if (res.confirm) {
  119. this_.refund()
  120. console.log("confirm, continued");
  121. } else if (res.cancel) {
  122. console.log("cancel, cold");
  123. } else {
  124. // what happend?
  125. }
  126. },
  127. fail(res) {
  128. console.log(`showModal调用失败`);
  129. },
  130. });
  131. }else if(this_.data.order.couponOrderStatus==3){//退款中
  132. tt.navigateTo({
  133. url: `/pages/refund/refund?id=${this.data.order.id}`,
  134. success: (res) => {
  135. },
  136. fail: (res) => {
  137. },
  138. });
  139. }
  140. },
  141. //刷新订单
  142. updetail() {
  143. let that = this
  144. let url = config.api.orderDetail
  145. Http.get({
  146. url: url,
  147. data: {
  148. orderId: this.data.orderId
  149. }
  150. }).then(res => {
  151. tt.hideLoading();
  152. var createDate = util.formatTime(res.data.orders[0].createDate, "yyyy-MM-dd hh:mm:ss");
  153. let tempData = res.data.orders[0]
  154. tempData.deliveryInfo = tempData.deliveryInfo ? JSON.parse(tempData.deliveryInfo) : ""
  155. tempData.itemGroup = tempData.itemGroup ? JSON.parse(tempData.itemGroup) : ""
  156. tempData.validStartDate = util.formatTime(tempData.validStartDate, "yyyy-MM-dd")
  157. tempData.validEndDate = util.formatTime(tempData.validEndDate, "yyyy-MM-dd")
  158. that.setData({
  159. order: tempData,
  160. showPage: true,
  161. createDate: createDate,
  162. composeOrderType: tempData.composeOrderType,
  163. contentType: tempData.contentType ? tempData.contentType : 0,
  164. orderFlag: tempData.type == 11 ? true : false ,//判断是不是线上配送
  165. })
  166. if (tempData.couponOrderId) { //0未付款 1已支付 2已取消 3退款中 4已退款
  167. that.setRq()
  168. // that.upStatus()
  169. let setInter = setInterval(() => {
  170. if (tempData.couponOrderStatus == 0) {
  171. Http.get({
  172. url: config.api.getStatus,
  173. data: {
  174. couponOrderId: tempData.couponOrderId
  175. }
  176. }).then(res => {
  177. console.log(res);
  178. that.setData({
  179. couponOrderStatus: res.data.CouponOrderStatus
  180. });
  181. if (res.data.CouponOrderStatus == 1 || res.data.CouponOrderStatus == 3) {
  182. /**
  183. * 动态改变上一级页面的核销状态
  184. */
  185. // that.getStaticGame()
  186. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  187. clearInterval(that.data.setInter);
  188. clearInterval(that.data.templTiem);
  189. that.updetail()
  190. that.setData({
  191. mystatus: res.data.CouponOrderStatus
  192. });
  193. }
  194. })
  195. .catch(err => {
  196. tt.showToast({
  197. title: err.errMsg,
  198. icon: 'none',
  199. duration: 2000,
  200. mask: false
  201. });
  202. })
  203. }
  204. }, 2000);
  205. that.setData({
  206. setInter: setInter
  207. })
  208. }
  209. if(tempData.couponOrderStatus&&tempData.couponOrderStatus==1){//核销后
  210. that.goIfEvaluate()//判断订单是否能评价
  211. }
  212. })
  213. .catch(error => {
  214. tt.hideLoading();
  215. tt.showModal({
  216. title: '提示',
  217. content: error.errMsg,
  218. showCancel: false
  219. })
  220. })
  221. },
  222. //确认收货
  223. verify() {
  224. Http.post({
  225. url: config.api.verify,
  226. data: {
  227. couponOrderId: this.data.order.couponOrderId
  228. }
  229. }).then(res => {
  230. tt.showToast({
  231. title: '签收成功',
  232. icon: "none"
  233. })
  234. this.updetail()
  235. }).catch(err => {
  236. tt.showModal({
  237. title: '提示',
  238. content: err.message ? err.message : err.data,
  239. showCancel: false
  240. })
  241. })
  242. },
  243. phone: function (e) {
  244. let that = this;
  245. console.log(e);
  246. tt.makePhoneCall({
  247. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  248. });
  249. },
  250. /**
  251. * 跳转到门店列表的详情页面
  252. */
  253. gotoDetail(e) {
  254. tt.navigateTo({
  255. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  256. })
  257. },
  258. getUserInfo: function () {
  259. let that = this;
  260. // 获取用户信息
  261. Http.get({
  262. url: config.api.getScore,
  263. data: {}
  264. })
  265. .then(res => {
  266. console.log(res)
  267. that.setData({
  268. userName: res.data.nickName,
  269. avatarUrl: res.data.avatarUrl
  270. })
  271. })
  272. },
  273. onShareAppMessage: function (res) {
  274. app.globalData.previewFlag = true
  275. if (res.from === 'button') {
  276. console.log(res, 3333333333333333333333)
  277. // 来自页面内转发按钮
  278. let _this = this;
  279. return {
  280. title: _this.data.userName + '赠送您一张' + _this.data.order.title,
  281. 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,
  282. imageUrl: this.data.order.coverImg,
  283. success: function (res) {
  284. // 转发成功
  285. },
  286. fail: function (res) {
  287. // 转发失败
  288. }
  289. }
  290. } else {
  291. console.log(res, 444444444444444444)
  292. }
  293. },
  294. createQrCode: function (url, canvasId, cavW, cavH) {
  295. //调用插件中的draw方法,绘制二维码图片
  296. let that = this;
  297. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  298. that.setData({
  299. tempFilePath: res
  300. })
  301. });
  302. },
  303. setRq() {
  304. let _this = this
  305. _this.setData({
  306. showhieRq: false,
  307. })
  308. Http.get({//获取动态二维码
  309. url: config.api.dynamicId,
  310. data: {
  311. couponOrderId: _this.data.order.couponOrderId
  312. }
  313. }).then(res => {
  314. console.log(res, "res")
  315. _this.setData({
  316. dynamicRq: res.data.dynamicId,
  317. expiredSeconds: res.data.expiredSeconds
  318. })
  319. let url = JSON.stringify({
  320. END: "C",
  321. TYPE: "couponorder",
  322. ID: _this.data.dynamicRq
  323. })
  324. if(res.data.expiredSeconds==0){
  325. //倒计时为零直接显示券码
  326. }else{
  327. let inre = setInterval(() => {
  328. if (_this.data.expiredSeconds > 1) {
  329. _this.setData({
  330. expiredSeconds: _this.data.expiredSeconds - 1
  331. })
  332. // console.log("有效", _this.data.expiredSeconds)
  333. } else {
  334. // console.log("无效", _this.data.expiredSeconds)
  335. clearInterval(_this.data.templTiem)
  336. _this.setData({
  337. showhieRq: true
  338. })
  339. }
  340. _this.setData({
  341. templTiem: inre
  342. })
  343. }, 1000)
  344. }
  345. _this.createQrCode(url, "qrcode", 350, 350);
  346. }).catch(err => {
  347. tt.showToast({
  348. title: err.message,
  349. icon: 'none',
  350. duration: 2000,
  351. mask: false
  352. });
  353. })
  354. },
  355. goPaySnapshoot(e) {
  356. let id = e.currentTarget.dataset.id;
  357. tt.navigateTo({
  358. url: `/pages/paySnapshoot/paySnapshoot?id=${id}`,
  359. success: (res) => {
  360. },
  361. fail: (res) => {
  362. },
  363. });
  364. },
  365. powerDrawer: function (e) {
  366. let that = this;
  367. console.log(e)
  368. // couponOrderStatus
  369. // 0 未使用
  370. // 1 已使用
  371. // 2 已过期
  372. // 3 已经退款
  373. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  374. tt.navigateTo({
  375. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  376. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  377. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  378. &contentType=${that.data.contentType}`
  379. });
  380. } else {
  381. tt.navigateTo({
  382. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  383. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  384. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  385. &contentType=${that.data.contentType}`
  386. });
  387. }
  388. },
  389. gotogame: function () {
  390. let that = this;
  391. tt.redirectTo({
  392. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  393. })
  394. },
  395. // 买完卡跳转到立即使用页面
  396. gotoUse: function () {
  397. tt.navigateTo({
  398. url: '/pages/cardorder/index/index'
  399. })
  400. },
  401. // 获取游戏
  402. getStaticGame(token) {
  403. let _this = this;
  404. Http.get({
  405. url: config.api.getGame,
  406. data: {
  407. triggleAction: 3 // 购买触发
  408. }
  409. }).then(res => {
  410. if (res.data.id) {
  411. _this.setData({
  412. showIf: true
  413. })
  414. }
  415. _this.setData({
  416. staticGamedata: res.data
  417. })
  418. })
  419. .catch(err => {
  420. console.log(err);
  421. })
  422. },
  423. goEvaluate(){
  424. let _this = this
  425. tt.rateAwemeOrder({
  426. orderId: _this.data.payOrderNo,
  427. success({ result }) {
  428. console.log(result);
  429. if (result) {
  430. tt.navigateBack({
  431. delta: 1,
  432. success: (res) => {
  433. },
  434. fail: (res) => {
  435. },
  436. });
  437. // 用户已经评价的逻辑
  438. } else {
  439. // 用户没有评价的逻辑
  440. }
  441. },
  442. fail(err) {
  443. console.log(err);
  444. },
  445. });
  446. },
  447. goIfEvaluate(){
  448. let _this = this
  449. Http.get({
  450. url:config.api.getchanId,
  451. data:{
  452. id:_this.data.order.couponOrderId
  453. }
  454. }).then(res=>{
  455. tt.canRateAwemeOrders({
  456. orderIds: [res.data.payOrderNo],
  457. success({ result }) {
  458. console.log("result", result);
  459. _this.setData({
  460. evaluateFlag:result[0],
  461. payOrderNo:res.data.payOrderNo
  462. })
  463. },
  464. fail(err) {
  465. console.log(err);
  466. },
  467. });
  468. }).catch(err=>{
  469. tt.showToast({
  470. title: err.message ? err.message : err.data, // 内容
  471. icon: "none"
  472. });
  473. })
  474. },
  475. /**
  476. * 生命周期函数--监听页面加载
  477. */
  478. onLoad: function (options) {
  479. this.getSeUrl()
  480. this.setData({
  481. mouldType: app.globalData.mouldType
  482. })
  483. let that = this;
  484. // if (options.dingdan && options.dingdan == "order") {
  485. // }
  486. that.setData({
  487. orderId: options.orderId,
  488. });
  489. tt.hideShareMenu()
  490. if (options.cardIf) {//转赠 展示不需
  491. that.setData({
  492. cardIf: true
  493. })
  494. }
  495. tt.showLoading({
  496. title: "加载中"
  497. });
  498. },
  499. onShow: function () {
  500. let that = this;
  501. that.setData({
  502. showButton: false
  503. })
  504. that.updetail()
  505. },
  506. getSeUrl(){//获取客服链接
  507. const openId = tt.getStorageSync('openId');
  508. Http.post({
  509. url:config.api.getServiceUrl,
  510. data:{
  511. appid: app.globalData.appId,
  512. openid: openId
  513. }
  514. }).then(res=>{
  515. this.setData({
  516. serviceUrl:res.data?res.data:''
  517. })
  518. if(res.data){
  519. tt.setStorageSync('serviceData', res.data);
  520. }
  521. })
  522. },
  523. goWebView(){
  524. let _this = this
  525. tt.navigateTo({
  526. url: `/pages/serviceWebView/serviceWebView`,
  527. success: (res) => {
  528. },
  529. fail: (res) => {
  530. },
  531. });
  532. },
  533. /**
  534. * 去拼团
  535. */
  536. goToOrderGroup(orderId, orderGroupId, _this) {
  537. let that = this;
  538. // 支付成功
  539. Http.post({
  540. url: config.api.toOrderGroup,
  541. data: {
  542. id: orderGroupId,
  543. orderId,
  544. couponId: _this.data.order.productId
  545. }
  546. })
  547. .then(res => {
  548. tt.redirectTo({
  549. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}`
  550. });
  551. })
  552. .catch(err => {
  553. console.log(err);
  554. })
  555. // return;
  556. },
  557. /**
  558. * 发起支付
  559. */
  560. orderFunc(e) {
  561. var that = this;
  562. that.setData({
  563. showButton: true
  564. })
  565. tt.showLoading({
  566. title: "加载中..."
  567. });
  568. const orderId = "" + that.data.orderId;
  569. if (that.data.order.payment > 0) {
  570. // 支付金额不为0
  571. Http.post({
  572. url: config.api.payOrderCreate,
  573. data: {
  574. orderId: orderId,
  575. composeOrderType: that.data.composeOrderType
  576. }
  577. }).then(res => {
  578. var payOrderId = "" + res.data.outOrderNo;
  579. tt.hideLoading();
  580. tt.pay({
  581. service: 5,
  582. orderInfo: {
  583. order_id: res.data.orderId,
  584. order_token: res.data.token,
  585. },
  586. success: res => {
  587. tt.showLoading({
  588. title: '订单正在处理中...',
  589. })
  590. if (res.code == 0) {
  591. setTimeout(function () {
  592. tt.hideLoading()
  593. }, 5000)
  594. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  595. if (res.errMsg == "requestPayment:ok") {
  596. if (that.data.order.type == 100) {
  597. tt.setStorage({
  598. key: 'couponNum2',
  599. data: "couponNum2"
  600. })
  601. } else if (that.data.order.type != 5) {
  602. tt.setStorage({
  603. key: 'couponNum',
  604. data: "couponNum"
  605. })
  606. }
  607. }
  608. } else if (res.code === 1) {
  609. that.setData({
  610. showButton: false
  611. })
  612. tt.hideLoading();
  613. tt.showToast({
  614. title: '支付超时', // 内容
  615. icon: "none"
  616. });
  617. } else if (res.code === 2) {
  618. that.setData({
  619. showButton: false
  620. })
  621. tt.hideLoading();
  622. tt.showToast({
  623. title: '支付失败', // 内容
  624. icon: "none"
  625. });
  626. } else if (res.code === 3) {
  627. that.setData({
  628. showButton: false
  629. })
  630. tt.hideLoading();
  631. tt.showToast({
  632. title: '支付关闭', // 内容
  633. icon: "none"
  634. });
  635. } else if (res.code === 4) {
  636. that.setData({
  637. showButton: false
  638. })
  639. tt.hideLoading();
  640. tt.showToast({
  641. title: '支付取消', // 内容
  642. icon: "none"
  643. });
  644. } else if (res.code === 9) {
  645. that.setData({
  646. showButton: false
  647. })
  648. tt.hideLoading();
  649. tt.showToast({
  650. title: '订单状态开发者自行获取', // 内容
  651. icon: "none"
  652. });
  653. }
  654. },
  655. fail: res => {
  656. that.setData({
  657. showButton: false
  658. })
  659. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  660. return;
  661. },
  662. });
  663. }).catch(err => {
  664. tt.hideLoading();
  665. that.setData({
  666. showButton: false
  667. })
  668. tt.showModal({
  669. title: "抱歉",
  670. content: err.message,
  671. showCancel: false
  672. })
  673. });
  674. } else {
  675. // 免费券
  676. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  677. if (that.data.order.type == 100) {
  678. tt.setStorage({
  679. key: 'couponNum2',
  680. data: "couponNum2"
  681. })
  682. } else if (that.data.order.type != "5") {
  683. tt.setStorage({
  684. key: 'couponNum',
  685. data: "couponNum"
  686. })
  687. }
  688. tt.showToast({
  689. title: "支付成功",
  690. duration: 2000,
  691. image: imgurl.success.url,
  692. });
  693. }
  694. },
  695. /**
  696. * 支付订单更新
  697. */
  698. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  699. // 支付成功
  700. Http.post({
  701. url: config.api.payOrderUpdate,
  702. data: {
  703. payOrderId: payOrderId,
  704. composeOrderId: orderId,
  705. status: status,
  706. reason: reason
  707. }
  708. })
  709. .then(res => {
  710. tt.hideLoading();
  711. _this.setData({
  712. showButton: false
  713. })
  714. if (!type && type != 'free') {
  715. tt.showToast({
  716. title: "购买成功",
  717. duration: 2000,
  718. image: imgurl.success.url,
  719. mask: false,
  720. success: function () {
  721. tt.showLoading({
  722. title: "加载中..."
  723. });
  724. setTimeout(function () {
  725. tt.hideLoading();
  726. }, 1600);
  727. setTimeout(() => {
  728. let url = ""
  729. if (_this.data.orderFlag) {
  730. tt.redirectTo({
  731. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order`
  732. });
  733. } else {
  734. tt.redirectTo({
  735. url: `/pages/order/detail/index?orderId=${orderId}`
  736. });
  737. }
  738. }, 1600);
  739. }
  740. });
  741. } else if (type == 'free') {
  742. tt.redirectTo({
  743. url: `/pages/order/detail/index?orderId=${orderId}`
  744. });
  745. }
  746. })
  747. .catch(err => {
  748. console.log(err)
  749. if (!type) {
  750. setTimeout(function () {
  751. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  752. }, 1500)
  753. }
  754. });
  755. },
  756. onUnload: function () {
  757. let that = this;
  758. clearInterval(that.data.setInter);
  759. clearInterval(that.data.templTiem);
  760. },
  761. onHide: function () {
  762. let that = this;
  763. clearInterval(that.data.setInter);
  764. clearInterval(that.data.templTiem);
  765. },
  766. });