<template>
  <div>
    <el-button size="small" style="width:120px" type="primary" @click="querySite_Parameter">设 置</el-button>
    <el-dialog title="客户查重规则" append-to-body :visible.sync="dialogEditVisible" width="860px">
      <el-row :gutter="16">
        <el-col :span="24" style="margin-top: -20px">
          <span style="color: red">注意：每层的查重条件可多选字段</span>
        </el-col>
        <el-col :span="24" style="margin-top: 20px">
          <div style="width: 50px" class="inline-16">
            第一层:
          </div>
          <div style="width: 580px;" class="inline-16" >
            <el-select v-model="fields1" multiple placeholder="请选择字段" style="width: 100%"  size="mini">
              <el-option
                  v-for="item in options"
                  :key="item.column_name"
                  :label="item.column_name"
                  :value="item.column_name">
                <span style="float: left">{{ item.column_name }}</span>
                <span style="float: right; color: #8492a6; font-size: 12px">{{ item.column_comment?item.column_comment:'' }}</span>
              </el-option>
            </el-select>
          </div>
          <div style="width: 100px;" class="inline-16" >
            <el-select v-model="relation" placeholder="请选择" style="width: 100%"  size="mini">
              <el-option
                  v-for="item in relations"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div style="width: 50px" class="inline-16">
            关系
          </div>
        </el-col>
        <el-col :span="24" style="margin-top: 20px">
          <div style="width: 50px" class="inline-16">
            第二层:
          </div>
          <div style="width: 580px;" class="inline-16" >
            <el-select v-model="fields2" multiple placeholder="请选择字段" style="width: 100%"  size="mini">
              <el-option
                  v-for="item in options"
                  :key="item.column_name"
                  :label="item.column_name"
                  :value="item.column_name">
                <span style="float: left">{{ item.column_name }}</span>
                <span style="float: right; color: #8492a6; font-size: 12px">{{ item.column_comment?item.column_comment:'' }}</span>
              </el-option>
            </el-select>
          </div>
          <div style="width: 100px;" class="inline-16" >
            <el-select v-model="relation" placeholder="请选择" style="width: 100%"  size="mini">
              <el-option
                  v-for="item in relations"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div style="width: 50px" class="inline-16">
            关系
          </div>
        </el-col>
        <el-col :span="24" style="margin-top: 20px">
          <div style="width: 50px" class="inline-16">
            第三层:
          </div>
          <div style="width: 580px;" class="inline-16" >
            <el-select v-model="fields3" multiple placeholder="请选择字段" style="width: 100%"  size="mini">
              <el-option
                  v-for="item in options"
                  :key="item.column_name"
                  :label="item.column_name"
                  :value="item.column_name">
                <span style="float: left">{{ item.column_name }}</span>
                <span style="float: right; color: #8492a6; font-size: 12px">{{ item.column_comment?item.column_comment:'' }}</span>
              </el-option>
            </el-select>
          </div>
          <div style="width: 100px;" class="inline-16" >
            <el-select v-model="relation" placeholder="请选择" style="width: 100%"  size="mini">
              <el-option
                  v-for="item in relations"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div style="width: 50px" class="inline-16">
            关系
          </div>
        </el-col>
        <el-col :span="24" style="margin-top: 20px">
          <span >项目报备成功保护期设置:</span>
        </el-col>
        <el-col :span="24" style="margin-top: 20px">
          <div style="width: 50px" class="inline-16">
            保护期:
          </div>
          <div style="width: 580px;" class="inline-16" >
            <el-select v-model="projectprotectionperiod"  placeholder="请选择" style="width: 100%"  size="mini">
              <el-option
                  v-for="item in monthOption"
                  :key="item.value"
                  :label="item.value"
                  :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div style="width: 50px" class="inline-16">
            个月
          </div>
        </el-col>
        <el-col :span="24" style="margin-top: 20px">
          <span style="color: red">项目保护期设为0，则不管控保护期；为1-12，则为保护期限；</span>
        </el-col>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogEditVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning"  class="normal-btn-width btn-warning" @click="onSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "customerCheckRule",
  data(){
    return {
      dialogEditVisible:false,
      monthOption:[
        {
          value:'0',
          label: '0'
        },
        {
          value:'1',
          label: '1'
        },
        {
          value:'2',
          label: '2'
        },
        {
          value:'3',
          label: '3'
        },
        {
          value:'4',
          label: '4'
        },
        {
          value:'5',
          label: '5'
        },
        {
          value:'6',
          label: '6'
        },
        {
          value:'7',
          label: '7'
        },
        {
          value:'8',
          label: '8'
        },
        {
          value:'9',
          label: '9'
        },
        {
          value:'10',
          label: '10'
        },
        {
          value:'11',
          label: '11'
        },
        {
          value:'12',
          label: '12'
        }
      ],
      projectprotectionperiod:'0',
      options: [],
      fields1: [],
      fields2: [],
      fields3: [],
      relations: [{
        value:'并且',
        label: '并且'
      }],
      relation:''
    }
  },
  methods:{
    querySite_Parameter(){
      this.dialogEditVisible = true
      this.relation = this.relations[0].value
      this.queryTable()
      this.queryRule()
    },
    async queryTable(){
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 50,
          "typename": "tablecolumnselect",
          "parameter": {
            "table_name": "sa_project"
          }
        }
      })
      this.options = res.data
    },
    async onSubmit(){
      const res = await this.$api.requested({
        "id": "20230408091702",
        "content": {
          "projectcheckrule": {
            "fields1": this.fields1,
            "factor1": "and",
            "fields2":this.fields2,
            "factor2": "and",
            "fields3":this.fields3,
            "factor3": "and"
          },
          "projectprotectionperiod":this.projectprotectionperiod
        },
      })
      this.tool.showMessage(res,()=>{
        this.$emit('queryRule')
        this.dialogEditVisible = false
        this.fields1 = []
        this.fields2 = []
        this.fields3 = []
        this.projectprotectionperiod = 0
      })
    },
    onClose(){
      this.dialogEditVisible = false
      this.fields1 = []
      this.fields2 = []
      this.fields3 = []
    },
    /*查重规则*/
    async queryRule(){
      const res = await this.$api.requested({
        "id": "20230410090502",
        "content": {},
      })
      this.fields1 = res.data.projectcheckrule.fields1
      this.fields2 = res.data.projectcheckrule.fields2
      this.fields3 = res.data.projectcheckrule.fields3
      this.projectprotectionperiod= res.data.projectprotectionperiod
    }
  }
}
</script>

<style scoped>

</style>