123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- import url from '../../url'
- import net from '../../net'
- import math from '../../math'
- Page({
- data: {
- // nav: [
- // { i: '../../imgs/shuiwu.png', t: '节税筹划' },
- // { i: '../../imgs/yanglao.png', t: '社保公积金计算' },
- // { i: '../../imgs/wuxian.png', t: '社保代缴' }
- // ],
- pageStatus: false,
- listStatus: false,
- hiddenList: true,
- hiddenGjj: true,
- cantap: true,
- mask: false,
- shebao: '',
- fund: '',
- pickerIndex: [0, 0],
- typeData: [{ name: '二档', index: 0 }, { name: '一档', index: 1 }],
- hukouData: [{ name: '本地城镇', index: 0 }, { name: '本地农村', index: 1 }, { name: '外地城镇', index: 2 }, { name: '外地农村', index: 3 }],
- },
- // navigation(e) {
- // let i = e.currentTarget.dataset.index
- // my.navigateTo({ url: `../web-view/web-view?i=${i}` })
- // },
- // goMiniProgram() {
- // my.navigateToMiniProgram({
- // appId: '2019031663552331',
- // success: (res) => {
- // console.log(JSON.stringify(res))
- // },
- // fail: (res) => {
- // console.log(JSON.stringify(res))
- // }
- // });
- // },
- show(e) {
- var className = e.target.dataset.class
- if (!this.data.cantap) return
- this.data.cantap = false
- // if (className === '.sbList' && this.data.hiddenList) {
- // this.scroll('.main')
- // let timer = setTimeout(() => {
- // this.scroll(className)
- // this.data.cantap = true
- // clearTimeout(timer)
- // }, 500);
- if (className === '.sbList') {
- if (this.data.hiddenList && this.data.hiddenGjj) {
- this.scroll('.main')
- } else if (this.data.hiddenList && !this.data.hiddenGjj) {
- this.scroll('.main')
- let timer = setTimeout(() => {
- this.scroll(className)
- }, 500);
- } else if (!this.data.hiddenList && this.data.hiddenGjj) {
- this.data.cantap = true
- return
- } else if (!this.data.hiddenList && !this.data.hiddenGjj) {
- this.scroll(className)
- }
- } else if (className === '.gjjList') {
- if (this.data.hiddenList && this.data.hiddenGjj) {
- this.scroll('.main')
- let timer = setTimeout(() => {
- this.scroll(".sbList")
- }, 500);
- } else if (this.data.hiddenList && !this.data.hiddenGjj) {
- this.scroll('.main')
- } else if (!this.data.hiddenList && this.data.hiddenGjj) {
- this.scroll(".sbList")
- } else if (!this.data.hiddenList && !this.data.hiddenGjj) {
- this.data.cantap = true
- return
- }
- } else {
- this.scroll(className)
- }
- let timer = setTimeout(() => {
- this.data.cantap = true
- clearTimeout(timer)
- }, 500);
- },
- scroll(className) {
- const obj1 = { h: 'mainHeight', oh: 'mainOriginHeight', hidden: 'hiddenList', status: 'pageStatus' },
- obj2 = { h: 'sbHeight', oh: 'sbOriginHeight', hidden: 'hiddenGjj', status: 'listStatus' }
- var obj = className === '.main' ? obj1 : obj2
- if (this.data[obj.hidden]) {
- var el = my.createSelectorQuery().select(className);
- el.boundingClientRect().exec((data) => {
- var h = data[0].height + 'px'
- this.setData({ [obj.h]: h, [obj.oh]: h, [obj.hidden]: false, [obj.status]: true })
- let timer = setTimeout(() => {
- this.setData({ [obj.h]: 0 })
- clearTimeout(timer)
- }, 0);
- })
- } else {
- this.setData({ [obj.h]: this.data[obj.oh], [obj.status]: false })
- let timer = setTimeout(() => {
- this.setData({ [obj.hidden]: true, [obj.h]: '' })
- clearTimeout(timer)
- }, 500);
- }
- },
- showPicker(e) {
- var pickerType = e.target.dataset.pickerType, pickerIndex = this.getPickerIndex(pickerType)
- this.setData({ bottom: 0, mask: true, pickerType, pickerIndex })
- this.changePickerData()
- },
- hiddePicker() {
- this.setData({ bottom: -this.data.pickerHeight, mask: false, currentValue: '' })
- },
- changePickerData() {
- switch (this.data.pickerType) {
- case '0':
- var p = this.data.cityData.p,
- c = this.getCity(p[this.data.pickerIndex[0]].id)
- this.setData({ pickerData: [p, c] })
- this.data.currentValue = c[this.data.pickerIndex[1]]
- break;
- case '1':
- this.setData({ pickerData: [this.data.typeData] })
- this.data.currentValue = this.data.pickerData[0][this.data.pickerIndex[0]]
- break;
- case '2':
- this.setData({ pickerData: [this.data.hukouData] })
- this.data.currentValue = this.data.pickerData[0][this.data.pickerIndex[0]]
- break;
- case '3':
- this.setData({ pickerData: [this.data.scaleData] })
- this.data.currentValue = this.data.pickerData[0][this.data.pickerIndex[0]]
- break;
- default:
- break;
- }
- },
- scrollPicker(e) {
- let index = e.detail.value[0]
- if (this.data.pickerType != '0') {
- this.data.currentValue = this.data.pickerData[0][index]
- } else {
- let index2 = e.detail.value[1], p = this.data.cityData.p,
- c = this.getCity(p[index].id)
- if (e.detail.value[0] != this.data.pickerIndex[0]) {
- this.data.pickerIndex = [e.detail.value[0], 0]
- } else {
- this.data.pickerIndex = e.detail.value
- }
- this.setData({ pickerData: [p, c], pickerIndex: this.data.pickerIndex })
- this.data.currentValue = this.data.pickerData[1][this.data.pickerIndex[1]]
- }
- },
- sureAction() {
- switch (this.data.pickerType) {
- case '0':
- this.data.city = this.data.currentValue
- this.setData({ city: this.data.city, shebao: '', fund: '', type: this.data.typeData[0] })
- this.getData(this.data.currentValue.id)
- break;
- case '1':
- this.data.type = this.data.currentValue
- this.setData({ type: this.data.type, wxyj: this.data.wxyjData[this.data.currentValue.index] })
- break;
- case '2':
- this.data.hukou = this.data.currentValue
- this.setData({ hukou: this.data.hukou })
- break;
- case '3':
- this.data.scale = this.data.currentValue
- this.setData({ scale: this.data.scale })
- break;
- default:
- break;
- }
- this.calc()
- this.hiddePicker()
- },
- getPickerIndex(pickerType) {
- var pickerIndex
- switch (pickerType) {
- case '0':
- const value = this.data.city,
- cityData = this.data.cityData
- let index1, index2
- cityData.p.map((item, index) => {
- if (item.id == value.pid) index1 = index
- })
- var city = this.getCity(cityData.p[index1].id)
- city.map((item, index) => {
- if (item.id == value.id) index2 = index
- })
- pickerIndex = [index1, index2]
- this.setData({ pickerData: [cityData.p, city] })
- break;
- case '1':
- pickerIndex = [this.data.type.index]
- break;
- case '2':
- pickerIndex = [this.data.hukou.index]
- break;
- case '3':
- pickerIndex = [this.data.scale.index]
- break;
- default:
- break;
- }
- return pickerIndex
- },
- getCity(id) {
- return this.data.cityData.c.filter((item) => {
- if (item.pid == id)
- return item
- })
- },
- getData(id) {
- const type = this.data.type.index
- net.request(
- url.baseUrl + url.getData,
- 'GET',
- { city_code: id }
- ).then((res) => {
- this.setData({ wxyjData: res.data, wxyj: res.data[type] })
- this.calc()
- })
- },
- inputAction(e) {
- let value = Number(e.detail.value) || ''
- if (e.target.dataset.input == 'shebao') {
- this.setData({ shebao: value })
- } else {
- this.setData({ fund: value })
- }
- this.calc()
- },
- calc() {
- this.calcShebao()
- this.calcFund()
- this.setData({ totalMoney: math.Addition(this.data.shebaoMoney, this.data.fundMoney) })
- },
- calcShebao() {
- const calcData = this.data.wxyj.hukouItemList[this.data.hukou.index].itemDataList
- var shebaoList = [], shebaoListTotal = [], fundList = [], arr, jishu, pm, em, pPrice = 0, ePrice = 0, itemTotal, total = 0, first_total = 0
- if (!this.data.shebao) {
- this.setData({ shebaoMoney: 0, shebaoList: '' })
- return
- }
- calcData.map(item => {
- pm = em = 0
- if (this.data.shebao < item.min) {
- jishu = item.min
- } else if (this.data.shebao > item.max) {
- jishu = item.max
- } else {
- jishu = this.data.shebao
- }
- if (!item.ep && !item.pp && !item.max) {
- jishu = '--'
- em = itemTotal = item.min
- pm = '--'
- ePrice = math.Addition(em, ePrice)
- arr = [[item.n], [jishu], [em], [pm], [itemTotal]]
- } else {
- if (item.ep > 0) {
- em = math.Multiplication(jishu, math.Division(item.ep, 100))
- }
- if (item.pp > 0) {
- pm = math.Multiplication(jishu, math.Division(item.pp, 100))
- }
- ePrice = math.Addition(em, ePrice)
- pPrice = math.Addition(pm, pPrice)
- itemTotal = math.Addition(em, pm)
- arr = [[item.n], [jishu], [em, `${item.ep}%`], [pm, `${item.pp}%`], [itemTotal]]
- }
- total = math.Addition(total, itemTotal)
- shebaoList.push(arr)
- if (item.yearPay) {
- first_total = math.Subtraction(total, itemTotal)
- shebaoListTotal = [[ePrice, pPrice, total], [math.Subtraction(first_total, pPrice), pPrice, first_total]]
- } else {
- shebaoListTotal = [[ePrice, pPrice, total]]
- }
- })
- this.setData({ shebaoMoney: total, shebaoListTotal, shebaoList })
- },
- calcFund() {
- const calcData = this.data.wxyj
- let jishu = this.data.fund, avgFund = 0, fundMoney = 0
- if (jishu == '') {
- jishu = 0
- } else if (jishu < calcData.fund_min) {
- jishu = calcData.fund_min
- } else if (jishu > calcData.fund_max) {
- jishu = calcData.fund_max
- }
- if (jishu) {
- avgFund = math.Multiplication(jishu, math.Division(this.data.scale.value, 100))
- fundMoney = math.Multiplication(avgFund, 2)
- }
- this.setData({ fundForm: jishu, avgFund, fundMoney })
- },
- lowest() {
- this.setData({ shebao: this.data.wxyj.shebao_min })
- this.calc()
- },
- sameShebao() {
- let fund
- this.setData({ fund: this.data.shebao })
- if (this.data.shebao > this.data.wxyj.fund_max) {
- fund = this.data.wxyj.fund_max
- } else if (this.data.shebao <= this.data.wxyj.fund_max && this.data.shebao >= this.data.wxyj.fund_min) {
- fund = this.data.shebao
- } else {
- fund = this.data.wxyj.fund_min
- }
- this.calc()
- },
- init() {
- my.createSelectorQuery().select('.picker').boundingClientRect().exec((data) => {
- this.setData({ pickerHeight: data[0].height, bottom: -data[0].height })
- })
- net.request(url.baseUrl + url.getCity, 'POST').then((res) => {
- const p = res.data.filter((item) => {
- if (item.isCity == 0)
- return item
- })
- const c = res.data.filter((item) => {
- if (item.isCity == 1)
- return item
- })
- this.data.cityData = { p, c }
- var city = this.getCity(p[0].id)[0],
- type = this.data.typeData[0],
- hukou = this.data.hukouData[0],
- scale = this.data.scaleData[0]
- this.setData({ city, type, hukou, scale, currentValue: city })
- this.getData(c[0].id)
- })
- var arr = [], index = 0
- for (let i = 5; i < 21; i++) {
- arr[index] = { name: `${i}%`, index, value: i }
- index++
- }
- this.data.scaleData = arr
- },
- onLoad(query) {
- // 页面加载
- this.init()
- },
- onReady() {
- // 页面加载完成
- },
- onShow() {
- // 页面显示
- },
- onHide() {
- // 页面隐藏
- },
- onUnload() {
- // 页面被关闭
- },
- onTitleClick() {
- // 标题被点击
- },
- onPullDownRefresh() {
- // 页面被下拉
- },
- onReachBottom() {
- // 页面被拉到底部
- },
- onShareAppMessage() {
- // 返回自定义分享信息
- return {
- title: '社保公积金代缴计算器',
- desc: '社保公积金代缴计算器',
- path: 'pages/index/index',
- };
- },
- });
|