card-comfirm-sub.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. if(this.subType === 1){
  138. this.$util.msg(successMsg, 2000, true, 'success')
  139. setTimeout(() => {
  140. this.handleSuccessHref()
  141. }, 2000)
  142. }else{
  143. this.handleSuccessHref()
  144. }
  145. } catch (error) {
  146. console.log(error)
  147. this.$util.msg(error.msg, 2000)
  148. }
  149. },
  150. handleSuccessHref() {
  151. // tiaozhuan
  152. if (this.subType === 1) {
  153. this.$api.navigateBack(2)
  154. } else {
  155. if (this.params.quickPayFlag === 1) {
  156. const linkData = {
  157. payAmount: this.params.payAmount,
  158. orderId: this.orderId,
  159. type: 'success'
  160. }
  161. this.$api.redirectTo(`/pages/user/pay/success?data=${JSON.stringify({ data: linkData })}`)
  162. } else {
  163. this.$api.redirectTo(`/pages/user/member/member`)
  164. }
  165. }
  166. },
  167. handleMobileCode() {
  168. // 获取短信验证码
  169. this.isMobileDisabled = true
  170. if (this.subType === 1) {
  171. this.orderPayQuickBindCard()
  172. } else {
  173. this.orderPayQuickPay()
  174. }
  175. },
  176. async orderPayQuickBindCard() {
  177. //直只绑卡
  178. try {
  179. const res = await this.PayService.orderPayQuickBindCard(this.params)
  180. this.handleCodeTime()
  181. } catch (error) {
  182. this.isMobileDisabled = false
  183. }
  184. },
  185. async orderPayQuickPay() {
  186. //绑卡并支付
  187. try {
  188. const res = await this.PayService.orderPayQuickPay(this.params)
  189. this.handleCodeTime()
  190. } catch (error) {
  191. console.log(error)
  192. this.isMobileDisabled = false
  193. }
  194. }
  195. },
  196. onShow() {
  197. }
  198. }
  199. </script>
  200. <style lang="scss">
  201. page,
  202. .container {
  203. background: #ffffff;
  204. height: 100%;
  205. }
  206. .card-content {
  207. width: 100%;
  208. height: auto;
  209. box-sizing: border-box;
  210. padding-top: 70rpx;
  211. }
  212. .card-title {
  213. width: 100%;
  214. height: auto;
  215. box-sizing: border-box;
  216. padding: 0 0 70rpx 0;
  217. .card-pay-text {
  218. width: 100%;
  219. height: 90rpx;
  220. line-height: 90rpx;
  221. text-align: center;
  222. font-size: 56rpx;
  223. color: #F3B574;
  224. font-weight: bold;
  225. box-sizing: border-box;
  226. }
  227. }
  228. .card-mains {
  229. width: 100%;
  230. height: 100rpx;
  231. box-sizing: border-box;
  232. padding: 0 50rpx 0 32rpx;
  233. .card-form-text {
  234. width: 100%;
  235. height: 40rpx;
  236. line-height: 40rpx;
  237. text-align: left;
  238. font-size: $font-size-28;
  239. color: #333;
  240. box-sizing: border-box;
  241. margin-bottom: 16rpx;
  242. }
  243. .card-form {
  244. width: 100%;
  245. height: 100%;
  246. box-sizing: border-box;
  247. border: 1px solid #cccccc;
  248. padding: 14rpx 0;
  249. border-radius: 16rpx;
  250. position: relative;
  251. .card-input {
  252. width: 460rpx;
  253. height: 100%;
  254. line-height: 96rpx;
  255. padding-left: 32rpx;
  256. box-sizing: border-box;
  257. font-size: $font-size-30;
  258. color: #333;
  259. border-right: 1px solid #e1e1e1;
  260. float: left;
  261. }
  262. .card-form-code {
  263. width: 204rpx;
  264. height: 72rpx;
  265. line-height: 72rpx;
  266. text-align: center;
  267. color: $color-system;
  268. font-size: $font-size-26;
  269. float: left;
  270. &.disabled {
  271. color: #999;
  272. }
  273. }
  274. }
  275. }
  276. .card-mains-btn {
  277. width: 100%;
  278. height: auto;
  279. box-sizing: border-box;
  280. padding: 0 75rpx;
  281. margin-top: 180rpx;
  282. .add-btn {
  283. width: 100%;
  284. height: 90rpx;
  285. font-size: $font-size-30;
  286. line-height: 90rpx;
  287. color: #ffffff;
  288. text-align: center;
  289. background: $btn-confirm;
  290. border-radius: 45rpx;
  291. border-radius: 44rpx;
  292. margin-top: 80rpx;
  293. &.disabled {
  294. background: #e1e1e1;
  295. border-radius: 44rpx;
  296. }
  297. }
  298. }
  299. </style>