Member.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const app = getApp();
  2. Page({
  3. data: {
  4. OccupationArray: [], // 职业-数据
  5. Occupationindex: 0, // 职业-下标
  6. Price:'', //价格
  7. Originalprice:'', //价格
  8. day:'', // 天
  9. Priceid: '', // 价格ID
  10. },
  11. onLoad: function (options) {
  12. var that =this;
  13. // 职业 ajax
  14. let Occupation_url = 'pay/recharge/setmealinfo';
  15. let Occupation_data = {
  16. pid: '0'
  17. };
  18. app.postRequest(Occupation_url, Occupation_data, function (res) { // 职业 ajax
  19. if (res.code == 201) {
  20. // 计算日均价 四舍五入
  21. var averageprice = Number(res.data[0].discount_peice / res.data[0].day);
  22. averageprice = averageprice.toFixed(2); //取小数点后两位
  23. // console.log(averageprice)
  24. that.setData({
  25. OccupationArray: res.data,
  26. Price: res.data[0].total_price, //原价
  27. Originalprice: res.data[0].discount_peice, //优惠价格
  28. Priceid: res.data[0].id, //价格ID
  29. day: averageprice, // 日均价
  30. })
  31. }
  32. })
  33. },
  34. OccupationEvent: function (e) { // 职业 单项选择器
  35. var _discount_peice = this.data.OccupationArray[e.detail.value].discount_peice //优惠价格
  36. var _day = this.data.OccupationArray[e.detail.value].day //天
  37. // 计算日均价 四舍五入
  38. var _averageprice = Number(_discount_peice / _day);
  39. _averageprice = _averageprice.toFixed(2); //取小数点后两位
  40. // console.log(this.data.OccupationArray[e.detail.value].id);
  41. // console.log('picker发送选择改变,携带值为', e.detail.value)
  42. this.setData({
  43. Priceid:this.data.OccupationArray[e.detail.value].id, //价格ID
  44. Price:this.data.OccupationArray[e.detail.value].total_price, //原价
  45. Originalprice: this.data.OccupationArray[e.detail.value].discount_peice, //优惠价格
  46. Occupationindex: e.detail.value,
  47. day: _averageprice,
  48. })
  49. },
  50. sfzfmclick(e) {
  51. },
  52. pay: function () {
  53. let _that = this;
  54. wx.login({
  55. success: function (res) {
  56. console.log(res.code)
  57. if (res.code) {
  58. // let p_url = 'public/wxlogin';
  59. // let p_data = {
  60. // code: res.code,
  61. // };
  62. var _Priceid = _that.data.Priceid
  63. let payment_url = 'pay/wxpay/index';
  64. let payment_data = {
  65. rid: _that.data.Priceid,
  66. total_price: _that.data.Price, //原价
  67. discount_peice: _that.data.Originalprice, //优惠
  68. code: res.code
  69. };
  70. app.postRequest(payment_url, payment_data, function (res) {
  71. console.log(res.data)
  72. if (res.code == 201) {
  73. wx.requestPayment({
  74. timeStamp: res.data.timeStamp,
  75. nonceStr: res.data.nonceStr,
  76. package: res.data.package,
  77. signType: res.data.signType,
  78. paySign: res.data.paySign,
  79. success(res) {
  80. wx.showToast({
  81. title: '支付成功',
  82. icon: 'success',
  83. duration: 2000
  84. })
  85. },
  86. fail(res) {
  87. getApp().Tips('支付失败');
  88. }
  89. })
  90. return
  91. }
  92. getApp().Tips('支付失败');
  93. })
  94. // app.postRequest(p_url, p_data, function (res) {
  95. // console.log(res);
  96. // if (res.code == 201) {
  97. // }
  98. // })
  99. }
  100. }
  101. })
  102. }
  103. })