property.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import HTTP from "../../../../requestFn/Api"
  2. const app = getApp();
  3. Page({
  4. data: {
  5. garden_id: "",
  6. house_id: "",
  7. propertyInfo: {},
  8. should_pay_amount: 0,
  9. order_id:""
  10. },
  11. onLoad(options) {
  12. const {
  13. garden_id,
  14. house_id
  15. } = app.globalData;
  16. this.setData({
  17. garden_id
  18. })
  19. this.getProperty(garden_id, house_id)
  20. },
  21. async getProperty(garden_id, house_id) {
  22. const data = await HTTP.GetMonthsProperty({
  23. garden_id,
  24. house_id
  25. })
  26. const month_list = data.month_list.map(item => {
  27. return {
  28. ...item,
  29. checked: false
  30. }
  31. })
  32. this.setData({
  33. propertyInfo: {
  34. ...data,
  35. month_list
  36. },
  37. })
  38. },
  39. choiceMonth(e) {
  40. const {
  41. index,
  42. months,
  43. package_id
  44. } = e.currentTarget.dataset;
  45. this.setData({
  46. months,
  47. package_id
  48. })
  49. const {
  50. propertyInfo,
  51. garden_id
  52. } = this.data;
  53. const month_list = propertyInfo.month_list.map((item, num) => {
  54. if (index == num) {
  55. return {
  56. ...item,
  57. checked: true
  58. }
  59. } else {
  60. return {
  61. ...item,
  62. checked: false
  63. }
  64. }
  65. })
  66. this.setData({
  67. propertyInfo: {
  68. ...propertyInfo,
  69. month_list
  70. }
  71. })
  72. const {
  73. bind_id
  74. } = propertyInfo;
  75. HTTP.Getpre_pay_info({
  76. garden_id,
  77. bind_id,
  78. months
  79. }).then(res => {
  80. console.log(res);
  81. const {
  82. should_pay_amount
  83. } = res;
  84. this.setData({
  85. should_pay_amount
  86. })
  87. })
  88. },
  89. pre_pay() {
  90. const that = this;
  91. const {
  92. propertyInfo: {
  93. bind_id
  94. },
  95. garden_id,
  96. months,
  97. package_id,
  98. should_pay_amount,
  99. } = that.data;
  100. if (!months) {
  101. wx.showToast({
  102. title: '请选择预存月份',
  103. icon: "error",
  104. })
  105. return false
  106. }
  107. HTTP.Pre_pay({
  108. bind_id,
  109. garden_id,
  110. months,
  111. package_id,
  112. should_pay_amount,
  113. pay_amount:should_pay_amount
  114. }).then(res=>{
  115. if(res.code==0){
  116. that.setData({
  117. order_id:res.data.order_id,
  118. })
  119. const data = JSON.parse(res.data.prepay_info)
  120. wx.requestPayment({
  121. ...data,
  122. timeStamp: data.timeStamp + "",
  123. success(res) {
  124. console.log(res);
  125. },
  126. fail(res) {
  127. const {order_id} = that.data;
  128. HTTP.CancleOrder({
  129. order_id,
  130. garden_id,
  131. by_user: false,
  132. }).then(res => {
  133. if (res.code == 0) {
  134. wx.showToast({
  135. title: '取消支付',
  136. icon:"error"
  137. })
  138. }
  139. })
  140. }
  141. })
  142. }
  143. })
  144. },
  145. })