wait-for-pay.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 orderModel = require('../../public/model/order-model.js')
  7. var app = getApp()
  8. var businessType = require('../../../../public/business-type.js')
  9. var pay = require('../../../../public/pay.js')
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. scroll: true,
  16. isLoading: true,
  17. detailsView: {
  18. data: {},
  19. scroll: false,
  20. left: 0,
  21. hidden: true,
  22. animation: {},
  23. mt: '',
  24. m: '',
  25. t: '',
  26. at: '',
  27. a: '',
  28. discountU: true,
  29. discountT: ['', '', ''],
  30. discountC: 0,
  31. discountS: '未使用',
  32. sa: true,
  33. status: 1
  34. },
  35. discount: {
  36. canChoose: 0,
  37. fee: '0.00',
  38. chose: [],
  39. data:[],
  40. page: 0,
  41. finish: false,
  42. isLoading: true
  43. },
  44. data: []//bs1是只有左边按钮,2是右边有一按钮,3都展示
  45. },
  46. payAction: businessT.action(function (sender) {
  47. businessT.debugLog(sender)
  48. var data = this.data.data[sender.currentTarget.id]
  49. this.showDetails(data)
  50. this.detailsScroll(1, false)
  51. }),
  52. cancelAction: businessT.action(function (sender) {
  53. businessT.debugLog(sender)
  54. var item = this.data.data[sender.currentTarget.id]
  55. var that = this
  56. wx.showModal({
  57. title: '取消后将无法恢复',
  58. content: item.cancelContent,
  59. confirmColor: '#3296FB',
  60. cancelColor: '#3296FB',
  61. confirmText: '确定',
  62. cancelText: '取消',
  63. success: function (res) {
  64. if (res.confirm) {
  65. that.cancelOrder(item.buy_no, () => {
  66. that.data.data.splice(Number(sender.currentTarget.id), 1)
  67. that.setData({
  68. data: that.data.data
  69. })
  70. })
  71. }
  72. }
  73. })
  74. }),
  75. cancelOrder: function (no, success) {
  76. wx.showLoading({
  77. title: '正在取消订单',
  78. mask: true
  79. })
  80. net.connectNeedLogin({
  81. url: url.app_host + url.cancelPurchaseOrder,
  82. data: { buy_no: no },
  83. success: (err, res) => {
  84. if (res.code == businessType.NetworkErrorCode.success) {
  85. success()
  86. wx.hideLoading()
  87. wx.showToast({
  88. title: '取消订单成功',
  89. icon: 'none'
  90. })
  91. } else {
  92. wx.hideLoading()
  93. businessT.showFailTips(err, '取消订单失败')
  94. }
  95. },
  96. fail: (err, res) => {
  97. wx.hideLoading()
  98. businessT.showFailTips(err, '取消订单失败')
  99. }
  100. })
  101. },
  102. detailsAction: businessT.action(function (sender) {
  103. businessT.debugLog(sender)
  104. if (!this.data.detailsView.hidden) {
  105. return
  106. }
  107. var data = this.data.data[sender.currentTarget.id]
  108. this.getTotal(data, true)
  109. }),
  110. getTotal: function (data, s) {
  111. wx.showLoading({
  112. title: '加载中',
  113. mask: true
  114. })
  115. var obj = {
  116. sbuId: data.sbuId,
  117. cid: data.cid,
  118. shebao_card: data.new_card,
  119. hukou_type: data.hukou_type,
  120. month: data.start_month,
  121. fund: (data.fund / data.nums).toFixed(2),
  122. nums: data.nums,
  123. pay_for: data.pay_for
  124. }
  125. var path = data.added ? url.app_host + url.getTotalSupplementaryPayFee : url.app_host + url.getTotalFee
  126. var that = this
  127. net.connectNeedLogin({
  128. url: path,
  129. data: obj,
  130. success: (err, res) => {
  131. data.total_fee = res.data.total_fee
  132. data.shebao = res.data.shebao
  133. data.shebao_charge = res.data.s_charge
  134. data.shebao_card = res.data.card_charge
  135. data.fund = res.data.fund
  136. data.fund_charge = res.data.f_charge
  137. wx.hideLoading()
  138. if (s) {
  139. that.showDetails(data)
  140. } else {
  141. that.pay()
  142. }
  143. },
  144. fail: (err, res) => {
  145. wx.hideLoading()
  146. businessT.showFailTips(err, '加载失败')
  147. }
  148. }, true)
  149. },
  150. detailsPay: businessT.action(function (sender) {
  151. businessT.debugLog(sender)
  152. this.detailsScroll(1, true)
  153. }),
  154. detailsScroll: function (i, a) {
  155. this.data.detailsView.scroll = true
  156. this.data.detailsView.sa = a
  157. this.setData({
  158. detailsView: this.data.detailsView
  159. })
  160. this.data.detailsView.left = i * sysT.sysInfo().windowWidth
  161. this.data.detailsView.scroll = false;
  162. this.setData({
  163. detailsView: this.data.detailsView
  164. })
  165. },
  166. showDetails: function (data) {
  167. if (!this.data.detailsView.hidden) {
  168. return
  169. }
  170. this.data.detailsView.data = data
  171. this.data.detailsView.status = data.status
  172. if (this.data.detailsView.discountC == 0) {
  173. this.data.detailsView.discountS = '暂无优惠券'
  174. } else {
  175. this.data.detailsView.discountS = '未使用'
  176. }
  177. businessT.debugLog(data)
  178. var title
  179. var content
  180. if (data.pay_for == 1 || data.pay_for == 3) {
  181. title = '参保姓名'
  182. } else {
  183. title = '购买人姓名'
  184. }
  185. title = title + '\n身份证号\n购买月份\n购买城市'
  186. content = data.u_name + '\n' + data.id_card + '\n' + data.showTime + '\n' + data.city_name
  187. if (data.status == 2) {
  188. title = title + '\n支付方式'
  189. content = content + '\n' + data.pay_channel
  190. }
  191. if (data.pay_no.length != 0) {
  192. title = title + '\n流水号'
  193. content = content + '\n' + data.pay_no
  194. }
  195. if (data.status == 1) {
  196. title = title + '\n生成时间'
  197. } else {
  198. title = title + '\n成交时间'
  199. }
  200. content = content + '\n' + data.time
  201. this.data.detailsView.mt = title
  202. this.data.detailsView.m = content
  203. this.data.detailsView.t = data.a
  204. // this.data.detailsView.id = i
  205. var at = ''
  206. var a = ''
  207. if (data.shebao > 0) {
  208. at = at + '社保'
  209. a = a + '¥' + data.shebao.toFixed(2)
  210. }
  211. if (data.shebao_card > 0) {
  212. at = at + '\n社保卡'
  213. a = a + '\n¥' + data.shebao_card.toFixed(2)
  214. }
  215. if (data.fund > 0) {
  216. if (at != '') {
  217. at = at + '\n'
  218. a = a + '\n'
  219. }
  220. at = at + '公积金'
  221. a = a + '¥' + data.fund.toFixed(2)
  222. }
  223. at = at + '\n服务费'
  224. a = a + '\n¥' + (data.shebao_charge + data.fund_charge).toFixed(2)
  225. this.data.detailsView.at = at
  226. this.data.detailsView.a = a
  227. this.data.discount = {
  228. canChoose: data.nums,
  229. fee: '0.00',
  230. chose: [],
  231. data: [],
  232. page: 0,
  233. finish: false,
  234. isLoading: true
  235. }
  236. this.data.detailsView.discountT = this.getDiscountTips()
  237. this.data.detailsView.hidden = false
  238. //为了兼容iOS低版本系统,不能用bottom,所以计算margan-top的位置
  239. sysT.adaptor()
  240. businessT.debugLog(sysT.sysInfo().windowHeight)
  241. var s = this.data.detailsView.suffix == '-X' ? -1068 : -1000
  242. s = sysT.rpxToPx() * s
  243. this.data.detailsView.top = sysT.sysInfo().windowHeight - s
  244. this.setData({
  245. detailsView: this.data.detailsView,
  246. scroll: false
  247. })
  248. setTimeout(function () {
  249. var animation = wx.createAnimation({
  250. duration: 300,
  251. timingFunction: 'ease',
  252. })
  253. // animation.bottom('0rpx').step()
  254. animation.translateY(s).step()
  255. this.data.detailsView.animation = animation.export()
  256. this.setData({
  257. detailsView: this.data.detailsView
  258. })
  259. }.bind(this), 100)
  260. },
  261. hiddenDetails: businessT.action(function (sender) {
  262. this.detailsScroll(0, false)
  263. var animation = wx.createAnimation({
  264. duration: 300,
  265. timingFunction: 'ease',
  266. })
  267. animation.translateY(0).step()
  268. this.data.detailsView.animation = animation.export()
  269. this.setData({
  270. detailsView: this.data.detailsView
  271. })
  272. setTimeout(function () {
  273. this.data.detailsView.hidden = true
  274. this.setData({
  275. detailsView: this.data.detailsView,
  276. scroll: true
  277. })
  278. }.bind(this), 300)
  279. }),
  280. getOrderData: function () {
  281. wx.showLoading({
  282. title: '加载中',
  283. mask: true
  284. })
  285. net.connectNeedLogin({
  286. url: url.app_host + url.getWaitForPayList,
  287. data: {},
  288. success: (err, res) => {
  289. this.data.data = orderModel.handleWaitForPayData(res.data)
  290. this.data.isLoading = false
  291. this.setData({
  292. data: this.data.data,
  293. isLoading: this.data.isLoading
  294. })
  295. wx.hideLoading()
  296. },
  297. fail: (err, res) => {
  298. wx.hideLoading()
  299. businessT.showFailTips(err, '加载失败')
  300. setTimeout(function () {
  301. wx.navigateBack({
  302. })
  303. }.bind(this), 1000)
  304. }
  305. }, true)
  306. },
  307. uploadDiscountView: businessT.action(function (sender) {
  308. businessT.debugLog('upload')
  309. if (this.data.discount.isLoading || this.data.discount.finish) {
  310. return
  311. }
  312. this.data.discount.isLoading = true
  313. this.getCashCouponList()
  314. businessT.debugLog('abc')
  315. }),
  316. getCashCouponList: function () {
  317. var page = this.data.discount.page + 1
  318. net.connectNeedLogin({
  319. url: url.app_host + url.getCashCoupon,
  320. data: {
  321. phone: app.globalData.userInfo.phone,
  322. page: page,
  323. expired: 0
  324. },
  325. success: (err, res) => {
  326. this.getCashCouponListSuccess(res)
  327. this.data.discount.isLoading = false
  328. wx.hideLoading()
  329. },
  330. fail: (err, res) => {
  331. this.data.discount.isLoading = false
  332. x.hideLoading()
  333. businessT.showFailTips(err, '加载失败')
  334. }
  335. }, true)
  336. },
  337. getCashCouponListSuccess: function (res) {
  338. this.data.discount.page = res.currentPage
  339. var data = res.data.list
  340. for (var index in data) {
  341. var item = data[index]
  342. if (item.status == 1 && item.expired == 0) {
  343. var now = new Date().format('yyyy-MM-dd h:m:s')
  344. var nowDate = now.slice(0, 10)
  345. var endDate = item.end_time.slice(0, 10)
  346. if (nowDate == endDate) {
  347. item.p = '今天过期'
  348. } else {
  349. var tempNowDate = nowDate + ' 00:00:00'
  350. var tempEndDate = endDate + ' 00:00:00'
  351. var d = businessT.dateDiff('d', tempNowDate, tempEndDate)
  352. if (tempEndDate == item.end_time) {
  353. d -= 1
  354. }
  355. if (d == 0) {
  356. item.p = '今天过期'
  357. } else {
  358. item.p = '还有' + d + '天过期'
  359. }
  360. }
  361. } else {
  362. if (item.status == 1) {
  363. item.p = '已过期'
  364. } else {
  365. item.p = '已使用'
  366. }
  367. }
  368. item.end = item.end_time.slice(0, 10)
  369. }
  370. this.data.discount.data = this.data.discount.data.concat(res.data.list)
  371. if (res.data.list.length < 10) {
  372. this.data.discount.finish = true
  373. } else {
  374. this.data.discount.finish = false
  375. }
  376. this.setData({
  377. discount: this.data.discount
  378. })
  379. },
  380. getDiscountCount: function () {
  381. net.connectNeedLogin({
  382. url: url.app_host + url.getCashCouponCount,
  383. data: {
  384. phone: app.globalData.userInfo.phone
  385. },
  386. success: (err, res) => {
  387. this.data.detailsView.discountC = res.data.total
  388. if (this.data.detailsView.discountC == 0) {
  389. this.data.detailsView.discountS = '暂无优惠券'
  390. } else {
  391. this.data.detailsView.discountS = '未使用'
  392. }
  393. }
  394. }, true)
  395. },
  396. getDiscountTips: function () {
  397. if (this.data.discount.chose.length > 0) {
  398. return ['您已选中优惠券 ' + this.data.discount.chose.length + ' 张,共可抵用', '¥' + this.data.discount.fee, '']
  399. }
  400. return ['您当前下了 ' + this.data.discount.canChoose + ' 个月订单,可同时选 ', this.data.discount.canChoose, ' 张优惠券']
  401. },
  402. chooseDiscount: businessT.action(function (sender) {
  403. if (this.data.detailsView.discountC == 0) {
  404. wx.showToast({
  405. title: '暂无优惠券',
  406. })
  407. return
  408. }
  409. this.detailsScroll(2, true)
  410. if (this.data.discount.data.length == 0) {
  411. wx.showLoading({
  412. title: '加载中',
  413. mask: true
  414. })
  415. this.getCashCouponList()
  416. }
  417. }),
  418. //点击选择优惠券
  419. chooseAction: businessT.action(function (sender) {
  420. businessT.debugLog(this.data.discount.chose)
  421. businessT.debugLog(sender.currentTarget.id)
  422. var c = Number(sender.currentTarget.id)
  423. var s = this.data.discount.chose.indexOf(c)
  424. businessT.debugLog(s)
  425. if (s >= 0) {
  426. this.data.discount.chose.splice(s, 1)
  427. } else {
  428. if (this.data.discount.canChoose <= this.data.discount.chose.length) {
  429. wx.showToast({
  430. title: '本次购买只可选择' + this.data.discount.canChoose + '张抵用券',
  431. icon: 'none'
  432. })
  433. return
  434. }
  435. this.data.discount.chose.push(c)
  436. }
  437. var fee = 0
  438. for (var i in this.data.discount.chose) {
  439. var index = this.data.discount.chose[i]
  440. fee += this.data.discount.data[index].coupon_price
  441. }
  442. this.data.discount.fee = fee.toFixed(2)
  443. this.data.detailsView.discountT = this.getDiscountTips()
  444. this.setData({
  445. discount: this.data.discount,
  446. detailsView: this.data.detailsView
  447. })
  448. }, 100),
  449. confirmDiscount: businessT.action(function (sender) {
  450. if (this.data.discount.chose.length > 0) {
  451. this.data.detailsView.discountS = '-¥' + this.data.discount.fee
  452. } else {
  453. this.data.detailsView.discountS = '未使用'
  454. }
  455. this.setData({
  456. detailsView: this.data.detailsView
  457. })
  458. this.detailsScroll(1, true)
  459. }),
  460. detailsConfirmPay: businessT.action(function (sender) {
  461. var data = this.data.detailsView.data
  462. this.getTotal(data, false)
  463. }),
  464. pay: function() {
  465. wx.showLoading({
  466. title: '正在提交订单',
  467. mask: true
  468. })
  469. pay.prepay({
  470. success: e => {
  471. var data = this.data.detailsView.data
  472. if (data.pay_for == businessType.PurchasePayFor.socialInsurance) {
  473. this.createSocialInsuranceOrder(businessType.ResultServeyType.resultServeyTypeSB)
  474. } else if (data.pay_for == businessType.PurchasePayFor.socialInsurancePackage) {
  475. this.createSocialInsuranceOrder(businessType.ResultServeyType.resultServeyTypePack)
  476. } else if (data.pay_for == businessType.PurchasePayFor.accumulationFund) {
  477. this.createAccumulationFundOrder(businessType.ResultServeyType.resultServeyTypeAF)
  478. } else if (data.pay_for == businessType.PurchasePayFor.accumulationFundPackage) {
  479. this.createAccumulationFundOrder(businessType.ResultServeyType.resultServeyTypePack)
  480. }
  481. },
  482. fail: e => {
  483. wx.hideLoading()
  484. businessT.showFailTips(err, '提交订单失败')
  485. }
  486. })
  487. },
  488. createSocialInsuranceOrder: function (type) {
  489. var data = this.data.detailsView.data
  490. var obj = this.getParameters({
  491. fund: data.fund
  492. })
  493. businessT.debugLog(data)
  494. var path = data.added ? url.app_host + url.createShebaoSupplementaryPayOrder : url.app_host + url.createShebaoOrder
  495. var that = this
  496. net.connectNeedLogin({
  497. url: path,
  498. data: obj,
  499. success: (err, res) => {
  500. pay.wxPay({
  501. data: res.data,
  502. success: e => {
  503. if (obj.sb_wage > 0) {
  504. that.checkSurvey(true, type)
  505. } else {
  506. that.checkSurvey(false, type)
  507. }
  508. },
  509. fail: e => {
  510. wx.hideLoading()
  511. businessT.showFailTips(err, '提交订单失败')
  512. }
  513. })
  514. },
  515. fail: (err, res) => {
  516. wx.hideLoading()
  517. businessT.showFailTips(err, '提交订单失败')
  518. }
  519. }, true)
  520. },
  521. createAccumulationFundOrder: function (type) {
  522. var data = this.data.detailsView.data
  523. var obj = this.getParameters({
  524. buyShebao: data.shebao == 0 ? 0 : 1,
  525. fund: data.fund / data.nums
  526. })
  527. var path = data.added ? url.app_host + url.createFundSupplementaryPayOrder : url.app_host + url.createFundOrder
  528. var that = this
  529. net.connectNeedLogin({
  530. url: path,
  531. data: obj,
  532. success: (err, res) => {
  533. pay.wxPay({
  534. data: res.data,
  535. success: e => {
  536. if (obj.sb_wage > 0) {
  537. that.checkSurvey(true, type)
  538. } else {
  539. that.checkSurvey(false, type)
  540. }
  541. },
  542. fail: e => {
  543. wx.hideLoading()
  544. businessT.showFailTips(err, '提交订单失败')
  545. }
  546. })
  547. },
  548. fail: (err, res) => {
  549. wx.hideLoading()
  550. businessT.showFailTips(err, '提交订单失败')
  551. }
  552. }, true)
  553. },
  554. checkSurvey: function (isNeedSalary, type) {
  555. var pages = getCurrentPages()
  556. if (isNeedSalary) {
  557. pages[0].route('../../public/pages/pay-success/pay-success?type=salary')
  558. return
  559. } else {
  560. net.connectNeedLogin({
  561. url: url.app_host + url.checkSurvey,
  562. data: {},
  563. success: (err, res) => {
  564. wx.hideLoading()
  565. if (res.data) {
  566. pages[0].route('../../public/pages/pay-success/pay-success?type=survey&surveyType=' + type)
  567. } else {
  568. this.queryPayPriceDifference()
  569. }
  570. },
  571. fail: (err, res) => {
  572. wx.hideLoading()
  573. pages[0].route('../../public/pages/pay-success/pay-success?type=share')
  574. }
  575. }, false)
  576. }
  577. },
  578. queryPayPriceDifference: function () {
  579. var pages = getCurrentPages()
  580. net.connectNeedLogin({
  581. url: url.app_host + url.queryPayPriceDifference,
  582. data: {},
  583. success: (err, res) => {
  584. wx.hideLoading()
  585. if (res.data > 0) {
  586. pages[0].route('../../public/pages/pay-success/pay-success?type=pay')
  587. } else {
  588. pages[0].route('../../public/pages/pay-success/pay-success?type=share')
  589. }
  590. },
  591. fail: (err, res) => {
  592. wx.hideLoading()
  593. pages[0].route('../../public/pages/pay-success/pay-success?type=share')
  594. }
  595. }, true)
  596. },
  597. getParameters: function (par) {
  598. var data = this.data.detailsView.data
  599. var ids = ''
  600. for (var i in this.data.discount.chose) {
  601. var item = this.data.discount.data[this.data.discount.chose[i]]
  602. if (i == 0) {
  603. ids = ids + item.id
  604. } else {
  605. ids = ids + ',' + item.id
  606. }
  607. }
  608. var np = {
  609. sbuId: data.sbuId,
  610. cid: data.cid,
  611. shebao_card: data.new_card,
  612. hukou_type: data.hukou_type,
  613. month: data.start_month,
  614. nums: data.nums,
  615. first_sb: data.first_sb,
  616. first_fund: data.first_fund,
  617. working: data.working,
  618. sb_wage: data.sb_wage,
  619. pay_channel: 5,
  620. couponuser_id: ids
  621. }
  622. for (var key in par) {
  623. np[key] = par[key]
  624. }
  625. return np
  626. },
  627. /**
  628. * 生命周期函数--监听页面加载
  629. */
  630. onLoad: function (options) {
  631. this.data.detailsView.suffix = sysT.suffixOfClass()
  632. this.getOrderData()
  633. this.getDiscountCount()
  634. },
  635. /**
  636. * 生命周期函数--监听页面初次渲染完成
  637. */
  638. onReady: function () {
  639. },
  640. /**
  641. * 生命周期函数--监听页面显示
  642. */
  643. onShow: function () {
  644. },
  645. /**
  646. * 生命周期函数--监听页面隐藏
  647. */
  648. onHide: function () {
  649. },
  650. /**
  651. * 生命周期函数--监听页面卸载
  652. */
  653. onUnload: function () {
  654. },
  655. /**
  656. * 页面相关事件处理函数--监听用户下拉动作
  657. */
  658. onPullDownRefresh: function () {
  659. },
  660. /**
  661. * 页面上拉触底事件的处理函数
  662. */
  663. onReachBottom: function () {
  664. },
  665. /**
  666. * 用户点击右上角分享
  667. */
  668. onShareAppMessage: function () {
  669. return {
  670. path: '/page/home/index',
  671. imageUrl: '../../../../icon/public/share_img.png',
  672. title: '自助缴社保公积金,覆盖200多个城市,专业团队操作'
  673. }
  674. }
  675. })