天波h5前端应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
9.0KB

  1. <!--
  2. * @Date: 2022-01-19 16:53:16
  3. * @LastEditors: JinxChen
  4. * @LastEditTime: 2022-03-04 11:08:17
  5. * @FilePath: \AntpayFrontEnd\src\views\AliPayForm.vue
  6. * @description: 春雨个性化表单
  7. -->
  8. <template>
  9. <div class="form-container">
  10. <!-- 头部 -->
  11. <div class="form-header">
  12. <div class="img-left">
  13. <van-image :src="goodsData.imgPath" height="120"></van-image>
  14. </div>
  15. <div class="content-right">
  16. <p>
  17. <strong>套餐名字:</strong>
  18. </p>
  19. <p>{{goodsData.mainTitle}}</p>
  20. <p>
  21. <strong>月套餐费:</strong>
  22. </p>
  23. <p>
  24. <span>¥{{ (goodsData.price/goodsData.count).toFixed(2) }}</span> x
  25. <span>{{goodsData.count}}期</span>
  26. <span v-show="goodsData.isAmountShow">=¥{{goodsData.price}}</span>
  27. </p>
  28. </div>
  29. </div>
  30. <!-- 中部表单 -->
  31. <div class="form-body">
  32. <van-form @submit="onSubmit" @failed="onFailed">
  33. <div class="form-box">
  34. <van-field
  35. v-model="form.phoneNumber"
  36. name="phoneNumber"
  37. label="电话"
  38. type="tel"
  39. placeholder="必填"
  40. maxlength="11"
  41. required
  42. clearable
  43. :rules="[{ required: true, message: '请填写电话' }]"
  44. />
  45. <van-field
  46. v-model="form.schoolName"
  47. name="schoolName"
  48. label="学校"
  49. placeholder="必填"
  50. maxlength="30"
  51. required
  52. clearable
  53. :rules="[{ required: true, message: '请填写学校' }]"
  54. />
  55. <van-field
  56. v-model="form.className"
  57. name="className"
  58. label="班级"
  59. placeholder="必填"
  60. maxlength="10"
  61. required
  62. clearable
  63. :rules="[{ required: true, message: '请填写班级' }]"
  64. />
  65. <van-field
  66. v-model="form.userName"
  67. name="userName"
  68. label="学生"
  69. placeholder="必填"
  70. maxlength="10"
  71. required
  72. clearable
  73. :rules="[{ required: true, message: '请填写学生' }]"
  74. />
  75. </div>
  76. <!-- '请知悉' 提示, -->
  77. <div class="know-tips">
  78. <h5>请知悉!</h5>
  79. <p>点击以下按钮,启动支付宝页面"立即支付"</p>
  80. <p>成功后,将分期每月从你的余额扣{{ (goodsData.price/goodsData.count).toFixed(2) }}元</p>
  81. </div>
  82. <div class="form-footer">
  83. <van-button
  84. native-type="onSubmit"
  85. >{{submitText}}</van-button>
  86. </div>
  87. </van-form>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import { APIAlipay } from "../api/alipay";
  93. import { IMAGE_URL } from '../config/models';
  94. export default {
  95. name:'alipay-form',
  96. data(){
  97. return {
  98. goodsData: {
  99. imgPath: '',
  100. price: null,
  101. count: null,
  102. isAmountShow: '',
  103. mainTitle: '',
  104. title: '4G电子学生证资费套餐开通服务协议',
  105. }, //接收从首页传过来的数据
  106. form: {
  107. phoneNumber: '',
  108. schoolName: '',
  109. className: '',
  110. userName: '',
  111. deviceImei: ''
  112. }, //输入的表单数据
  113. alipayForm: '', //接收支付宝接口返回的表单
  114. submitText: '办理支付宝分期业务', //submit标题
  115. }
  116. },
  117. mounted() {
  118. this.getGoodsDetails();
  119. },
  120. methods: {
  121. // 根据商品编号获取商品详情
  122. getGoodsDetails() {
  123. APIAlipay.getGoodsDetails(this.$store.getters.goodsNo)
  124. .then(res => {
  125. if(res.data.code === 20000) {
  126. let good = res.data.data.goods;
  127. console.log("good", good);
  128. // 图片路径
  129. this.goodsData.imgPath = IMAGE_URL[ process.env.NODE_ENV ] + good.goodsImg;
  130. // 价格
  131. this.goodsData.price = good.price;
  132. // 是否是老用户
  133. this.isOld = good.descriptionText === '' ? true : false;
  134. // 商品名称
  135. this.goodsData.mainTitle = good.mainTitle;
  136. // 分期数
  137. let count = good.periodizationJson.substring(1, good.periodizationJson.length - 1).split(',');
  138. // 是否显示金额总数, todo 后期需从接口获取
  139. this.goodsData.isAmountShow = JSON.parse(this.$route.query.isAmountShow);
  140. this.goodsData.count = Math.max(...count);
  141. this.goodsData.goodDefCount = Math.max(...count).toString();
  142. }
  143. })
  144. },
  145. // 办理支付宝分期业务表单校验通过后
  146. onSubmit() {
  147. let reg = /^1[3456789]\d{9}$/; //手机号码正则验证
  148. if(!reg.test(this.form.phoneNumber)) {
  149. this.$notify({
  150. message: '请输入正确的手机号码',
  151. type: 'warning',
  152. duration: 1500
  153. })
  154. } else {
  155. let reqBody = {
  156. username: this.form.userName,
  157. deviceImei: this.form.deviceImei === '' ? '123' : this.form.deviceImei,
  158. schoolName: this.form.schoolName,
  159. className: this.form.className,
  160. phoneNumber: this.form.phoneNumber,
  161. periodizationNum: Number(this.goodsData.count),
  162. goodsNo: this.$store.getters.goodsNo,
  163. alipayStateType: Number(this.goodsData.payType),
  164. userId: this.$store.getters.userId,
  165. }
  166. APIAlipay.getAlipayForm(reqBody)
  167. .then(res => {
  168. this.alipayForm = res.data;
  169. this.$store.commit('price', Number(this.goodsData.price));
  170. this.$store.commit('count', Number(this.goodsData.count));
  171. // 跳转到一个中转页 form,再通过这个中转页来调起支付宝的收银台
  172. this.$router.push({path: 'redirect', query: {alipayForm: this.alipayForm}});
  173. })
  174. .catch(error => {
  175. console.log(error);
  176. })
  177. }
  178. },
  179. // 表单不通过时
  180. onFailed() {
  181. console.log("表单输入不完整!");
  182. },
  183. }
  184. }
  185. </script>
  186. <style scoped lang="scss">
  187. .form-container {
  188. height: 100vh;
  189. width: 100vw;
  190. display: flex;
  191. flex-direction: column;
  192. overflow: hidden;
  193. /* padding: 5px;
  194. border-radius: 20px; */
  195. background-color: #f7f8fa;
  196. .form-header {
  197. height: 25vh;
  198. display: flex;
  199. justify-content: center;
  200. align-items: center;
  201. padding: 10px;
  202. box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px,
  203. rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
  204. background-color: rgba(235, 233, 229, 0.726);
  205. .img-left {
  206. width: 120px;
  207. }
  208. .content-right {
  209. flex: 1;
  210. p {
  211. font-size: 14px;
  212. text-align: left;
  213. padding: 5px 10px;
  214. strong {
  215. text-align: left;
  216. }
  217. }
  218. }
  219. }
  220. .form-body {
  221. flex: 1;
  222. position: relative;
  223. overflow: scroll;
  224. /* padding: 10px; */
  225. box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px,
  226. rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
  227. .know-tips {
  228. height: 120px;
  229. width: 100%;
  230. padding: 10px;
  231. h5 {
  232. font-size: 16px;
  233. text-align: left;
  234. padding: 5px;
  235. color: red;
  236. }
  237. p {
  238. font-size: 14px;
  239. padding: 5px;
  240. text-align: left;
  241. }
  242. }
  243. }
  244. .form-footer {
  245. height: 15vh;
  246. width: 100%;
  247. position: absolute;
  248. padding: 10px;
  249. bottom: 10px;
  250. left: 0;
  251. display: flex;
  252. justify-content: center;
  253. flex-direction: column;
  254. .van-button {
  255. height: 40px;
  256. background-color: #1989fa;
  257. color: white;
  258. border-radius: 5px;
  259. &.notSubmit {
  260. background-color: rgba(150, 150, 146, 0.904);
  261. }
  262. }
  263. }
  264. }
  265. </style>