C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

893 wiersze
26 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. var config = require("../../../config/config.js");
  3. var app = getApp();
  4. const Http = require("../../../utils/HttpBasics");
  5. const util = require("../../../utils/util");
  6. const imgurl = require("../../../utils/imgurl");
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. navigationBarHeight,
  13. bannerUrl: imgurl.banner.url,
  14. wmhome: imgurl.wmhome.url,
  15. wmhelp: imgurl.wmhelp.url,
  16. chenggong: imgurl.chenggong.url,
  17. fail: imgurl.fail.url,
  18. data: null,
  19. from: null,
  20. day: null,
  21. hour: null,
  22. min: null,
  23. sec: null,
  24. showPage: false,
  25. discountStatus: null,
  26. disabled: false,
  27. display: "block!important",
  28. showButton1: false
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function(options) {
  34. if(app.globalData.token) {
  35. Http.get({
  36. url: config.api.checkUserStatus,
  37. data: {
  38. token: app.globalData.token
  39. }
  40. }).then(res => {
  41. Http.get({
  42. url: config.api.checkPhoneStatus,
  43. data: {}
  44. }).then(res => {
  45. let that = this;
  46. if (options.orderId || options.orderId && options.from == 'discount') {
  47. console.log(options, "options")
  48. if (options.from) {
  49. that.setData({
  50. orderId: options.orderId,
  51. composeOrderType: options.composeOrderType,
  52. from: "discount"
  53. })
  54. } else {
  55. that.setData({
  56. orderId: options.orderId,
  57. composeOrderType: options.composeOrderType,
  58. })
  59. }
  60. app.globalData.wmorder = options.orderId
  61. that.pressOrderDetail(options.orderId);
  62. }
  63. this.getUserInfo()
  64. }).catch(res => {
  65. wx.redirectTo({
  66. url: `/pages/getphoneInfo/index`
  67. });
  68. })
  69. }).catch(res => {
  70. wx.redirectTo({
  71. url: `/pages/getuserinfo/index`
  72. })
  73. })
  74. }else{
  75. app.tokenCallback = token =>{
  76. Http.get({
  77. url: config.api.checkUserStatus,
  78. data: {
  79. token: app.globalData.token
  80. }
  81. }).then(res => {
  82. Http.get({
  83. url: config.api.checkPhoneStatus,
  84. data: {}
  85. }).then(res => {
  86. let that = this;
  87. if (options.orderId || options.orderId && options.from == 'discount') {
  88. console.log(options, "options")
  89. if (options.from) {
  90. that.setData({
  91. orderId: options.orderId,
  92. composeOrderType: options.composeOrderType,
  93. from: "discount"
  94. })
  95. } else {
  96. that.setData({
  97. orderId: options.orderId,
  98. composeOrderType: options.composeOrderType,
  99. })
  100. }
  101. app.globalData.wmorder = options.orderId
  102. that.pressOrderDetail(options.orderId);
  103. }
  104. this.getUserInfo()
  105. }).catch(res => {
  106. app.globalData.type = "bg"
  107. wx.redirectTo({
  108. url: `/pages/getuserinfo/index?orderId=${options.orderId}&composeOrderType=${options.composeOrderType}`
  109. });
  110. })
  111. }).catch(res => {
  112. app.globalData.type = "bg"
  113. wx.redirectTo({
  114. url: `/pages/getuserinfo/index?orderId=${options.orderId}&composeOrderType=${options.composeOrderType}`
  115. })
  116. })
  117. }
  118. }
  119. },
  120. getUserInfo: function() {
  121. let that = this;
  122. // 获取用户信息
  123. Http.get({
  124. url: config.api.getScore,
  125. data: {}
  126. })
  127. .then(res => {
  128. console.log(res)
  129. that.setData({
  130. nickName: res.data.nickName,
  131. avatarUrl: res.data.avatarUrl
  132. })
  133. })
  134. },
  135. onShow: function() {
  136. let that = this;
  137. var todayDate = new Date().getTime();
  138. that.setData({
  139. todayDate: todayDate,
  140. showButton1: false
  141. })
  142. if (that.data.pressEndDate) {
  143. that.countdown(that.data.pressEndDate)
  144. }
  145. },
  146. goback: function() {
  147. wx.switchTab({
  148. url: '/index/index',
  149. })
  150. },
  151. /**
  152. * 更多砍价商品
  153. */
  154. gotomore: function() {
  155. wx.navigateTo({
  156. url: '/pages/bargain/bargain',
  157. })
  158. },
  159. /**
  160. * @param {砍价状态(1:我发起的砍价,2:未参与的砍价, 3:已参与的砍价)} orderId
  161. */
  162. getPressOrderStatus: function(orderId) {
  163. let that = this;
  164. Http.get({
  165. url: config.api.getPressOrderStatus,
  166. data: {
  167. orderId: orderId
  168. }
  169. })
  170. .then(res => {
  171. if (res.data.status == 1) {
  172. that.setData({
  173. discountStatus: 1
  174. })
  175. } else if (res.data.status == 2) {
  176. that.setData({
  177. discountStatus: 2
  178. })
  179. } else if (res.data.status == 3) {
  180. that.setData({
  181. discountStatus: 3
  182. })
  183. }
  184. wx.stopPullDownRefresh();
  185. })
  186. .catch(err => {
  187. console.log(err)
  188. wx.stopPullDownRefresh();
  189. wx.showToast({
  190. title: err.errMsg,
  191. icon: "none"
  192. })
  193. })
  194. },
  195. helpDiscount: function() {
  196. let that = this;
  197. that.pressOrderJoin(that.data.orderId);
  198. },
  199. //参与砍价
  200. pressOrderJoin: function(orderId) {
  201. let that = this;
  202. Http.post({
  203. url: config.api.pressOrderJoin,
  204. data: {
  205. orderId: orderId
  206. }
  207. })
  208. .then(res => {
  209. console.log(res);
  210. // id 是订单号
  211. that.pressOrderDetail(orderId);
  212. })
  213. .catch(err => {
  214. console.log(err)
  215. wx.showToast({
  216. title: err.message,
  217. icon: "none"
  218. })
  219. })
  220. },
  221. // 订单详情
  222. pressOrderDetail: function(orderId) {
  223. let that = this;
  224. Http.get({
  225. url: config.api.pressOrderDetail,
  226. data: {
  227. orderId: orderId
  228. }
  229. })
  230. .then(res => {
  231. console.log(res);
  232. res.data.orderPressList.map(file => {
  233. file.createDate = diffTime(file.createDate)
  234. })
  235. that.countdown(res.data.pressEndDate);
  236. that.setData({
  237. pressEndDate: res.data.pressEndDate
  238. })
  239. res.data.orderPressList.map(file => {
  240. compare(file.first);
  241. })
  242. console.log(res.data.orderPressList.sort(compare('first')))
  243. that.setData({
  244. data: res.data,
  245. already: (res.data.price / 100 - res.data.salePrice / 100 - res.data.pressCurrentValue / 100).toFixed(2),
  246. remain: (res.data.pressCurrentValue / 100).toFixed(2),
  247. showPage: true
  248. })
  249. that.getPressOrderStatus(orderId);
  250. })
  251. .catch(err => {
  252. wx.showToast({
  253. title: err.message,
  254. icon: "none"
  255. })
  256. wx.stopPullDownRefresh();
  257. })
  258. },
  259. setIntervalTime(end_time) {
  260. let that = this;
  261. var EndTime = end_time;
  262. var NowTime = new Date().getTime();
  263. var total_micro_second = EndTime - NowTime || [];
  264. // 渲染倒计时时钟
  265. let obj = that.dateformat(total_micro_second);
  266. if (total_micro_second > 0) {
  267. that.setData({
  268. clock: obj,
  269. day: obj.a1,
  270. hour: obj.b1,
  271. min: obj.c1,
  272. sec: obj.d1,
  273. })
  274. } else {
  275. that.setData({
  276. clock: "00",
  277. day: "00",
  278. hour: "00",
  279. min: "00",
  280. sec: "00",
  281. })
  282. //如果倒计时结束,需要重新查询一下券的状态
  283. // 给getDetail一个标识
  284. }
  285. total_micro_second -= 1000;
  286. },
  287. countdown: function(end_time) {
  288. let that = this;
  289. that.setIntervalTime(end_time);
  290. that.data.setInterval = setInterval(function() {
  291. that.setIntervalTime(end_time);
  292. }, 1000)
  293. },
  294. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  295. dateformat(micro_second) {
  296. // 总秒数
  297. var second = Math.floor(micro_second / 1000);
  298. // 天数
  299. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  300. // 小时
  301. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  302. // 分钟
  303. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  304. // 秒
  305. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  306. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  307. return {
  308. a1: day,
  309. b1: hr,
  310. c1: min,
  311. d1: sec
  312. }
  313. },
  314. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  315. let that = this;
  316. console.log(that)
  317. console.log(_this)
  318. // 支付成功
  319. Http.post({
  320. url: config.api.payOrderUpdate,
  321. data: {
  322. payOrderId: payOrderId,
  323. composeOrderId: orderId,
  324. status: status,
  325. reason: reason
  326. }
  327. })
  328. .then(res => {
  329. wx.hideLoading();
  330. _this.setData({
  331. display: "none!important",
  332. })
  333. // 有价券
  334. if (!type && type != 'free') {
  335. wx.navigateTo({
  336. url: `/pages/order/detail/index?orderId=${
  337. orderId
  338. }`
  339. });
  340. } else if (type == 'free') {
  341. wx.navigateTo({
  342. url: `/pages/order/detail/index?orderId=${
  343. orderId
  344. }`
  345. });
  346. }
  347. })
  348. .catch(err => {
  349. console.log(err);
  350. if (!type) {
  351. setTimeout(function() {
  352. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  353. }, 2000)
  354. }
  355. })
  356. },
  357. /**
  358. * 按原价付款
  359. */
  360. // orderFunc1(e) {
  361. // var that = this;
  362. // let formId = e.detail.formId;
  363. // that.setData({
  364. // showButton: true
  365. // })
  366. // Http.get({
  367. // url: config.api.checkPhoneStatus,
  368. // data: {}
  369. // })
  370. // .then(res => {
  371. // that.setData({
  372. // showButton: false
  373. // })
  374. // /**
  375. // * orderSave 下单
  376. // */
  377. // var data = {
  378. // couponChannelId:e.currentTarget.dataset.couponchannelid,
  379. // couponId:e.currentTarget.dataset.couponid,
  380. // formId:formId
  381. // }
  382. // return Http.post({
  383. // url: config.api.orderSave,
  384. // data: data
  385. // });
  386. // })
  387. // .catch(err => {
  388. // that.setData({
  389. // showButton: true
  390. // })
  391. // if (err.code == 2011) {
  392. // wx.showToast({
  393. // title: "商户信息没找到",
  394. // image: './../../../assets/images/fail.png',
  395. // duration: 2000,
  396. // mask: false
  397. // });
  398. // } else if (err.code == 2013) {
  399. // wx.showToast({
  400. // title: "商户信息禁用",
  401. // image: './../../../assets/images/fail.png',
  402. // duration: 2000,
  403. // mask: false
  404. // });
  405. // } else if (err.code == 3000) {
  406. // wx.showToast({
  407. // title: "库存不足",
  408. // image: './../../../assets/images/fail.png',
  409. // duration: 2000,
  410. // mask: false
  411. // });
  412. // } else if (err.code == 3001) {
  413. // wx.showToast({
  414. // title: "您已超过限购",
  415. // image: './../../../assets/images/fail.png',
  416. // duration: 2000,
  417. // mask: false
  418. // });
  419. // } else if (err.code == 3002) {
  420. // wx.showToast({
  421. // title: "订单失败",
  422. // image: './../../../assets/images/fail.png',
  423. // duration: 2000,
  424. // mask: false
  425. // });
  426. // } else if (err.code == 3003) {
  427. // wx.showToast({
  428. // title: "订单不存在",
  429. // image: './../../../assets/images/fail.png',
  430. // duration: 2000,
  431. // mask: false
  432. // });
  433. // } else if (err.code == 3004) {
  434. // wx.showToast({
  435. // title: "订单不存在",
  436. // image: './../../../assets/images/fail.png',
  437. // duration: 2000,
  438. // mask: false
  439. // });
  440. // } else if (err.code == 4003) {
  441. // wx.showToast({
  442. // title: "卡券已作废",
  443. // image: './../../../assets/images/fail.png',
  444. // duration: 2000,
  445. // mask: false
  446. // });
  447. // } else if (err.code == 3012) {
  448. // wx.showModal({
  449. // title: '提示',
  450. // content: "您有未支付订单进行支付",
  451. // showCancel: false,
  452. // success: function (res) {
  453. // console.log(res.confirm)
  454. // if (res.confirm) {
  455. // }
  456. // }
  457. // })
  458. // }else if (err.code == 11005) {
  459. // /**
  460. // * 将值传到用户手机号授权的页面
  461. // *
  462. // */
  463. // wx.redirectTo({
  464. // url: "/pages/getphoneInfo/index?couponChannelId=" +
  465. // that.data.couponChannelId +
  466. // "&couponId=" +
  467. // that.data.couponId
  468. // });
  469. // } else if (err.code == 11006) {
  470. // // 用户手机已加密
  471. // wx.redirectTo({
  472. // url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  473. // that.data.couponChannelId +
  474. // "&couponId=" +
  475. // that.data.couponId
  476. // });
  477. // } else {
  478. // wx.showToast({
  479. // title: err.message,
  480. // icon: 'none',
  481. // duration: 2000,
  482. // mask: false
  483. // });
  484. // }
  485. // }).then(res => {
  486. // console.log(res);
  487. // if (typeof(res) != "undefined") {
  488. // let orderId = "" + res.data.id;
  489. // that.setData({
  490. // orderId: orderId
  491. // });
  492. // if (e.currentTarget.dataset.saleprice / 100 > 0 || e.currentTarget.dataset.price / 100 > 0) {
  493. // /**
  494. // * 支付订单创建
  495. // */
  496. // Http.post({
  497. // url: config.api.payOrderCreate,
  498. // data: {
  499. // orderId: orderId
  500. // }
  501. // })
  502. // .then(res => {
  503. // var payOrderId = "" + res.data.payOrderId;
  504. // wx.hideLoading();
  505. // wx.requestPayment({
  506. // timeStamp: res.data.timeStamp,
  507. // nonceStr: res.data.nonceStr,
  508. // package: res.data.package,
  509. // signType: (res.data.signType) ? res.data.signType : "MD5",
  510. // paySign: res.data.paySign,
  511. // success: res => {
  512. // wx.showLoading({
  513. // title: '订单正在处理中...',
  514. // })
  515. // setTimeout(function() {
  516. // wx.hideLoading()
  517. // }, 5000)
  518. // that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  519. // if (res.errMsg == "requestPayment:ok") {
  520. // setTimeout(function() {
  521. // wx.hideLoading();
  522. // }, 2000);
  523. // /**
  524. // * 用户支付成功以后跳转到券包列表
  525. // */
  526. // if (that.data.cardType == 100) {
  527. // wx.setStorage({
  528. // key: 'couponNum2',
  529. // data: "couponNum2"
  530. // })
  531. // } else {
  532. // wx.setStorage({
  533. // key: 'couponNum',
  534. // data: "couponNum"
  535. // })
  536. // }
  537. // }
  538. // },
  539. // fail: res => {
  540. // /**
  541. // * 支付失败,需要更新订单的状态
  542. // */
  543. // that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  544. // that.setData({
  545. // showbutton: false
  546. // })
  547. // return;
  548. // },
  549. // complete: res => {}
  550. // });
  551. // /// End payment --------
  552. // })
  553. // .catch(err => {
  554. // console.log(err);
  555. // wx.showToast({
  556. // title: err.message,
  557. // icon: 'none',
  558. // duration: 2000,
  559. // mask: false
  560. // });
  561. // })
  562. // } else {
  563. // // 免费券
  564. // that.payOrderUpdate(orderId, "0", 1, '', 'free', that);
  565. // if (that.data.cardType == 100) {
  566. // wx.setStorage({
  567. // key: 'couponNum2',
  568. // data: "couponNum2"
  569. // })
  570. // } else {
  571. // wx.setStorage({
  572. // key: 'couponNum',
  573. // data: "couponNum"
  574. // })
  575. // }
  576. // }
  577. // }
  578. // })
  579. // },
  580. /**
  581. * 发起支付
  582. */
  583. orderFunc(e) {
  584. var that = this;
  585. that.setData({
  586. showButton1: true
  587. })
  588. Http.get({
  589. url: config.api.checkPhoneStatus,
  590. data: {}
  591. })
  592. .then(res => {
  593. that.setData({
  594. showButton1: false
  595. })
  596. if (typeof(res) != "undefined") {
  597. let orderId = "" + e.currentTarget.dataset.orderid;
  598. that.setData({
  599. orderId: orderId
  600. });
  601. if (e.currentTarget.dataset.saleprice / 100 > 0 || e.currentTarget.dataset.price / 100 > 0) {
  602. /**
  603. * 支付订单创建
  604. */
  605. Http.post({
  606. url: config.api.payOrderCreate,
  607. data: {
  608. orderId: orderId,
  609. composeOrderType: that.data.composeOrderType
  610. }
  611. })
  612. .then(res => {
  613. var payOrderId = "" + res.data.payOrderId;
  614. wx.hideLoading();
  615. wx.requestPayment({
  616. timeStamp: res.data.timeStamp,
  617. nonceStr: res.data.nonceStr,
  618. package: res.data.package,
  619. signType: (res.data.signType) ? res.data.signType : "MD5",
  620. paySign: res.data.paySign,
  621. success: res => {
  622. wx.showLoading({
  623. title: '订单正在处理中...',
  624. })
  625. setTimeout(function() {
  626. wx.hideLoading()
  627. }, 5000)
  628. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  629. if (res.errMsg == "requestPayment:ok") {
  630. setTimeout(function() {
  631. wx.hideLoading();
  632. }, 2000);
  633. /**
  634. * 用户支付成功以后跳转到券包列表
  635. */
  636. if (that.data.cardType == 100) {
  637. wx.setStorage({
  638. key: 'couponNum2',
  639. data: "couponNum2"
  640. })
  641. } else {
  642. wx.setStorage({
  643. key: 'couponNum',
  644. data: "couponNum"
  645. })
  646. }
  647. }
  648. },
  649. fail: res => {
  650. /**
  651. * 支付失败,需要更新订单的状态
  652. */
  653. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  654. that.setData({
  655. showbutton1: false
  656. })
  657. return;
  658. },
  659. complete: res => {}
  660. });
  661. /// End payment --------
  662. })
  663. .catch(err => {
  664. console.log(err);
  665. wx.showToast({
  666. title: err.message,
  667. icon: 'none',
  668. duration: 2000,
  669. mask: false
  670. });
  671. })
  672. } else {
  673. // 免费券
  674. that.payOrderUpdate(orderId, "0", 1, '', 'free', that);
  675. if (that.data.cardType == 100) {
  676. wx.setStorage({
  677. key: 'couponNum2',
  678. data: "couponNum2"
  679. })
  680. } else {
  681. wx.setStorage({
  682. key: 'couponNum',
  683. data: "couponNum"
  684. })
  685. }
  686. }
  687. }
  688. })
  689. .catch(err => {
  690. that.setData({
  691. showButton1: true
  692. })
  693. if (err.code == 2011) {
  694. wx.showToast({
  695. title: "商户信息没找到",
  696. image: './../../../assets/images/fail.png',
  697. duration: 2000,
  698. mask: false
  699. });
  700. } else if (err.code == 2013) {
  701. wx.showToast({
  702. title: "商户信息禁用",
  703. image: './../../../assets/images/fail.png',
  704. duration: 2000,
  705. mask: false
  706. });
  707. } else if (err.code == 3000) {
  708. wx.showToast({
  709. title: "库存不足",
  710. image: './../../../assets/images/fail.png',
  711. duration: 2000,
  712. mask: false
  713. });
  714. } else if (err.code == 3001) {
  715. wx.showToast({
  716. title: "您已超过限购",
  717. image: './../../../assets/images/fail.png',
  718. duration: 2000,
  719. mask: false
  720. });
  721. } else if (err.code == 3002) {
  722. wx.showToast({
  723. title: "订单失败",
  724. image: './../../../assets/images/fail.png',
  725. duration: 2000,
  726. mask: false
  727. });
  728. } else if (err.code == 3003) {
  729. wx.showToast({
  730. title: "订单不存在",
  731. image: './../../../assets/images/fail.png',
  732. duration: 2000,
  733. mask: false
  734. });
  735. } else if (err.code == 3004) {
  736. wx.showToast({
  737. title: "订单不存在",
  738. image: './../../../assets/images/fail.png',
  739. duration: 2000,
  740. mask: false
  741. });
  742. } else if (err.code == 4003) {
  743. wx.showToast({
  744. title: "卡券已作废",
  745. image: './../../../assets/images/fail.png',
  746. duration: 2000,
  747. mask: false
  748. });
  749. } else if (err.code == 3012) {
  750. wx.showModal({
  751. title: '提示',
  752. content: '您有未支付订单,请先进行支付',
  753. confirmText: "去支付",
  754. success: function(res) {
  755. console.log(res.confirm)
  756. if (res.confirm) {
  757. wx.navigateTo({
  758. url: '/pages/order/index/index?id=all',
  759. })
  760. }
  761. }
  762. })
  763. } else if (err.code == 11005) {
  764. /**
  765. * 将值传到用户手机号授权的页面
  766. *
  767. */
  768. wx.redirectTo({
  769. url: "/pages/getphoneInfo/index?couponChannelId=" +
  770. that.data.couponChannelId +
  771. "&couponId=" +
  772. that.data.couponId
  773. });
  774. } else if (err.code == 11006) {
  775. // 用户手机已加密
  776. wx.redirectTo({
  777. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  778. that.data.couponChannelId +
  779. "&couponId=" +
  780. that.data.couponId
  781. });
  782. } else {
  783. wx.showToast({
  784. title: err.message,
  785. icon: 'none',
  786. duration: 2000,
  787. mask: false
  788. });
  789. }
  790. })
  791. },
  792. onUnload: function() {
  793. let that = this;
  794. clearInterval(that.data.setInterval)
  795. },
  796. onHide: function() {
  797. let that = this;
  798. clearInterval(that.data.setInterval)
  799. },
  800. /**
  801. *
  802. * @param {朋友邀请砍价} e
  803. */
  804. barginAgain: function(e) {
  805. let that = this;
  806. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  807. let couponId = e.currentTarget.dataset.couponid;
  808. wx.navigateTo({
  809. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  810. })
  811. },
  812. /**
  813. * 刷新
  814. */
  815. onPullDownRefresh: function(e) {
  816. let that = this;
  817. console.log(app.globalData.wmorder);
  818. if (app.globalData.wmorder) {
  819. that.pressOrderDetail(app.globalData.wmorder);
  820. }
  821. },
  822. onShareAppMessage: function(options) {
  823. app.globalData.previewFlag = true
  824. var that = this;
  825. console.log(`/pages/index/index?orderId=${that.data.orderId}&from=${"discount"}&composeOrderType=${that.data.composeOrderType}`)
  826. var shareObj = {
  827. title: that.data.nickName + '邀请您帮砍' + that.data.data.title,
  828. path: `/pages/index/index?orderId=${that.data.orderId}&from=${"discount"}&composeOrderType=${that.data.composeOrderType}`,
  829. success: function(res) {
  830. if (res.errMsg == 'shareAppMessage:ok') {}
  831. },
  832. fail: function(error) {
  833. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  834. }
  835. };
  836. // 来自页面内的按钮的转发
  837. if (options.from == 'button') {
  838. // var orderId = options.target.dataset.orderid;
  839. shareObj.path = `/pages/index/index?orderId=${that.data.orderId}&from=${"discount"}&composeOrderType=${that.data.composeOrderType}`;
  840. }
  841. console.log(shareObj)
  842. // 返回shareObj
  843. // return shareObj;
  844. },
  845. })
  846. function diffTime(startDate) {
  847. var diff = new Date().getTime() - startDate;
  848. var days = Math.floor(diff / (24 * 3600 * 1000));
  849. var leave1 = diff % (24 * 3600 * 1000);
  850. var hours = Math.floor(leave1 / (3600 * 1000));
  851. var leave2 = leave1 % (3600 * 1000);
  852. var minutes = Math.floor(leave2 / (60 * 1000));
  853. var leave3 = leave2 % (60 * 1000);
  854. var seconds = Math.round(leave3 / 1000);
  855. var returnStr = seconds + "秒";
  856. if (minutes > 0) {
  857. returnStr = minutes + "分" + returnStr;
  858. }
  859. if (hours > 0) {
  860. returnStr = hours + "小时" + returnStr;
  861. }
  862. if (days > 0) {
  863. returnStr = days + "天" + returnStr;
  864. }
  865. if (returnStr.indexOf('-1') == -1) {
  866. return returnStr;
  867. } else {
  868. return '1秒'
  869. }
  870. }
  871. function compare(property) {
  872. return function(a, b) {
  873. var value1 = a[property];
  874. var value2 = b[property];
  875. return value2 - value1;
  876. }
  877. }