<template>
  <div style="margin-bottom:16px">
    <el-button size="mini" type="text" @click="Btn">互斥标签</el-button>
    <el-dialog title="新 增" append-to-body :visible.sync="dialogFormVisible" width="500px">
      <div slot="title" style="font-size: 15px">
        设置互斥标签
      </div>
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" label-width="90px" label-position="left" size="mini">
          <el-col :span="24">
            <el-form-item label="选择标签" prop="mutextags">
              <el-select v-model="result" multiple placeholder="请选择标签">
                <el-option
                  v-for="item in allData"
                  :key="item.sys_systemtagdetailid"
                  :label="item.tag"
                  :value="item.sys_systemtagdetailid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "add",
  props:['allData','rowData','tagData'],
  data(){
    return {
      dialogFormVisible:false,
      result:[],
      form: {
        "sys_systemtagid": 1,
        "sys_systemtagdetailid": 1,
        "mutextags": [],
      },
      rules:{
      }
    }
  },
  methods:{
    Btn () {
      this.dialogFormVisible = true
      this.result = this.rowData.mutextags.map(item => {
        return item.sys_systemtagdetailid
      })
    },
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        this.form.sys_systemtagid = this.tagData.sys_systemtagid
        this.form.sys_systemtagdetailid = this.rowData.sys_systemtagdetailid
        this.form.mutextags = this.result.map(item => {
          return {
            "sys_systemtagdetailid": item,
          }
        })
        const res = await this.$api.requested({
          "id": "20221014122501",
          "version":1,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    }
  }
}
</script>

<style scoped>
/deep/.el-select {
  width: 100% !important;
}
</style>