card-comfirm-sub.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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-title" v-if="subType === 2 || subType === 3">
  13. <view class="card-pay-text">¥{{ payAmount }}</view>
  14. </view>
  15. <view class="card-mains">
  16. <view class="card-form-text">已发送至手机号 {{ phoneNumbe }}</view>
  17. <view class="card-form">
  18. <input
  19. class="card-input"
  20. v-model="codeParams.bindCode"
  21. @input="handleInput"
  22. type="number"
  23. maxlength="6"
  24. placeholder="请输入短信验证码"
  25. />
  26. <view
  27. class="card-form-code"
  28. :class="isMobileDisabled ? 'disabled' : ''"
  29. @click.stop="handleMobileCode"
  30. >
  31. <text>{{ mobileCodeText }}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="card-mains-btn">
  36. <button
  37. class="add-btn"
  38. :disabled="disabled"
  39. :class="[disabled ? 'disabled' : '']"
  40. @click="handleAddCard"
  41. >
  42. {{ suBbtnText }}
  43. </button>
  44. </view>
  45. </view>
  46. </template>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. orderId: 0,
  54. params: {},
  55. payAmount: '',
  56. subType: 1, // 1直接绑卡 2//首次绑卡并支付 3//确认支付
  57. isMobileDisabled: true, //手机验证码按钮控制
  58. mobilCount: '', //倒计时
  59. mobileCodeText: '重新发送',
  60. mobilTime: null,
  61. codeParams: {
  62. orderId: '',
  63. infoId: '',
  64. bindCode: '',
  65. flag: 1 // 1绑卡 2 付款
  66. },
  67. skeletonShow: true,
  68. suBbtnText: '确认绑定'
  69. }
  70. },
  71. onLoad(option) {
  72. this.initOption(option)
  73. },
  74. filters: {},
  75. computed: {
  76. phoneNumbe() {
  77. // 手机号仅显示前三位及后四位数字,隐藏信息用*代替
  78. return this.params.quickPayMobile.substr(0, 3) + '****' + this.params.quickPayMobile.substring(7)
  79. },
  80. disabled() {
  81. return !(this.codeParams.bindCode.length > 4)
  82. }
  83. },
  84. methods: {
  85. initOption(option) {
  86. console.log('option', option)
  87. const data = JSON.parse(option.data)
  88. this.subType = Number(option.type)
  89. this.params = data.params
  90. this.codeParams = Object.assign(this.codeParams, data.payData)
  91. if (this.subType === 1) {
  92. this.codeParams.flag = 1
  93. } else {
  94. this.codeParams.flag = 2
  95. this.orderId = data.orderId
  96. this.payAmount = this.params.quickPayFlag === 2 ? data.payAmount : this.params.payAmount
  97. }
  98. this.handleCodeTime()
  99. this.handleBbtnText(this.subType)
  100. setTimeout(() => {
  101. this.skeletonShow = false
  102. }, 500)
  103. },
  104. handleCodeTime() {
  105. // 倒计时
  106. const TIME_COUNT = 60
  107. if (!this.mobilTime) {
  108. this.mobilCount = TIME_COUNT
  109. this.isMobileDisabled = true
  110. this.mobilTime = setInterval(() => {
  111. if (this.mobilCount > 1 && this.mobilCount <= TIME_COUNT) {
  112. this.mobilCount--
  113. this.mobileCodeText = this.mobilCount + '秒后重发'
  114. } else {
  115. this.isMobileDisabled = false
  116. clearInterval(this.mobilTime)
  117. this.mobilTime = null
  118. this.mobileCodeText = '重新发送'
  119. }
  120. }, 1000)
  121. }
  122. },
  123. handleBbtnText(value) {
  124. const textMap = {
  125. 1: '确认绑定',
  126. 2: '确认绑定支付',
  127. 3: '确认支付'
  128. }
  129. this.suBbtnText = textMap[value]
  130. },
  131. async handleAddCard() {
  132. //提交绑定或支付
  133. try {
  134. const loadText = this.subType === 1 ? '绑定中...' : '支付中...'
  135. const successMsg = this.subType === 1 ? '绑定成功' : '支付成功'
  136. const res = await this.PayService.orderPayQuickBindCode(this.codeParams, loadText)
  137. this.$util.msg(successMsg, 2000, true, 'success')
  138. setTimeout(() => {
  139. this.handleSuccessHref()
  140. }, 2000)
  141. } catch (error) {
  142. console.log(error)
  143. this.$util.msg(error.msg, 2000)
  144. }
  145. },
  146. handleSuccessHref() {
  147. // tiaozhuan
  148. if (this.subType === 1) {
  149. this.$api.navigateBack(2)
  150. } else {
  151. if (this.params.quickPayFlag === 1) {
  152. const linkData = {
  153. payAmount: this.params.payAmount,
  154. orderId: this.orderId,
  155. type: 'success'
  156. }
  157. this.$api.redirectTo(`/pages/user/pay/success?data=${JSON.stringify({ data: linkData })}`)
  158. } else {
  159. this.$api.redirectTo(`/pages/user/member/member`)
  160. }
  161. }
  162. },
  163. handleMobileCode() {
  164. // 获取短信验证码
  165. this.isMobileDisabled = true
  166. if (this.subType === 1) {
  167. this.orderPayQuickBindCard()
  168. } else {
  169. this.orderPayQuickPay()
  170. }
  171. },
  172. async orderPayQuickBindCard() {
  173. //直只绑卡
  174. try {
  175. const res = await this.PayService.orderPayQuickBindCard(this.params)
  176. this.handleCodeTime()
  177. } catch (error) {
  178. this.isMobileDisabled = false
  179. }
  180. },
  181. async orderPayQuickPay() {
  182. //绑卡并支付
  183. try {
  184. const res = await this.PayService.orderPayQuickPay(this.params)
  185. this.handleCodeTime()
  186. } catch (error) {
  187. console.log(error)
  188. this.isMobileDisabled = false
  189. }
  190. }
  191. },
  192. onShow() {
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. page,
  198. .container {
  199. background: #ffffff;
  200. height: 100%;
  201. }
  202. .card-content {
  203. width: 100%;
  204. height: auto;
  205. box-sizing: border-box;
  206. padding-top: 70rpx;
  207. }
  208. .card-title {
  209. width: 100%;
  210. height: auto;
  211. box-sizing: border-box;
  212. padding: 0 0 70rpx 0;
  213. .card-pay-text {
  214. width: 100%;
  215. height: 90rpx;
  216. line-height: 90rpx;
  217. text-align: center;
  218. font-size: 56rpx;
  219. color: #F3B574;
  220. font-weight: bold;
  221. box-sizing: border-box;
  222. }
  223. }
  224. .card-mains {
  225. width: 100%;
  226. height: 100rpx;
  227. box-sizing: border-box;
  228. padding: 0 50rpx 0 32rpx;
  229. .card-form-text {
  230. width: 100%;
  231. height: 40rpx;
  232. line-height: 40rpx;
  233. text-align: left;
  234. font-size: $font-size-28;
  235. color: #333;
  236. box-sizing: border-box;
  237. margin-bottom: 16rpx;
  238. }
  239. .card-form {
  240. width: 100%;
  241. height: 100%;
  242. box-sizing: border-box;
  243. border: 1px solid #cccccc;
  244. padding: 14rpx 0;
  245. border-radius: 16rpx;
  246. position: relative;
  247. .card-input {
  248. width: 460rpx;
  249. height: 100%;
  250. line-height: 96rpx;
  251. padding-left: 32rpx;
  252. box-sizing: border-box;
  253. font-size: $font-size-30;
  254. color: #333;
  255. border-right: 1px solid #e1e1e1;
  256. float: left;
  257. }
  258. .card-form-code {
  259. width: 204rpx;
  260. height: 72rpx;
  261. line-height: 72rpx;
  262. text-align: center;
  263. color: $color-system;
  264. font-size: $font-size-26;
  265. float: left;
  266. &.disabled {
  267. color: #999;
  268. }
  269. }
  270. }
  271. }
  272. .card-mains-btn {
  273. width: 100%;
  274. height: auto;
  275. box-sizing: border-box;
  276. padding: 0 75rpx;
  277. margin-top: 180rpx;
  278. .add-btn {
  279. width: 100%;
  280. height: 90rpx;
  281. font-size: $font-size-30;
  282. line-height: 90rpx;
  283. color: #ffffff;
  284. text-align: center;
  285. background: $btn-confirm;
  286. border-radius: 45rpx;
  287. border-radius: 44rpx;
  288. margin-top: 80rpx;
  289. &.disabled {
  290. background: #e1e1e1;
  291. border-radius: 44rpx;
  292. }
  293. }
  294. }
  295. </style>