<template>
  <div>
    <el-card class="el-card">
      <div slot="header" style="font-weight: bold">
        <span>产品项目码选择</span>
      </div>
      <el-form
        :inline="true"
        :model="filterQuery"
        style="display: flex"
        size="mini"
      >
        <el-form-item class="query-form-item">
          <el-input
            v-model="filterQuery.IdentifierCode"
            placeholder="产品项目码"
          ></el-input>
        </el-form-item>
        <el-row>
          <el-col>
            <el-form-item class="query-form-item"  label="已使用UDI">
              <el-select
                v-model="filterQuery.IsUDI"
                placeholder="是否已使用UDI" style="width: 60px"
              >
                <el-option label="否" value="0"></el-option>
                <el-option label="是" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="query-form-item" label="已使用商品条码">
              <el-select
                v-model="filterQuery.isSPTM"
                placeholder="是否已使用商品条码"
                style="width: 60px"
              >
                <el-option label="否" value="0"></el-option>
                <el-option label="是" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="query-form-item" label="已使用注册证">
              <el-select
                v-model="filterQuery.IsReg"
                placeholder="已使用注册证"
                style="width: 60px"
              >
                <el-option label="否" value="0"></el-option>
                <el-option label="是" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item>
          <el-button-group>
            <el-button
              type="primary"
              icon="el-icon-refresh"
              @click="onReset"
            ></el-button>
            <el-button type="primary" icon="search" @click="getList"
              >查询</el-button
            >
          </el-button-group>
        </el-form-item>
      </el-form>

      <el-table
        v-loading="loading"
        @row-click="intentDetail"
        :data="list"
        border
        style="width: 100%"
      >
        <el-table-column prop="IdentifierCode" label="产品项目码 " width="150">
        </el-table-column>
        <el-table-column label="厂商识别码" width="150">
          <template slot-scope="scope">
            <span>{{ scope.row.IdentifierCode.substring(0, 6) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="SeqNumber" label="顺序号" width="150">
        </el-table-column>
        <el-table-column prop="IsUDI" label="是否使用UDI" width="120">
          <template slot-scope="scope">
            <span>{{ isTip[scope.row.IsUDI] }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="isSPTM" label="是否使用商品条码" width="120">
          <template slot-scope="scope">
            <span>{{ isTip[scope.row.isSPTM] }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="IsReg" label="是否使用注册证" width="120">
          <template slot-scope="scope">
            <span>{{ isTip[scope.row.IsReg] }}</span>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog
        :visible.sync="addDialogVisible"
        width="95%"
        v-if="addDialogVisible"
      >
        <modifySp :productDetail="productDetail"></modifySp>
      </el-dialog>

      <el-pagination
        :page-size="filterQuery.limit"
        @current-change="handleSubCurrentChange"
        layout="prev, pager, next"
        :total="total"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
import {
  listIdentifier,
  addIdentifier,
  modifyIdentifier,
  deleteIdentifier,
  generateIdentifier,
} from "../../api/basic/identifier";
import store from "../../store/index";

export default {
  props: {
    closeDialog: {
      type: Function,
      required: true,
    },
    facidentcode: {
      type: Object,
      required: true,
    },
  },

  data() {
    return {
      filterQuery: {
        IdentifierCode: "",
        facidentcode: "",
        IsUDI: "0",
        isSPTM: "0",
        IsReg: "0",
        page: 1,
        limit: 10,
        // customerId: store.getters.customerId,
      },

      formVisible: false,
      list: [],
      total: 0,

      isTip: {
        0: "否",
        1: "是",
      },

      productId: "",
      addDialogVisible: false,
    };
  },

  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        IdentifierCode: "",
        facidentcode: this.facidentcode,
        page: 1,
        limit: 10,
        // customerId: store.getters.customerId,
      };
      this.getList();
    },

    getList() {
      this.loading = true;
      listIdentifier(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;
        });
    },

    handleCurrentChange(val) {
      this.filterQuery.page = val;
      this.getList();
    },

    handleSubCurrentChange(val) {
      this.filterQuery.page = val;
      this.getSubList();
    },
    intentDetail(row) {
      this.$emit("identifyInfo", row);
      this.closeDialog();
    },
  },
  mounted() {},

  created() {
    console.log(this.facidentcode + "---");
    this.filterQuery.facidentcode = this.facidentcode;
    this.getList();
  },
};
</script>
<style>
.edit-text {
  width: 100%;
  font-size: 12px;
  margin-top: 10px;
  font-family: "Microsoft YaHei";
  color: #000000;
}
</style>