card-comfirm.vue 10 KB

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