<template>
  <div>
    <el-card>
      <el-form>
          <el-row type="flex">
            <el-col type="flex">
              <el-form-item label="记录号:">
                <el-input v-model="filterQuery.recordCode"
                          style="width: 200px;"
                          placeholder="请输入记录号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col type="flex">
              <el-form-item label="产品名称:">
                <el-input v-model="filterQuery.cpmctymc"
                          style="width: 200px;"
                          placeholder="请输入产品名称"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col type="flex">
              <el-form-item label="规格型号:">
                <el-input v-model="filterQuery.ggxh"
                          style="width: 200px;"
                          placeholder="请输入规格型号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col type="flex">
              <el-form-item label="批次号:">
                <el-input v-model="filterQuery.batchNo"
                          style="width: 200px;"
                          placeholder="请输入批次号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col type="flex">
              <el-form-item>
                <el-button-group style="display:flex;">
                  <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
                  <el-button type="primary" icon="el-icon-refresh" @click="onReset">重置</el-button>
                </el-button-group>
              </el-form-item>
            </el-col>
          </el-row>
      </el-form>
      <el-divider style="margin: 15px"></el-divider>

      <el-table v-loading="loading" :data="list"
                style="width: 100%"
                highlight-current-row border>
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column label="查询记录号" prop="recordCode" width="180"></el-table-column>
        <el-table-column label="UDI码" prop="udiCode" width="220"></el-table-column>
        <el-table-column label="产品名称" prop="cpmctymc" width="180"></el-table-column>
        <el-table-column label="规格型号" prop="ggxh" width="120"></el-table-column>
        <el-table-column label="医疗器械注册人" prop="ylqxzcrbarmc" width="180"></el-table-column>
        <el-table-column label="注册/备案号" prop="zczbhhzbapzbh" width="180"></el-table-column>
        <el-table-column label="批次号" prop="batchNo" width="180"></el-table-column>
        <el-table-column label="查询人" prop="createUser" width="180"></el-table-column>
        <el-table-column label="发货单位" prop="fromCorp" width="180"></el-table-column>
        <el-table-column label="收货单位" prop="toCorp" width="180"></el-table-column>
        <el-table-column label="所属企业" prop="companyName" width="180"></el-table-column>
        <el-table-column label="查询方式" prop="traceType" width="120"></el-table-column>
        <el-table-column label="备注" prop="remark" width="220"></el-table-column>
        <el-table-column label="操作" width="100" fixed="right">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click.native="handleView(scope.row,scope.index)"
            >详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :limit.sync="filterQuery.limit"
        :page.sync="filterQuery.page"
        @pagination="getList"
      ></pagination>
    </el-card>
    <el-dialog
      title="单据-详情"
      :visible.sync="open"
      class="dialog-two"
      width="60%"
      top="5vh"
    >
      <el-form :model="formView" :rules="formRules" ref="dataForm" label-width="100px">
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="查询方案" prop="traceType">
              <el-input v-model="formView.traceType" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="UDI码" prop="udiCode">
              <el-input v-model="formView.udiCode" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="社会信用号" prop="creditNum">
              <el-input v-model="formView.creditNum" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="注册备案人" prop="ylqxzcrbarmc">
              <el-input v-model="formView.ylqxzcrbarmc" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="注册/备案证号" prop="zczbhhzbapzbh">
              <el-input v-model="formView.zczbhhzbapzbh" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="产品主DI标识" prop="nameCode">
              <el-input v-model="formView.nameCode" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="产品通用名" prop="cpmctymc">
              <el-input v-model="formView.cpmctymc" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="规格型号" prop="ggxh">
              <el-input v-model="formView.ggxh" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="生产批次号" prop="batchNo">
              <el-input v-model="formView.batchNo" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="生产日期" prop="produceDate">
              <el-input v-model="formView.produceDate" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="失效日期" prop="expireDate">
              <el-input v-model="formView.expireDate" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="序列号" prop="serialNo">
              <el-input v-model="formView.serialNo" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="查询记录号" prop="recordCode">
              <el-input v-model="formView.recordCode" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="查询人" prop="createUser">
              <el-input v-model="formView.createUser" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="发货单位" prop="fromCorp">
              <el-input v-model="formView.fromCorp" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="收货单位" prop="toCorp">
              <el-input v-model="formView.toCorp" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="所属企业" prop="companyName">
              <el-input v-model="formView.companyName" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11" class="el-col">
            <el-form-item label="查询方式" prop="traceType">
              <el-input v-model="formView.traceType" size="small"
                        style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="11" type="flex">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="formView.remark" size="small" style="width: 90%" :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="open = false" size="small">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {getTraceRecordList} from "@/api/udi/udiTrace";

export default {
  data() {
    return {
      filterQuery: {
        recordCode: null,
        cpmctymc: null,
        ggxh: null,
        batchNo: null,
        page: 1,
        limit: 10,
      },
      options: [
        {value: 'A', label: 'UDI码查询(源头查询)'},
        {value: 'B', label: '按产品信息组合查询'},
        {value: 'C', label: '现场检查查询'}
      ],
      total: 0,
      loading: true,
      list: [],
      open: false,
      formView: {}
    }
  },
  methods: {
    handleView(row){
      this.list.forEach(obj => {
        if (row.id == obj.id) {
          this.formView = obj
        }
      })
      console.log(this.formView)
      this.open = true
    },
    onReset(){
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        recordCode: null,
        cpmctymc: null,
        ggxh: null,
        batchNo: null,
        page: 1,
        limit: 10,
      };
      this.getList();
    },
    onSubmit(){
      this.filterQuery.page = 1;
      this.getList()
    },
    getList() {
      this.loading = true;
      getTraceRecordList(this.filterQuery).then((res) => {
        this.loading = false;
        if (res.code === 20000) {
          this.list = res.data.list || [];
          this.total = res.data.total || 0;
          console.log(this.list)
        } else {
          this.$message.error(res.message);
          this.list = [];
          this.total = 0;
        }
      }).catch((error) => {
        this.loading = false;
        this.$message.error(error.message);
        this.list = [];
        this.total = 0;
      })
    },
  },
  created() {
    this.getList()
  }
}
</script>

<style scoped>
.el-col {
  border-radius: 4px;
  flex-wrap: wrap;
}
.query-form-item {
  display: block !important;
  margin-right: 10px;
  margin-bottom: 5px;
}

</style>
