index.js 2.84 KB
import {
  mineApi,
} from '~/api/api'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: Boolean,
    userName:{
      type:String,
      observer(name){
        this.handleName(name)
      }
    },
    verifyId:Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    textList: [],
    disable: true,
    status: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleName(str) {
      if (!str) return
      const len = str.length
      const arr = str.split('')
      let temp = []
      arr.forEach(el => {
        let obj = {
          text: el,
          needFill: false,
          verify: ''
        }
        temp.push(obj)
      })
      // 姓名为两个或三个字:展示第一和第三个字,第二个字需输入,
      // 姓名为四个字:展示第一和第四个字,第二和第三个字需输入,
      // 姓名为五个字或大于五个字,展示第一、第二、第五及以后的字,第三和第四个字需输入 
      if (len < 4) {
        temp[1].needFill = true
      } else if (len == 4) {
        temp[1].needFill = true
        temp[2].needFill = true
      } else if (len > 4) {
        temp[2].needFill = true
        temp[3].needFill = true
      }
      this.setData({
        textList: temp
      })
    },
    intText(e) {
      const { index } = e.currentTarget.dataset
      const value = e.detail.value
      const name = `textList[${index}].verify`
      this.setData({
        [name]: value
      }, () => {
        const { textList } = this.data
        let flag = false
        textList.forEach(el => {
          if (el.needFill) {
            if (!el.verify) {
              flag = true
            }
          }
        })
        this.setData({
          disable: flag
        })
      })
    },
    confirmText() {
      const { textList, disable } = this.data
      let success = true
      if (disable) return
      textList.forEach(el => {
        if (el.needFill && el.verify != el.text) {
          if (el.verify != el.text) {
            success = false
          }
        }
      })
      if (!success) return this.setData({ status: 2 })
      if (success) {
        this.setData({ status: 1 })
        this.toJumpMineJF()
        setTimeout(() => {
          this.setData({ status: 0 })
          this.cancel()
        }, 1500)
      }
    },
    cancel() {
      this.setData({
        show: false
      })
    },
    confirmCancel() {
      this.setData({
        status: 0,
        disable: true
      })
    },
    // 获取需要匹配账户的名称
    async toJumpMineJF() {
      const id = this.data.verifyId
      const res = await mineApi.getUserForGR({id})
      if(res){
        wx.$router.go(`/packageShopmall/packageMine/pages/integral/index/index`,{source:'mine'})
      }
    }
  },
  lifetimes: {
    // attached() {
    //   this.getMatchAcconut()
    // },
  }
})