<template>
  <el-form ref="form" :rules="rules" :model="form" label-width="80px" label-position="top" size="small">
    <el-row :gutter="40">
      <el-col :span="12">
        <el-form-item label="责任人姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入责任人姓名" disabled />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" disabled />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  name: 'FlowPersonInfo',
  props: {
    data: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      form: {
        name: '',
        phone: ''
      },
      rules: {
        name: [{ required: true, message: '请输入责任人姓名', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' }]
      }
    }
  },
  computed: {
    ...mapGetters(['dict'])
  },
  watch: {
    data() {
      this.updateInternalData()
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.updateInternalData()
    },

    updateInternalData() {
      if (typeof this.data === 'object' && this.data !== null) {
        const { name, phone } = this.data
        this.form = {
          name,
          phone
        }
      } else {
        this.form = {
          name: '',
          phone: ''
        }
      }
    },

    getPendingCacheData() {
      return this.getFormData()
    },

    /**
    * 获取当前模块数据
    * @time 2022-04-23 15:50:05
    */
    async validate(isErrorAnchor = false) {
      try {
        await this.$refs.form.validate()
        return true
      } catch (e) {
        if (isErrorAnchor) {
          this.$refs.form.fields.filter(item => item.validateState === 'error')[0].$el.scrollIntoView(true)
        }
        let temp = {
          anchor: () => {
            this.$refs.form.fields.filter(item => item.validateState === 'error')[0].$el.scrollIntoView(true)
            temp = null
          }
        }
        throw temp
      }
    },

    /**
    * 获取表单数据
    * @time 2022-04-23 18:02:02
    */
    getFormData() {
      return this.form
    }
  }
}
</script>
