pay-success.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. Page({
  8. data: {
  9. type: '',
  10. surveyData: [
  11. { q: ' 缴纳社保,请问您是为了?', t: '(可多选)', a: ['买房', '买车', '退休养老金', '入户', '子女入学', '贷款', '其他'], btn: ' 下一题' },
  12. { q: ' 缴存公积金,请问您是为了?', t: '(可多选)', a: ['买房', '贷款', '存钱储蓄', '其他'], btn: ' 下一题' },
  13. { q: ' 您是如何知道“我的社保”小程序?', a: ['朋友介绍', '百度关键词搜索', '支付宝生活号/小程序', '微信公众号', '其他'], btn: ' 提交' },
  14. ],
  15. scorllLeft: 0,
  16. status: false,
  17. current: 0,
  18. seleted: [],
  19. answerData: [],
  20. modalStatus: false,
  21. },
  22. next(e) {
  23. var id = Number(e.currentTarget.id), screenWidth = sysT.sysInfo().screenWidth, current = this.data.current, str = ''
  24. if (!this.data.status) { return }
  25. this.data.topic[current].a.forEach((item, index) => {
  26. if (this.data.seleted[index]) {
  27. str += item + '#'
  28. }
  29. })
  30. str = str.slice(0, -1)
  31. this.data.answerData[current] = str
  32. console.log(this.data.answerData)
  33. this.data.scorllLeft += screenWidth
  34. current += 1
  35. if (id + 1 == this.data.topic.length) {
  36. var answer1, answer2, answer3
  37. if (this.data.surveyType == 1) {
  38. answer1 = this.data.answerData[0]
  39. answer2 = ''
  40. answer3 = this.data.answerData[1]
  41. } else if (this.data.surveyType == 2) {
  42. answer1 = ''
  43. answer2 = this.data.answerData[0]
  44. answer3 = this.data.answerData[1]
  45. } else {
  46. answer1 = this.data.answerData[0]
  47. answer2 = this.data.answerData[1]
  48. answer3 = this.data.answerData[2]
  49. }
  50. swan.showLoading({
  51. title: '请稍后...',
  52. mask: true
  53. });
  54. net.connectNeedLogin({
  55. url: url.app_host + url.saveSurvey,
  56. data: { answer1, answer2, answer3 },
  57. success: (err, res) => {
  58. swan.hideLoading()
  59. this.setData({ scorllLeft: this.data.scorllLeft, current, status: false, seleted: [], discount: res.data })
  60. this.countTime()
  61. },
  62. fail: (err, res) => {
  63. swan.hideLoading()
  64. businessT.showFailTips(err)
  65. this.hiddenModal()
  66. }
  67. })
  68. } else {
  69. this.setData({ scorllLeft: this.data.scorllLeft, current, status: false, seleted: [] })
  70. }
  71. },
  72. choose(e) {
  73. var index = e.currentTarget.dataset.index, current = this.data.current, status
  74. this.data.seleted[index] = !this.data.seleted[index]
  75. if (this.data.seleted[index]) {
  76. status = true
  77. } else {
  78. status = false
  79. this.data.seleted.forEach(item => {
  80. if (item) {
  81. status = true
  82. }
  83. })
  84. }
  85. this.setData({ seleted: this.data.seleted, status })
  86. },
  87. showModal() {
  88. const animation = swan.createAnimation()
  89. animation.translateY(-600).step();
  90. this.setData({ modalStatus: true }, () => {
  91. this.setData({
  92. animationData: animation.export()
  93. })
  94. })
  95. },
  96. hiddenModal() {
  97. const animation = swan.createAnimation()
  98. animation.translateY(0).step();
  99. this.setData({ animationData: animation.export() }, () => {
  100. setTimeout(() => {
  101. this.setData({
  102. modalStatus: false,
  103. scorllLeft: 0,
  104. answerData: [],
  105. seleted: [],
  106. current: 0
  107. })
  108. }, 400)
  109. })
  110. },
  111. countTime() {
  112. var now = new Date().format('yyyy-MM-dd h:m:s'), discount = this.data.discount
  113. var nowDate = now.slice(0, 10)
  114. var endDate = discount.end_time.slice(0, 10)
  115. if (nowDate == endDate) {
  116. discount.p = '今天过期'
  117. } else {
  118. var tempNowDate = nowDate + ' 00:00:00'
  119. var tempEndDate = endDate + ' 00:00:00'
  120. var d = businessT.dateDiff('d', tempNowDate, tempEndDate)
  121. if (tempEndDate == discount.end_time) {
  122. d -= 1
  123. }
  124. if (d == 0) {
  125. discount.p = '今天过期'
  126. } else {
  127. discount.p = '还有' + d + '天过期'
  128. }
  129. }
  130. this.setData({ discount })
  131. },
  132. shareAction() {
  133. swan.openShare({
  134. path: '/page/home/index/index',
  135. imageUrl: '../../../icon/public/share_img.png',
  136. title: '自助缴社保公积金,覆盖200多个城市,专业团队操作',
  137. success:()=>{
  138. swan.switchTab({
  139. url: '../../../page/mypage/index/index',
  140. });
  141. }
  142. });
  143. },
  144. repair(){
  145. swan.navigateTo({
  146. url: '../../../page/mypage/pages/repair/repair',
  147. });
  148. },
  149. goMypage(){
  150. swan.switchTab({
  151. url: '../../../page/mypage/index/index',
  152. });
  153. },
  154. salary(){
  155. swan.navigateTo({
  156. url: '../../../page/mypage/pages/turnover/turnover',
  157. });
  158. },
  159. addCard(){
  160. var arr=app.globalData.customerList.filter(item=>{
  161. return item.id==this.data.id
  162. })
  163. swan.navigateTo({
  164. url: '../edit-bank/edit-bank?current='+JSON.stringify(arr[0]),
  165. });
  166. },
  167. onLoad: function (res) {
  168. // 监听页面加载的生命周期函数
  169. var topic, surveyData = this.data.surveyData, surveyType
  170. if (res.payfor == 1) {
  171. surveyType = 1
  172. topic = [surveyData[0], surveyData[2]]
  173. } else if (res.payfor == 2) {
  174. surveyType = 2
  175. topic = [surveyData[1], surveyData[2]]
  176. } else {
  177. surveyType = 3
  178. topic = [surveyData[0], surveyData[1], surveyData[2]]
  179. }
  180. this.setData({ suffix: sysT.suffixOfClass(), surveyType, topic, type: res.type,id:res.id })
  181. },
  182. onReady: function () {
  183. // 监听页面初次渲染完成的生命周期函数
  184. },
  185. onShow: function () {
  186. // 监听页面显示的生命周期函数
  187. },
  188. onHide: function () {
  189. // 监听页面隐藏的生命周期函数
  190. },
  191. onUnload: function () {
  192. // 监听页面卸载的生命周期函数
  193. },
  194. onPullDownRefresh: function () {
  195. // 监听用户下拉动作
  196. },
  197. onReachBottom: function () {
  198. // 页面上拉触底事件的处理函数
  199. },
  200. onShareAppMessage: function () {
  201. // 用户点击右上角转发
  202. }
  203. });