<template>
  <div>
    <el-card class="el-card">

      <el-form v-if="queryList && queryList.length > 0" :inline="true" :model="filterQuery" class="query-form" size="mini" @submit.native.prevent>
        <!-- <el-form-item class="query-form-item" label-width="100px">
          <el-input
            v-model="filterQuery.sickAd"
            placeholder="请输入病人住院号"
            clearable
            style="width: 500px"
            @keypress.enter.native="enterKey($event)"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button-group>
            <el-button type="primary" icon="el-icon-refresh" @click="onReset">重置</el-button>
            <el-button type="primary"icon="el-icon-search" @click="getList"
            >查询
            </el-button>
          </el-button-group>
        </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"
                />
                <span style="float: left">{{ item.name }}</span>
                <span v-if="item.isShowXx == '1'" style="float: right; color: #8492a6; font-size: 13px">{{ item.code }}</span>
              </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"
                :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"
                />
                <span style="float: left">{{ item.name }}</span>
                <span v-if="item.isShowXx == '1'" style="float: right; color: #8492a6; font-size: 13px">{{ item.code }}</span>
              </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-form-item>
            <el-button-group>
              <el-button type="primary" icon="el-icon-refresh" @click="onReset">重置</el-button>
              <el-button type="primary"icon="el-icon-search" @click="getList"
              >查询
              </el-button>
            </el-button-group>
          </el-form-item>
        </el-row>
      </el-form>
      <el-table
        v-loading="loading"
        :data="list"
        style="width: 100%"
        border
        @row-click="(row) => executeFuc(row,'0',tableObj.handleChangeFuc)"
        highlight-current-row
        @selection-change="handleSelectionChange"
      >
      <!--  <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column label="扫码单据类型" prop="billTypeName">
        </el-table-column>
        <el-table-column
          label="订单号"
          prop="billNo"
          show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column label="来源" prop="fromType">
          <template slot-scope="scope">
            <span>{{ fromTypeMap[scope.row.fromType] }}</span>
          </template>
        </el-table-column>
        <el-table-column label="所在仓库" prop="invName" width="250">
        </el-table-column>
        <el-table-column
          label="创建时间"
          prop="actDate"
          width="150"
          show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span>{{ scope.row.createTime }}</span>
          </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"
        :limit.sync="filterQuery.limit"
        :page.sync="filterQuery.page"
        @pagination="handleCurrentChange"
      ></pagination>

    </el-card>

    <el-card class="el-card">
      <el-table
        v-loading="loading"
        border
        :data="detailList"
        style="width: 100%"
      >
       <!-- <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column
          label="UDI码"
          prop="code"
          :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column
          label="产品通用名"
          prop="productName"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="包装规格"
          prop="ggxh"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          width="100"
          label="批次号"
          prop="batchNo"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="生产日期"
          prop="productDate"
          width="100"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="失效日期"
          prop="expireDate"
          width="100"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="生产企业"
          prop="manufactory"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="注册/备案凭证号"
          prop="zczbhhzbapzbh"
          :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click.native.stop="intentDetail(scope.row)"
            >流向详情
            </el-button
            >
          </template>
        </el-table-column> -->
        <template v-for="(item, index) in tableHeader2">
          <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>
    </el-card>


    <el-dialog
      title="UDI码流向"
      :visible.sync="udiCodeTraceVisible"
      width="80%"
      v-if="udiCodeTraceVisible"
    >
      <udiCodeTrace
        :udiCode="udiCode"
        :diloadTrue="false"
        v-on:closeDetailDialog="closeDetailDialog"
      ></udiCodeTrace>
    </el-dialog>

  </div>
</template>

<script>
import draggable from "vuedraggable";
import udiCodeTrace from "./invUdiTraceOrder"
import {filterSickTrace} from "@/api/inventory/invSickTrace";
import {getBasicUnitMaintains} from "@/api/basic/basicUnitMaintain";
import {getCodeList} from "@/api/inout/code";
import {
  getHead,executeFuc
} from "@/utils/customConfig";

export default {
  name: "sickerUdiTraceOrder",
  data() {
    return {
      query: {
        code: null,
        batchNo: null,
        productIdFk: null,
        customerId: null,
        page: 1,
        limit: 20,
        supId: null,
      },
      sitcomScan: false,
      checkStatus: {
        1: "校验异常",
        0: "未校验",
        2: "正常",
      },
      fromOptions: [],
      erpCheckStatus: {
        1: "校验异常",
        0: "未校验",
        2: "校验成功",
      },
      fromTypeMap: {
        "1": "UDIMS平台",
        "2": "网页新增",
        "3": "pda即时校验",
        "4": "pda未校验",
        "5": "pc端扫码精灵",
        "6": "缺量补录单据",
        "7": "UDI供应商平台",
        "8": "平衡补录单据",
        "10": "手动补单",
        "11": "仓库盘点",
        "12": "采购计划",
        "13": "领用单据",
        "14": "第三方系统单据",
      },
      //往来单位
      list: [],
      tableHeader:[],
      queryList:[],
      fromList:[],
      tableHeader2:[],
      queryList2:[],
      fromList2:[],
      options: {

      },
      detailList: [],
      filterQuery: {
        sickAd: null,
        page: 1,
        limit: 20,
      },
      detailQuery: {
        orderId: "",
      },
      deleteData: {
        id: "",
      },
      idQuery: {
        id: "",
      },
      curIndex: "",
      adListNoDataText: "无数据",
      codeDetailVisible: false,
      udiCodeTraceVisible: false,
      udiCode: null,
      total: 0,
      loading: false,
      index: null,
      formName: null,
      orderId: "",
      formMap: {
        add: "新增",
        edit: "编辑",
      },
      exportQuery: {
        orderId: "",
        exportStatus: "",
      },

      uploadQuery: {
        orderId: "",
      },
      multipleSelection: [],
      dialogTableVisible: false,
      formLoading: false,
      formVisible: false,
      deleteLoading: false,
      addDialogVisible: false,
    };
  },
  components: {
    draggable,
    udiCodeTrace,
  },
  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        code: null,
        batchNo: null,
        productIdFk: null,
        customerId: null,
        page: 1,
        limit: 20,
        supId: null,
      };
      this.actDateRange = [];
      //this.getList();
    },

    enterKey(_this,event) {
      _this.onSubmit();
    },
    onSubmit() {
      this.getList();
    },
    handleSizeChange(val) {
      this.filterQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val;
      this.getList();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    findMethod(query) {
      this.fromOptions = [];
      let cQuery = {
        key: query,
      };
      getBasicUnitMaintains(cQuery)
        .then((response) => {
          this.loading = false;
          this.fromOptions = response.data.page.list || [];
        })
        .catch(() => {
          this.loading = false;
        });
    },
    //获取订单列表
    getList() {
      this.loading = true;
      if (!this.$isBlank(this.filterQuery.sickAd)) {
        let code = this.filterQuery.sickAd;
        this.filterQuery.sickAd = code.replace("\r", "")
      }
      filterSickTrace(this.filterQuery)
        .then((response) => {
          if (response.code == 20000) {
            this.loading = false;
            this.list = response.data.list || [];
            this.detailList = [];
            this.total = response.data.total || 0;
          } else {
            this.loading = false;
            this.list = [];
            this.detailList = [];
            this.total = 0;
            this.$message.error(response.message);
          }


        })
        .catch(() => {
          this.loading = false;
          this.list = [];
          this.total = 0;
        });
    },
    //业务明细表
    getOrderDetail(_this,row) {
      _this.loading = true;
      _this.detailQuery = {
        orderId: row.billNo,
        showType: 1,
      };
      _this.refresgOrderDetail();
    },
    refresgOrderDetail() {
      getCodeList(this.detailQuery)
        .then((response) => {
          this.loading = false;
          this.detailList = response.data.list || [];
        })
        .catch(() => {
          this.loading = false;
          this.detailList = [];
        });
    },
    intentDetail(_this,row) {
      _this.udiCode = row.code;
      _this.udiCodeTraceVisible = true;
      _this.idQuery.id = row.id;
    },


    closeDetailDialog(val) {
      this.codeDetailVisible = false;
      this.udiCodeTraceVisible = false;
    },
    cancelDialog() {
      this.addDialogVisible = false;
    },
    importOrder(row) {
      this.orderId = row.id;
      this.addDialogVisible = true;
    },
    executeFuc(row,type,clickFuc,value){
      return executeFuc(this,row,type,clickFuc,value);
    },
    executeEval(row,expression,defaultRet){
      if(expression){
        return eval(expression);
      }
      return defaultRet;
    }
  },
  filters: {
    statusFilterType(status) {
      const statusMap = {
        false: "success",
        true: "danger",
      };
      return statusMap[status];
    },
  },
  mounted() {

  },

  created() {
    let query = this.$route.query;
    this.query = Object.assign(this.query, query);
    this.query.limit = parseInt(this.query.limit);
    getHead("sickerUdiTraceOrder-1","1").then((re) => {
      // 处理返回的数据
      this.tableObj = re.data;
      this.tableHeader = re.data.tableList;
      this.queryList = re.data.queryList;
      this.fromList = re.data.fromList;
    });
    getHead("sickerUdiTraceOrder-2","1").then((re) => {
      // 处理返回的数据
      this.tableObj2 = re.data;
      this.tableHeader2 = re.data.tableList;
      this.queryList2 = re.data.queryList;
      this.fromList2 = re.data.fromList;
    });
  },
};
</script>


<style scoped>

#inputer {
  width: 100%;
  min-height: 30px;
  background-color: white;
  border: #d0d0d0;
  border-style: solid;
  border-width: 0.1px;
  color: #4a4a4a;

}

#inputer:focus {
  width: 100%;
  min-height: 30px;
  background-color: white;
  border: #0080FF;
  border-style: solid;
  border-width: 0.1px;
  color: #4a4a4a;

}

.el-table .warning-row {
  background: #ffb5b5;
}

.el-table .success-row {
  background: #ffffff;
}
</style>
