<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
                <template slot="menuRight"> 
                    <div style="display:flex">
                        <el-select v-model="optionvalue" clearable placeholder="请选择文件存储类型">
                            <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                        <el-link :underline="false" @click="setMetadata"><i class="el-icon-s-tools" size="large" style="line-height: 38px; font-size: 24px;margin-left: 5px;"></i></el-link>
                        
                    </div>
                </template>
    </avue-crud>
      <!-- 编辑元素表单信息 -->
    <el-dialog
      title="设置分类元素数据"
      :visible.sync="setMetadataTag"
      width="60%"
      :modal-append-to-body="false"
    >
      <div>
        <div style="float:right;margin-bottom:20px">
          <el-select v-model="optionvalue" clearable placeholder="请选择文件存储类型">
                            <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
           </el-select>
          <el-button type="primary">保存</el-button>
        </div>
          
        <el-table
          :data="MetadataformDatass"
          border
          style="width: 100%;">
          <el-table-column
            prop="metadataitem"
            label="元数据项">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.metadataitem"
                placeholder="请输入"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="capture"
            label="捕获方式">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.capture"
                placeholder="请选择">
                <el-option
                  v-for="(item,key) in tableTypelist"
                  :key="key"
                  :label="item.dictValue"
                  :value="item.dictKey">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="isrequired"
            label="是否必选">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.isrequired"
                placeholder="请选择">
                <el-option
                  v-for="(item,key) in ownerTypeList"
                  :key="key"
                  :label="item.dictValue"
                  :value="item.dictKey">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
       
        </el-table>
      </div>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="setMetadataTag = false">取 消</el-button>
        <el-button
          type="primary"
          @click="editeditElementFormMF()"
        >确 定</el-button>
      </span>
    </el-dialog>
  </basic-container>
  
</template>

<script>
import {getList, getDetail, add, update, remove} from "@/api/tentative/testcollect";
import {mapGetters} from "vuex";

export default {
  data() {
    return {
    options: [{
          value: '选项1',
          label: '竣工图'
        }, {
          value: '选项2',
          label: '计量'
        }, {
          value: '选项3',
          label: '质检'
        }, {
          value: '选项4',
          label: '声像'
        }, {
          value: '选项5',
          label: '隐蔽'
        }],
     optionvalue: '',
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      search:{},
      selectionList: [],
      option: {
         refreshBtn: false,      // 刷新 
        columnBtn: false,       // 操作列显隐
        addBtn:true,
        menuWidth:330,
        height:'auto',
        calcHeight: 30,
        tip: false,
        searchShow: false,
        searchMenuSpan: 0,
        border: true,
        index: true,
        viewBtn: true,
        selection: true,
        dialogClickModal: false,
        labelWidth:150,
        column: [
          {
            label: "元数据项",
            prop: "metadataitem",
            rules: [{
              required: true,
              message: "请输入元数据项",
              trigger: "blur"
            }]
          },
           {
            label: "编号",
            prop: "id",
            rules: [{
              required: true,
              message: "编号",
              trigger: "blur"
            }]
          },
           {
            label: "数据类型",
            prop: "datatype",
            type:'select',
            dicData:[{
              label:'数值',
              value:0
            },{
              label:'字符串',
              value:1
            }],
            rules: [{
              required: true,
              message: "数据类型",
              trigger: "blur"
            }]
          },
           {
            label: "容器类型",
            prop: "containertype",
            type:'select',
            rules: [{
              required: true,
              message: "容器类型",
              trigger: "blur"
            }],
             dicData:[{
              label:'来源',
              value:0
            },{
              label:'文件联',
              value:1
            }],
          },
            {
            label: "捕获方式",
            prop: "capture",
            rules: [{
              required: true,
              message: "捕获方式",
              trigger: "blur"
            }],
            type:'select',
            dicData:[{
              label:'手动',
              value:0
            },{
              label:'自动',
              value:1
            }],
          },
              {
            label: "是否必选",
            prop: "isrequired",
            rules: [{
              required: true,
              message: "是否必选",
              trigger: "blur"
            }],
             type:'select',
             dicData:[{
              label:'可选',
              value:0
            },{
              label:'必选',
              value:1
            }],
          }

        ]
      },
      data: [],
      setMetadataTag:false,
      MetadataformDatass:[],
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        viewBtn: false,
        //addBtn: this.vaildData(this.permission.imageclassificationconfig_add, false),
        //viewBtn: this.vaildData(this.permission.imageclassificationconfig_view, false),
        //delBtn: this.vaildData(this.permission.imageclassificationconfig_delete, false),
       // editBtn: this.vaildData(this.permission.imageclassificationconfig_edit, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {

    rowSave(row, done, loading) {
      add(row).then(() => {
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done();
      }, error => {
        loading();
        window.console.log(error);
      });
    },
    rowUpdate(row, index, done, loading) {
      update(row).then(() => {
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done();
      }, error => {
        loading();
        console.log(error);
      });
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetail(this.form.id).then(res => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage){
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize){
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      // getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
      //   const data = res.data.data;
      //   this.page.total = data.total;
      //   this.data = data.records;
      //   this.loading = false;
      //   this.selectionClear();
      // });
        const data = [{
          metadataitem:'全宗名称',
          id:'1',
          datatype:'字符串',
          containertype:'来源',
          capture:'手动',
          isrequired:'是',
          
        }];
         this.page.total = 1;
        this.data = data;
        this.loading = false;
        this.selectionClear();
    },

    setMetadata(){
      console.log(this.selectionList,'this.selectionList');
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      if (this.data.length) {
        let da = []
        this.MetadataformDatass = [...this.selectionList];
        console.log(this.MetadataformDatass,'his.formDatass111');
        // this.MetadataformDatass.forEach(val => {
        //   da.push({
        //     tableType: val.tabType,
        //     tableOwner: val.tabOwner,
        //     id: val.id,
        //     tableName: val.title,
        //     fillRate: val.fillRate,
        //   })
        // })
        // this.MetadataformDatass = da
        // console.log(this.MetadataformDatass,'this.formDatass');
        // let fa=[]
        // this.MetadataformDatass.forEach(val=>{
        //      let newarr= this.tableTypelist.filter(e => e.dictValue===val.tableType);
        //      let newarr1= this.ownerTypeList.filter(e => e.dictValue===val.tableOwner);
        //       fa.push({
        //       tableType: newarr[0].dictKey,
        //       tableOwner: newarr1[0].dictKey,
        //       id: val.id,
        //       tableName: val.tableName,
        //       fillRate: val.fillRate,
        //     })
        // })
        // this.MetadataformDatass=fa
      

      }
       this.setMetadataTag=true;
    }
  }
};
</script>

<style>

</style>
