pay-order.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. var sysT = require('../../../../tool/sys-tool.js')
  2. var businessT = require('../../../../tool/business-tool.js')
  3. var businessType = require('../../../../public/business-type.js')
  4. var p = require('../../public/model/public.js')
  5. var publicData = require('../../../../constant/data.js')
  6. var url = require('../../../../constant/url.js')
  7. import Net from '../../../../tool/net.js'
  8. var net = new Net()
  9. var pay = require('../../../../public/pay.js')
  10. var app = getApp()
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. adapter: {
  17. suffix: ''
  18. },
  19. head: [],
  20. list: {},
  21. total: 0,
  22. pay: {
  23. i: '',
  24. d: ''
  25. },
  26. discount: {
  27. count: 0,
  28. fee: 0,
  29. status: '未使用'
  30. },
  31. discountId:''
  32. },
  33. refreshDiscount: function (dis) {
  34. this.data.discount.fee = dis.fee
  35. this.data.discountId = dis.ids
  36. if (this.data.discount.fee > 0) {
  37. this.data.discount.status = '-¥' + this.data.discount.fee.toFixed(2)
  38. } else {
  39. this.data.discount.status = '未使用'
  40. }
  41. var order = app.purchase.order
  42. var pay = (order.totalFee.total_fee - this.data.discount.fee).toFixed(2)
  43. this.data.pay = {
  44. i: pay.slice(0, -2),
  45. d: pay.slice(-2)
  46. }
  47. this.setData({
  48. discount: this.data.discount,
  49. pay: this.data.pay
  50. })
  51. },
  52. payLaterAction: businessT.action(function (sender) {
  53. wx.showLoading({
  54. title: '正在提交订单',
  55. mask: true
  56. })
  57. var order = app.purchase.order
  58. var obj = this.getParameters({
  59. pay_channel: 5,
  60. fund: order.payFor == businessType.PurchasePayFor.socialInsurance ? 0 : order.accumulationFund,
  61. pay_for: order.payFor
  62. })
  63. var path = order.isSupplementaryPay ? url.createLaterSupplementaryPayOrder : url.createPayLaterOrder
  64. net.connectNeedLogin({
  65. url: url.app_host + path,
  66. data: obj,
  67. success: (err, res) => {
  68. wx.hideLoading()
  69. var pages = getCurrentPages()
  70. businessT.debugLog(pages)
  71. pages[0].route('../../page/mine/pages/wait-for-pay/wait-for-pay')
  72. },
  73. fail: (err, res) => {
  74. wx.hideLoading()
  75. businessT.showFailTips(err, '提交订单失败')
  76. }
  77. })
  78. }),
  79. payAction: businessT.action(function (sender) {
  80. wx.showLoading({
  81. title: '正在提交订单',
  82. mask: true
  83. })
  84. var that = this
  85. pay.prepay({
  86. success: e => {
  87. var order = app.purchase.order
  88. if (order.purchaseType == businessType.PurchaseType.socialInsurance) {
  89. this.createSocialInsuranceOrder(businessType.ResultServeyType.resultServeyTypeSB)
  90. } else if (order.purchaseType == businessType.PurchaseType.socialInsurancePackage) {
  91. this.createSocialInsuranceOrder(businessType.ResultServeyType.resultServeyTypePack)
  92. } else if (order.purchaseType == businessType.PurchaseType.accumulationFund) {
  93. this.createAccumulationFundOrder(businessType.ResultServeyType.resultServeyTypeAF)
  94. } else if (order.purchaseType == businessType.PurchaseType.accumulationFundPackage) {
  95. this.createAccumulationFundOrder(businessType.ResultServeyType.resultServeyTypePack)
  96. }
  97. },
  98. fail: e => {
  99. wx.hideLoading()
  100. businessT.showFailTips(err, '提交订单失败')
  101. }
  102. })
  103. }),
  104. createSocialInsuranceOrder: function (type) {
  105. var order = app.purchase.order
  106. var obj = this.getParameters({
  107. pay_channel: 5,
  108. fund: order.pack ? order.accumulationFund : 0,
  109. couponuser_id: this.data.discountId
  110. })
  111. var path = order.isSupplementaryPay ? url.createShebaoSupplementaryPayOrder : url.createShebaoOrder
  112. var that = this
  113. net.connectNeedLogin({
  114. url: url.app_host + path,
  115. data: obj,
  116. success: (err, res) => {
  117. pay.wxPay({
  118. data: res.data,
  119. success: e => {
  120. if (order.isNeedSalary) {
  121. that.checkSurvey(true, type)
  122. } else {
  123. that.checkSurvey(false, type)
  124. }
  125. },
  126. fail: e => {
  127. wx.hideLoading()
  128. businessT.showFailTips(err, '提交订单失败')
  129. }
  130. })
  131. },
  132. fail: (err, res) => {
  133. wx.hideLoading()
  134. businessT.showFailTips(err, '提交订单失败')
  135. }
  136. }, true)
  137. },
  138. createAccumulationFundOrder: function (type) {
  139. var order = app.purchase.order
  140. var obj = this.getParameters({
  141. pay_channel: 5,
  142. buyShebao: order.pack ? 1 : 0,
  143. fund: order.accumulationFund,
  144. couponuser_id: this.data.discountId
  145. })
  146. var path = order.isSupplementaryPay ? url.createFundSupplementaryPayOrder : url.createFundOrder
  147. var that = this
  148. net.connectNeedLogin({
  149. url: url.app_host + path,
  150. data: obj,
  151. success: (err, res) => {
  152. pay.wxPay({
  153. data: res.data,
  154. success: e => {
  155. if (order.isNeedSalary) {
  156. that.checkSurvey(true, type)
  157. } else {
  158. that.checkSurvey(false, type)
  159. }
  160. },
  161. fail: e => {
  162. wx.hideLoading()
  163. businessT.showFailTips(err, '提交订单失败')
  164. }
  165. })
  166. },
  167. fail: (err, res) => {
  168. wx.hideLoading()
  169. businessT.showFailTips(err, '提交订单失败')
  170. }
  171. }, true)
  172. },
  173. checkSurvey: function (isNeedSalary, type) {
  174. var pages = getCurrentPages()
  175. if (isNeedSalary) {
  176. pages[0].route('../../public/pages/pay-success/pay-success?type=salary')
  177. return
  178. } else {
  179. net.connectNeedLogin({
  180. url: url.app_host + url.checkSurvey,
  181. data: {},
  182. success: (err, res) => {
  183. wx.hideLoading()
  184. if (res.data) {
  185. pages[0].route('../../public/pages/pay-success/pay-success?type=survey&surveyType=' + type)
  186. } else {
  187. this.queryPayPriceDifference()
  188. }
  189. },
  190. fail: (err, res) => {
  191. wx.hideLoading()
  192. pages[0].route('../../public/pages/pay-success/pay-success?type=share')
  193. }
  194. }, false)
  195. }
  196. },
  197. queryPayPriceDifference: function() {
  198. var pages = getCurrentPages()
  199. net.connectNeedLogin({
  200. url: url.app_host + url.queryPayPriceDifference,
  201. data: {},
  202. success: (err, res) => {
  203. wx.hideLoading()
  204. if (res.data > 0) {
  205. pages[0].route('../../public/pages/pay-success/pay-success?type=pay')
  206. } else {
  207. pages[0].route('../../public/pages/pay-success/pay-success?type=share')
  208. }
  209. },
  210. fail: (err, res) => {
  211. wx.hideLoading()
  212. pages[0].route('../../public/pages/pay-success/pay-success?type=share')
  213. }
  214. }, true)
  215. },
  216. getParameters: function (par) {
  217. var order = app.purchase.order
  218. var np = {
  219. sbuId: order.customerData.sbuId,
  220. cid: order.id,
  221. shebao_card: order.SSCard,
  222. hukou_type: order.accountType,
  223. month: businessT.changeTimeToNumber(order.beginTime),
  224. nums: order.timeInterval,
  225. first_sb: order.isFirstBuyShebao ? 1 : 0,
  226. first_fund: order.isFirstBuyFund ? 1 : 0,
  227. sb_wage: (order.isNeedSalary && !order.isInOffice) ? order.salary : 0,
  228. working: order.isNeedSalary ? (order.isInOffice ? 1 : 0) : 0
  229. }
  230. businessT.debugLog(order)
  231. businessT.debugLog(np)
  232. for (var key in par) {
  233. np[key] = par[key]
  234. }
  235. return np
  236. },
  237. discountChoose: businessT.action(function (sender) {
  238. wx.navigateTo({
  239. url: '../../../../public/pages/discount-view/discount-view?type=choose',
  240. })
  241. }),
  242. setUp: function () {
  243. var order = app.purchase.order
  244. //head
  245. var time = order.beginTime
  246. if (order.timeInterval > 1) {
  247. if (order.beginTime.slice(0, 4) == order.endTime.slice(0, 4)) {
  248. time = order.beginTime + '-' + order.endTime.slice(5, 8)
  249. } else {
  250. time = order.beginTime + '-' + order.endTime
  251. }
  252. }
  253. var se = order.customerData.user_name + ' ' + order.customerData.id_card + '\n' + order.cityName + '/' + publicData.accounts[order.accountType - 1]
  254. this.data.head = [time, se]
  255. //list
  256. var l = '购买时长'
  257. var r = order.timeInterval + '个月'
  258. if (order.totalFee.shebao) {
  259. l = l + '\n社保费'
  260. r = r + '\n¥ ' + Number(order.totalFee.shebao).toFixed(2)
  261. }
  262. if (order.totalFee.fund) {
  263. l = l + '\n公积金费用'
  264. r = r + '\n¥ ' + Number(order.totalFee.fund).toFixed(2)
  265. }
  266. if (order.totalFee.card_charge) {
  267. l = l + '\n社保卡'
  268. r = r + '\n¥ ' + Number(order.totalFee.card_charge).toFixed(2) + '/一次性'
  269. }
  270. l = l + '\n服务费'
  271. r = r + '\n¥ ' + Number(order.totalFee.s_charge + order.totalFee.f_charge).toFixed(2)
  272. this.data.list = {l: l, r: r}
  273. this.data.total = order.totalFee.total_fee.toFixed(2)
  274. var pay = (order.totalFee.total_fee - this.data.discount.fee).toFixed(2)
  275. this.data.pay = {
  276. i: pay.slice(0, -2),
  277. d: pay.slice(-2)
  278. }
  279. },
  280. getDiscountCount: function () {
  281. net.connectNeedLogin({
  282. url: url.app_host + url.getCashCouponCount,
  283. data: {
  284. phone: app.globalData.userInfo.phone
  285. },
  286. success: (err, res) => {
  287. this.data.discount.count = res.data.total
  288. if (this.data.discount.count == 0) {
  289. this.data.discount.status = '暂无优惠券'
  290. }
  291. this.setData({
  292. discount: this.data.discount
  293. })
  294. }
  295. }, true)
  296. },
  297. /**
  298. * 生命周期函数--监听页面加载
  299. */
  300. onLoad: function (options) {
  301. this.data.adapter = {
  302. suffix: sysT.suffixOfClass()
  303. }
  304. this.setUp()
  305. this.setData({
  306. adapter: this.data.adapter,
  307. head: this.data.head,
  308. list: this.data.list,
  309. total: this.data.total,
  310. pay: this.data.pay
  311. })
  312. },
  313. /**
  314. * 生命周期函数--监听页面初次渲染完成
  315. */
  316. onReady: function () {
  317. },
  318. /**
  319. * 生命周期函数--监听页面显示
  320. */
  321. onShow: function () {
  322. this.getDiscountCount()
  323. },
  324. /**
  325. * 生命周期函数--监听页面隐藏
  326. */
  327. onHide: function () {
  328. },
  329. /**
  330. * 生命周期函数--监听页面卸载
  331. */
  332. onUnload: function () {
  333. },
  334. /**
  335. * 页面相关事件处理函数--监听用户下拉动作
  336. */
  337. onPullDownRefresh: function () {
  338. },
  339. /**
  340. * 页面上拉触底事件的处理函数
  341. */
  342. onReachBottom: function () {
  343. },
  344. /**
  345. * 用户点击右上角分享
  346. */
  347. // onShareAppMessage: function () {
  348. // }
  349. })