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

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