抖音小程序C端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

799 rindas
20 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&&(tempData.orderStatus != 0&&tempData.orderStatus != 2)) { //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. let inre = setInterval(() => {
  325. if (_this.data.expiredSeconds > 1) {
  326. _this.setData({
  327. expiredSeconds: _this.data.expiredSeconds - 1
  328. })
  329. // console.log("有效", _this.data.expiredSeconds)
  330. } else {
  331. // console.log("无效", _this.data.expiredSeconds)
  332. clearInterval(_this.data.templTiem)
  333. _this.setData({
  334. showhieRq: true
  335. })
  336. }
  337. }, 1000)
  338. _this.setData({
  339. templTiem: inre
  340. })
  341. _this.createQrCode(url, "qrcode", 350, 350);
  342. }).catch(err => {
  343. tt.showToast({
  344. title: err.message,
  345. icon: 'none',
  346. duration: 2000,
  347. mask: false
  348. });
  349. })
  350. },
  351. goPaySnapshoot(e) {
  352. let id = e.currentTarget.dataset.id;
  353. tt.navigateTo({
  354. url: `/pages/paySnapshoot/paySnapshoot?id=${id}`,
  355. success: (res) => {
  356. },
  357. fail: (res) => {
  358. },
  359. });
  360. },
  361. powerDrawer: function (e) {
  362. let that = this;
  363. console.log(e)
  364. // couponOrderStatus
  365. // 0 未使用
  366. // 1 已使用
  367. // 2 已过期
  368. // 3 已经退款
  369. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  370. tt.navigateTo({
  371. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  372. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  373. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  374. &contentType=${that.data.contentType}`
  375. });
  376. } else {
  377. tt.navigateTo({
  378. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  379. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  380. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  381. &contentType=${that.data.contentType}`
  382. });
  383. }
  384. },
  385. gotogame: function () {
  386. let that = this;
  387. tt.redirectTo({
  388. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  389. })
  390. },
  391. // 买完卡跳转到立即使用页面
  392. gotoUse: function () {
  393. tt.navigateTo({
  394. url: '/pages/cardorder/index/index'
  395. })
  396. },
  397. // 获取游戏
  398. getStaticGame(token) {
  399. let _this = this;
  400. Http.get({
  401. url: config.api.getGame,
  402. data: {
  403. triggleAction: 3 // 购买触发
  404. }
  405. }).then(res => {
  406. if (res.data.id) {
  407. _this.setData({
  408. showIf: true
  409. })
  410. }
  411. _this.setData({
  412. staticGamedata: res.data
  413. })
  414. })
  415. .catch(err => {
  416. console.log(err);
  417. })
  418. },
  419. goEvaluate(){
  420. let _this = this
  421. tt.rateAwemeOrder({
  422. orderId: _this.data.payOrderNo,
  423. success({ result }) {
  424. console.log(result);
  425. if (result) {
  426. tt.navigateBack({
  427. delta: 1,
  428. success: (res) => {
  429. },
  430. fail: (res) => {
  431. },
  432. });
  433. // 用户已经评价的逻辑
  434. } else {
  435. // 用户没有评价的逻辑
  436. }
  437. },
  438. fail(err) {
  439. console.log(err);
  440. },
  441. });
  442. },
  443. goIfEvaluate(){
  444. let _this = this
  445. Http.get({
  446. url:config.api.getchanId,
  447. data:{
  448. id:_this.data.order.couponOrderId
  449. }
  450. }).then(res=>{
  451. tt.canRateAwemeOrders({
  452. orderIds: [res.data.payOrderNo],
  453. success({ result }) {
  454. console.log("result", result);
  455. _this.setData({
  456. evaluateFlag:result[0],
  457. payOrderNo:res.data.payOrderNo
  458. })
  459. },
  460. fail(err) {
  461. console.log(err);
  462. },
  463. });
  464. }).catch(err=>{
  465. tt.showToast({
  466. title: err.message ? err.message : err.data, // 内容
  467. icon: "none"
  468. });
  469. })
  470. },
  471. /**
  472. * 生命周期函数--监听页面加载
  473. */
  474. onLoad: function (options) {
  475. this.getSeUrl()
  476. this.setData({
  477. mouldType: app.globalData.mouldType
  478. })
  479. let that = this;
  480. // if (options.dingdan && options.dingdan == "order") {
  481. // }
  482. that.setData({
  483. orderId: options.orderId,
  484. });
  485. tt.hideShareMenu()
  486. if (options.cardIf) {//转赠 展示不需
  487. that.setData({
  488. cardIf: true
  489. })
  490. }
  491. tt.showLoading({
  492. title: "加载中"
  493. });
  494. },
  495. onShow: function () {
  496. let that = this;
  497. that.setData({
  498. showButton: false
  499. })
  500. that.updetail()
  501. },
  502. getSeUrl(){//获取客服链接
  503. const openId = tt.getStorageSync('openId');
  504. Http.post({
  505. url:config.api.getServiceUrl,
  506. data:{
  507. appid: app.globalData.appId,
  508. openid: openId
  509. }
  510. }).then(res=>{
  511. this.setData({
  512. serviceUrl:res.data?res.data:''
  513. })
  514. if(res.data){
  515. tt.setStorageSync('serviceData', res.data);
  516. }
  517. })
  518. },
  519. goWebView(){
  520. let _this = this
  521. tt.navigateTo({
  522. url: `/pages/serviceWebView/serviceWebView`,
  523. success: (res) => {
  524. },
  525. fail: (res) => {
  526. },
  527. });
  528. },
  529. /**
  530. * 去拼团
  531. */
  532. goToOrderGroup(orderId, orderGroupId, _this) {
  533. let that = this;
  534. // 支付成功
  535. Http.post({
  536. url: config.api.toOrderGroup,
  537. data: {
  538. id: orderGroupId,
  539. orderId,
  540. couponId: _this.data.order.productId
  541. }
  542. })
  543. .then(res => {
  544. tt.redirectTo({
  545. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}`
  546. });
  547. })
  548. .catch(err => {
  549. console.log(err);
  550. })
  551. // return;
  552. },
  553. /**
  554. * 发起支付
  555. */
  556. orderFunc(e) {
  557. var that = this;
  558. that.setData({
  559. showButton: true
  560. })
  561. tt.showLoading({
  562. title: "加载中..."
  563. });
  564. const orderId = "" + that.data.orderId;
  565. if (that.data.order.payment > 0) {
  566. // 支付金额不为0
  567. Http.post({
  568. url: config.api.payOrderCreate,
  569. data: {
  570. orderId: orderId,
  571. composeOrderType: that.data.composeOrderType
  572. }
  573. }).then(res => {
  574. var payOrderId = "" + res.data.outOrderNo;
  575. tt.hideLoading();
  576. tt.pay({
  577. service: 5,
  578. orderInfo: {
  579. order_id: res.data.orderId,
  580. order_token: res.data.token,
  581. },
  582. success: res => {
  583. tt.showLoading({
  584. title: '订单正在处理中...',
  585. })
  586. if (res.code == 0) {
  587. setTimeout(function () {
  588. tt.hideLoading()
  589. }, 5000)
  590. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  591. if (res.errMsg == "requestPayment:ok") {
  592. if (that.data.order.type == 100) {
  593. tt.setStorage({
  594. key: 'couponNum2',
  595. data: "couponNum2"
  596. })
  597. } else if (that.data.order.type != 5) {
  598. tt.setStorage({
  599. key: 'couponNum',
  600. data: "couponNum"
  601. })
  602. }
  603. }
  604. } else if (res.code === 1) {
  605. that.setData({
  606. showButton: false
  607. })
  608. tt.hideLoading();
  609. tt.showToast({
  610. title: '支付超时', // 内容
  611. icon: "none"
  612. });
  613. } else if (res.code === 2) {
  614. that.setData({
  615. showButton: false
  616. })
  617. tt.hideLoading();
  618. tt.showToast({
  619. title: '支付失败', // 内容
  620. icon: "none"
  621. });
  622. } else if (res.code === 3) {
  623. that.setData({
  624. showButton: false
  625. })
  626. tt.hideLoading();
  627. tt.showToast({
  628. title: '支付关闭', // 内容
  629. icon: "none"
  630. });
  631. } else if (res.code === 4) {
  632. that.setData({
  633. showButton: false
  634. })
  635. tt.hideLoading();
  636. tt.showToast({
  637. title: '支付取消', // 内容
  638. icon: "none"
  639. });
  640. } else if (res.code === 9) {
  641. that.setData({
  642. showButton: false
  643. })
  644. tt.hideLoading();
  645. tt.showToast({
  646. title: '订单状态开发者自行获取', // 内容
  647. icon: "none"
  648. });
  649. }
  650. },
  651. fail: res => {
  652. that.setData({
  653. showButton: false
  654. })
  655. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  656. return;
  657. },
  658. });
  659. }).catch(err => {
  660. tt.hideLoading();
  661. that.setData({
  662. showButton: false
  663. })
  664. tt.showModal({
  665. title: "抱歉",
  666. content: err.message,
  667. showCancel: false
  668. })
  669. });
  670. } else {
  671. // 免费券
  672. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  673. if (that.data.order.type == 100) {
  674. tt.setStorage({
  675. key: 'couponNum2',
  676. data: "couponNum2"
  677. })
  678. } else if (that.data.order.type != "5") {
  679. tt.setStorage({
  680. key: 'couponNum',
  681. data: "couponNum"
  682. })
  683. }
  684. tt.showToast({
  685. title: "支付成功",
  686. duration: 2000,
  687. image: imgurl.success.url,
  688. });
  689. }
  690. },
  691. /**
  692. * 支付订单更新
  693. */
  694. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  695. // 支付成功
  696. Http.post({
  697. url: config.api.payOrderUpdate,
  698. data: {
  699. payOrderId: payOrderId,
  700. composeOrderId: orderId,
  701. status: status,
  702. reason: reason
  703. }
  704. })
  705. .then(res => {
  706. tt.hideLoading();
  707. _this.setData({
  708. showButton: false
  709. })
  710. if (!type && type != 'free') {
  711. tt.showToast({
  712. title: "购买成功",
  713. duration: 2000,
  714. image: imgurl.success.url,
  715. mask: false,
  716. success: function () {
  717. tt.showLoading({
  718. title: "加载中..."
  719. });
  720. setTimeout(function () {
  721. tt.hideLoading();
  722. }, 1600);
  723. setTimeout(() => {
  724. let url = ""
  725. if (_this.data.orderFlag) {
  726. tt.redirectTo({
  727. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order`
  728. });
  729. } else {
  730. tt.redirectTo({
  731. url: `/pages/order/detail/index?orderId=${orderId}`
  732. });
  733. }
  734. }, 1600);
  735. }
  736. });
  737. } else if (type == 'free') {
  738. tt.redirectTo({
  739. url: `/pages/order/detail/index?orderId=${orderId}`
  740. });
  741. }
  742. })
  743. .catch(err => {
  744. console.log(err)
  745. if (!type) {
  746. setTimeout(function () {
  747. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  748. }, 1500)
  749. }
  750. });
  751. },
  752. onUnload: function () {
  753. let that = this;
  754. clearInterval(that.data.setInter);
  755. clearInterval(that.data.templTiem);
  756. },
  757. onHide: function () {
  758. let that = this;
  759. clearInterval(that.data.setInter);
  760. clearInterval(that.data.templTiem);
  761. },
  762. });