<template>
  <div>
    <el-card>
      <el-form v-if="queryList && queryList.length > 0" :model="filterQuery" class="query-form" size="mini" label-width="120px" :inline="true">
       <!-- <el-form-item label="当前仓库:">
          <el-input v-model="filterQuery.curInv" placeholder="请输入当前仓库名称" clearable></el-input>
        </el-form-item> -->
        <el-row style=" display:flex;  flex-wrap: wrap; ">
          <template v-for="(item, index) in queryList" >
            <el-form-item v-if="item.columnType == 'input' && executeEval(row,item.expression,true)" :label="item.columnDesc+`:`" :key="item.id">
              <el-input
                v-model="filterQuery[item.columnName]"
                :placeholder="item.columnDesc"
                :disabled="executeEval(null,item.disabledFuc,false)"
                @keyup.enter.native="executeFuc($event,'5',item.clickFuc)"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item v-if="item.columnType == 'select' && executeEval(row,item.expression,true)" :label="item.columnDesc+`:`">
              <el-select v-model="filterQuery[item.columnName]"
                         :placeholder="item.columnDesc"
                         :disabled="executeEval(null,item.disabledFuc,false)"
                         clearable>
                <el-option
                  v-for="dict in item.lableRuleObj"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item v-if="item.columnType == 'selectServer' && executeEval(row,item.expression,true)" :label="item.columnDesc+`:`">
              <el-select
                v-model="filterQuery[item.columnName]"
                :placeholder="item.columnDesc"
                @change="executeFuc($event,'5',item.checkRules)"
                :disabled="executeEval(null,item.disabledFuc,false)"
                filterable
                remote
                :remote-method="(query) => executeFuc(query,'5',item.clickFuc)"
                clearable>
                <el-option
                  v-for="item in options[item.clickFuc]"
                  :key="item.code"
                  :label="item.label"
                  :value="item.code"
                />
              </el-select>
            </el-form-item>
            <el-form-item v-if="item.columnType == 'datePicker' && executeEval(row,item.expression,true)" :label="item.columnDesc+`:`">
              <el-date-picker
                :picker-options="pickerOptions"
                v-model="actDateRange"
                type="daterange"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item v-if="item.columnType == 'date' && executeEval(row,item.expression,true)" :label="item.columnDesc+`:`">
              <el-date-picker
                v-model="filterQuery[item.columnName]"
                :style="`width:${item.width+'px'}`"
                value-format="yyyy-MM-dd"
                :disabled="executeEval(null,item.disabledFuc,false)"
                type="date"
                :placeholder="item.columnDesc"
              ></el-date-picker>
            </el-form-item>
          </template>
        </el-row>
        <el-form-item>
          <el-button-group>
            <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
            <el-button type="primary" icon="el-icon-plus" @click="addOrderMuti">新增</el-button>
          </el-button-group>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="list" style="width: 100%"  border highlight-current-row>
       <!-- <el-table-column label="序号" type="index" width="60"></el-table-column>
        <el-table-column label="当前仓库" prop="invName"></el-table-column>
        <el-table-column label="生成出库单默认往来单位" prop="fromCorpName"></el-table-column>
        <el-table-column label="生成出库单默认单据类型" prop="targetActionName"></el-table-column>
        <el-table-column label="是否个人使用" prop="checkUse">
          <template slot-scope="scope">
            <span>{{ checkUseMap[scope.row.checkUse] }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="remark"></el-table-column>
        <el-table-column label="操作" width="120px">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.native="editDialog(scope.row)">编辑</el-button>
            <el-button type="text" size="small" @click.native.stop="deleteDialog(scope.row)">删除</el-button>
          </template>
        </el-table-column> -->
        <template v-for="(item, index) in tableHeader">
          <el-table-column
            v-if="item.columnType == 'id' && executeEval(row,item.expression,true)"
            type="index" :label="item.columnDesc"></el-table-column>
          <el-table-column
            v-if="item.columnType == 'selection'"
            type="selection"
            :width="item.width"
            :selectable="(row,number) => executeFuc(row,'3',item.clickFuc)"
          ></el-table-column>

          <el-table-column
            v-if="item.columnType == 'radio' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :sortable="item.sort"
            :width="item.width"
            :show-overflow-tooltip="item.tooltip"
            :key="item.columnName"
          >
            <template  slot-scope="scope">
              <el-radio :label="scope.row.id" v-model="radioCheck"><span></span></el-radio>
            </template>
          </el-table-column>
          <el-table-column
            v-if="item.columnType == 'laber' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :sortable="item.sort"
            :width="item.width"
            :show-overflow-tooltip="item.tooltip"
            :key="item.columnName"
          >
            <template   slot-scope="scope">
              <span :style="{color: executeFuc(scope.row,'4',item.lableRuleObj[scope.row[item.columnName]])}">{{ item.lableRuleObj[scope.row[item.columnName]] }}</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="item.columnType == 'eltag' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :sortable="item.sort"
            :width="item.width"
            :show-overflow-tooltip="item.tooltip"
            :key="item.columnName"
          >
            <template   slot-scope="scope">
              <el-tag :type="executeFuc(scope.row,'4',item,item.lableRuleObj?item.lableRuleObj[scope.row[item.columnName]]:scope.row[item.columnName])">
                <span>{{ item.lableRuleObj?item.lableRuleObj[scope.row[item.columnName]]:scope.row[item.columnName] }}</span>
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            v-if="item.columnType == 'button' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :width="item.width"
            :key="item.columnName"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button v-for="(buttonItem, buttonIndex) in item.buttonRulObj"
                         :type="buttonItem.type"
                         :size="buttonItem.size"
                         :style="buttonItem.style"
                         :key="buttonItem"
                         v-if="executeEval(scope.row,buttonItem.hasPermi,true)"
                         :disabled="executeEval(scope.row,buttonItem.disabledFuc,false)"
                         @click.native.stop="executeFuc(scope.row,'1',buttonItem.clickFuc)"
              >{{ buttonItem.name }}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            v-if="item.columnType == 'text' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :sortable="item.sort"
            :width="item.width"
            :show-overflow-tooltip="item.tooltip"
            :key="item.columnName"
          >
            <template slot-scope="scope">
              <span :style="{color: executeFuc(scope.row,'4',item,scope.row[item.columnName])}">{{ scope.row[item.columnName] }}</span>
            </template>
          </el-table-column>
        </template>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="filterQuery.page"
        :limit.sync="filterQuery.limit"
        @pagination="handleCurrentChange"

      ></pagination>
    </el-card>

    <el-dialog
      :title="formMap[formName]"
      :visible.sync="orderMutiSetVisible"
      :before-close="close"
      width="40%"
      v-if="orderMutiSetVisible"
      @close='closeDialog'
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <ioOrderMutiSetDialog
        :closeDialog="closeDialog"
        :inputQuery="inputQuery"
        :formName="formName"
      ></ioOrderMutiSetDialog>
    </el-dialog>

  </div>
</template>



<script>
import ioOrderMutiSetDialog from "@/views/inout/muti/ioOrderMutiSetDialog";
import {detailMuti, filterList} from "@/api/inout/orderMuti";
import {
  getHead,executeFuc
} from "@/utils/customConfig";

export default {
  name: "ioOrderMutiSet",
  data() {
    return {
      filterQuery: {
        curInv: null,
        fromCorp: null,
        targetAction: null,
        remark: null,
        updateTime: null,
        page: 1,
        limit: 10,
      },
      inputQuery: {
        curInv: null,
        fromCorp: "",
        targetAction: null,
        remark: null,
        updateTime: null,
      },
      total: 0,
      loading: false,
      list: [],
      formName: 1,
      formMap: {
        1: "新增出库设置",
        2: "编辑出库设置",
      },
      checkUseMap: {
        1: "是",
        0: "否",
      },
      orderMutiSetVisible: false,
    };
  },
  methods: {
    onSubmit() {
      this.filterQuery.page = 1;
      this.getList();
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getList();
    },
    closeDialog(){
      this.orderMutiSetVisible = false;
      this.getList();
    },
    addOrderMuti(){
      this.inputQuery={
        curInv: null,
        checkUse: null,
        fromCorp: null,
        targetAction: null,
        remark: null,
        updateTime: null,
      }
      this.formName=1;
      this.orderMutiSetVisible = true;
    },
    editDialog(_this,row){
      _this.formName=2;
      _this.inputQuery=row;
      _this.orderMutiSetVisible = true;
    },
    getList() {
      this.loading = true;
      filterList(this.filterQuery)
        .then((response) => {
          this.loading = false;
          this.list = response.data.list || [];
          this.total = response.data.total || 0;
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
          this.total = 0;
        });
    },
    deleteDialog(_this,row) {
      detailMuti(row)
        .then((response) => {
          if(response.code == 20000){
            _this.getList()
          }else{
            _this.$message.error(response.message);
          }
        })
        .catch(() => {
          _this.$message.error(response.message);
        });
    },
    executeFuc(row,type,clickFuc,value){
      return executeFuc(this,row,type,clickFuc,value);
    },
    executeEval(row,expression,defaultRet){
      if(expression){
        return eval(expression);
      }
      return defaultRet;
    }
  },
  components: {ioOrderMutiSetDialog},
  created() {
     getHead("ioOrderMutiSet","1").then((re) => {
       // 处理返回的数据
       this.tableObj = re.data;
       this.tableHeader = re.data.tableList;
       this.queryList = re.data.queryList;
       this.fromList = re.data.fromList;
       this.getList()
     });
  },
}
</script>

<style scoped>

</style>
