C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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