purchase-imformation.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import Net from '../../../../tool/net.js'
  2. var net = null
  3. var url = require('../../../../constant/url.js')
  4. var p = require('../model/public.js')
  5. var businessType = require('../../../../public/business-type.js')
  6. var businessT = require('../../../../tool/business-tool.js')
  7. var isS = true
  8. var _reload = null
  9. var app = getApp()
  10. var _shebao = 0
  11. var _cardCharge = 0
  12. function setOut (i) {
  13. net = new Net()
  14. isS = i
  15. }
  16. function finish () {
  17. net = null
  18. }
  19. function handleImformation (reload) {
  20. wx.showLoading({
  21. title: '加载中',
  22. mask: true
  23. })
  24. _reload = reload
  25. var order = p.getOrder()
  26. getBuyTotalFee()
  27. // if (order.customerData.sbuId && order.customerData.sbuId != '') {
  28. // getBuyTotalFee()
  29. // } else {
  30. // uploadImage()
  31. // }
  32. }
  33. // function uploadImage () {
  34. // uploadFirstImage()
  35. // }
  36. // function uploadFirstImage() {
  37. // var order = p.getOrder()
  38. // net.uploadImage({
  39. // url: url.www_host + url.uploadIdcardByNumber,
  40. // imgPath: order.imageDict.first,
  41. // imgName: 'file1',
  42. // data: { id_card: order.customerData.id_card, pos: 0 },
  43. // success: (err, res) => {
  44. // uploadSecondImage(res.data)
  45. // },
  46. // fail: (err, res) => {
  47. // wx.hideLoading()
  48. // businessT.showFailTips(err, '生成参保人信息失败')
  49. // }
  50. // }, true)
  51. // }
  52. // function uploadSecondImage(firstPath) {
  53. // var order = p.getOrder()
  54. // net.uploadImage({
  55. // url: url.www_host + url.uploadIdcardByNumber,
  56. // imgPath: order.imageDict.second,
  57. // imgName: 'file2',
  58. // data: { id_card: order.customerData.id_card, pos: 1 },
  59. // success: (err, res) => {
  60. // uploadCustomerImformation(firstPath, res.data)
  61. // },
  62. // fail: (err, res) => {
  63. // wx.hideLoading()
  64. // businessT.showFailTips(err, '生成参保人信息失败')
  65. // }
  66. // }, true)
  67. // }
  68. // function uploadCustomerImformation (fp, sp) {
  69. // businessT.debugLog(fp)
  70. // businessT.debugLog(sp)
  71. // var order = p.getOrder()
  72. // var data = order.customerData
  73. // data.id_card_img = fp
  74. // data.id_card_img1 = sp
  75. // net.connectNeedLogin({
  76. // url: url.app_host + url.modifyCustomer,
  77. // data: data,
  78. // success: (err, res) => {
  79. // modifyCustomerNetworkGetData(res.data.id)
  80. // getBuyTotalFee()
  81. // },
  82. // fail: (err, res) => {
  83. // wx.hideLoading()
  84. // businessT.showFailTips(err, '生成参保人信息失败')
  85. // }
  86. // })
  87. // }
  88. // function modifyCustomerNetworkGetData (id) {
  89. // var order = p.getOrder()
  90. // order.customerData.sbuId = id
  91. // order.customerData.id = id
  92. // order.customerData.id_card_img = null
  93. // order.customerData.id_card_img1 = null
  94. // order.customerData.id_card = String(order.customerData.id_card).slice(0, 2) + '**************' + String(order.customerData.id_card).slice(16, 18)
  95. // var isNew = true
  96. // for (var i in app.globalData.customerList) {
  97. // var customer = app.globalData.customerList[i]
  98. // if (customer.id == order.customerData.id) {
  99. // order.customerData.shebao_card = customer.shebao_card
  100. // order.customerData.fund_card = customer.fund_card
  101. // app.globalData.customerList[i] = order.customerData
  102. // isNew = false
  103. // break
  104. // }
  105. // }
  106. // if (isNew) {
  107. // app.globalData.customerList.push(order.customerData)
  108. // }
  109. // }
  110. function calculateBuyTotalFee(o) {
  111. var order = p.getOrder()
  112. var path = order.isSupplementaryPay ? url.getTotalSupplementaryPayFee : url.getTotalFee
  113. var obj = {
  114. sbuId: order.customerData.sbuId,
  115. cid: order.id,
  116. shebao_card: order.SSCard,
  117. hukou_type: order.accountType,
  118. month: businessT.changeTimeToNumber(order.beginTime),
  119. fund: '0',
  120. nums: order.timeInterval,
  121. pay_for: businessType.PurchasePayFor.socialInsurance
  122. }
  123. net.connectNeedLogin({
  124. url: url.app_host + path,
  125. data: obj,
  126. success: (err, res) => {
  127. wx.hideLoading()
  128. setTotal(res.data)
  129. o.success(res.data)
  130. },
  131. fail: (err, res) => {
  132. wx.hideLoading()
  133. if (err.code == businessType.NetworkErrorCode.netwrokMiss) {
  134. o.failure(err)
  135. businessT.showFailTips(err, '切换失败')
  136. return
  137. }
  138. setTotal(null)
  139. o.success(null)
  140. }
  141. }, true)
  142. }
  143. function setTotal(data) {
  144. if (data) {
  145. _shebao = Number(data.shebao).toFixed(2)
  146. _cardCharge = String(data.card_charge)
  147. businessT.debugLog('you')
  148. } else {
  149. var order = p.getOrder()
  150. var purchase = app.purchase.purchaseData
  151. _cardCharge = order.SSCard == 0 ? 0 : app.purchase.purchaseData.shebao_card_charge
  152. var shebao = 0
  153. if (purchase.shebaos && Object.prototype.toString.call(purchase.shebaos) == '[object Array]') {
  154. var arr = purchase.shebaos[order.accountType - 1].data
  155. for (var index in arr) {
  156. var item = arr[index]
  157. shebao += Number(item.p)
  158. }
  159. }
  160. _shebao = (shebao * order.timeInterval).toFixed(2)
  161. businessT.debugLog('meiyou')
  162. }
  163. }
  164. function getTotal() {
  165. return [_shebao, _cardCharge]
  166. }
  167. function getBuyTotalFee() {
  168. var order = p.getOrder()
  169. if (isS) {
  170. order.payFor = order.pack ? businessType.PurchasePayFor.socialInsurancePackage : businessType.PurchasePayFor.socialInsurance
  171. var fund = order.pack ? Number(order.accumulationFund) : 0
  172. } else {
  173. order.payFor = order.pack ? businessType.PurchasePayFor.accumulationFundPackage : businessType.PurchasePayFor.accumulationFund
  174. var fund = Number(order.accumulationFund)
  175. }
  176. var path = order.isSupplementaryPay ? url.getTotalSupplementaryPayFee : url.getTotalFee
  177. var obj = {
  178. sbuId: order.customerData.sbuId,
  179. cid: order.id,
  180. shebao_card: order.SSCard,
  181. hukou_type: order.accountType,
  182. month: businessT.changeTimeToNumber(order.beginTime),
  183. fund: fund,
  184. nums: order.timeInterval,
  185. pay_for: order.payFor
  186. }
  187. net.connectNeedLogin({
  188. url: url.app_host + path,
  189. data: obj,
  190. success: (err, res) => {
  191. order.totalFee = res.data
  192. if (order.payFor == businessType.PurchasePayFor.socialInsurance) {
  193. goToOrder()
  194. } else {
  195. getFundOfBuyBefore()
  196. }
  197. },
  198. fail: (err, res) => {
  199. wx.hideLoading()
  200. businessT.showFailTips(err, '生成参保人信息失败')
  201. }
  202. }, true)
  203. }
  204. function getFundOfBuyBefore() {
  205. var order = p.getOrder()
  206. net.connectNeedLogin({
  207. url: url.app_host + url.getFundOfBuyBefore,
  208. data: {
  209. sbuId: order.customerData.sbuId,
  210. city_code: order.city
  211. },
  212. success: (err, res) => {
  213. var fund = Number(res.data)
  214. if (fund != 0 && Number(order.accumulationFund) - fund > 0) {
  215. wx.hideLoading()
  216. wx.showModal({
  217. title: '',
  218. content: '你最近一次缴公积金金额为' + fund + '元,若非系统调整请不要随意更改',
  219. confirmColor: '#3296FB',
  220. cancelColor: '#3296FB',
  221. confirmText: '返回修改',
  222. cancelText: '继续购买',
  223. success: function (res) {
  224. if (res.confirm) {
  225. _reload(fund)
  226. } else if (res.cancel) {
  227. goToOrder()
  228. }
  229. }
  230. })
  231. } else if (fund != 0 && Number(order.accumulationFund) - fund < 0) {
  232. wx.hideLoading()
  233. wx.showModal({
  234. title: '',
  235. content: '你最近一次缴公积金金额为' + fund + '元,若非系统调整请不要随意更改',
  236. confirmColor: '#3296FB',
  237. cancelColor: '#3296FB',
  238. confirmText: '我知道了',
  239. showCancel: false,
  240. success: function (res) {
  241. if (res.confirm) {
  242. _reload(fund)
  243. }
  244. }
  245. })
  246. } else {
  247. goToOrder()
  248. }
  249. },
  250. fail: (err, res) => {
  251. wx.hideLoading()
  252. businessT.showFailTips(err, '生成参保人信息失败')
  253. }
  254. })
  255. }
  256. function goToOrder() {
  257. wx.hideLoading()
  258. var order = p.getOrder()
  259. var app = getApp()
  260. app.purchase.order = order
  261. wx.navigateTo({
  262. url: '../pay-order/pay-order',
  263. })
  264. }
  265. module.exports = {
  266. setOut: setOut,
  267. finish: finish,
  268. handleImformation: handleImformation,
  269. calculateBuyTotalFee: calculateBuyTotalFee,
  270. getTotal: getTotal
  271. }