card-comfirm-sub.vue 6.6 KB

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