<template>
   <el-dialog v-model="dialogData.visible" title="项目模板">
    <el-form :model="dialogData.formData" :rules="dialogData.rules" label-width="100px">
      <el-form-item label="模板名称" prop="name">
        <el-input v-model="dialogData.formData.name" autocomplete="off" />
      </el-form-item>
      <el-form-item label="事业部">
        <el-select v-model="dialogData.formData.bizUnits" placeholder="请选择事业部" multiple>
          <el-option label="研发事业部" value="研发事业部" />
          <el-option label="业务事业部" value="业务事业部" />
          <el-option label="电梯事业部" value="电梯事业部" />
        </el-select>
      </el-form-item>
      <el-form-item label="适用于">
        <el-radio-group v-model="dialogData.formData.radioType" class="ml-4">
          <el-radio label="0" size="large">项目类型</el-radio>
          <el-radio label="1" size="large">项目分类</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="范围选择" v-show="dialogData.formData.radioType === '0'">
        <el-radio-group v-model="dialogData.formData.range" class="ml-4">
          <el-radio label="0" size="large">所有项目类型</el-radio>
          <el-radio label="1" size="large">部分项目类型</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="项目类型" v-show="dialogData.formData.radioType === '1'">
        <el-radio-group v-model="dialogData.formData.projectType" class="ml-4">
          <el-radio :label="item.id" size="large" v-for="(item, index) in list" :key="index">{{item.cname}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="项目类型" v-show="dialogData.formData.range === '1'">
        <el-checkbox-group v-model="dialogData.formData.checkList1">
          <el-checkbox :label="item.cname" v-for="(item, index) in list" :key="index"/>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="项目分类" v-show="dialogData.formData.radioType === '1'">
        <el-checkbox-group v-model="dialogData.formData.checkList2">
          <el-checkbox :label="item.cname" v-for="(item, index) in list" :key="index"/>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogData.visible = false">取消</el-button>
        <el-button type="primary" @click="dialogData.onConfirm"
          >确定</el-button
        >
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import {  reactive } from 'vue'
export default {
  name: 'ProjectMasterEdit',
  props: {
    list: {
      type: Array,
      default: null
    }
  },
  setup(props, context) {
    const dialogData = reactive({
      visible: false,
      formData: {
        name: '',
        bizUnits: '',
        radioType: '0',
        range: '0',
        projectType: '',
        checkList1: [],
        checkList2: []
      },
      rules: {
        name: {
          required: true, message: '请输入模板名称', trigger: 'blur'
        }
      },
      show: () => {
        dialogData.visible = true
      },
      onConfirm: () => {
        context.emit('onConfirm', dialogData.formData)
      }
    })
    return {
      dialogData
    }
  }
}
</script>

<style>

</style>