index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. var publicData = require('../../constant/data.js')
  2. var calculate = require('../../constant/calculate.js')
  3. var businessT = require('../../tools/business-tool.js')
  4. var sysT = require('../../tools/sys-tool.js')
  5. var url = require('../../constant/url.js')
  6. var app = getApp()
  7. import Net from '../../tools/net.js'
  8. var net = new Net()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. showShopPopup: false, // 是否显示收藏提示层
  15. animationData: {}, // 动画数据
  16. cityData: [],
  17. gearsArr:[],
  18. min: 0,
  19. getData:false,
  20. tab: 0,
  21. picker: [
  22. { t: '工作城市', c: '', v: [0,0], a: [], i: 0 },
  23. { t: '社保缴纳基数', c: '最低基数', v: '0', a: ['最低基数', '工资基数', '不交社保'], i: 1 },
  24. { t: '公积金缴存基数', c: '最低基数', v: '0', a: ['最低基数', '工资基数', '不交公积金'], i: 2 },
  25. { t: '个人比例', c: '', v: '0', a: [], i: 3 },
  26. { t: '参保方案', c: '', v: '0', a: [], i: 4 },
  27. ],
  28. input: { t: '税前工资(元)', c: '1000', p: '请输入当前税前工资', i: 0 },
  29. tips: {
  30. s: false,
  31. t: '',
  32. c: []
  33. },
  34. deduct: { t: '专项附加扣除(元)', c: '0.00' },
  35. deductData: {
  36. medical: 0,
  37. other: 0
  38. },
  39. interval: 0,
  40. collegeTips:"点击'添加到我的小程序'"
  41. },
  42. //显示提示
  43. showModal() {
  44. // 创建动画
  45. var animation = wx.createAnimation({
  46. duration: 1000,
  47. timingFunction: "ease-in-out",
  48. delay: 0
  49. })
  50. this.animation = animation
  51. animation.translateX(0).step()
  52. this.setData({
  53. animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
  54. showShopPopup: true
  55. })
  56. animation.translateX(-202).step()
  57. this.setData({
  58. animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
  59. showShopPopup: true
  60. })
  61. setTimeout(() => {
  62. animation.translateX(0).step()
  63. this.setData({
  64. animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
  65. showShopPopup: true
  66. })
  67. },2500)
  68. },
  69. //公众号关注组件加载
  70. successload:function(e){
  71. businessT.debugLog('成功码' + e.detail.status + e.detail.errMsg)
  72. },
  73. failload:function(e){
  74. businessT.debugLog('失败码' + e.detail.status + e.detail.errMsg)
  75. },
  76. toDeduct: businessT.action(function (sender) {
  77. wx.navigateTo({
  78. url: 'deduct/deduct'
  79. })
  80. }),
  81. //tips
  82. tipsAction: businessT.action(function (sender) {
  83. if (sender.currentTarget.id == '0') {
  84. this.data.tips.t = '社保基数';
  85. this.data.tips.c = ['最低基数:是指以所在城市的最低缴费基数为基准缴纳社保。', '工资基数:是指以实际工资为基准来缴纳社保。']
  86. } else {
  87. this.data.tips.t = '公积金基数';
  88. this.data.tips.c = ['最低基数:是指以所在城市的最低缴费基数为基准缴纳公积金。', '工资基数:是指以实际工资为基准来缴纳公积金。']
  89. }
  90. this.data.tips.s = true;
  91. this.setData({
  92. tips: this.data.tips
  93. })
  94. }),
  95. dismissTipsView: businessT.action(function (sender) {
  96. this.data.tips.s = false;
  97. this.setData({
  98. tips: this.data.tips
  99. })
  100. }),
  101. //imfo下拉框确认键
  102. pickerChange: businessT.action(function (sender) {
  103. businessT.debugLog(sender)
  104. var index = sender.currentTarget.id
  105. if (index == 4) {
  106. this.changeGears(sender.detail.value)
  107. this.setData({
  108. input: this.data.input,
  109. min: this.data.min,
  110. picker: this.data.picker
  111. })
  112. } else if (index == 0){
  113. businessT.debugLog(this.data.picker[0].a)
  114. businessT.debugLog(sender.detail.value)
  115. this.data.picker[index].v = sender.detail.value
  116. this.data.picker[index].c = this.data.picker[index].a[1][sender.detail.value[1]]
  117. this.getData()
  118. }else {
  119. businessT.debugLog(sender.detail.value)//选中数组下标
  120. this.data.picker[index].v = sender.detail.value
  121. this.data.picker[index].c = this.data.picker[index].a[sender.detail.value]
  122. this.setData({
  123. picker: this.data.picker
  124. })
  125. }
  126. }),
  127. inputAction: function (sender) {
  128. businessT.debugLog(sender)
  129. if (sender.currentTarget.id == 0) {
  130. this.data.input.c = sender.detail.value
  131. this.setData({
  132. input: this.data.input
  133. })
  134. }
  135. },
  136. bindblurAction: function (sender) {
  137. businessT.debugLog(sender)
  138. if (Number(sender.detail.value) < this.data.min) {
  139. wx.showModal({
  140. title: '提示',
  141. content: '税前工资需高于最低工资(' + this.data.min + '元)' ,
  142. showCancel: false,
  143. success: res => {
  144. if (res.confirm) {
  145. this.data.input.c = this.data.min
  146. this.setData({
  147. input: this.data.input
  148. })
  149. }
  150. }
  151. })
  152. }
  153. },
  154. //button
  155. onGotUserInfo: function (sender) {
  156. businessT.debugLog(sender)
  157. if (sender.detail.errMsg == 'getUserInfo:ok') {
  158. let avatarUrl = sender.detail.userInfo.avatarUrl
  159. let nickName = sender.detail.userInfo.nickName
  160. this.calculate(avatarUrl, nickName)
  161. }
  162. },
  163. calculate: function (avatarUrl, nickName) {
  164. if (!this.data.getData) {
  165. wx.showToast({
  166. title: '请重新选择城市获取数据',
  167. icon: 'none'
  168. })
  169. return
  170. }
  171. if (this.data.input.c < this.data.min) {
  172. return
  173. }
  174. if (this.data.input.c == '') {
  175. wx.showToast({
  176. title: '请输入税前工资',
  177. icon: 'none'
  178. })
  179. return
  180. }
  181. wx.showLoading({
  182. title: '计算中',
  183. mask: true,
  184. })
  185. var data = this.data.cityData[this.data.picker[4].v]
  186. var a = 0
  187. if (this.data.picker[2].v == 0) {
  188. a = data.fund_min * (0.05 + this.data.picker[3].v * 0.01)
  189. } else if (this.data.picker[2].v == 1) {
  190. if (Number(this.data.input.c) > data.fund_max) {
  191. a = data.fund_max * (0.05 + this.data.picker[3].v * 0.01)
  192. } else {
  193. a = Number(this.data.input.c) * (0.05 + this.data.picker[3].v * 0.01)
  194. }
  195. }
  196. if (this.data.picker[1].v == 2) {
  197. this.calculateDeduct(0, a, avatarUrl, nickName)
  198. } else {
  199. var salary = Number(this.data.input.c)
  200. if (this.data.picker[1].v == 0) {
  201. salary = data.shebao_min
  202. }
  203. net.connect({
  204. url: url.app_host + url.getShebao,
  205. method: 'POST',
  206. data: {
  207. cid: data.id,
  208. hukou_type: data.id == 18 ? '3' : '1',
  209. shebao_salary: salary
  210. },
  211. success: (err, res) => {
  212. this.calculateDeduct(res.data, a, avatarUrl, nickName)
  213. },
  214. fail: (err, res) => {
  215. businessT.showFailTips(err, '加载失败')
  216. }
  217. })
  218. }
  219. },
  220. calculateDeduct: function (s, a, avatarUrl, nickName) {
  221. var result = calculate.calculate(this.data.input.c, s, a, this.data.picker[3].v, this.data.deductData.other, this.data.deductData.medical)
  222. businessT.debugLog(result)
  223. app.result = result
  224. if (this.data.deductData.medical > 0) {
  225. app.medical.s = true
  226. } else {
  227. app.medical.s = false
  228. }
  229. app.medical.rebate = result[4]
  230. var date = new Date()
  231. var month = date.getMonth()
  232. wx.navigateTo({
  233. 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],
  234. })
  235. wx.hideLoading()
  236. },
  237. changeGears: function (i) {
  238. this.data.picker[4].v = i
  239. this.data.picker[4].c = this.data.picker[4].a[i]
  240. var data = this.data.cityData[i]
  241. this.data.min = data.fund_min >= data.shebao_min ? data.fund_min : data.shebao_min
  242. if (Number(this.data.input.c) < this.data.min) {
  243. this.data.input.c = this.data.min
  244. }
  245. },
  246. //获取城市社保数据
  247. getData: function () {
  248. wx.showLoading({
  249. title: '加载中',
  250. mask: true
  251. })
  252. net.connect({
  253. url: url.app_host + url.getCityData,
  254. method: 'GET',
  255. data: {
  256. city_code: publicData.cityCodes[this.data.picker[0].v[1]]
  257. },
  258. success: (err, res) => {
  259. if (Object.prototype.toString.call(res.data) == '[object Array]' && res.data.length > 0) {
  260. this.data.cityData = res.data
  261. var gearsArr = []
  262. for (var i = 0; i < res.data.length; i ++) {
  263. gearsArr.push(res.data[i].shebao_type)
  264. }
  265. this.data.picker[4].a = gearsArr
  266. this.changeGears(0)
  267. businessT.debugLog(gearsArr)
  268. this.data.getData = true
  269. this.setData({
  270. input :this.data.input,
  271. min: this.data.min,
  272. picker: this.data.picker
  273. })
  274. wx.hideLoading()
  275. } else {
  276. this.data.getData = false
  277. businessT.showFailTips({ code: 0, msg: '' }, '加载失败')
  278. }
  279. },
  280. fail: (err, res) => {
  281. this.data.getData = false
  282. businessT.showFailTips(err, '加载失败')
  283. }
  284. }, true)
  285. },
  286. //获取工作的城市
  287. getCityData:function(){
  288. net.connect({
  289. url: url.app_host + url.getWordCity,
  290. method: 'GET',
  291. data: {},
  292. success: (err, res) => {
  293. if (Object.prototype.toString.call(res.data) == '[object Array]' && res.data.length > 0) {
  294. businessT.debugLog(res.data)
  295. let p_Data = res.data.filter(item => item.isCity == 0);
  296. let c_Data = res.data.filter(item => item.isCity == 1);
  297. let provinceData = p_Data.map(item => item.name);
  298. let cityCodes = c_Data.map(item => item.id);
  299. publicData.cityCodes = cityCodes;
  300. businessT.debugLog(provinceData);
  301. var default_p_id = p_Data[0]['id'];//1000默认省id
  302. let cityData = c_Data.filter(item => item.pid == default_p_id);
  303. let cityNameData = cityData.map(item => item.name);
  304. this.data.picker[0].a = [provinceData, cityNameData];
  305. this.data.picker[0].c = this.data.picker[0]['a'][1][this.data.picker[0].v[1]]//默认城市
  306. this.setData({
  307. p_Data,
  308. c_Data,
  309. provinceData,
  310. picker: this.data.picker
  311. })
  312. } else {
  313. businessT.showFailTips({ code: 0, msg: '' }, '加载失败')
  314. }
  315. },
  316. fail: (err, res) => {
  317. businessT.debugLog(res)
  318. businessT.showFailTips(err, '加载失败')
  319. }
  320. }, true);
  321. // callback();
  322. },
  323. //省市列改变
  324. pickerColumnChange:function(e){
  325. businessT.debugLog('修改的列为', e.detail.column, ',值为', e.detail.value);
  326. this.data.picker[0].v[e.detail.column] = e.detail.value;
  327. switch (e.detail.column){
  328. case 0:
  329. let id = this.data.p_Data[e.detail.value]['id']
  330. let cityData = this.data.c_Data.filter(item => item.pid == id)
  331. let cityCodes = cityData.map(item => item.id)
  332. let cityNameData = cityData.map(item => item.name)
  333. publicData.cityCodes = cityCodes
  334. this.data.picker[0].a = [this.data.provinceData, cityNameData]
  335. this.setData({
  336. picker: this.data.picker
  337. })
  338. break;
  339. }
  340. },
  341. //跳转H5
  342. toweb:function(e){
  343. wx:wx.navigateTo({
  344. url: 'webView/webView',
  345. success: function(res) {},
  346. fail: function(res) {},
  347. complete: function(res) {},
  348. })
  349. },
  350. /**
  351. * 生命周期函数--监听页面加载
  352. */
  353. onLoad: function (options) {
  354. this.getCityData()
  355. // this.data.picker[0].a = publicData.citys
  356. // this.data.picker[0].c = publicData.citys[this.data.picker[0].v]
  357. this.data.picker[3].a = publicData.proportions
  358. this.data.picker[3].c = publicData.proportions[0]
  359. this.setData({
  360. picker: this.data.picker
  361. })
  362. this.getData()
  363. },
  364. /**
  365. * 生命周期函数--监听页面初次渲染完成
  366. */
  367. onReady: function () {
  368. var query = wx.createSelectorQuery();
  369. query.select('#bannerBottom').boundingClientRect()
  370. var that = this;
  371. query.exec(function (res) {
  372. //res就是 该元素的信息 数组
  373. businessT.debugLog(res[0])
  374. var h = sysT.sysInfo().windowHeight - res[0].top - res[0].height - 230 * sysT.rpxToPx()
  375. if (h > 0) {
  376. that.setData({
  377. interval: h
  378. })
  379. }
  380. businessT.debugLog(h)
  381. })
  382. },
  383. /**
  384. * 生命周期函数--监听页面显示
  385. */
  386. onShow: function () {
  387. if (typeof this.getTabBar === 'function' &&
  388. this.getTabBar()) {
  389. this.getTabBar().setData({
  390. selected: 0
  391. })
  392. }
  393. this.setData({
  394. deduct: this.data.deduct
  395. })
  396. this.showModal();
  397. },
  398. /**
  399. * 生命周期函数--监听页面隐藏
  400. */
  401. onHide: function () {
  402. },
  403. /**
  404. * 生命周期函数--监听页面卸载
  405. */
  406. onUnload: function () {
  407. },
  408. /**
  409. * 页面相关事件处理函数--监听用户下拉动作
  410. */
  411. onPullDownRefresh: function () {
  412. console.log("测试下拉")
  413. },
  414. /**
  415. * 页面上拉触底事件的处理函数
  416. */
  417. onReachBottom: function () {
  418. },
  419. /**
  420. * 用户点击右上角分享
  421. */
  422. onShareAppMessage: function () {
  423. }
  424. })