Rap 原分销系统代码Web
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

87 lignes
2.6KB

  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" :rules="rules" style="margin-top: 6px;" size="small" label-width="90px">
  4. <el-form-item label="商品名称" prop="subject">
  5. <el-input v-model="form.subject" style="width: 35%" />
  6. </el-form-item>
  7. <el-form-item label="商品价格" prop="totalAmount">
  8. <el-input v-model="form.totalAmount" style="width: 35%" />
  9. <span style="color: #C0C0C0;margin-left: 10px;">测试允许区间(0,5000]</span>
  10. </el-form-item>
  11. <el-form-item label="商品描述" prop="body">
  12. <el-input v-model="form.body" style="width: 35%" rows="8" type="textarea" />
  13. </el-form-item>
  14. <el-form-item label="">
  15. <el-button :loading="loading" size="medium" type="primary" @click="doSubmit">去支付</el-button>
  16. </el-form-item>
  17. </el-form>
  18. </div>
  19. </template>
  20. <script>
  21. import { toAliPay } from '@/api/tools/alipay'
  22. export default {
  23. data() {
  24. return {
  25. url: '',
  26. // 新窗口的引用
  27. newWin: null,
  28. loading: false, form: { subject: '', totalAmount: '', body: '' },
  29. rules: {
  30. subject: [
  31. { required: true, message: '商品名称不能为空', trigger: 'blur' }
  32. ],
  33. totalAmount: [
  34. { required: true, message: '商品价格不能为空', trigger: 'blur' }
  35. ],
  36. body: [
  37. { required: true, message: '商品描述不能为空', trigger: 'blur' }
  38. ]
  39. }
  40. }
  41. },
  42. watch: {
  43. url(newVal, oldVal) {
  44. if (newVal && this.newWin) {
  45. this.newWin.sessionStorage.clear()
  46. this.newWin.location.href = newVal
  47. // 重定向后把url和newWin重置
  48. this.url = ''
  49. this.newWin = null
  50. }
  51. }
  52. },
  53. methods: {
  54. doSubmit() {
  55. this.$refs['form'].validate((valid) => {
  56. if (valid) {
  57. this.loading = true
  58. // 先打开一个空的新窗口,再请求
  59. this.newWin = window.open()
  60. let url = ''
  61. if (/(Android)/i.test(navigator.userAgent)) { // 判断是否为Android手机
  62. url = 'aliPay/toPayAsWeb'
  63. } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { // 判断是否为苹果手机
  64. url = 'aliPay/toPayAsWeb'
  65. } else {
  66. url = 'aliPay/toPayAsPC'
  67. }
  68. toAliPay(url, this.form).then(res => {
  69. this.loading = false
  70. this.url = res
  71. }).catch(err => {
  72. this.loading = false
  73. console.log(err.response.data.message)
  74. })
  75. } else {
  76. return false
  77. }
  78. })
  79. }
  80. }
  81. }
  82. </script>
  83. <style scoped>
  84. </style>