order.js 20 KB

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