card-comfirm.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <view class="container card clearfix">
  3. <tui-skeleton
  4. v-if="skeletonShow"
  5. backgroundColor="#fafafa"
  6. borderRadius="10rpx"
  7. :isLoading="true"
  8. :loadingType="5"
  9. ></tui-skeleton>
  10. <template v-else>
  11. <view class="card-content">
  12. <view class="card-row">
  13. <view class="form-label">卡号</view>
  14. <view class="form-input">
  15. <input
  16. class="card-input"
  17. v-model="showCardNumber"
  18. @input="handleInput"
  19. type="number"
  20. :maxlength="maxLen"
  21. placeholder="请输入本人的银行卡号"
  22. />
  23. <view class="card-clear" v-if="!showClear" @click="handleClearInput"
  24. ><text class="iconfont icon-shanchu1"></text
  25. ></view>
  26. </view>
  27. </view>
  28. <view class="card-row picker">
  29. <view class="form-label">卡类型</view>
  30. <view class="form-input">
  31. <picker @change="handleBindPicker($event)" :value="index" :range="stateActions" range-key="name">
  32. <input
  33. class="form-input"
  34. type="text"
  35. disabled="false"
  36. v-model="cardTytpeText"
  37. placeholder="请选择"
  38. />
  39. </picker>
  40. </view>
  41. <view class="iconfont icon-xiayibu"></view>
  42. </view>
  43. <view class="card-row">
  44. <view class="form-label">姓名</view>
  45. <input
  46. class="form-input"
  47. type="number"
  48. name="input"
  49. v-model="params.quickPayUserName"
  50. placeholder="请输入您的姓名"
  51. maxlength="10"
  52. />
  53. </view>
  54. <view class="card-row">
  55. <view class="form-label">身份证</view>
  56. <input
  57. class="form-input"
  58. type="number"
  59. name="input"
  60. v-model="params.idCard"
  61. placeholder="请输入您的身份证号"
  62. maxlength="18"
  63. />
  64. </view>
  65. <view class="card-row">
  66. <view class="form-label">预留手机号</view>
  67. <input
  68. class="form-input"
  69. type="number"
  70. name="input"
  71. v-model="params.quickPayMobile"
  72. placeholder="请输入您的银行预留手机号"
  73. maxlength="11"
  74. />
  75. </view>
  76. <view class="card-row" v-if="pickerIndex === 2">
  77. <view class="form-label">有效期</view>
  78. <input
  79. class="form-input"
  80. type="number"
  81. name="input"
  82. v-model="params.quickPayBankExpireTime"
  83. placeholder="请输入贷记卡有效期(示例:23/04)"
  84. maxlength="5"
  85. />
  86. </view>
  87. <view class="card-row" v-if="pickerIndex === 2">
  88. <view class="form-label">CVV2</view>
  89. <input
  90. class="form-input"
  91. type="number"
  92. name="input"
  93. v-model="params.cvvCode"
  94. placeholder="请输入贷记卡背面的安全码"
  95. maxlength="3"
  96. />
  97. </view>
  98. <view class="card-mains-btn">
  99. <button
  100. class="add-btn"
  101. :disabled="disabled"
  102. :class="[disabled ? 'disabled' : '']"
  103. @click="handleAddCard"
  104. >
  105. {{ subButtonText }}
  106. </button>
  107. </view>
  108. <view class="card-mains-text" @click="handleGoSusList">查看支持银行 ></view>
  109. </view>
  110. </template>
  111. </view>
  112. </template>
  113. <script>
  114. export default {
  115. data() {
  116. return {
  117. skeletonShow:true,
  118. pickerIndex: 1,
  119. orderId: 0,
  120. payAmount: '',
  121. params: {
  122. userId: 0, //机构UserId
  123. quickPayBankNumber: '', //快捷支付用户银行卡号/信用卡号
  124. quickPayMobile: '', //快捷支付银行卡绑定手机号
  125. quickPayBankExpireTime: '', //快捷支付信用卡过期时间,只包含年月,格式yy-MM
  126. quickPayUserName: '', //快捷支付用户姓名
  127. idCard: '', //身份证号
  128. cvvCode: '' //信用卡安全码
  129. },
  130. showCardNumber: '',
  131. maxLen: 26,
  132. subType: 0, // 1直接绑卡 2//首次绑卡并支付 3//确认支付
  133. cardTytpeText: '借记卡',
  134. subButtonText: '下一步',
  135. stateActions: [{ name: '借记卡', value: 1 }, { name: '贷记卡', value: 2 }]
  136. }
  137. },
  138. onLoad(option) {
  139. this.subType = Number(option.type)
  140. this.initGetStotage(option)
  141. },
  142. filters: {},
  143. computed: {
  144. showClear() {
  145. return this.params.quickPayBankNumber.length <= 12
  146. },
  147. disabled() {
  148. if (this.pickerIndex === 1) {
  149. return !(
  150. this.params.quickPayBankNumber.length > 12 &&
  151. this.params.quickPayUserName != '' &&
  152. this.params.idCard != '' &&
  153. this.params.quickPayMobile != ''
  154. )
  155. } else {
  156. return !(
  157. this.params.quickPayBankNumber.length > 12 &&
  158. this.params.quickPayUserName != '' &&
  159. this.params.idCard != '' &&
  160. this.params.quickPayMobile != '' &&
  161. this.params.quickPayBankExpireTime != '' &&
  162. this.params.cvvCode != ''
  163. )
  164. }
  165. }
  166. },
  167. methods: {
  168. async initGetStotage(option) {
  169. const userInfo = await this.$api.getStorage()
  170. this.params.userId = userInfo.userId ? userInfo.userId : 0
  171. if (this.subType != 1) {
  172. const data = JSON.parse(option.data)
  173. this.params = { ...this.params, ...data.payData }
  174. this.orderId = data.orderId ? data.orderId : 0
  175. this.payAmount = data.payAmount ? data.payAmount :0
  176. }
  177. console.log('params', this.params)
  178. setTimeout(()=>{
  179. this.skeletonShow = false
  180. },500)
  181. },
  182. handleAddCard() {
  183. //提交卡号
  184. if (!this.$reg.isIdCard(this.params.idCard)) {
  185. this.$util.msg('请输入正确的身份证号', 2000)
  186. return
  187. }
  188. if (!this.$reg.isMobile(this.params.quickPayMobile)) {
  189. this.$util.msg('请输入正确的手机号', 2000)
  190. return
  191. }
  192. if (this.subType === 1) {
  193. this.orderPayQuickBindCard()
  194. } else {
  195. this.orderPayQuickPay()
  196. }
  197. },
  198. async orderPayQuickBindCard() {
  199. //直接绑卡
  200. try {
  201. const res = await this.PayService.orderPayQuickBindCard(this.params)
  202. console.log('res', res.data)
  203. const data = JSON.stringify({ params: this.params, payData: res.data })
  204. this.$api.navigateTo(`/pages/user/pay/card-comfirm-sub?type=${this.subType}&data=${data}`)
  205. } catch (error) {
  206. this.$util.msg(error.msg, 2000)
  207. }
  208. },
  209. async orderPayQuickPay() {
  210. //绑卡并支付
  211. try {
  212. const res = await this.PayService.orderPayQuickPay(this.params)
  213. console.log('res', res.data)
  214. const data = {
  215. params: this.params,
  216. payData: res.data,
  217. orderId: this.orderId,
  218. payAmount: this.payAmount
  219. }
  220. this.$api.navigateTo(`/pages/user/pay/card-comfirm-sub?type=${this.subType}&data=${JSON.stringify(data)}`)
  221. } catch (error) {
  222. this.$util.msg(error.msg, 2000)
  223. }
  224. },
  225. handleBindPicker(e) {
  226. //选择联系人身份
  227. this.cardTytpeText = this.stateActions[e.target.value].name
  228. this.pickerIndex = this.stateActions[e.target.value].value
  229. },
  230. handleClearInput() {
  231. //清空银行卡
  232. this.params.quickPayBankNumber = this.showCardNumber = ''
  233. },
  234. handleInput(e) {
  235. this.showCardNumber = this.formatAccNo(e.detail.value)
  236. this.params.quickPayBankNumber = this.showCardNumber.split(/[\t\r\f\n\s]*/g).join('')
  237. },
  238. handleGoSusList() {
  239. // 跳转支持银行
  240. this.$api.navigateTo(`/pages/user/pay/card-sus-list`)
  241. },
  242. formatAccNo(value) {
  243. const newValue = value.replace(/([^0-9])/g, '') // 只允许输入数字
  244. const formatValue = newValue.replace(/(\d{4})(?=\d)/g, '$1 ') // 每4个数字后面加一个空格
  245. const inputLen = this.getOriginValue().length
  246. if (inputLen > this.maxLen) {
  247. // 如果输入的字符大于最大输入长度则禁止继续输入
  248. return
  249. }
  250. return formatValue
  251. },
  252. getOriginValue() {
  253. //获取input的原始值
  254. return this.showCardNumber.split(' ').join('')
  255. }
  256. },
  257. onShow() {
  258. // this.beansList = []
  259. }
  260. }
  261. </script>
  262. <style lang="scss">
  263. page,
  264. .container {
  265. background: #ffffff;
  266. height: 100%;
  267. }
  268. .card-content {
  269. width: 100%;
  270. height: auto;
  271. box-sizing: border-box;
  272. padding: 32rpx;
  273. .card-row {
  274. width: 100%;
  275. height: 100rpx;
  276. box-sizing: border-box;
  277. border-bottom: 1px solid #e1e1e1;
  278. position: relative;
  279. float: left;
  280. &.picker {
  281. padding-right: 60rpx;
  282. }
  283. .form-label {
  284. float: left;
  285. height: 100%;
  286. line-height: 98rpx;
  287. font-size: $font-size-28;
  288. text-align: left;
  289. color: #666666;
  290. }
  291. .form-input {
  292. min-width: 500rpx;
  293. height: 98rpx;
  294. line-height: 98rpx;
  295. font-size: $font-size-28;
  296. text-align: right;
  297. color: #333333;
  298. float: right;
  299. position: relative;
  300. .card-input {
  301. width: 568rpx;
  302. height: 100%;
  303. line-height: 96rpx;
  304. padding-left: 20rpx;
  305. box-sizing: border-box;
  306. font-size: $font-size-30;
  307. color: #333;
  308. padding-right: 60rpx;
  309. }
  310. .card-clear {
  311. width: 60rpx;
  312. height: 96rpx;
  313. position: absolute;
  314. right: 0;
  315. top: 0;
  316. line-height: 96rpx;
  317. text-align: center;
  318. .icon-shanchu1 {
  319. font-size: $font-size-32;
  320. color: #d5d5d5;
  321. }
  322. }
  323. }
  324. .icon-xiayibu {
  325. width: 60rpx;
  326. height: 100rpx;
  327. position: absolute;
  328. right: 0;
  329. top: 0;
  330. line-height: 100rpx;
  331. text-align: center;
  332. color: #b2b2b2;
  333. }
  334. }
  335. .card-mains-btn {
  336. width: 100%;
  337. height: auto;
  338. box-sizing: border-box;
  339. padding: 0 43rpx;
  340. margin-top: 180rpx;
  341. float: left;
  342. .add-btn {
  343. width: 100%;
  344. height: 90rpx;
  345. font-size: $font-size-30;
  346. line-height: 90rpx;
  347. color: #ffffff;
  348. text-align: center;
  349. background: $btn-confirm;
  350. border-radius: 45rpx;
  351. border-radius: 44rpx;
  352. margin-top: 80rpx;
  353. &.disabled {
  354. background: #e1e1e1;
  355. border-radius: 44rpx;
  356. }
  357. }
  358. }
  359. .card-mains-text {
  360. width: 100%;
  361. line-height: 88rpx;
  362. box-sizing: border-box;
  363. padding: 0 56rpx;
  364. font-size: $font-size-28;
  365. color: #1890f9;
  366. text-align: center;
  367. }
  368. }
  369. </style>