quick-purchase.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. var app = getApp()
  2. var publicData = require('../../../../constant/data.js')
  3. var businessT = require('../../../../tool/business-tool.js')
  4. var url = require('../../../../constant/url.js')
  5. import Net from '../../../../tool/net.js'
  6. var net = new Net()
  7. var businessType = require('../../../../public/business-type.js')
  8. var key = require('../../../../constant/key.js')
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. businessType: 's',
  15. header: {
  16. t: '',
  17. s: '省去繁琐流程,购买更快捷',
  18. src: ''
  19. },
  20. list: '',
  21. option: [
  22. {t: '', c: ''},
  23. {t: '', c: '', s: false, i: '1'}
  24. ],
  25. minMonths: 1,
  26. beginTime: '',
  27. isNeedSalary: false,
  28. minSalary: 2500,
  29. isInOffice: { t: '是否在职', s: false, tips: true, c: false, i: '2' },
  30. salary: { t: '社保流水', p: '', v: '', s: false },
  31. tipsInfo: { h: true, a: '' },
  32. },
  33. commitAction: businessT.action(function (sender) {
  34. var time = Number(sender.currentTarget.id)
  35. if (time < this.data.minMonths) {
  36. wx.showToast({
  37. title: '该城市需要至少购买' + this.data.minMonths + '个月',
  38. icon: 'none'
  39. })
  40. return
  41. }
  42. var order = app.purchase.order
  43. var isNeedSalary = false
  44. if ((this.data.businessType == 's' && this.data.isNeedSalary) || (this.data.businessType == 'a' && order.pack && this.data.isNeedSalary)) {
  45. if (!order.isInOffice) {
  46. if (order.salary == 0) {
  47. wx.showToast({
  48. title: '请填写范围内的社保流水',
  49. icon: 'none'
  50. })
  51. return
  52. }
  53. if (order.salary < this.data.minSalary || order.salary > 5000) {
  54. wx.showToast({
  55. title: '请填写范围内的社保流水',
  56. icon: 'none'
  57. })
  58. return
  59. }
  60. }
  61. isNeedSalary = true
  62. }
  63. wx.showLoading({
  64. title: '加载中',
  65. mask: true
  66. })
  67. order.isNeedSalary = isNeedSalary
  68. order.timeInterval = time
  69. if (order.timeInterval == 1) {
  70. order.endTime = order.beginTime
  71. } else {
  72. var year = Number(order.beginTime.slice(0, 4))
  73. var month = Number(order.beginTime.slice(5, 7)) + order.timeInterval - 1
  74. if (month > 12) {
  75. year += 1
  76. month -= 12
  77. }
  78. if (month < 10) {
  79. order.endTime = year + '年0' + month + '月'
  80. } else {
  81. order.endTime = year + '年' + month + '月'
  82. }
  83. }
  84. if (this.data.businessType == 's') {
  85. order.payFor = order.pack ? businessType.PurchasePayFor.socialInsurancePackage : businessType.PurchasePayFor.socialInsurance
  86. var fund = order.pack ? Number(order.accumulationFund) : 0
  87. } else {
  88. order.payFor = order.pack ? businessType.PurchasePayFor.accumulationFundPackage : businessType.PurchasePayFor.accumulationFund
  89. var fund = Number(order.accumulationFund)
  90. }
  91. var obj = {
  92. sbuId: order.customerData.sbuId,
  93. cid: order.id,
  94. shebao_card: order.SSCard,
  95. hukou_type: order.accountType,
  96. month: businessT.changeTimeToNumber(order.beginTime),
  97. fund: fund,
  98. nums: order.timeInterval,
  99. pay_for: order.payFor
  100. }
  101. businessT.debugLog(obj)
  102. net.connectNeedLogin({
  103. url: url.app_host + url.getTotalFee,
  104. data: obj,
  105. success: (err, res) => {
  106. order.totalFee = res.data
  107. wx.hideLoading()
  108. wx.navigateTo({
  109. url: '../pay-order/pay-order',
  110. })
  111. },
  112. fail: (err, res) => {
  113. wx.hideLoading()
  114. businessT.showFailTips(err, '加载失败')
  115. }
  116. }, true)
  117. }),
  118. switchAction: function (sender) {
  119. var order = app.purchase.order
  120. if (sender.currentTarget.id == '1') {
  121. order.pack = sender.detail.value
  122. this.data.option[1].c = sender.detail.value
  123. } else if (sender.currentTarget.id == '2') {
  124. order.isInOffice = sender.detail.value
  125. this.data.isInOffice.c = sender.detail.value
  126. }
  127. this.judgeSalary()
  128. this.setData({
  129. option: this.data.option,
  130. salary: this.data.salary,
  131. isInOffice: this.data.isInOffice
  132. })
  133. },
  134. chooseTime: businessT.action(function (sender) {
  135. wx.navigateTo({
  136. url: '../choose-date/choose-date?type=single&beginTime=' + this.data.beginTime,
  137. })
  138. }),
  139. finishChooseDate: function (date) {
  140. businessT.debugLog(date)
  141. var order = app.purchase.order
  142. var beginMonth = date.beginMonth % 100
  143. if (beginMonth < 10) {
  144. order.beginTime = ((date.beginMonth / 100) | 0) + '年0' + beginMonth + '月'
  145. } else {
  146. order.beginTime = ((date.beginMonth / 100) | 0) + '年' + beginMonth + '月'
  147. }
  148. this.data.option[0].c = beginMonth + '月份'
  149. this.setData({
  150. option: this.data.option
  151. })
  152. },
  153. judgeSalary: function () {
  154. var order = app.purchase.order
  155. if ((this.data.businessType == 's' && this.data.isNeedSalary) || (this.data.businessType == 'a' && order.pack && this.data.isNeedSalary)) {
  156. this.data.isInOffice.s = true
  157. if (order.isInOffice) {
  158. this.data.salary.s = false
  159. } else {
  160. this.data.salary.s = true
  161. }
  162. } else {
  163. this.data.isInOffice.s = false
  164. this.data.salary.s = false
  165. }
  166. this.data.minSalary = wx.getStorageSync(key.StorageKey.minSalary)
  167. this.data.salary.p = this.data.minSalary + '元-5000元'
  168. },
  169. inputAction: function (sender) {
  170. businessT.debugLog(sender)
  171. this.changeSalary(sender.detail.value)
  172. },
  173. changeSalary: function (salary) {
  174. var order = app.purchase.order
  175. order.salary = salary
  176. this.data.salary.v = salary
  177. this.setData({
  178. salary: this.data.salary
  179. })
  180. },
  181. wxvoid: function () {
  182. },
  183. tipsInfo: businessT.action(function (sender) {
  184. if (!this.data.tipsInfo.h) {
  185. return
  186. }
  187. this.data.tipsInfo.h = false
  188. this.setData({
  189. tipsInfo: this.data.tipsInfo
  190. })
  191. var animation = wx.createAnimation({
  192. duration: 300,
  193. timingFunction: 'ease',
  194. })
  195. animation.bottom('0rpx').step()
  196. this.setData({
  197. tipsInfo: {
  198. a: animation.export(),
  199. h: false
  200. }
  201. })
  202. }),
  203. dismissSalaryInfo: businessT.action(function (sender) {
  204. var animation = wx.createAnimation({
  205. duration: 300,
  206. timingFunction: 'ease',
  207. })
  208. animation.bottom('-800rpx').step()
  209. this.setData({
  210. tipsInfo: {
  211. a: animation.export(),
  212. h: false
  213. }
  214. })
  215. setTimeout(function () {
  216. this.data.tipsInfo.h = true
  217. this.setData({
  218. tipsInfo: this.data.tipsInfo
  219. })
  220. }.bind(this), 300)
  221. }),
  222. /**
  223. * 生命周期函数--监听页面加载
  224. */
  225. onLoad: function (options) {
  226. if (options.businessType) {
  227. this.data.businessType = options.businessType
  228. }
  229. this.data.minMonths = options.minMonths
  230. this.data.beginTime = options.beginTime
  231. this.data.isNeedSalary = options.isNeedSalary == 1
  232. // businessT.debugLog(options.businessType)
  233. this.judgeSalary()
  234. var order = app.purchase.order
  235. businessT.debugLog(order)
  236. this.data.list = order.customerData.user_name + '\n' + order.customerData.id_card + '\n' + publicData.accounts[order.accountType - 1] + '\n' + options.cityName
  237. var beginTime = Number(order.beginTime.slice(5, 7)) + '月份'
  238. if (this.data.businessType == 's') {
  239. this.data.header.t = '社保一键续缴'
  240. this.data.header.src = '../../../../icon/public/customer_header_s.png'
  241. this.data.option = [
  242. { t: '续缴月份', c: beginTime },
  243. { t: '是否同时购买公积金', c: order.pack, s: order.pack }
  244. ]
  245. wx.setNavigationBarTitle({
  246. title: '社保续缴',
  247. })
  248. } else {
  249. this.data.header.t = '公积金一键续存'
  250. this.data.header.src = '../../../../icon/public/customer_header_a.png'
  251. this.data.option = [
  252. { t: '续存月份', c: beginTime },
  253. { t: '是否同时购买社保', c: order.pack, s: order.pack }
  254. ]
  255. wx.setNavigationBarTitle({
  256. title: '公积金续存',
  257. })
  258. }
  259. this.setData({
  260. minMonths: this.data.minMonths,
  261. list: this.data.list,
  262. option: this.data.option,
  263. header: this.data.header,
  264. salary: this.data.salary,
  265. isInOffice: this.data.isInOffice
  266. })
  267. },
  268. /**
  269. * 生命周期函数--监听页面初次渲染完成
  270. */
  271. onReady: function () {
  272. },
  273. /**
  274. * 生命周期函数--监听页面显示
  275. */
  276. onShow: function () {
  277. },
  278. /**
  279. * 生命周期函数--监听页面隐藏
  280. */
  281. onHide: function () {
  282. },
  283. /**
  284. * 生命周期函数--监听页面卸载
  285. */
  286. onUnload: function () {
  287. },
  288. /**
  289. * 页面相关事件处理函数--监听用户下拉动作
  290. */
  291. onPullDownRefresh: function () {
  292. },
  293. /**
  294. * 页面上拉触底事件的处理函数
  295. */
  296. onReachBottom: function () {
  297. },
  298. /**
  299. * 用户点击右上角分享
  300. */
  301. // onShareAppMessage: function () {
  302. // }
  303. })