Member.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. var _Priceid = this.data.Priceid
  52. let payment_url = 'pay/wxpay/index';
  53. let payment_data = {
  54. rid: this.data.Priceid,
  55. total_price: this.data.Price, //原价
  56. discount_peice: this.data.Originalprice, //优惠
  57. };
  58. app.postRequest(payment_url, payment_data, function (res) { // 年龄 ajax
  59. console.log(res.data)
  60. if (res.code == 201) {
  61. wx.requestPayment({
  62. timeStamp: res.data.timeStamp,
  63. nonceStr: res.data.nonceStr,
  64. package: res.data.package,
  65. signType: res.data.signType,
  66. paySign: res.data.paySign,
  67. success(res) {
  68. wx.showToast({
  69. title: '支付成功',
  70. icon: 'success',
  71. duration: 2000
  72. })
  73. },
  74. fail(res) {
  75. var _fail = '支付失败'
  76. getApp().Tips(_fail);
  77. }
  78. })
  79. return
  80. }
  81. var _fail = '支付失败'
  82. getApp().Tips(_fail);
  83. })
  84. }
  85. })