salary.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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 pay = require('../../../../public/pay.js')
  7. var businessType = require('../../../../public/business-type.js')
  8. var app = getApp()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. scroll: true,
  15. isLoading: true,
  16. detailsView: {
  17. // data: {},
  18. // scroll: false,
  19. // left: 0,
  20. hidden: true,
  21. // animation: {},
  22. // discountU: false,
  23. // status: 1,
  24. // sa: false,
  25. // isSalary: true
  26. },
  27. tab: {
  28. id: '1',
  29. animation: {}
  30. },
  31. data: [[], []],//bs1是只有左边按钮,2是右边有一按钮,3都展示,4流水
  32. hadLeft: false,//判断左边是否有数据
  33. hadRight: false,//判断右边边是否有数据
  34. bgAnimation: {}
  35. },
  36. getDetailsView: function () {
  37. return {
  38. data: {},
  39. scroll: false,
  40. left: 0,
  41. hidden: true,
  42. animation: { },
  43. discountU: false,
  44. status: 1,
  45. sa: false,
  46. isSalary: true,
  47. failReason: ''
  48. }
  49. },
  50. tabChoose: businessT.action(function (sender) {
  51. if (sender.currentTarget.id == this.data.tab.id) {
  52. return
  53. }
  54. // this.data.bgScrollView.scroll = true;
  55. // this.setData({
  56. // bgScrollView: this.data.bgScrollView
  57. // })
  58. var animation = wx.createAnimation({
  59. duration: 300,
  60. timingFunction: 'ease',
  61. })
  62. var bgAnimation = wx.createAnimation({
  63. duration: 300,
  64. timingFunction: 'ease',
  65. })
  66. var w = sysT.sysInfo().windowWidth
  67. businessT.debugLog(w)
  68. var s = sender.currentTarget.id - 1
  69. // if (sender.currentTarget.id == "1") {
  70. // animation.translateX(0).step()
  71. // this.data.bgScrollView.left = 0
  72. // } else {
  73. // animation.translateX(w / 2).step()
  74. // this.data.bgScrollView.left = sysT.sysInfo().windowWidth
  75. // }
  76. animation.translateX(s * w / 2).step()
  77. bgAnimation.translateX(-w * s).step()
  78. this.data.tab.id = sender.currentTarget.id
  79. this.data.tab.animation = animation.export()
  80. // this.data.bgScrollView.scroll = false;
  81. this.setData({
  82. tab: this.data.tab,
  83. bgAnimation: bgAnimation.export()
  84. // bgScrollView: this.data.bgScrollView
  85. })
  86. businessT.debugLog(sender.currentTarget.id)
  87. if (this.data.tab.id == "1") {
  88. if (!this.data.hadLeft) {
  89. this.getOrderData(true)
  90. }
  91. } else {
  92. if (!this.data.hadRight) {
  93. this.getOrderData(false)
  94. }
  95. }
  96. }),
  97. progressAction: businessT.action(function (sender) {
  98. this.showDetails(sender.currentTarget.id, '返还状态')
  99. this.detailsScroll(1, false)
  100. }),
  101. payAction: businessT.action(function (sender) {
  102. businessT.debugLog(sender)
  103. this.showDetails(sender.currentTarget.id, '社保流水订单详情')
  104. this.detailsScroll(1, false)
  105. }),
  106. detailsAction: businessT.action(function (sender) {
  107. businessT.debugLog(sender)
  108. this.showDetails(sender.currentTarget.id, '社保流水订单详情')
  109. }),
  110. detailsPay: businessT.action(function (sender) {
  111. businessT.debugLog(sender)
  112. this.detailsScroll(1, true)
  113. }),
  114. showProgress: businessT.action(function (sender) {
  115. this.data.detailsView.title = '返还状态'
  116. this.setData({
  117. detailsView: this.data.detailsView
  118. })
  119. this.detailsScroll(1, true)
  120. }),
  121. showDetails: function (i, title) {
  122. if (!this.data.detailsView.hidden) {
  123. return
  124. }
  125. var t = Number(this.data.tab.id)
  126. var data = this.data.data[t - 1][i]
  127. this.data.detailsView = this.getDetailsView()
  128. this.data.detailsView.suffix = sysT.suffixOfClass()
  129. this.data.detailsView.data = data
  130. this.data.detailsView.title = title
  131. this.data.detailsView.status = data.pay_status
  132. var month = String(data.opt_month)
  133. month = month.substring(0, 4) + '年' + month.substring(4,6) + '月'
  134. if (data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusNotPay) {
  135. var time = data.gen_time
  136. if (time.length > 16) {
  137. time = String(time).substring(0, 16)
  138. }
  139. this.data.detailsView.mt = '参保姓名\n月份\n城市\n截止付款时间\n预计返还时间\n创建时间'
  140. this.data.detailsView.m = data.uname + '\n' + month + '\n' + data.city + '\n' + data.pay_date + '\n流水月逢周三返还' + '\n' + time
  141. } else {
  142. var time = data.pay_time
  143. if (time.length > 16) {
  144. time = String(time).substring(0, 16)
  145. }
  146. this.data.detailsView.mt = '参保姓名\n月份\n城市\n预计返还时间\n成交时间'
  147. this.data.detailsView.m = data.uname + '\n' + month + '\n' + data.city + '\n流水月逢周三返还' + '\n' + time
  148. //需要流水进度
  149. var bankCard = null
  150. var haveCustomer = false
  151. for (var i = 0; i < app.globalData.customerList.length; i ++) {
  152. var customer = app.globalData.customerList[i]
  153. // businessT.debugLog(customer)
  154. if (customer.id == data.sbu_id) {
  155. haveCustomer = true
  156. this.data.editCustomerIndex = i
  157. if (customer.bank && customer.bank.length != 0 && customer.bank_code && customer.bank_code.length != 0) {
  158. var bankCode = String(customer.bank_code)
  159. bankCard = customer.bank + '(' + bankCode.substring(bankCode.length - 4) + ')'
  160. }
  161. break
  162. }
  163. }
  164. this.data.detailsView.haveNoCustomer = false
  165. this.data.detailsView.haveNoBank = false
  166. this.data.detailsView.isFail = false
  167. // if(1) {
  168. if (data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusPaySuccessAndNotBack && !haveCustomer) {
  169. this.data.detailsView.haveNoCustomer = true
  170. this.data.detailsView.progressInfoT = '收款姓名\n返还账户'
  171. this.data.detailsView.progressInfoC = data.uname + '\n暂无'
  172. // } else if (1) {
  173. } else if (data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusPaySuccessAndNotBack && !bankCard) {
  174. this.data.detailsView.haveNoBank = true
  175. this.data.detailsView.progressInfoT = '收款姓名\n返还账户'
  176. this.data.detailsView.progressInfoC = data.uname + '\n暂无'
  177. // } else if (1) {
  178. } else if (data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusPaySuccessAndBackFail) {
  179. this.data.detailsView.isFail = true
  180. this.data.detailsView.failReason = data.fail_reason
  181. if (!haveCustomer) {
  182. this.data.detailsView.haveNoCustomer = true
  183. this.data.detailsView.progressInfoT = '收款姓名'
  184. this.data.detailsView.progressInfoC = data.uname
  185. } else if (!bankCard) {
  186. this.data.detailsView.haveNoBank = true
  187. this.data.detailsView.progressInfoT = '收款姓名'
  188. this.data.detailsView.progressInfoC = data.uname
  189. } else {
  190. this.data.detailsView.progressInfoT = '收款姓名\n返还账户'
  191. this.data.detailsView.progressInfoC = data.uname + '\n' + bankCard
  192. }
  193. } else if (!haveCustomer || !bankCard || data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusReturnBack || data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusRefund) {
  194. this.data.detailsView.progressInfoT = '收款姓名'
  195. this.data.detailsView.progressInfoC = data.uname
  196. } else {
  197. this.data.detailsView.progressInfoT = '收款姓名\n返还账户'
  198. this.data.detailsView.progressInfoC = data.uname + '\n' + bankCard
  199. }
  200. this.data.detailsView.progressPayT = data.pay_time.substring(5, 16)
  201. this.data.detailsView.progressBack = data.wage.toFixed(2)
  202. this.data.detailsView.progressPayTime = data.pay_time
  203. if (this.data.detailsView.progressPayTime.length > 16) {
  204. this.data.detailsView.progressPayTime = this.data.detailsView.progressPayTime.substring(0,16)
  205. }
  206. if (data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusBack || data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusReturnBack || data.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusRefund) {
  207. this.data.detailsView.progressStatus = '交易成功'
  208. this.data.detailsView.progressStatusColor = '#3AB261'
  209. this.data.detailsView.progressLineImg = 'salary_line'
  210. this.data.detailsView.progressBackImg = 'salary_done'
  211. this.data.detailsView.progressBackColor = '#3296FB'
  212. this.data.detailsView.progressBackT = data.hf_time.substring(5, 16)
  213. } else {
  214. this.data.detailsView.progressStatus = '等待处理'
  215. this.data.detailsView.progressStatusColor = '#FF8D36'
  216. if (this.data.detailsView.isFail) {
  217. this.data.detailsView.progressLineImg = 'salary_line'
  218. this.data.detailsView.progressBackImg = 'salary_failure'
  219. this.data.detailsView.progressBackColor = '#FF5E5E'
  220. this.data.detailsView.progressBackT = null
  221. } else {
  222. this.data.detailsView.progressLineImg = 'salary_dashed'
  223. this.data.detailsView.progressBackImg = 'salary_undone'
  224. this.data.detailsView.progressBackColor = '#999999'
  225. this.data.detailsView.progressBackT = null
  226. }
  227. }
  228. }
  229. this.data.detailsView.t = data.a
  230. // this.data.detailsView.id = i
  231. var at = '社保流水 (返还费用)\n服务费'
  232. var a = '¥' + data.wage.toFixed(2) + '\n¥' + data.charge.toFixed(2)
  233. this.data.detailsView.at = at
  234. this.data.detailsView.a = a
  235. this.data.detailsView.hidden = false
  236. //为了兼容iOS低版本系统,不能用bottom,所以计算margan-top的位置
  237. sysT.adaptor()
  238. businessT.debugLog(sysT.sysInfo().windowHeight)
  239. var s = this.data.detailsView.suffix == '-X' ? -1068 : -1000
  240. s = sysT.rpxToPx() * s
  241. this.data.detailsView.top = sysT.sysInfo().windowHeight - s
  242. this.setData({
  243. detailsView: this.data.detailsView,
  244. scroll: false
  245. })
  246. setTimeout(function () {
  247. var animation = wx.createAnimation({
  248. duration: 300,
  249. timingFunction: 'ease',
  250. })
  251. // animation.top('0rpx').step()
  252. animation.translateY(s).step()
  253. this.data.detailsView.animation = animation.export()
  254. this.setData({
  255. detailsView: this.data.detailsView
  256. })
  257. }.bind(this), 100)
  258. },
  259. hiddenDetails: businessT.action(function (sender) {
  260. this.hiddenDetailsAction()
  261. }),
  262. hiddenDetailsAction: function () {
  263. this.detailsScroll(0, false)
  264. var animation = wx.createAnimation({
  265. duration: 300,
  266. timingFunction: 'ease',
  267. })
  268. animation.translateY(0).step()
  269. this.data.detailsView.animation = animation.export()
  270. this.setData({
  271. detailsView: this.data.detailsView
  272. })
  273. setTimeout(function () {
  274. this.data.detailsView.hidden = true
  275. this.setData({
  276. detailsView: this.data.detailsView,
  277. scroll: true
  278. })
  279. }.bind(this), 300)
  280. },
  281. detailsScroll: function (i, a) {
  282. this.data.detailsView.scroll = true
  283. this.data.detailsView.sa = a
  284. this.setData({
  285. detailsView: this.data.detailsView
  286. })
  287. this.data.detailsView.left = i * sysT.sysInfo().windowWidth
  288. this.data.detailsView.scroll = false;
  289. this.setData({
  290. detailsView: this.data.detailsView
  291. })
  292. },
  293. detailsConfirmPay: businessT.action(function (sender) {
  294. wx.showLoading({
  295. title: '正在提交订单',
  296. mask: true
  297. })
  298. pay.prepay({
  299. success: e => {
  300. this.createOrder()
  301. },
  302. fail: e => {
  303. wx.hideLoading()
  304. businessT.showFailTips(err, '提交订单失败')
  305. }
  306. })
  307. }),
  308. createOrder: function () {
  309. var data = this.data.detailsView.data
  310. var that = this
  311. net.connectNeedLogin({
  312. url: url.app_host + url.createSalaryOrder,
  313. data: {
  314. order_no: data.order_no,
  315. pay_channel: 5
  316. },
  317. success: (err, res) => {
  318. pay.wxPay({
  319. data: res.data,
  320. success: e => {
  321. that.judgeCustomer()
  322. },
  323. fail: e => {
  324. wx.hideLoading()
  325. businessT.showFailTips(err, '提交订单失败')
  326. }
  327. })
  328. },
  329. fail: (err, res) => {
  330. wx.hideLoading()
  331. businessT.showFailTips(err, '提交订单失败')
  332. }
  333. }, true)
  334. },
  335. judgeCustomer: function () {
  336. var id = this.data.detailsView.data.sbu_id
  337. var haveBank = false
  338. var haveCustomer = false
  339. for (var i = 0; i < app.globalData.customerList.length; i++) {
  340. var customer = app.globalData.customerList[i]
  341. // businessT.debugLog(customer)
  342. if (customer.id == id) {
  343. haveCustomer = true
  344. if (customer.bank && customer.bank.length != 0 && customer.bank_code && customer.bank_code.length != 0) {
  345. haveBank = true
  346. }
  347. break
  348. }
  349. }
  350. var pages = getCurrentPages()
  351. if (!haveCustomer) {
  352. businessT.debugLog('haveNoCustomer')
  353. pages[0].route('../../public/pages/pay-success/pay-success?type=tipsCard')
  354. } else if (!haveBank) {
  355. businessT.debugLog('haveNoBank')
  356. pages[0].route('../../public/pages/pay-success/pay-success?type=addCard&customerId='+ id)
  357. } else {
  358. pages[0].route('../../public/pages/pay-success/pay-success?type=none')
  359. }
  360. },
  361. getOrderData: function (isLeft) {
  362. wx.showLoading({
  363. title: '加载中',
  364. mask: true
  365. })
  366. this.setData({
  367. isLoading: true
  368. })
  369. var u = isLeft ? url.getUndoneSalaryList : url.getDoneSalaryList
  370. net.connectNeedLogin({
  371. url: url.app_host + u,
  372. data: {},
  373. success: (err, res) => {
  374. var data = this.handleOrderData(res.data)
  375. businessT.debugLog(res.data)
  376. if (isLeft) {
  377. this.data.hadLeft = true
  378. this.data.data[0] = data
  379. } else {
  380. this.data.hadRight = true
  381. this.data.data[1] = data
  382. }
  383. this.data.isLoading = false
  384. this.setData({
  385. data: this.data.data,
  386. isLoading: this.data.isLoading
  387. })
  388. wx.hideLoading()
  389. },
  390. fail: (err, res) => {
  391. wx.hideLoading()
  392. businessT.showFailTips(err, '加载失败')
  393. setTimeout(function () {
  394. wx.navigateBack({
  395. })
  396. }.bind(this), 1000)
  397. }
  398. }, true)
  399. },
  400. handleOrderData: function (data) {
  401. var r = []
  402. for (var i in data) {
  403. var item = data[i]
  404. item.orderListType = businessType.OrderListType.orderListTypeSalary
  405. item.isSalary = true
  406. item.a = item.total_fee.toFixed(2)
  407. item.title = String(item.opt_month).substring(4, 6) + '月社保流水'
  408. // item.details = '查看补差额月份'
  409. item.ct = '参保姓名\n购买月份'
  410. var month = String(item.opt_month).substring(0, 4) + '年' + String(item.opt_month).substring(4, 6) + '月'
  411. item.c = item.uname + '\n' + month
  412. if (item.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusNotPay) {
  413. item.s = {
  414. t: '等待付款',
  415. c: 'order-item-status-w'
  416. }
  417. item.hasSalaryTips = true
  418. item.salaryTips = 'salary_sj_w'
  419. item.salaryTipsC = 'salary-tips-status-w'
  420. item.st = '截止付款时间'
  421. item.sc = item.pay_date
  422. item.bs = 2
  423. } else {
  424. if (item.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusBack || item.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusRefund || item.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusReturnBack) {
  425. item.hasSalaryTips = false
  426. item.s = {
  427. t: '返还成功',
  428. c: 'order-item-status-f'
  429. }
  430. } else if (item.pay_status == businessType.SalaryOrderStatus.salaryOrderStatusPaySuccessAndBackFail) {
  431. item.hasSalaryTips = true
  432. item.s = {
  433. t: '返还失败',
  434. c: 'order-item-status-fail'
  435. }
  436. } else {
  437. item.hasSalaryTips = true
  438. item.s = {
  439. t: '交易完成',
  440. c: 'order-item-status-f'
  441. }
  442. }
  443. item.salaryTips = 'salary_sj_f'
  444. item.salaryTipsC = 'salary-tips-status-f'
  445. item.st = '预计返还时间'
  446. item.sc = '流水月逢周三返还'
  447. item.bs = 4
  448. }
  449. r.push(item)
  450. }
  451. return r
  452. },
  453. editCustomer: businessT.action(function (sender) {
  454. this.hiddenDetailsAction()
  455. this.data.hadLeft = false
  456. this.data.hadRight = false
  457. wx.navigateTo({
  458. url: '../../../../public/pages/edit-bank/edit-bank?i=' + this.data.editCustomerIndex,
  459. })
  460. }),
  461. /**
  462. * 生命周期函数--监听页面加载
  463. */
  464. onLoad: function (options) {
  465. // this.data.detailsView.suffix = sysT.suffixOfClass()
  466. this.getOrderData(true)
  467. },
  468. /**
  469. * 生命周期函数--监听页面初次渲染完成
  470. */
  471. onReady: function () {
  472. },
  473. /**
  474. * 生命周期函数--监听页面显示
  475. */
  476. onShow: function () {
  477. if (this.data.tab.id == "1") {
  478. if (!this.data.hadLeft) {
  479. this.getOrderData(true)
  480. }
  481. } else {
  482. if (!this.data.hadRight) {
  483. this.getOrderData(false)
  484. }
  485. }
  486. },
  487. /**
  488. * 生命周期函数--监听页面隐藏
  489. */
  490. onHide: function () {
  491. },
  492. /**
  493. * 生命周期函数--监听页面卸载
  494. */
  495. onUnload: function () {
  496. },
  497. /**
  498. * 页面相关事件处理函数--监听用户下拉动作
  499. */
  500. onPullDownRefresh: function () {
  501. },
  502. /**
  503. * 页面上拉触底事件的处理函数
  504. */
  505. onReachBottom: function () {
  506. },
  507. /**
  508. * 用户点击右上角分享
  509. */
  510. onShareAppMessage: function () {
  511. return {
  512. path: '/page/home/index',
  513. imageUrl: '../../../../icon/public/share_img.png',
  514. title: '自助缴社保公积金,覆盖200多个城市,专业团队操作'
  515. }
  516. }
  517. })