pay-success.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. var businessT = require('../../../tool/business-tool.js')
  2. var businessType = require('../../business-type.js')
  3. var sysT = require('../../../tool/sys-tool.js')
  4. var url = require('../../../constant/url.js')
  5. import Net from '../../../tool/net.js'
  6. var net = new Net()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. type: 'none',
  13. surveyType: businessType.ResultServeyType.resultServeyTypeNo,
  14. survey: {
  15. hidden: true,
  16. animation: {},
  17. scrollAnimation: {}
  18. }
  19. },
  20. salary: businessT.action(function (sender) {
  21. var pages = getCurrentPages()
  22. businessT.debugLog(pages)
  23. pages[0].route('../../page/mine/pages/salary/salary')
  24. }),
  25. pay: businessT.action(function (sender) {
  26. var pages = getCurrentPages()
  27. businessT.debugLog(pages)
  28. pages[0].route('../../page/mine/pages/pay-price-difference/pay-price-difference')
  29. }),
  30. doNotPay: businessT.action(function (sender) {
  31. wx.navigateBack({
  32. })
  33. }),
  34. addCard: businessT.action(function (sender) {
  35. var pages = getCurrentPages()
  36. businessT.debugLog(pages)
  37. pages[0].route('../../public/pages/edit-bank/edit-bank?i=' + this.data.customerId)
  38. }),
  39. survey: businessT.action(function (sender) {
  40. if (!this.data.survey.hidden) {
  41. return
  42. }
  43. var questions
  44. var answers
  45. if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypeSB) {
  46. questions = ['1. 缴纳社保,请问您是为了?', '2. 您是如何知道“我的社保”小程序?']
  47. answers = [
  48. ['买房', '买车', '退休养老金', '入户', '子女入学', '贷款', '其他'],
  49. ['朋友介绍', '百度关键词搜索', '支付宝生活号/小程序', '微信公众号', '其他']
  50. ]
  51. this.data.survey.bgvc = 'd-bg-view'
  52. this.data.survey.chose = [[], []]
  53. } else if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypeAF) {
  54. questions = ['1. 缴存公积金,请问您是为了?', '2. 您是如何知道“我的社保”小程序?']
  55. answers = [
  56. ['买房', '贷款', '存钱储蓄', '其他'],
  57. ['朋友介绍', '百度关键词搜索', '支付宝生活号/小程序', '微信小程序', '其他']
  58. ]
  59. this.data.survey.bgvc = 'd-bg-view'
  60. this.data.survey.chose = [[], []]
  61. } else {
  62. questions = ['1. 缴纳社保,请问您是为了?', '2. 缴存公积金,请问您是为了?', '3. 您是如何知道“我的社保”小程序?']
  63. answers = [
  64. ['买房', '买车', '退休养老金', '入户', '子女入学', '贷款', '其他'],
  65. ['买房', '贷款', '存钱储蓄', '其他'],
  66. ['朋友介绍', '百度关键词搜索', '支付宝生活号/小程序', '微信公众号', '其他']
  67. ]
  68. this.data.survey.bgvc = 't-bg-view'
  69. this.data.survey.chose = [[], [], []]
  70. }
  71. this.data.survey.questions = questions
  72. this.data.survey.answers = answers
  73. this.data.survey.index = 0
  74. this.data.survey.hidden = false
  75. var y = sysT.rpxToPx() * 1068
  76. var animation = wx.createAnimation({
  77. duration: 100,
  78. timingFunction: 'ease',
  79. })
  80. animation.translateY(y).step()
  81. this.data.survey.animation = animation.export()
  82. var scrollAnimation = wx.createAnimation({
  83. duration: 100,
  84. timingFunction: 'ease',
  85. })
  86. scrollAnimation.translateX(0).step()
  87. this.data.survey.scrollAnimation = scrollAnimation.export()
  88. this.setData({
  89. survey: this.data.survey
  90. })
  91. setTimeout(function () {
  92. // this.data.survey.hidden = false
  93. var animation = wx.createAnimation({
  94. duration: 300,
  95. timingFunction: 'ease',
  96. })
  97. animation.translateY(0).step()
  98. this.data.survey.animation = animation.export()
  99. this.setData({
  100. survey: this.data.survey
  101. })
  102. }.bind(this), 100)
  103. }),
  104. hiddenSurveyView: businessT.action(function (sender) {
  105. this.hiddenSurvey()
  106. }),
  107. hiddenSurvey: function () {
  108. var y = sysT.rpxToPx() * 1068
  109. var animation = wx.createAnimation({
  110. duration: 300,
  111. timingFunction: 'ease',
  112. })
  113. animation.translateY(y).step()
  114. this.setData({
  115. survey: {
  116. animation: animation.export(),
  117. hidden: false
  118. }
  119. })
  120. setTimeout(function () {
  121. this.data.survey.hidden = true
  122. this.setData({
  123. survey: this.data.survey,
  124. })
  125. }.bind(this), 300)
  126. },
  127. surveyAction: businessT.action(function (sender) {
  128. var chose = this.data.survey.chose[this.data.survey.index]
  129. if (chose.length == 0) {
  130. wx.showToast({
  131. icon: 'none',
  132. title: '请选择',
  133. })
  134. return
  135. }
  136. if (this.data.survey.index == this.data.survey.questions.length - 1) {
  137. this.saveSurveyAction()
  138. return
  139. }
  140. this.scrollSurveyView()
  141. this.setData({
  142. survey: this.data.survey,
  143. })
  144. }),
  145. scrollSurveyView: function () {
  146. this.data.survey.index++
  147. var w = sysT.sysInfo().windowWidth
  148. var animation = wx.createAnimation({
  149. duration: 300,
  150. timingFunction: 'ease',
  151. })
  152. businessT.debugLog(w)
  153. animation.translateX(-w * this.data.survey.index).step()
  154. this.data.survey.scrollAnimation = animation.export()
  155. },
  156. surveyChooseAction: businessT.action(function (sender) {
  157. var chose = this.data.survey.chose[this.data.survey.index]
  158. var c = Number(sender.currentTarget.id)
  159. businessT.debugLog(chose)
  160. var s = chose.indexOf(c)
  161. if (this.data.survey.index != this.data.survey.questions.length - 1) {
  162. //多选
  163. if (s >= 0) {
  164. chose.splice(s, 1)
  165. } else {
  166. chose.push(c)
  167. }
  168. } else {
  169. //单选
  170. if (s < 0) {
  171. chose = [c]
  172. }
  173. }
  174. businessT.debugLog(chose)
  175. this.data.survey.chose[this.data.survey.index] = chose
  176. this.setData({
  177. survey: this.data.survey
  178. })
  179. }),
  180. saveSurveyAction: function () {
  181. wx.showLoading({
  182. title: '正在提交',
  183. mask: true
  184. })
  185. businessT.debugLog(this.data.survey.chose)
  186. var result = []
  187. for (var i in this.data.survey.chose) {
  188. var chose = this.data.survey.chose[i]
  189. var r = ''
  190. for (var j in chose) {
  191. var index = chose[j]
  192. if (j == 0) {
  193. r = r + String(this.data.survey.answers[i][index])
  194. } else {
  195. r = r + '#' + String(this.data.survey.answers[i][index])
  196. }
  197. }
  198. businessT.debugLog(r)
  199. result.push(r)
  200. }
  201. businessT.debugLog(result)
  202. var parameter = { 'answer1': '', 'answer2': '', 'answer3': ''}
  203. if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypeSB) {
  204. parameter['answer1'] = result[0]
  205. parameter['answer3'] = result[1]
  206. } else if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypeAF) {
  207. parameter['answer2'] = result[0]
  208. parameter['answer3'] = result[1]
  209. } else if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypePack) {
  210. parameter['answer1'] = result[0]
  211. parameter['answer2'] = result[1]
  212. parameter['answer3'] = result[2]
  213. }
  214. // this.saveSurveySuccess('a')
  215. // return
  216. net.connectNeedLogin({
  217. url: url.app_host + url.saveSurvey,
  218. data: parameter,
  219. success: (err, res) => {
  220. wx.hideLoading()
  221. this.saveSurveySuccess(res.data)
  222. },
  223. fail: (err, res) => {
  224. businessT.showFailTips(err, '提交失败')
  225. }
  226. }, true)
  227. },
  228. saveSurveySuccess: function(data) {
  229. var now = new Date().format('yyyy-MM-dd h:m:s')
  230. var nowDate = now.slice(0, 10)
  231. var endDate = data.end_time.slice(0, 10)
  232. if (nowDate == endDate) {
  233. data.p = '今天过期'
  234. } else {
  235. var tempNowDate = nowDate + ' 00:00:00'
  236. var tempEndDate = endDate + ' 00:00:00'
  237. var d = businessT.dateDiff('d', tempNowDate, tempEndDate)
  238. if (tempEndDate == data.end_time) {
  239. d -= 1
  240. }
  241. if (d == 0) {
  242. data.p = '今天过期'
  243. } else {
  244. data.p = '还有' + d + '天过期'
  245. }
  246. }
  247. data.end = data.end_time.slice(0, 10)
  248. data.status = 1
  249. data.expired = 0
  250. data.coupon_desc = data['description']
  251. data.coupon_name = data['name']
  252. this.data.survey.result = data
  253. this.scrollSurveyView()
  254. this.setData({
  255. survey: this.data.survey,
  256. })
  257. },
  258. chooseAction: businessT.action(function (sender) {
  259. wx.switchTab({
  260. url: '../../../page/home/index',
  261. })
  262. }),
  263. /**
  264. * 生命周期函数--监听页面加载
  265. */
  266. onLoad: function (options) {
  267. sysT.adaptor()
  268. this.data.type = options.type
  269. if (options.customerId) {
  270. this.data.customerId = options.customerId
  271. }
  272. if (options.surveyType) {
  273. this.data.surveyType = options.surveyType
  274. }
  275. this.setData({
  276. type: this.data.type
  277. })
  278. },
  279. /**
  280. * 生命周期函数--监听页面初次渲染完成
  281. */
  282. onReady: function () {
  283. },
  284. /**
  285. * 生命周期函数--监听页面显示
  286. */
  287. onShow: function () {
  288. },
  289. /**
  290. * 生命周期函数--监听页面隐藏
  291. */
  292. onHide: function () {
  293. },
  294. /**
  295. * 生命周期函数--监听页面卸载
  296. */
  297. onUnload: function () {
  298. },
  299. /**
  300. * 页面相关事件处理函数--监听用户下拉动作
  301. */
  302. onPullDownRefresh: function () {
  303. },
  304. /**
  305. * 页面上拉触底事件的处理函数
  306. */
  307. onReachBottom: function () {
  308. },
  309. /**
  310. * 用户点击右上角分享
  311. */
  312. onShareAppMessage: function () {
  313. return {
  314. path: '/page/home/index',
  315. imageUrl: '../../../icon/public/share_img.png',
  316. title: '自助缴社保公积金,覆盖200多个城市,专业团队操作'
  317. }
  318. }
  319. })