C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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