Member.js 4.7 KB

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