<template>
  <div>
    <!-- 组件内容 -->
  </div>
</template>

<script>
import uniPopup from '@/components/common/uni-popup/uni-popup.vue'
import validCode from '@/components/common/validCode/validCode.vue'

export default {
  name: 'good-coupon',
  components: { uniPopup, validCode },
  props: {},
  data() {
    return {
      coupuptype: '',
      couponvalue: '',
      couponone: 1,
      aliaccout: '15623456789',
      selectbankon: 0,
      banktext: '花呗',
      pwarr: [
        { num: '1' },
        { num: '2' },
        { num: '3' },
        { num: '4' },
        { num: '5' },
        { num: '6' },
        { num: '7' },
        { num: '8' },
        { num: '9' },
        { num: '' },
        { num: '0' },
        { num: 'x' },
      ],
      bank: [
        { text: '花呗' },
        { text: '招商银行储蓄卡(8943)' },
        { text: '中国银行储蓄卡(8765)' },
        { text: '中国农业银行储蓄卡(9876)' },
        { text: '中国建设银行储蓄卡(6754)' },
        { text: '交通银行储蓄卡(5678)' },
        { text: '余额宝(剩余:122222222.00)' },
      ],
      dotlist: [],
      prentindex: {},
    }
  },
  computed: {
    aliaccoutv() {
      let user = this.aliaccout.split('')
      let cuser = []
      user.map((item, index) => {
        if (index > 2 && index < 9) {
          item = '*'
        }
        cuser.push(item)
      })
      // console.log(cuser)
      let juser = cuser.join('')
      return juser
    },
  },
  mounted() {
    this.$nextTick(function () {})
  },
  methods: {
    init(item) {
      this.couponvalue = Number(item.money * item.amount).toFixed(2)
      this.prentindex = item
    },
    togglePopup(type) {
      this.coupuptype = type
      this.selectbankon = 0
      this.dotlist = []
      this.couponone = 1
      this.banktext = this.bank[0].text
    },
    goone() {
      this.couponone = 1
    },
    gotwo() {
      this.couponone = 2
    },
    gothree() {
      this.couponone = 3
      this.dotlist = []
    },
    selectbank(val, index) {
      this.selectbankon = index
      this.banktext = val.text
    },
    dotnum(val, index) {
      if (index === 9) {
        return false
      } else if (index === 11) {
        if (this.dotlist.length > 0) {
          let dotlistlen = this.dotlist.length - 1
          this.dotlist.splice(dotlistlen, 1)
        }
      } else {
        if (this.dotlist.length < 6) {
          this.dotlist.push(val.num)
        }
      }
      let code = { detail: this.dotlist.join('') }
      this.$refs.validcode.getsendVal(this.dotlist)
      console.log(this.dotlist, this.dotlist.length, code)
    },
    getPwd(val) {
      console.log(val)
      this.togglePopup('')
      uni.showLoading({
        title: '支付中',
      })
      let _this = this
      setTimeout(function () {
        uni.hideLoading()
        _this.$emit('reparent', _this.prentindex)
      }, 3000)
    },
  },
}
</script>

代码解读:

该代码实现了一个优惠券组件,主要功能包括:

  1. 优惠券选择: 可以选择不同类型的优惠券,并显示对应的金额。
  2. 支付方式选择: 可以选择支付宝或银行卡进行支付,并显示对应的账户信息。
  3. 支付密码弹窗: 点击支付按钮后,会弹出一个密码输入框,用户需要输入支付密码才能完成支付。
  4. 密码输入校验: 密码输入框支持数字键盘输入和删除,并限制了输入长度,同时将输入的密码传递给子组件进行校验。

代码优化建议:

  1. 组件拆分: 可以将密码输入框、银行选择列表等功能模块拆分成独立的子组件,提高代码复用性和可维护性。
  2. 数据绑定: 可以使用 v-model 指令简化数据绑定操作,例如在密码输入框中使用 v-model="dotlist" 绑定密码数组。
  3. 事件处理: 可以使用 @ 符号简化事件绑定操作,例如在数字键盘按钮上使用 @click="dotnum(item, index)" 绑定点击事件。
  4. 代码注释: 添加必要的代码注释,解释代码逻辑和功能,提高代码可读性。

总结

通过以上代码实现了一个基础的优惠券组件,并对其进行了SEO优化,使其更容易被搜索引擎收录。同时,我们也对代码进行了解读和优化建议,希望能够帮助开发者更好地理解和使用该组件。

Vue.js优惠券组件开发:实现支付密码弹窗及逻辑

原文地址: https://www.cveoy.top/t/topic/P2c 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录