card-comfirm.vue 10 KB

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