pay.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. var wxyj = require('../../../../public/wxyj.js')
  8. Page({
  9. data: {
  10. orderStatus: false,
  11. discountStatus: false,
  12. discountData: '',
  13. cheapData: []
  14. },
  15. showModal(e) {
  16. var index = e.currentTarget.dataset.index
  17. if (e.currentTarget.dataset.type == 'delete') {
  18. var syear = this.data.list[index].syear
  19. var smonth = this.data.list[index].smonth
  20. var eyear = this.data.list[index].eyear
  21. var emonth = this.data.list[index].emonth
  22. var type
  23. var content
  24. if (this.data.list[index].pay_for == 1 || this.data.list[index].pay_for == 2) {
  25. type = this.data.list[index].title + '缴纳'
  26. } else {
  27. type = this.data.list[index].title
  28. }
  29. if (this.data.list[index].nums == 1) {
  30. content = '是否要取消' + syear + '年' + smonth + '月的' + type + '订单'
  31. } else {
  32. content = '是否要取消' + syear + '年' + smonth + '月-' + eyear + '年' + emonth + '月的' + type + '订单'
  33. }
  34. swan.showModal({
  35. title: '取消后将无法恢复',
  36. content: content,
  37. showCancel: true,
  38. cancelText: '取消',
  39. cancelColor: '#3296FB',
  40. confirmText: '确定',
  41. confirmColor: '#3296FB',
  42. success: res => {
  43. if (res.confirm) {
  44. this.deleteOrder(index)
  45. }
  46. }
  47. })
  48. } else if (e.currentTarget.dataset.type == 'detail') {
  49. const animation = swan.createAnimation()
  50. animation.translateY(-500).step();
  51. this.setData({ orderStatus: true }, () => {
  52. this.setData({
  53. animationData: animation.export()
  54. })
  55. })
  56. var detail = {}
  57. detail.data = this.data.list[index]
  58. if (this.data.list[index].nums == 1) {
  59. detail.date = this.data.list[index].syear + '年' + this.data.list[index].smonth + '月'
  60. } else {
  61. detail.date = this.data.list[index].syear + '年' + this.data.list[index].smonth + '月-' + this.data.list[index].eyear + '年' + this.data.list[index].emonth + '月'
  62. }
  63. this.setData({
  64. orderStatus: true,
  65. detail,
  66. currentData: this.data.list[index]
  67. })
  68. }
  69. },
  70. closeModal(status) {
  71. const animation = swan.createAnimation()
  72. animation.translateY(0).step();
  73. this.setData({ animationData: animation.export(), cheapData: [] }, () => {
  74. setTimeout(() => {
  75. this.setData({
  76. orderStatus: false,
  77. discountStatus: false
  78. })
  79. if(status=='showPay'){
  80. this.showPayModal()
  81. }
  82. }, 400)
  83. })
  84. this.data.discountData.forEach((item) => {
  85. item.isSelected = false
  86. })
  87. this.setData({discountData:this.data.discountData,cheapDataLength:0})
  88. },
  89. initData() {
  90. swan.showLoading({
  91. title: '请稍后...',
  92. mask: true,
  93. });
  94. net.connectNeedLogin({
  95. url: url.app_host + url.getWaitForPayList,
  96. data: {},
  97. success: (err, res) => {
  98. this.setData({
  99. list: res.data
  100. })
  101. if (this.data.list.length) {
  102. this.setData({
  103. isEmpty: false
  104. })
  105. } else {
  106. this.setData({
  107. isEmpty: true
  108. })
  109. }
  110. swan.hideLoading();
  111. this.countTime()
  112. },
  113. failed: (err, res) => {
  114. swan.hideLoading();
  115. businessT.showFailTips(err)
  116. }
  117. })
  118. net.connectNeedLogin({
  119. url: url.app_host + url.getCashCoupon,
  120. data: { phone: app.globalData.userInfo.phone, page: 1, expired: 0 },
  121. success: (err, res) => {
  122. this.getCashCouponListSuccess(res, 0)
  123. },
  124. failed: (err, res) => {
  125. businessT.showFailTips(err)
  126. }
  127. })
  128. },
  129. getCashCouponListSuccess(res, expired) {
  130. var data = res.data.list
  131. if (data.length == 0) {
  132. this.setData({ haveCashCoupon: false })
  133. return
  134. } else {
  135. this.setData({ haveCashCoupon: true })
  136. }
  137. for (var index in data) {
  138. var item = data[index]
  139. if (item.status == 1 && item.expired == 0) {
  140. // item.end_time = '2019-03-17 00:00:01'
  141. var now = new Date().format('yyyy-MM-dd h:m:s')
  142. var nowDate = now.slice(0, 10)
  143. var endDate = item.end_time.slice(0, 10)
  144. if (nowDate == endDate) {
  145. item.p = '今天过期'
  146. } else {
  147. var tempNowDate = nowDate + ' 00:00:00'
  148. var tempEndDate = endDate + ' 00:00:00'
  149. var d = businessT.dateDiff('d', tempNowDate, tempEndDate)
  150. if (tempEndDate == item.end_time) {
  151. d -= 1
  152. }
  153. if (d == 0) {
  154. item.p = '今天过期'
  155. } else {
  156. item.p = '还有' + d + '天过期'
  157. }
  158. }
  159. } else {
  160. if (item.status == 1) {
  161. item.p = '已过期'
  162. } else {
  163. item.p = '已使用'
  164. }
  165. }
  166. item.end = item.end_time.slice(0, 10)
  167. }
  168. this.setData({ discountData: data })
  169. },
  170. choose(e) {
  171. let current = this.data.discountData[e.currentTarget.id]
  172. var i, cheapMoney = 0
  173. if (current.isSelected) {
  174. current.isSelected = false
  175. this.data.cheapData.forEach((item, index) => {
  176. if (current.id == item.id) {
  177. i = index
  178. }
  179. })
  180. this.data.cheapData.splice(i, 1)
  181. } else {
  182. if (this.data.cheapData.length < this.data.nums) {
  183. current.isSelected = true
  184. this.data.cheapData.push(current)
  185. } else {
  186. swan.showToast({
  187. title: '本次购买仅可选择' + this.data.nums + '张抵用券',
  188. icon: 'none',
  189. mask: false
  190. });
  191. }
  192. }
  193. this.data.cheapData.forEach((item, index) => {
  194. cheapMoney += item.coupon_price
  195. })
  196. this.setData({ discountData: this.data.discountData, cheapDataLength: this.data.cheapData.length, cheapMoney: cheapMoney.toFixed(2) })
  197. },
  198. deleteOrder(index) {
  199. swan.showLoading({
  200. title: '请稍后...',
  201. mask: true,
  202. });
  203. net.connectNeedLogin({
  204. url: url.app_host + url.cancelPurchaseOrder,
  205. data: { key: app.loginStatus.key, buy_no: this.data.list[index].buy_no },
  206. success: (err, res) => {
  207. this.data.list.splice(index, 1)
  208. console.log(this.data.list)
  209. this.setData({
  210. list: this.data.list
  211. })
  212. swan.hideLoading();
  213. swan.showToast({
  214. title: '取消订单成功',
  215. icon: 'none'
  216. });
  217. if (this.data.list.length == 0) {
  218. this.setData({
  219. isEmpty: true
  220. })
  221. }
  222. },
  223. fail: (err, res) => {
  224. swan.hideLoading();
  225. businessT.showFailTips(err)
  226. }
  227. })
  228. },
  229. countTime() {
  230. var length = String(this.data.list[0].start_month).length
  231. this.data.list.forEach((item) => {
  232. item.syear = String(item.start_month).substring(0, length - 2)
  233. item.smonth = String(item.start_month).slice(-2)
  234. if (item.smonth.indexOf('0') == 0) {
  235. item.smonth = item.smonth.slice(1)
  236. }
  237. if (Number(item.smonth) + item.nums == 13) {
  238. item.eyear = item.syear
  239. item.emonth = 12
  240. } else if (Number(item.smonth) + item.nums > 13) {
  241. item.eyear = Number(item.syear) + 1
  242. item.emonth = Number(item.smonth) + item.nums - 13
  243. } else {
  244. item.eyear = Number(item.syear)
  245. item.emonth = Number(item.smonth) + item.nums - 1
  246. }
  247. })
  248. this.setData({ list: this.data.list })
  249. },
  250. showPayModal(e) {
  251. if (e) {
  252. var currentData = this.data.list[e.currentTarget.dataset.index]
  253. } else {
  254. var currentData = this.data.currentData
  255. }
  256. this.setData({ currentData })
  257. this.getParams(currentData)
  258. if (this.data.discountData.length) {
  259. const animation = swan.createAnimation()
  260. animation.translateY(-500).step();
  261. this.setData({ discountStatus: true, nums: currentData.nums }, () => {
  262. this.setData({
  263. animationData: animation.export()
  264. })
  265. })
  266. } else {
  267. this.pay()
  268. }
  269. },
  270. showPayModalLater() {
  271. this.closeModal('showPay')
  272. },
  273. getParams(currentData) {
  274. var obj = {
  275. sbuId: currentData.sbuId,
  276. id_card: '',
  277. cid: currentData.cid,
  278. month: currentData.start_month,
  279. newCard: currentData.newCard,
  280. shebao_card: currentData.shebao_card,
  281. hukou_type: currentData.hukou_type,
  282. fund: currentData.fund / currentData.nums,
  283. couponuser_id: '',
  284. pay_channel: 13,
  285. nums: currentData.nums,
  286. first_sb: currentData.first_sb,
  287. first_fund: currentData.first_fund,
  288. sb_wage: currentData.sb_wage,
  289. working: currentData.working
  290. }
  291. if (currentData.pay_for == 2) {
  292. obj.buyShebao = false
  293. } else {
  294. obj.buyShebao = true
  295. }
  296. this.setData({ payData: obj })
  297. console.log(obj)
  298. },
  299. pay() {
  300. var currentData = this.data.currentData, path
  301. if (this.data.cheapData.length) {
  302. var id = ''
  303. this.data.cheapData.forEach((item) => {
  304. if (item) {
  305. id += item.id + ','
  306. }
  307. })
  308. if (id) { id = id.slice(0, -1) }
  309. this.data.payData.couponuser_id = id
  310. }
  311. if (currentData.pay_for == 1 || currentData.pay_for == 3) {
  312. if (currentData.added) {
  313. path = url.createShebaoSupplementaryPayOrder
  314. } else {
  315. path = url.createShebaoOrder
  316. }
  317. } else if (currentData.pay_for == 2 || currentData.pay_for == 4) {
  318. if (currentData.added) {
  319. path = url.createFundSupplementaryPayOrder
  320. } else {
  321. path = url.createFundOrder
  322. }
  323. }
  324. net.connectNeedLogin({
  325. url: url.app_host + path,
  326. data: this.data.payData,
  327. success: (err, res) => {
  328. swan.requestPolymerPayment({
  329. orderInfo: res.data,
  330. success: res => {
  331. this.needSurvey()
  332. },
  333. fail: err => {
  334. swan.showToast({
  335. title: '支付失败',
  336. icon: 'none'
  337. });
  338. }
  339. });
  340. },
  341. fail: (err, res) => {
  342. swan.hideLoading()
  343. businessT.showFailTips(err, '提交订单失败')
  344. }
  345. }, true)
  346. if (this.data.orderStatus || this.data.discountStatus) {
  347. this.closeModal()
  348. }
  349. },
  350. needSurvey() {
  351. if(wxyj.wxyjData.order.sb_wage){
  352. swan.navigateTo({
  353. url: '../../../../public/pages/pay-success/pay-success?type=salary'
  354. });
  355. return
  356. }
  357. net.connectNeedLogin({
  358. url: url.app_host + url.checkSurvey,
  359. data: {},
  360. success: (err, res) => {
  361. if (res.data) {
  362. swan.navigateTo({
  363. url: '../../../../public/pages/pay-success/pay-success?type=survey&payfor=' + order.pay_for,
  364. });
  365. }else{
  366. this.needRepair()
  367. }
  368. },
  369. fail: (err, res) => {
  370. swan.navigateTo({
  371. url: '../../../../public/pages/pay-success/pay-success?type=share'
  372. });
  373. }
  374. }, false)
  375. },
  376. needRepair(){
  377. net.connectNeedLogin({
  378. url: url.app_host + url.queryPayPriceDifference,
  379. data: {},
  380. success: (err, res) => {
  381. if(res.data){
  382. swan.navigateTo({
  383. url: '../../../../public/pages/pay-success/pay-success?type=repair'
  384. });
  385. }else{
  386. swan.navigateTo({
  387. url: '../../../../public/pages/pay-success/pay-success?type=share'
  388. });
  389. }
  390. },
  391. fail: (err, res) => {
  392. swan.navigateTo({
  393. url: '../../../../public/pages/pay-success/pay-success?type=share'
  394. });
  395. }
  396. },false)
  397. },
  398. onLoad: function () {
  399. // 监听页面加载的生命周期函数
  400. this.initData()
  401. this.setData({ suffix: sysT.suffixOfClass() })
  402. swan.setPageInfo && swan.setPageInfo({
  403. title: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  404. keywords: '我的社保,我的社保网,我的社保APP,社会保障,社保,社保代缴,公积金代缴,社会保险,五险一金,医保,医疗保险,公积金,养老,生育,工伤,失业,住房公积金,社保代理,代缴社保,公积金代理,查悦社保,大社保,亲亲小保,社保掌上通,招聘求职,创业,买房,贷款,计算器,人社局,摇号',
  405. description: '我的社保APP是为个人、企业提供社保代缴代扣、公积金代扣代缴、社保查询、公积金查询服务的名牌产品。解决个体工商户、自由职业者、待业人员、全职妈妈、创业者等的个人社保公积金断缴难题,同时解决贷款, 买房, 买车, 养老, 医疗, 生育, 医疗报销等难题。同时为企业提供全国专业社保代理和公积金代理。',
  406. articleTitle: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  407. release_date: '2019-02-23 20:00:00',
  408. success: function () {
  409. console.log('页面基础信息设置完成');
  410. },
  411. fail: function (res) {
  412. console.log('设置失败');
  413. },
  414. })
  415. },
  416. onReady: function () {
  417. // 监听页面初次渲染完成的生命周期函数
  418. },
  419. onShow: function () {
  420. // 监听页面显示的生命周期函数
  421. },
  422. onHide: function () {
  423. // 监听页面隐藏的生命周期函数
  424. },
  425. onUnload: function () {
  426. // 监听页面卸载的生命周期函数
  427. },
  428. onPullDownRefresh: function () {
  429. // 监听用户下拉动作
  430. },
  431. onReachBottom: function () {
  432. // 页面上拉触底事件的处理函数
  433. },
  434. onShareAppMessage: function () {
  435. // 用户点击右上角转发
  436. }
  437. });