var businessT = require('../../../tool/business-tool.js') var businessType = require('../../business-type.js') var sysT = require('../../../tool/sys-tool.js') var url = require('../../../constant/url.js') import Net from '../../../tool/net.js' var net = new Net() Page({ /** * 页面的初始数据 */ data: { type: 'none', surveyType: businessType.ResultServeyType.resultServeyTypeNo, survey: { hidden: true, animation: {}, scrollAnimation: {} } }, salary: businessT.action(function (sender) { var pages = getCurrentPages() businessT.debugLog(pages) pages[0].route('../../page/mine/pages/salary/salary') }), pay: businessT.action(function (sender) { var pages = getCurrentPages() businessT.debugLog(pages) pages[0].route('../../page/mine/pages/pay-price-difference/pay-price-difference') }), doNotPay: businessT.action(function (sender) { wx.navigateBack({ }) }), addCard: businessT.action(function (sender) { var pages = getCurrentPages() businessT.debugLog(pages) pages[0].route('../../public/pages/edit-bank/edit-bank?i=' + this.data.customerId) }), survey: businessT.action(function (sender) { if (!this.data.survey.hidden) { return } var questions var answers if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypeSB) { questions = ['1. 缴纳社保,请问您是为了?', '2. 您是如何知道“我的社保”小程序?'] answers = [ ['买房', '买车', '退休养老金', '入户', '子女入学', '贷款', '其他'], ['朋友介绍', '百度关键词搜索', '支付宝生活号/小程序', '微信公众号', '其他'] ] this.data.survey.bgvc = 'd-bg-view' this.data.survey.chose = [[], []] } else if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypeAF) { questions = ['1. 缴存公积金,请问您是为了?', '2. 您是如何知道“我的社保”小程序?'] answers = [ ['买房', '贷款', '存钱储蓄', '其他'], ['朋友介绍', '百度关键词搜索', '支付宝生活号/小程序', '微信小程序', '其他'] ] this.data.survey.bgvc = 'd-bg-view' this.data.survey.chose = [[], []] } else { questions = ['1. 缴纳社保,请问您是为了?', '2. 缴存公积金,请问您是为了?', '3. 您是如何知道“我的社保”小程序?'] answers = [ ['买房', '买车', '退休养老金', '入户', '子女入学', '贷款', '其他'], ['买房', '贷款', '存钱储蓄', '其他'], ['朋友介绍', '百度关键词搜索', '支付宝生活号/小程序', '微信公众号', '其他'] ] this.data.survey.bgvc = 't-bg-view' this.data.survey.chose = [[], [], []] } this.data.survey.questions = questions this.data.survey.answers = answers this.data.survey.index = 0 this.data.survey.hidden = false var y = sysT.rpxToPx() * 1068 var animation = wx.createAnimation({ duration: 100, timingFunction: 'ease', }) animation.translateY(y).step() this.data.survey.animation = animation.export() var scrollAnimation = wx.createAnimation({ duration: 100, timingFunction: 'ease', }) scrollAnimation.translateX(0).step() this.data.survey.scrollAnimation = scrollAnimation.export() this.setData({ survey: this.data.survey }) setTimeout(function () { // this.data.survey.hidden = false var animation = wx.createAnimation({ duration: 300, timingFunction: 'ease', }) animation.translateY(0).step() this.data.survey.animation = animation.export() this.setData({ survey: this.data.survey }) }.bind(this), 100) }), hiddenSurveyView: businessT.action(function (sender) { this.hiddenSurvey() }), hiddenSurvey: function () { var y = sysT.rpxToPx() * 1068 var animation = wx.createAnimation({ duration: 300, timingFunction: 'ease', }) animation.translateY(y).step() this.setData({ survey: { animation: animation.export(), hidden: false } }) setTimeout(function () { this.data.survey.hidden = true this.setData({ survey: this.data.survey, }) }.bind(this), 300) }, surveyAction: businessT.action(function (sender) { var chose = this.data.survey.chose[this.data.survey.index] if (chose.length == 0) { wx.showToast({ icon: 'none', title: '请选择', }) return } if (this.data.survey.index == this.data.survey.questions.length - 1) { this.saveSurveyAction() return } this.scrollSurveyView() this.setData({ survey: this.data.survey, }) }), scrollSurveyView: function () { this.data.survey.index++ var w = sysT.sysInfo().windowWidth var animation = wx.createAnimation({ duration: 300, timingFunction: 'ease', }) businessT.debugLog(w) animation.translateX(-w * this.data.survey.index).step() this.data.survey.scrollAnimation = animation.export() }, surveyChooseAction: businessT.action(function (sender) { var chose = this.data.survey.chose[this.data.survey.index] var c = Number(sender.currentTarget.id) businessT.debugLog(chose) var s = chose.indexOf(c) if (this.data.survey.index != this.data.survey.questions.length - 1) { //多选 if (s >= 0) { chose.splice(s, 1) } else { chose.push(c) } } else { //单选 if (s < 0) { chose = [c] } } businessT.debugLog(chose) this.data.survey.chose[this.data.survey.index] = chose this.setData({ survey: this.data.survey }) }), saveSurveyAction: function () { wx.showLoading({ title: '正在提交', mask: true }) businessT.debugLog(this.data.survey.chose) var result = [] for (var i in this.data.survey.chose) { var chose = this.data.survey.chose[i] var r = '' for (var j in chose) { var index = chose[j] if (j == 0) { r = r + String(this.data.survey.answers[i][index]) } else { r = r + '#' + String(this.data.survey.answers[i][index]) } } businessT.debugLog(r) result.push(r) } businessT.debugLog(result) var parameter = { 'answer1': '', 'answer2': '', 'answer3': ''} if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypeSB) { parameter['answer1'] = result[0] parameter['answer3'] = result[1] } else if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypeAF) { parameter['answer2'] = result[0] parameter['answer3'] = result[1] } else if (this.data.surveyType == businessType.ResultServeyType.resultServeyTypePack) { parameter['answer1'] = result[0] parameter['answer2'] = result[1] parameter['answer3'] = result[2] } // this.saveSurveySuccess('a') // return net.connectNeedLogin({ url: url.app_host + url.saveSurvey, data: parameter, success: (err, res) => { wx.hideLoading() this.saveSurveySuccess(res.data) }, fail: (err, res) => { businessT.showFailTips(err, '提交失败') } }, true) }, saveSurveySuccess: function(data) { var now = new Date().format('yyyy-MM-dd h:m:s') var nowDate = now.slice(0, 10) var endDate = data.end_time.slice(0, 10) if (nowDate == endDate) { data.p = '今天过期' } else { var tempNowDate = nowDate + ' 00:00:00' var tempEndDate = endDate + ' 00:00:00' var d = businessT.dateDiff('d', tempNowDate, tempEndDate) if (tempEndDate == data.end_time) { d -= 1 } if (d == 0) { data.p = '今天过期' } else { data.p = '还有' + d + '天过期' } } data.end = data.end_time.slice(0, 10) data.status = 1 data.expired = 0 data.coupon_desc = data['description'] data.coupon_name = data['name'] this.data.survey.result = data this.scrollSurveyView() this.setData({ survey: this.data.survey, }) }, chooseAction: businessT.action(function (sender) { wx.switchTab({ url: '../../../page/home/index', }) }), /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { sysT.adaptor() this.data.type = options.type if (options.customerId) { this.data.customerId = options.customerId } if (options.surveyType) { this.data.surveyType = options.surveyType } this.setData({ type: this.data.type }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return { path: '/page/home/index', imageUrl: '../../../icon/public/share_img.png', title: '自助缴社保公积金,覆盖200多个城市,专业团队操作' } } })