123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- var publicData = require('../../constant/data.js')
- var calculate = require('../../constant/calculate.js')
- var businessT = require('../../tools/business-tool.js')
- var sysT = require('../../tools/sys-tool.js')
- var url = require('../../constant/url.js')
- var app = getApp()
- import Net from '../../tools/net.js'
- var net = new Net()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- showShopPopup: false, // 是否显示收藏提示层
- animationData: {}, // 动画数据
- cityData: [],
- gearsArr:[],
- min: 0,
- getData:false,
- tab: 0,
- picker: [
- { t: '工作城市', c: '', v: [0,0], a: [], i: 0 },
- { t: '社保缴纳基数', c: '最低基数', v: '0', a: ['最低基数', '工资基数', '不交社保'], i: 1 },
- { t: '公积金缴存基数', c: '最低基数', v: '0', a: ['最低基数', '工资基数', '不交公积金'], i: 2 },
- { t: '个人比例', c: '', v: '0', a: [], i: 3 },
- { t: '参保方案', c: '', v: '0', a: [], i: 4 },
- ],
- input: { t: '税前工资(元)', c: '1000', p: '请输入当前税前工资', i: 0 },
- tips: {
- s: false,
- t: '',
- c: []
- },
- deduct: { t: '专项附加扣除(元)', c: '0.00' },
- deductData: {
- medical: 0,
- other: 0
- },
- interval: 0,
- collegeTips:"点击'添加到我的小程序'"
- },
- //显示提示
- showModal() {
- // 创建动画
- var animation = wx.createAnimation({
- duration: 1000,
- timingFunction: "ease-in-out",
- delay: 0
- })
- this.animation = animation
- animation.translateX(0).step()
- this.setData({
- animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
- showShopPopup: true
- })
- animation.translateX(-202).step()
- this.setData({
- animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
- showShopPopup: true
- })
- setTimeout(() => {
- animation.translateX(0).step()
- this.setData({
- animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
- showShopPopup: true
- })
- },2500)
- },
- //公众号关注组件加载
- successload:function(e){
- businessT.debugLog('成功码' + e.detail.status + e.detail.errMsg)
- },
- failload:function(e){
- businessT.debugLog('失败码' + e.detail.status + e.detail.errMsg)
- },
- toDeduct: businessT.action(function (sender) {
- wx.navigateTo({
- url: 'deduct/deduct'
- })
- }),
- //tips
- tipsAction: businessT.action(function (sender) {
- if (sender.currentTarget.id == '0') {
- this.data.tips.t = '社保基数';
- this.data.tips.c = ['最低基数:是指以所在城市的最低缴费基数为基准缴纳社保。', '工资基数:是指以实际工资为基准来缴纳社保。']
- } else {
- this.data.tips.t = '公积金基数';
- this.data.tips.c = ['最低基数:是指以所在城市的最低缴费基数为基准缴纳公积金。', '工资基数:是指以实际工资为基准来缴纳公积金。']
- }
- this.data.tips.s = true;
- this.setData({
- tips: this.data.tips
- })
- }),
- dismissTipsView: businessT.action(function (sender) {
- this.data.tips.s = false;
- this.setData({
- tips: this.data.tips
- })
- }),
- //imfo下拉框确认键
- pickerChange: businessT.action(function (sender) {
- businessT.debugLog(sender)
- var index = sender.currentTarget.id
- if (index == 4) {
- this.changeGears(sender.detail.value)
- this.setData({
- input: this.data.input,
- min: this.data.min,
- picker: this.data.picker
- })
- } else if (index == 0){
- businessT.debugLog(this.data.picker[0].a)
- businessT.debugLog(sender.detail.value)
- this.data.picker[index].v = sender.detail.value
- this.data.picker[index].c = this.data.picker[index].a[1][sender.detail.value[1]]
- this.getData()
- }else {
- businessT.debugLog(sender.detail.value)//选中数组下标
- this.data.picker[index].v = sender.detail.value
- this.data.picker[index].c = this.data.picker[index].a[sender.detail.value]
- this.setData({
- picker: this.data.picker
- })
- }
- }),
- inputAction: function (sender) {
- businessT.debugLog(sender)
- if (sender.currentTarget.id == 0) {
- this.data.input.c = sender.detail.value
- this.setData({
- input: this.data.input
- })
- }
-
- },
- bindblurAction: function (sender) {
- businessT.debugLog(sender)
- if (Number(sender.detail.value) < this.data.min) {
- wx.showModal({
- title: '提示',
- content: '税前工资需高于最低工资(' + this.data.min + '元)' ,
- showCancel: false,
- success: res => {
- if (res.confirm) {
- this.data.input.c = this.data.min
- this.setData({
- input: this.data.input
- })
- }
- }
- })
- }
- },
-
- //button
- onGotUserInfo: function (sender) {
- businessT.debugLog(sender)
- if (sender.detail.errMsg == 'getUserInfo:ok') {
- let avatarUrl = sender.detail.userInfo.avatarUrl
- let nickName = sender.detail.userInfo.nickName
- this.calculate(avatarUrl, nickName)
- }
- },
- calculate: function (avatarUrl, nickName) {
- if (!this.data.getData) {
- wx.showToast({
- title: '请重新选择城市获取数据',
- icon: 'none'
- })
- return
- }
- if (this.data.input.c < this.data.min) {
- return
- }
- if (this.data.input.c == '') {
- wx.showToast({
- title: '请输入税前工资',
- icon: 'none'
- })
- return
- }
- wx.showLoading({
- title: '计算中',
- mask: true,
- })
- var data = this.data.cityData[this.data.picker[4].v]
- var a = 0
- if (this.data.picker[2].v == 0) {
- a = data.fund_min * (0.05 + this.data.picker[3].v * 0.01)
- } else if (this.data.picker[2].v == 1) {
- if (Number(this.data.input.c) > data.fund_max) {
- a = data.fund_max * (0.05 + this.data.picker[3].v * 0.01)
- } else {
- a = Number(this.data.input.c) * (0.05 + this.data.picker[3].v * 0.01)
- }
- }
-
- if (this.data.picker[1].v == 2) {
- this.calculateDeduct(0, a, avatarUrl, nickName)
- } else {
- var salary = Number(this.data.input.c)
- if (this.data.picker[1].v == 0) {
- salary = data.shebao_min
- }
- net.connect({
- url: url.app_host + url.getShebao,
- method: 'POST',
- data: {
- cid: data.id,
- hukou_type: data.id == 18 ? '3' : '1',
- shebao_salary: salary
- },
- success: (err, res) => {
- this.calculateDeduct(res.data, a, avatarUrl, nickName)
- },
- fail: (err, res) => {
- businessT.showFailTips(err, '加载失败')
- }
- })
- }
- },
- calculateDeduct: function (s, a, avatarUrl, nickName) {
- var result = calculate.calculate(this.data.input.c, s, a, this.data.picker[3].v, this.data.deductData.other, this.data.deductData.medical)
- businessT.debugLog(result)
- app.result = result
- if (this.data.deductData.medical > 0) {
- app.medical.s = true
- } else {
- app.medical.s = false
- }
- app.medical.rebate = result[4]
- var date = new Date()
- var month = date.getMonth()
- wx.navigateTo({
- url: 'result/result?url=' + avatarUrl + '&nick=' + nickName + '&A=' + result[0] + '&B=' + result[1] + '&C=' + result[2][month] + '&income=' + result[3][month] + '&city=' + this.data.picker[0].v[1],
- })
- wx.hideLoading()
- },
- changeGears: function (i) {
- this.data.picker[4].v = i
- this.data.picker[4].c = this.data.picker[4].a[i]
- var data = this.data.cityData[i]
- this.data.min = data.fund_min >= data.shebao_min ? data.fund_min : data.shebao_min
- if (Number(this.data.input.c) < this.data.min) {
- this.data.input.c = this.data.min
- }
- },
- //获取城市社保数据
- getData: function () {
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- net.connect({
- url: url.app_host + url.getCityData,
- method: 'GET',
- data: {
- city_code: publicData.cityCodes[this.data.picker[0].v[1]]
- },
- success: (err, res) => {
- if (Object.prototype.toString.call(res.data) == '[object Array]' && res.data.length > 0) {
- this.data.cityData = res.data
- var gearsArr = []
- for (var i = 0; i < res.data.length; i ++) {
- gearsArr.push(res.data[i].shebao_type)
- }
- this.data.picker[4].a = gearsArr
- this.changeGears(0)
-
- businessT.debugLog(gearsArr)
-
- this.data.getData = true
- this.setData({
- input :this.data.input,
- min: this.data.min,
- picker: this.data.picker
- })
- wx.hideLoading()
- } else {
- this.data.getData = false
- businessT.showFailTips({ code: 0, msg: '' }, '加载失败')
- }
- },
- fail: (err, res) => {
- this.data.getData = false
- businessT.showFailTips(err, '加载失败')
- }
- }, true)
- },
- //获取工作的城市
- getCityData:function(){
- net.connect({
- url: url.app_host + url.getWordCity,
- method: 'GET',
- data: {},
- success: (err, res) => {
- if (Object.prototype.toString.call(res.data) == '[object Array]' && res.data.length > 0) {
- businessT.debugLog(res.data)
- let p_Data = res.data.filter(item => item.isCity == 0);
- let c_Data = res.data.filter(item => item.isCity == 1);
- let provinceData = p_Data.map(item => item.name);
- let cityCodes = c_Data.map(item => item.id);
- publicData.cityCodes = cityCodes;
- businessT.debugLog(provinceData);
- var default_p_id = p_Data[0]['id'];//1000默认省id
- let cityData = c_Data.filter(item => item.pid == default_p_id);
- let cityNameData = cityData.map(item => item.name);
- this.data.picker[0].a = [provinceData, cityNameData];
- this.data.picker[0].c = this.data.picker[0]['a'][1][this.data.picker[0].v[1]]//默认城市
- this.setData({
- p_Data,
- c_Data,
- provinceData,
- picker: this.data.picker
- })
- } else {
- businessT.showFailTips({ code: 0, msg: '' }, '加载失败')
- }
- },
- fail: (err, res) => {
- businessT.debugLog(res)
- businessT.showFailTips(err, '加载失败')
- }
- }, true);
- // callback();
- },
- //省市列改变
- pickerColumnChange:function(e){
- businessT.debugLog('修改的列为', e.detail.column, ',值为', e.detail.value);
- this.data.picker[0].v[e.detail.column] = e.detail.value;
- switch (e.detail.column){
- case 0:
- let id = this.data.p_Data[e.detail.value]['id']
- let cityData = this.data.c_Data.filter(item => item.pid == id)
- let cityCodes = cityData.map(item => item.id)
- let cityNameData = cityData.map(item => item.name)
- publicData.cityCodes = cityCodes
- this.data.picker[0].a = [this.data.provinceData, cityNameData]
- this.setData({
- picker: this.data.picker
- })
- break;
- }
- },
- //跳转H5
- toweb:function(e){
- wx:wx.navigateTo({
- url: 'webView/webView',
- success: function(res) {},
- fail: function(res) {},
- complete: function(res) {},
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getCityData()
- // this.data.picker[0].a = publicData.citys
- // this.data.picker[0].c = publicData.citys[this.data.picker[0].v]
- this.data.picker[3].a = publicData.proportions
- this.data.picker[3].c = publicData.proportions[0]
- this.setData({
- picker: this.data.picker
- })
- this.getData()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- var query = wx.createSelectorQuery();
- query.select('#bannerBottom').boundingClientRect()
- var that = this;
- query.exec(function (res) {
- //res就是 该元素的信息 数组
- businessT.debugLog(res[0])
- var h = sysT.sysInfo().windowHeight - res[0].top - res[0].height - 230 * sysT.rpxToPx()
- if (h > 0) {
- that.setData({
- interval: h
- })
- }
- businessT.debugLog(h)
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (typeof this.getTabBar === 'function' &&
- this.getTabBar()) {
- this.getTabBar().setData({
- selected: 0
- })
- }
- this.setData({
- deduct: this.data.deduct
- })
- this.showModal();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- console.log("测试下拉")
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|