rechargeModel.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div class="chioseWrap">
  3. <el-form :inline="true" ref="payForm" :model="payForm">
  4. <el-form-item
  5. prop="payType"
  6. :rules="[
  7. { required: true, message: '请选择支付方式', trigger: 'change' }
  8. ]"
  9. >
  10. <el-select
  11. v-model.trim="payForm.payType"
  12. style="width: 180px"
  13. clearable
  14. filterable
  15. placeholder="请选择支付方式"
  16. >
  17. <el-option label="支付宝支付" value="alipay_qr"></el-option>
  18. <el-option label="微信支付" value="wx_pub"></el-option>
  19. </el-select>
  20. </el-form-item>
  21. </el-form>
  22. <el-table
  23. style="width: 100%"
  24. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  25. :data="tableList"
  26. >
  27. <el-table-column align="center" prop="name" label="产品名称">
  28. </el-table-column>
  29. <el-table-column align="center" label="充值金额(元)">
  30. <template slot-scope="scope">
  31. {{ scope.row.rechargeAmount | hasMoneyFormat }}
  32. </template>
  33. </el-table-column>
  34. <el-table-column align="center" label="支付价格(元)">
  35. <template slot-scope="scope">
  36. <span style="color: red;">{{
  37. scope.row.amount | hasMoneyFormat
  38. }}</span>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. <span slot="footer" class="dialog-footer">
  43. <el-button @click="$listeners.close()">取 消</el-button>
  44. <el-button @click="onMemberPay" type="primary">确 定</el-button>
  45. </span>
  46. <el-dialog
  47. title="支付二维码"
  48. :visible.sync="payMentVisible"
  49. :before-close="onClose"
  50. v-if="payMentVisible"
  51. width="500px"
  52. append-to-body
  53. >
  54. <payment
  55. :tableList="tableList"
  56. :orderNo="orderNo"
  57. v-on="$listeners"
  58. :codeUrl="codeUrl"
  59. @close="onPaymentClose"
  60. />
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. import { recharge } from "../api";
  66. import { vaildStudentUrl } from "@/utils/validate";
  67. import payment from "@/views/productService/model/payment";
  68. export default {
  69. props: ["amount"],
  70. components: { payment },
  71. data() {
  72. return {
  73. payForm: {
  74. payType: null
  75. },
  76. pay_channel: null, //支付渠道
  77. selectStudentMoney: 0, // 选中学生金额
  78. payMentVisible: false,
  79. codeUrl: null,
  80. orderNo: null,
  81. tableList: []
  82. };
  83. },
  84. async mounted() {
  85. if (this.amount) {
  86. this.tableList = [
  87. {
  88. name: "云教室充值",
  89. rechargeAmount: this.amount,
  90. amount: this.amount
  91. }
  92. ];
  93. }
  94. },
  95. methods: {
  96. onMemberPay() {
  97. this.$refs.payForm.validate(async _ => {
  98. if (_) {
  99. try {
  100. const res = await recharge({ amount: this.amount });
  101. console.log(res.data.amount, res.data.orderNo);
  102. if (res.data.amount == 0 && res.data.orderNo) {
  103. this.$message.success("您已成功缴费");
  104. this.onPaymentClose(true);
  105. this.$listeners.getList();
  106. return;
  107. }
  108. const payForm = this.payForm;
  109. // // 二维码页面, 唤起支付页面
  110. const {
  111. orderNo,
  112. sign,
  113. amount,
  114. orderBody,
  115. orderSubject,
  116. tenantId,
  117. returnUrl,
  118. alipayAppId,
  119. wxAppId
  120. } = res.data.payMap;
  121. this.orderNo = orderNo;
  122. this.codeUrl =
  123. vaildStudentUrl() +
  124. "/#/payCenter?orderNo=" +
  125. orderNo +
  126. "&sign=" +
  127. sign +
  128. "&amount=" +
  129. amount +
  130. "&payType=" +
  131. payForm.payType +
  132. "&orderBody=" +
  133. orderBody +
  134. "&orderSubject=" +
  135. orderSubject +
  136. "&platform=tenantRecharge" +
  137. "&tenantId=" +
  138. tenantId +
  139. "&returnUrl=" +
  140. returnUrl +
  141. "&type=" +
  142. res.data.type +
  143. "&wxAppId=" +
  144. wxAppId +
  145. "&alipayAppId=" +
  146. alipayAppId;
  147. console.log(this.codeUrl, "codeUrl");
  148. this.payMentVisible = true;
  149. } catch (e) {}
  150. }
  151. });
  152. },
  153. onClose(done) {
  154. this.onPaymentClose(false, done);
  155. },
  156. onPaymentClose(hideTip = false, callBack) {
  157. if (hideTip) {
  158. this.payMentVisible = false;
  159. this.$emit("close");
  160. return;
  161. }
  162. this.$confirm(`是否支付完成?`, "提示", {
  163. confirmButtonText: "已完成支付",
  164. cancelButtonText: "未完成支付",
  165. type: "warning"
  166. })
  167. .then(async res => {
  168. if (typeof callBack == "function") {
  169. callBack();
  170. }
  171. this.payMentVisible = false;
  172. })
  173. .catch(e => {
  174. if (typeof callBack == "function") {
  175. callBack();
  176. }
  177. this.payMentVisible = false;
  178. });
  179. }
  180. }
  181. };
  182. </script>
  183. <style lang="less" scoped>
  184. .chioseWrap {
  185. font-size: 16px;
  186. > p {
  187. font-weight: 500;
  188. padding-bottom: 15px;
  189. span {
  190. color: red;
  191. padding: 0 3px;
  192. }
  193. }
  194. }
  195. .dialog-footer {
  196. text-align: right;
  197. display: block;
  198. padding-top: 15px;
  199. }
  200. </style>