index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="rechargePopup-box">
  3. <view class="rechargePopup-title">
  4. <view>代金券充值</view>
  5. <view @click="cancel">取消</view>
  6. </view>
  7. <view class="rechargePopup-list">
  8. <view
  9. class="rechargePopup-item"
  10. v-for="(item, index) in transferPriceList"
  11. :key="index"
  12. :class="idx === index ? 'act' : ''"
  13. @click="changeIdx(index)"
  14. >
  15. <view>{{ item.number }}</view>
  16. <view>售价:{{ item.payGrade }}元</view>
  17. </view>
  18. </view>
  19. <view class="custom" :class="idx === 5 ? 'act' : ''" @click="changeIdx(5)">
  20. <view class="custom-left">自定义代金券</view>
  21. <view class="custom-input">
  22. <input type="number" v-model="customNum" />
  23. </view>
  24. <view class="custom-right">售价:{{ realityNum }}元</view>
  25. </view>
  26. <view class="immediately-btn" @click="getOrder">立即充值</view>
  27. </view>
  28. </template>
  29. <script>
  30. import { voucherOrderApi, voucherPayApi } from "@/config/index.js";
  31. export default {
  32. computed: {
  33. realityNum() {
  34. return this.customNum / 2;
  35. },
  36. },
  37. data() {
  38. return {
  39. // 激活态
  40. idx: "",
  41. // 转赠金额列表
  42. // 50, 100, 200, 1000, 2000, ""
  43. transferPriceList: [
  44. {
  45. number: "50",
  46. payGrade: "25",
  47. },
  48. {
  49. number: "100",
  50. payGrade: "50",
  51. },
  52. {
  53. number: "200",
  54. payGrade: "100",
  55. },
  56. {
  57. number: "1000",
  58. payGrade: "500",
  59. },
  60. {
  61. number: "2000",
  62. payGrade: "1000",
  63. },
  64. {
  65. number: "",
  66. payGrade: "",
  67. },
  68. ],
  69. customNum: "",
  70. };
  71. },
  72. methods: {
  73. // 提交订单
  74. async getOrder() {
  75. // this.$showToast("功能正在开发....")
  76. // return
  77. console.log(this.idx);
  78. if (this.idx === "") {
  79. this.$showToast("请选择充值金额");
  80. return;
  81. }
  82. let obj = {
  83. voucherId: 168,
  84. ...(this.idx === 5
  85. ? { number: this.customNum, payGrade: this.realityNum }
  86. : this.transferPriceList[this.idx]),
  87. };
  88. let res = await voucherOrderApi(obj);
  89. if (res.code == "") {
  90. // 结构出来需要的参数
  91. const {
  92. data: { orderId, money, orderSn },
  93. } = res;
  94. let payObj = {
  95. collageId: 0,
  96. money,
  97. orderId,
  98. orderFormid: orderSn,
  99. orderSn: "",
  100. type: 2,
  101. paymentMode: 4,
  102. huabeiPeriod: -1,
  103. purchaseMode: 1,
  104. };
  105. let { data } = await voucherPayApi(payObj);
  106. wx.openEmbeddedMiniProgram({
  107. appId: "wxef277996acc166c3",
  108. path: "pages/orderDetail/orderDetail",
  109. extraData: JSON.parse(data.package),
  110. });
  111. console.log({
  112. appId: "wxef277996acc166c3",
  113. path: "pages/orderDetail/orderDetail",
  114. extraData: JSON.parse(data.package),
  115. });
  116. }
  117. },
  118. // 修改激活态
  119. changeIdx(val) {
  120. this.idx = val;
  121. },
  122. // 取消按钮
  123. cancel() {
  124. this.$emit("cancel");
  125. },
  126. },
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. @import "./index.scss";
  131. </style>