card-comfirm-sub.vue 6.7 KB

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