<template>
  <div style="box-sizing: border-box; padding: 20px">
    <zj-form-container
      ref="formRef"
      :formData="formData"
      :formRules="formRules"
      :formAttributes="{ 'label-position': 'top' }"
    >
      <zj-form-module title="中差评申诉配置" :formData="formData" :formItems="formItems" :column="1"> </zj-form-module>
    </zj-form-container>
    <div>
      <el-button size="mini" type="primary" @click="submit">提交</el-button>
      <el-button size="mini" type="success" @click="reset">重置</el-button>
    </div>
  </div>
</template>

<script>
import { insureEmailConfig, insureEmailDetail } from '@/api/InsuranceManagement.js'
import editTable from '@/components/template/editTable.js'
import { getDataDictionary } from '@/api/dataDictionary.js'
export default {
  mixins: [editTable],
  data() {
    return {
      formData: {
        accidentMailbox: '',
        employerMailbox: '',
        receiveMailbox: '',
        appToken: '',
        companyId: '',
        overNum: '',
        sendMailbox: '',
        sendName: '',
        sendPassword: '',
        sendTime: '',
        mailboxReceives: []
      },
      formRules: {
        appToken: [{ required: true, message: '请输入', trigger: 'blur' }],
        companyId: [{ required: true, message: '请输入', trigger: 'blur' }],
        overNum: [{ required: true, message: '请输入', trigger: 'blur' }],
        sendMailbox: [{ required: true, message: '请输入', trigger: 'blur' }],
        sendName: [{ required: true, message: '请输入', trigger: 'blur' }],
        sendMailbox: [{ required: true, message: '请输入', trigger: 'blur' }],
        sendPassword: [{ required: true, message: '请输入', trigger: 'blur' }],
        sendTime: [{ required: true, message: '请输入', trigger: 'blur' }]
      },
      INSURE_STEAD_UNIT: []
    }
  },
  computed: {
    formItems() {
      return [
        {
          name: 'el-input',
          md: 24,
          attributes: {},
          formItemAttributes: { label: '接收邮箱,（意外险专用）,多邮箱以英文逗号隔开', prop: 'accidentMailbox' }
        },
        {
          name: 'el-input',
          md: 24,
          attributes: {},
          formItemAttributes: { label: '接收邮箱,（雇主险专用）,多邮箱以英文逗号隔开', prop: 'employerMailbox' }
        },
        {
          name: 'el-input',
          md: 24,
          attributes: {},
          formItemAttributes: { label: '接收邮箱,（意外险专用）,多邮箱以英文逗号隔开', prop: 'accidentMailbox' }
        },
        {
          name: 'el-input',
          md: 24,
          attributes: {},
          formItemAttributes: { label: '接收邮箱,（雇主险专用）,多邮箱以英文逗号隔开', prop: 'employerMailbox' }
        }
      ]
    }
  },
  created() {
    // 获取详情
    insureEmailDetail().then(res => {
      this.formData = { ...res.data, mailboxReceives: res?.data?.mailboxReceives || [] }
    })
    getDataDictionary({
      pageNum: 1,
      pageSize: -1,
      params: [
        { param: 'a.status', compare: '=', value: 'ON' },
        { param: 'a.dict_type', compare: '=', value: 'INSURE_STEAD_UNIT' }
      ]
    }).then(res => {
      this.INSURE_STEAD_UNIT = res.data.records.map(item => ({
        value: item.dictCode,
        label: item.dictValue
      }))
    })
  },
  methods: {
    submit() {
      this.$refs['formRef'].validate(valid => {
        if (valid) {
          insureEmailConfig({
            ...this.formData
          }).then(res => {
            this.$message({
              type: 'success',
              message: `保存成功!`
            })
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    }
  }
}
</script>

<style lang="scss" scoped></style>
