<template>
  <el-dialog title="按条件批量配置" :visible.sync="dialog.config" @close="handleClose" width="900px">
    <el-form ref="dataForm" :model="form" label-width="90px">
      <el-form-item label="方案：">
        <el-radio-group v-model="form.SchemeId">
          <el-radio label="schemeZero">全新设定</el-radio>
          <el-radio label="schemeOne">预置方案</el-radio>
          <el-radio label="schemeTwo">万达专用方案</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-show="form.SchemeId == 'schemeZero'" label="优先级：">
        <el-checkbox-group v-model="form.PriorityList">
          <el-checkbox v-for="item in PriorityList" :key="item.Priority" :label="item.Priority" name="priority">{{ item.name }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item v-show="form.SchemeId == 'schemeZero'" label="一级标签：">
        <el-checkbox-group v-model="form.FirstNameList">
          <el-checkbox style="width:99px;" v-for="(item, index) in FirstNameList" :key="index" :label="item.FirstName" name="firstTag"></el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item v-show="form.SchemeId == 'schemeZero'" label="二级标签：">
        <span style="color:#bbb;font-size:12px;">二级标签暂未提供，如确实需要请联系产品添加。</span>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="dialog.config = false">取 消</el-button>
      <el-button type="primary" @click="onSubmit" :loading="loading">确 认</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { getDataDictionary, setInfoPoint } from "@/api/scan/request"
import { mapGetters, mapActions } from "vuex"
export default {
  props: {
    dialog: {
      type: Object,
      default: function () {
        return {
          config: false
        };
      }
    }
  },
  data() {
    return {
      form: {
        SchemeId: 'schemeZero',
        PriorityList: [],
        FirstNameList: []
      },
      FirstNameList: [],
      PriorityList: [],
      loading: false
    };
  },
  created() {
    this.getInfos()
  },
  computed: {
    ...mapGetters("layout", ["projectId", "secret", "userId"])
  },
  methods: {
    getInfos() {
      let params1 = {
        data: {
          Distinct: true,
          Filters: "FirstName != ''",
          Orders: "FirstName desc",
          PageNumber: 1,
          PageSize: 1000,
          Projection: [ "FirstName" ]
        },
        type: ""
      }, params2 = {
        data: {
          Distinct: true,
          Filters: "Priority != '';Priority != 'null'",
          Orders: "Priority desc",
          PageNumber: 1,
          PageSize: 1000,
          Projection: [ "Priority" ]
        },
        type: ""
      };
      let promise1 = new Promise((resolve, reject) => {
        getDataDictionary(params1, res => {
          resolve(res)
        })
      })
      let promise2 = new Promise((resolve, reject) => {
        getDataDictionary(params2, res => {
          resolve(res)
        })
      })
      Promise.all([promise1, promise2]).then(values => {
        this.FirstNameList = values[0].Content
        this.PriorityList = values[1].Content.map((item) => {
          if (item.Priority == "S") {
            item.name = `(${item.Priority})关键信息`
            return item
          } else if (item.Priority == "M") {
            item.name = `(${item.Priority})次要信息`
            return item
          } else if (item.Priority == "R") {
            item.name = `(${item.Priority})参考信息`
            return item
          }
        })
      })
    },
    //确定
    onSubmit() {
      let params = {}
      this.loading = true
      if (this.form.SchemeId == 'schemeZero') {
        params = this.form
      } else {
        params = {
          SchemeId: this.form.SchemeId
        }
      }
      setInfoPoint(params, res => {
        this.form.SchemeId = 'schemeZero'
        this.form.FirstNameList = []
        this.form.PriorityList = []
        this.dialog.config = false
        this.loading = false
        this.$emit('configInfo')
      })
    },
    //弹窗关闭回调
    handleClose() {
      this.form.SchemeId = 'schemeZero'
      this.form.FirstNameList = []
      this.form.PriorityList = []
      this.loading = false
    }
  }
};
</script>
<style lang="scss">
  .el-dialog__body {
    max-height: 420px;
    overflow-y: auto;
  }
</style>
