pay.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. var businessT = require('../../../tool/business-tool.js')
  2. var sysT = require('../../../tool/sys-tool.js')
  3. var url = require('../../../constant/url.js')
  4. import Net from '../../../tool/net.js'
  5. var net = new Net()
  6. var app = getApp()
  7. var wxyj = require('../../../public/wxyj.js')
  8. Page({
  9. data: {
  10. cheapMoney: 0,
  11. cheapCount: 0,
  12. cheapStatus: '未使用',
  13. cheapData: []
  14. },
  15. initData(res) {
  16. var order = wxyj.wxyjData.order, date, userIndex, sy, sm, ey, em
  17. sy = Number(order.month.substring(0, 4))
  18. sm = Number(order.month.slice(-2))
  19. ey = sy
  20. em = sm
  21. res.nums = Number(res.nums)
  22. if (res.nums == 1) {
  23. date = sy + '年' + sm + '月'
  24. } else {
  25. console.log(sm + res.nums)
  26. if (sm + res.nums > 13) {
  27. ey += 1
  28. em = sm + res.nums - 13
  29. } else if (sm + res.nums == 13) {
  30. em = 12
  31. } else {
  32. em = sm + res.nums - 1
  33. }
  34. // if (sy == ey) {
  35. // date = sy + '年' + sm + '月-' + em + '月'
  36. // } else {
  37. date = sy + '年' + sm + '月-' + ey + '年' + em + '月'
  38. // }
  39. }
  40. app.globalData.customerList.forEach((item, index) => {
  41. if (item.id == order.sbuId) {
  42. userIndex = index
  43. }
  44. })
  45. this.setData({
  46. res,
  47. date,
  48. newCard: wxyj.wxyjData.order.newCard,
  49. name: app.globalData.customerList[userIndex].user_name,
  50. idcard: app.globalData.customerList[userIndex].id_card,
  51. card_charge: res.price.card_charge.toFixed(2),
  52. service: (res.price.f_charge + res.price.s_charge).toFixed(2),
  53. shebao: res.price.shebao.toFixed(2),
  54. fund: res.price.fund.toFixed(2),
  55. totalPrice: res.price.total_fee.toFixed(2)
  56. })
  57. var totalPrice = String((this.data.totalPrice - this.data.cheapMoney).toFixed(2))
  58. var totalPriceArr = []
  59. totalPriceArr[0] = totalPrice.substring(0, totalPrice.length - 2)
  60. totalPriceArr[1] = totalPrice.slice(-2)
  61. this.setData({ totalPriceArr })
  62. },
  63. goCheap() {
  64. swan.navigateTo({
  65. url: '.././../../page/mypage/pages/cheap/cheap?status=choose&nums=' + this.data.res.nums,
  66. })
  67. },
  68. createPayLaterOrder() {
  69. swan.showLoading({
  70. title: '正在提交订单',
  71. mask: true
  72. })
  73. var order = wxyj.wxyjData.order
  74. var path
  75. if (this.data.res.type == 0 || this.data.res.type == 2) {
  76. path = url.createPayLaterOrder
  77. } else {
  78. path = url.createLaterSupplementaryPayOrder
  79. }
  80. var obj = this.getParameters()
  81. net.connectNeedLogin({
  82. url: url.app_host + path,
  83. data: obj,
  84. success: (err, res) => {
  85. swan.hideLoading()
  86. swan.switchTab({
  87. url: '../../../page/mypage/index/index',
  88. success: res => {
  89. swan.navigateTo({
  90. url: '../../../page/mypage/pages/pay/pay',
  91. });
  92. },
  93. });
  94. },
  95. fail: (err, res) => {
  96. swan.hideLoading()
  97. businessT.showFailTips(err, '提交订单失败')
  98. }
  99. })
  100. },
  101. getParameters: function (par) {
  102. var order = wxyj.wxyjData.order
  103. var np = {
  104. sbuId: order.sbuId,
  105. id_card: order.id_card,
  106. cid: order.cid,
  107. buyShebao: order.buyShebao,
  108. shebao_card: order.shebao_card ? order.shebao_card : 0,
  109. hukou_type: order.hukou_type,
  110. fund: order.fund,
  111. pay_channel: 13,
  112. pay_for: order.pay_for,
  113. couponuser_id: this.data.couponuser_id ? this.data.couponuser_id : '',
  114. month: order.month,
  115. nums: order.nums,
  116. newCard: order.newCard,
  117. first_sb: order.first_sb,
  118. first_fund: order.first_fund,
  119. sb_wage: order.sb_wage,
  120. working: order.working
  121. }
  122. for (var key in par) {
  123. np[key] = par[key]
  124. }
  125. return np
  126. },
  127. getDiscountCount() {
  128. net.connectNeedLogin({
  129. url: url.app_host + url.getCashCouponCount,
  130. data: {
  131. phone: app.globalData.userInfo.phone
  132. },
  133. success: (err, res) => {
  134. console.log(res)
  135. this.data.cheapCount = res.data.total
  136. if (this.data.cheapCount == 0) {
  137. this.data.cheapStatus = '暂无优惠券'
  138. }
  139. this.setData({
  140. cheapCount: this.data.cheapCount
  141. })
  142. }
  143. }, true)
  144. },
  145. refreshCheap() {
  146. var totalPrice = this.data.totalPrice, totalPriceArr = this.data.totalPriceArr, cheapMoney = 0
  147. if (this.data.cheapData.length) {
  148. this.data.cheapData.forEach((item) => {
  149. cheapMoney += item.coupon_price
  150. })
  151. cheapMoney = cheapMoney.toFixed(2)
  152. totalPrice = totalPrice - cheapMoney
  153. totalPrice = String(totalPrice)
  154. totalPriceArr[0] = totalPrice.substring(0, totalPrice.length - 2)
  155. totalPriceArr[1] = totalPrice.slice(-2)
  156. this.setData({
  157. cheapStatus: "-¥" + cheapMoney,
  158. cheapMoney,
  159. totalPriceArr
  160. })
  161. } else {
  162. this.setData({
  163. cheapStatus: '未使用',
  164. cheapMoney: 0
  165. })
  166. this.initData(this.data.res)
  167. }
  168. },
  169. payAction() {
  170. var id = '', path, order = wxyj.wxyjData.order
  171. this.data.cheapData.forEach((item) => {
  172. if (item) {
  173. id += item.id + ','
  174. }
  175. })
  176. if (id) { id = id.slice(0, -1) }
  177. var obj = this.getParameters({ pay_channel: 13, couponuser_id: id })
  178. switch (this.data.res.orderStatus) {
  179. case '0':
  180. path = url.createShebaoOrder
  181. break
  182. case '1':
  183. path = url.createShebaoSupplementaryPayOrder
  184. break
  185. case '2':
  186. path = url.createFundOrder
  187. break
  188. case '3':
  189. path = url.createFundSupplementaryPayOrder
  190. break
  191. }
  192. net.connectNeedLogin({
  193. url: url.app_host + path,
  194. data: obj,
  195. success: (err, res) => {
  196. swan.requestPolymerPayment({
  197. orderInfo: res.data,
  198. success: res => {
  199. this.needSurvey()
  200. },
  201. fail: err => {
  202. swan.showToast({
  203. title: '支付失败',
  204. icon: 'none'
  205. });
  206. }
  207. });
  208. },
  209. fail: (err, res) => {
  210. swan.hideLoading()
  211. businessT.showFailTips(err, '提交订单失败')
  212. }
  213. }, true)
  214. },
  215. needSurvey() {
  216. if(wxyj.wxyjData.order.sb_wage){
  217. swan.navigateTo({
  218. url: '../pay-success/pay-success?type=salary'
  219. });
  220. return
  221. }
  222. net.connectNeedLogin({
  223. url: url.app_host + url.checkSurvey,
  224. data: {},
  225. success: (err, res) => {
  226. if (res.data) {
  227. swan.navigateTo({
  228. url: '../pay-success/pay-success?type=survey&payfor=' + order.pay_for,
  229. });
  230. }else{
  231. this.needRepair()
  232. }
  233. },
  234. fail: (err, res) => {
  235. swan.navigateTo({
  236. url: '../pay-success/pay-success?type=share'
  237. });
  238. }
  239. }, false)
  240. },
  241. needRepair(){
  242. net.connectNeedLogin({
  243. url: url.app_host + url.queryPayPriceDifference,
  244. data: {},
  245. success: (err, res) => {
  246. if(res.data){
  247. swan.navigateTo({
  248. url: '../pay-success/pay-success?type=repair'
  249. });
  250. }else{
  251. swan.navigateTo({
  252. url: '../pay-success/pay-success?type=share'
  253. });
  254. }
  255. },
  256. fail: (err, res) => {
  257. swan.navigateTo({
  258. url: '../pay-success/pay-success?type=share'
  259. });
  260. }
  261. },false)
  262. },
  263. onLoad: function (res) {
  264. // 监听页面加载的生命周期函数
  265. swan.setPageInfo && swan.setPageInfo({
  266. title: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  267. keywords: '我的社保,我的社保网,我的社保APP,社会保障,社保,社保代缴,公积金代缴,社会保险,五险一金,医保,医疗保险,公积金,养老,生育,工伤,失业,住房公积金,社保代理,代缴社保,公积金代理,查悦社保,大社保,亲亲小保,社保掌上通,招聘求职,创业,买房,贷款,计算器,人社局,摇号',
  268. description: '我的社保APP是为个人、企业提供社保代缴代扣、公积金代扣代缴、社保查询、公积金查询服务的名牌产品。解决个体工商户、自由职业者、待业人员、全职妈妈、创业者等的个人社保公积金断缴难题,同时解决贷款, 买房, 买车, 养老, 医疗, 生育, 医疗报销等难题。同时为企业提供全国专业社保代理和公积金代理。',
  269. articleTitle: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  270. release_date: '2019-02-23 20:00:00',
  271. success: function () {
  272. console.log('页面基础信息设置完成');
  273. },
  274. fail: function (res) {
  275. console.log('设置失败');
  276. },
  277. })
  278. console.log(res)
  279. res.price = JSON.parse(res.price)
  280. this.initData(res)
  281. this.setData({ suffix: sysT.suffixOfClass() })
  282. this.getDiscountCount()
  283. },
  284. onReady: function () {
  285. // 监听页面初次渲染完成的生命周期函数
  286. },
  287. onShow: function () {
  288. // 监听页面显示的生命周期函数
  289. this.refreshCheap()
  290. },
  291. onHide: function () {
  292. // 监听页面隐藏的生命周期函数
  293. },
  294. onUnload: function () {
  295. // 监听页面卸载的生命周期函数
  296. },
  297. onPullDownRefresh: function () {
  298. // 监听用户下拉动作
  299. },
  300. onReachBottom: function () {
  301. // 页面上拉触底事件的处理函数
  302. },
  303. onShareAppMessage: function () {
  304. // 用户点击右上角转发
  305. }
  306. });