choose-date.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. var wxyj = require('../../../public/wxyj.js')
  2. Page({
  3. data: {
  4. selected: 0,
  5. monthData: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, '', '', ''],
  6. calendarStatus: 0,
  7. tabbarStatus: 0,
  8. canChoose: true
  9. },
  10. initData() {
  11. if (this.data.quickPay) {
  12. var year = String(this.data.date).slice(0, 4)
  13. var month = String(this.data.date).slice(4)
  14. var y = Number(year), yearData = [y, y + 1, y + 2]
  15. this.setData({
  16. initMonth: Number(month),
  17. sYear: year,
  18. yearData
  19. })
  20. this.data.sMonth[0][0] = this.data.initMonth - 1
  21. this.data.sMonth[0][1] = this.data.initMonth + 6
  22. if (this.data.initMonth > 6) {
  23. this.data.sMonth[1][1] = this.data.initMonth - 6
  24. } else {
  25. this.data.sMonth[1][1] = 0
  26. }
  27. this.setData({
  28. sMonth: this.data.sMonth
  29. })
  30. } else {
  31. var year = String(wxyj.wxyjData.data.wxyj[0].month).slice(0, 4)
  32. var month = String(wxyj.wxyjData.data.wxyj[0].month).slice(4)
  33. var minNums = wxyj.wxyjData.data.wxyj[0].nums
  34. if (this.data.type == 0 || this.data.type == 2) {
  35. console.log(this.data.sMonth)
  36. var y = Number(year), yearData = [y, y + 1, y + 2]
  37. this.setData({
  38. initMonth: Number(month),
  39. sYear: year,
  40. minNums,
  41. yearData
  42. })
  43. this.data.sMonth[0][0] = this.data.initMonth - 1
  44. this.data.sMonth[0][1] = this.data.initMonth + 6
  45. if (this.data.initMonth > 6) {
  46. this.data.sMonth[1][1] = this.data.initMonth - 6
  47. } else {
  48. this.data.sMonth[1][1] = 0
  49. }
  50. this.setData({
  51. sMonth: this.data.sMonth
  52. })
  53. } else if (this.data.type == 1) {
  54. var y = Number(year), yearData = [y - 1, y]
  55. var n = wxyj.wxyjData.data.wxyj[0].addeds_num
  56. this.setData({
  57. initMonth: Number(month) - 1,
  58. sYear: year,
  59. minNums,
  60. yearData
  61. })
  62. if (n > this.data.initMonth) {
  63. this.data.sMonth[0][0] = 12 - n + this.data.initMonth
  64. this.data.sMonth[0][1] = 13
  65. this.data.sMonth[1][0] = 0
  66. this.data.sMonth[1][1] = this.data.initMonth + 1
  67. } else {
  68. this.data.sMonth[1][0] = this.data.initMonth - n
  69. this.data.sMonth[1][1] = this.data.initMonth + 1
  70. }
  71. this.setData({
  72. sMonth: this.data.sMonth
  73. })
  74. console.log(this.data.sMonth)
  75. } else if (this.data.type == 3) {
  76. var y = Number(year), yearData = [y - 1, y]
  77. var n = wxyj.wxyjData.data.wxyj[0].addedf_num
  78. this.setData({
  79. initMonth: Number(month) - 1,
  80. sYear: year,
  81. minNums,
  82. yearData
  83. })
  84. if (n > this.data.initMonth) {
  85. this.data.sMonth[0][0] = 12 - n + this.data.initMonth
  86. this.data.sMonth[0][1] = 13
  87. this.data.sMonth[1][0] = 0
  88. this.data.sMonth[1][1] = this.data.initMonth + 1
  89. } else {
  90. this.data.sMonth[1][0] = this.data.initMonth - n
  91. this.data.sMonth[1][1] = this.data.initMonth + 1
  92. }
  93. this.setData({
  94. sMonth: this.data.sMonth
  95. })
  96. }
  97. }
  98. },
  99. createAnimation() {
  100. var width, moveX
  101. swan.createSelectorQuery().select('#tabItem').boundingClientRect((rect) => {
  102. width = parseInt(rect.width)
  103. }).exec()
  104. swan.createSelectorQuery().select('#tabbar').boundingClientRect((rect) => {
  105. moveX = parseInt(rect.width) - width
  106. var animation = swan.createAnimation()
  107. animation.translateX(moveX).step();
  108. this.setData({
  109. selected: 1,
  110. animationData: animation.export()
  111. })
  112. }).exec()
  113. },
  114. choose(e) {
  115. if (e.currentTarget.dataset.status == "able") {
  116. if (this.data.quickPay) {
  117. var sy, sm
  118. sy = e.currentTarget.dataset.value.substring(0, 4)
  119. sm = e.currentTarget.dataset.value.slice(4)
  120. var page = getCurrentPages()
  121. var prevPage = page[page.length - 2]
  122. prevPage.setData({ year: sy, month: sm })
  123. this.setData({ canChoose: false, sy, sm })
  124. setTimeout(() => {
  125. swan.navigateBack()
  126. }, 1000)
  127. return
  128. }
  129. if (this.data.type == 0 || this.data.type == 2) {
  130. if (this.data.calendarStatus == 0) {
  131. var sy, sm
  132. sy = Number(e.currentTarget.dataset.value.substring(0, 4))
  133. sm = Number(e.currentTarget.dataset.value.slice(4))
  134. if (this.data.sYear == sy) {
  135. this.data.sMonth[0][1] = sm + 12
  136. this.data.sMonth[1][1] = sm
  137. } else {
  138. this.data.sMonth[1][1] = sm + 12
  139. this.data.sMonth[2][1] = sm
  140. }
  141. this.setData({
  142. calendarStatus: 1,
  143. tabbarStatus: 1,
  144. sMonth: this.data.sMonth,
  145. sy,
  146. sm
  147. })
  148. this.createAnimation()
  149. } else if (this.data.calendarStatus == 1) {
  150. var ey, em
  151. ey = Number(e.currentTarget.dataset.value.substring(0, 4))
  152. em = Number(e.currentTarget.dataset.value.slice(4))
  153. if (ey == this.data.sy && em < this.data.sm) {
  154. if (ey == this.data.sYear) {
  155. this.data.sMonth[0][1] = em + 12
  156. this.data.sMonth[1][1] = em
  157. this.data.sMonth[2][1] = 0
  158. } else {
  159. this.data.sMonth[1][1] = em + 12
  160. this.data.sMonth[2][1] = em
  161. }
  162. this.setData({
  163. calendarStatus: 1,
  164. tabbarStatus: 1,
  165. sMonth: this.data.sMonth,
  166. sy: ey,
  167. sm: em
  168. })
  169. } else if (ey < this.data.sy) {
  170. this.data.sMonth[0][1] = em + 12
  171. this.data.sMonth[1][1] = em
  172. this.data.sMonth[2][1] = 0
  173. console.log(this.data.sMonth)
  174. this.setData({
  175. calendarStatus: 1,
  176. tabbarStatus: 1,
  177. sMonth: this.data.sMonth,
  178. sy: ey,
  179. sm: em
  180. })
  181. } else {
  182. if (this.data.sy == ey) {
  183. wxyj.wxyjData.order.nums = em - this.data.sm + 1
  184. } else {
  185. wxyj.wxyjData.order.nums = 13 - this.data.sm + em
  186. }
  187. if (wxyj.wxyjData.order.nums < wxyj.wxyjData.data.wxyj[0].nums) {
  188. swan.showToast({
  189. title: '你选择的城市至少需要购买2个月',
  190. icon: 'none',
  191. mask: true
  192. });
  193. return
  194. }
  195. this.setData({
  196. calendarStatus: 2,
  197. tabbarStatus: 2,
  198. ey,
  199. em
  200. })
  201. }
  202. }
  203. } else {
  204. if (this.data.calendarStatus == 0) {
  205. var sy, sm
  206. sy = Number(e.currentTarget.dataset.value.substring(0, 4))
  207. sm = Number(e.currentTarget.dataset.value.slice(4))
  208. this.setData({
  209. calendarStatus: 1,
  210. tabbarStatus: 1,
  211. sMonth: this.data.sMonth,
  212. sy,
  213. sm
  214. })
  215. this.createAnimation()
  216. } else if (this.data.calendarStatus == 1) {
  217. var ey, em
  218. ey = Number(e.currentTarget.dataset.value.substring(0, 4))
  219. em = Number(e.currentTarget.dataset.value.slice(4))
  220. if (ey == this.data.sy) {
  221. if (em < this.data.sm) {
  222. this.setData({
  223. calendarStatus: 1,
  224. tabbarStatus: 1,
  225. sMonth: this.data.sMonth,
  226. sy: ey,
  227. sm: em
  228. })
  229. } else {
  230. this.setData({
  231. calendarStatus: 2,
  232. tabbarStatus: 2,
  233. sMonth: this.data.sMonth,
  234. ey,
  235. em
  236. })
  237. }
  238. } else if ((ey > this.data.sy)) {
  239. this.setData({
  240. calendarStatus: 2,
  241. tabbarStatus: 2,
  242. sMonth: this.data.sMonth,
  243. ey,
  244. em
  245. })
  246. } else {
  247. this.setData({
  248. calendarStatus: 1,
  249. tabbarStatus: 1,
  250. sMonth: this.data.sMonth,
  251. sy: ey,
  252. sm: em
  253. })
  254. }
  255. }
  256. }
  257. if (this.data.calendarStatus == 2) {
  258. if (this.data.sy == this.data.ey) {
  259. wxyj.wxyjData.order.nums = this.data.em - this.data.sm + 1
  260. } else {
  261. wxyj.wxyjData.order.nums = 13 - this.data.sm + this.data.em
  262. }
  263. wxyj.wxyjData.startTime = [this.data.sy, this.data.sm]
  264. wxyj.wxyjData.endTime = [this.data.ey, this.data.em]
  265. this.setData({ canChoose: false })
  266. setTimeout(() => {
  267. swan.navigateBack()
  268. }, 1000)
  269. }
  270. } else {
  271. return
  272. }
  273. },
  274. onLoad: function (res) {
  275. // 监听页面加载的生命周期函数
  276. this.setData({
  277. type: res.type,
  278. quickPay: res.quickPay,
  279. date: res.date,
  280. sMonth: [[0, 0], [0, 0], [0, 0]]
  281. })
  282. this.initData()
  283. },
  284. onReady: function () {
  285. // 监听页面初次渲染完成的生命周期函数
  286. },
  287. onShow: function () {
  288. // 监听页面显示的生命周期函数
  289. swan.setPageInfo && swan.setPageInfo({
  290. title: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  291. keywords: '我的社保,我的社保网,我的社保APP,社会保障,社保,社保代缴,公积金代缴,社会保险,五险一金,医保,医疗保险,公积金,养老,生育,工伤,失业,住房公积金,社保代理,代缴社保,公积金代理,查悦社保,大社保,亲亲小保,社保掌上通,招聘求职,创业,买房,贷款,计算器,人社局,摇号',
  292. description: '我的社保APP是为个人、企业提供社保代缴代扣、公积金代扣代缴、社保查询、公积金查询服务的名牌产品。解决个体工商户、自由职业者、待业人员、全职妈妈、创业者等的个人社保公积金断缴难题,同时解决贷款, 买房, 买车, 养老, 医疗, 生育, 医疗报销等难题。同时为企业提供全国专业社保代理和公积金代理。',
  293. articleTitle: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  294. release_date: '2019-02-23 20:00:00',
  295. success: function () {
  296. console.log('页面基础信息设置完成');
  297. },
  298. fail: function (res) {
  299. console.log('设置失败');
  300. },
  301. })
  302. wxyj.wxyjData.startTime = []
  303. wxyj.wxyjData.endTime = []
  304. },
  305. onHide: function () {
  306. // 监听页面隐藏的生命周期函数
  307. },
  308. onUnload: function () {
  309. // 监听页面卸载的生命周期函数
  310. },
  311. onPullDownRefresh: function () {
  312. // 监听用户下拉动作
  313. },
  314. onReachBottom: function () {
  315. // 页面上拉触底事件的处理函数
  316. },
  317. onShareAppMessage: function () {
  318. // 用户点击右上角转发
  319. }
  320. });