Member.js 5.1 KB

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