cheap.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. var businessT = require('../../../../tool/business-tool.js')
  2. var sysT = require('../../../../tool/sys-tool.js')
  3. var url = require('../../../../constant/url.js')
  4. import Net from '../../../../tool/net.js'
  5. var net = new Net()
  6. var app = getApp()
  7. Page({
  8. data: {
  9. ui: ['未使用', '已失效'],
  10. left: 0,
  11. className: 0,
  12. lineLeft: 120,
  13. list: [[], []],
  14. current: 0,
  15. choose: false,
  16. cheapData: [],
  17. status: false
  18. },
  19. getSysInfo() {
  20. var tabWidth
  21. swan.getSystemInfo({
  22. success: res => {
  23. this.setData({ width: res.screenWidth })
  24. },
  25. });
  26. swan.createSelectorQuery().select('#tabWrap').boundingClientRect((rect) => {
  27. tabWidth = rect.width
  28. }).exec()
  29. swan.createSelectorQuery().select('#tabItem').boundingClientRect((rect) => {
  30. this.setData({ moveX: tabWidth - rect.width })
  31. }).exec()
  32. },
  33. //点击tab
  34. ontab(e) {
  35. var n = e.currentTarget.dataset.class;
  36. const animation = swan.createAnimation()
  37. const animationLine = swan.createAnimation()
  38. if (n == 1) {
  39. animation.translateX(-this.data.width).step()
  40. animationLine.translateX(this.data.moveX).step()
  41. if (this.data.list[1].length == 0) {
  42. if (!this.data.status) {
  43. this.initData(n)
  44. this.data.status = true
  45. }
  46. }
  47. } else {
  48. animation.translateX(0).step()
  49. animationLine.translateX(0).step()
  50. }
  51. this.setData({ animationData: animation.export(), animationLine: animationLine.export(), current: n })
  52. },
  53. initData(expired) {
  54. swan.showLoading({
  55. title: '请稍后...',
  56. mask: true,
  57. });
  58. net.connectNeedLogin({
  59. url: url.app_host + url.getCashCoupon,
  60. data: { phone: app.globalData.userInfo.phone, page: 1, expired },
  61. success: (err, res) => {
  62. console.log(res)
  63. swan.hideLoading();
  64. this.getCashCouponListSuccess(res, expired)
  65. },
  66. failed: (err, res) => {
  67. swan.hideLoading();
  68. businessT.showFailTips(err)
  69. }
  70. })
  71. },
  72. getCashCouponListSuccess(res, expired) {
  73. var data = res.data.list
  74. if (data.length == 0) {
  75. this.data.list[expired] = []
  76. this.setData({ list: this.data.list })
  77. return
  78. }
  79. for (var index in data) {
  80. var item = data[index]
  81. if (item.status == 1 && item.expired == 0) {
  82. // item.end_time = '2019-03-17 00:00:01'
  83. var now = new Date().format('yyyy-MM-dd h:m:s')
  84. var nowDate = now.slice(0, 10)
  85. var endDate = item.end_time.slice(0, 10)
  86. if (nowDate == endDate) {
  87. item.p = '今天过期'
  88. } else {
  89. var tempNowDate = nowDate + ' 00:00:00'
  90. var tempEndDate = endDate + ' 00:00:00'
  91. var d = businessT.dateDiff('d', tempNowDate, tempEndDate)
  92. if (tempEndDate == item.end_time) {
  93. d -= 1
  94. }
  95. if (d == 0) {
  96. item.p = '今天过期'
  97. } else {
  98. item.p = '还有' + d + '天过期'
  99. }
  100. }
  101. } else {
  102. if (item.status == 1) {
  103. item.p = '已过期'
  104. } else {
  105. item.p = '已使用'
  106. }
  107. }
  108. item.end = item.end_time.slice(0, 10)
  109. }
  110. this.data.list[expired] = data
  111. this.setData({ list: this.data.list })
  112. },
  113. //选择优惠券
  114. choose(e) {
  115. let current = this.data.list[0][e.currentTarget.id]
  116. var i, cheapMoney = 0
  117. if (current.isSelected) {
  118. current.isSelected = false
  119. this.data.cheapData.forEach((item, index) => {
  120. if (current.id == item.id) {
  121. i = index
  122. }
  123. })
  124. this.data.cheapData.splice(i, 1)
  125. } else {
  126. if (this.data.cheapData.length < this.data.nums) {
  127. current.isSelected = true
  128. this.data.cheapData.push(current)
  129. } else {
  130. swan.showToast({
  131. title: '本次购买仅可选择' + this.data.nums + '张抵用券',
  132. icon: 'none',
  133. mask: false
  134. });
  135. }
  136. }
  137. this.data.cheapData.forEach((item, index) => {
  138. cheapMoney += item.coupon_price
  139. })
  140. if (this.data.cheapData.length) {
  141. this.setData({ chooesdCashCoupon: true })
  142. } else {
  143. this.setData({ chooesdCashCoupon: false })
  144. }
  145. this.setData({ list: this.data.list, cheapDataLength: this.data.cheapData.length, cheapMoney:cheapMoney.toFixed(2) })
  146. },
  147. goBack() {
  148. var page = getCurrentPages()
  149. var prePage = page[page.length - 2]
  150. prePage.setData({ cheapData: this.data.cheapData })
  151. swan.navigateBack()
  152. },
  153. onLoad: function (e) {
  154. // 监听页面加载的生命周期函数
  155. this.initData(this.data.current)
  156. if (e.status) {
  157. this.setData({
  158. choose: true,
  159. nums: e.nums,
  160. suffix: sysT.suffixOfClass()
  161. })
  162. }
  163. console.log(this.data.choose)
  164. },
  165. onReady: function () {
  166. // 监听页面初次渲染完成的生命周期函数
  167. this.getSysInfo()
  168. },
  169. onShow: function () {
  170. // 监听页面显示的生命周期函数
  171. swan.setPageInfo && swan.setPageInfo({
  172. title: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  173. keywords: '我的社保,我的社保网,我的社保APP,社会保障,社保,社保代缴,公积金代缴,社会保险,五险一金,医保,医疗保险,公积金,养老,生育,工伤,失业,住房公积金,社保代理,代缴社保,公积金代理,查悦社保,大社保,亲亲小保,社保掌上通,招聘求职,创业,买房,贷款,计算器,人社局,摇号',
  174. description: '我的社保APP是为个人、企业提供社保代缴代扣、公积金代扣代缴、社保查询、公积金查询服务的名牌产品。解决个体工商户、自由职业者、待业人员、全职妈妈、创业者等的个人社保公积金断缴难题,同时解决贷款, 买房, 买车, 养老, 医疗, 生育, 医疗报销等难题。同时为企业提供全国专业社保代理和公积金代理。',
  175. articleTitle: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  176. release_date: '2019-02-23 20:00:00',
  177. success: function () {
  178. console.log('页面基础信息设置完成');
  179. },
  180. fail: function (res) {
  181. console.log('设置失败');
  182. },
  183. })
  184. },
  185. onHide: function () {
  186. // 监听页面隐藏的生命周期函数
  187. },
  188. onUnload: function () {
  189. // 监听页面卸载的生命周期函数
  190. },
  191. onPullDownRefresh: function () {
  192. // 监听用户下拉动作
  193. },
  194. onReachBottom: function () {
  195. // 页面上拉触底事件的处理函数
  196. },
  197. onShareAppMessage: function () {
  198. // 用户点击右上角转发
  199. }
  200. });