<template>
  <div class="container">
    <div class="tabs">
      <div class="headerText">
        <div class="searchP">查询条件</div>
      </div>
      <el-form ref="form1" :model="form1" label-width="100px">
        <div style="margin-top: 10px">
          <el-row>
            <el-col :span="7">
              <el-form-item label="产品名称">
                <el-input v-model="form1.cpmc"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="备案编号">
                <el-input v-model="form1.babm"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="生产企业">
                <el-input v-model="form1.scqy"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="7">
              <el-form-item label="注册证编号">
                <el-input v-model="form1.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="化妆品类型">
                <el-select
                  v-model="types"
                  placeholder="请选择化妆品类型"
                  @change="changeType"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
          </el-row>
        </div>
      </el-form>
      <div class="footBox">
        <el-button icon="el-icon-refresh-left" @click="reset">重置</el-button>
        <el-button type="primary" icon="el-icon-search" @click="searchList"
          >查询</el-button
        >
      </div>
    </div>
    <div class="tabsBottom">
      <div class="foot-main">
        <div class="headerText">
          <div class="searchP">产品列表</div>
        </div>
        <div class="exportBtn">
          <el-button type="primary" icon="el-icon-edit-outline">导出</el-button>
        </div>
        <section class="table-box">
          <div class="table-item">
            <el-table
              v-loading="loading"
              :data="tableData"
              border
              height="300"
              :stripe="false"
            >
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column
                type="index"
                label="序号"
                width="55"
                align="center"
              />
              <el-table-column label="产品名称" align="center">
                <template slot-scope="scope">
                  {{ scope.row.mc || scope.row.cpmc }}
                </template>
              </el-table-column>
              <el-table-column :label="A2" align="center">
                <template slot-scope="scope">
                  {{ scope.row.bah || scope.row.pzrq }}
                </template>
              </el-table-column>
              <el-table-column :label="A3" align="center">
                <template slot-scope="scope">
                  {{ scope.row.qy || scope.row.sf }}
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                class-name="small-padding fixed-width"
                width="140"
                align="center"
              >
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    plain
                    type="primary"
                    @click="toDetail(scope.row)"
                    >详情</el-button
                  >
                  <!-- <el-button size="mini" plain type="warning">编辑</el-button> -->
                </template>
              </el-table-column>
            </el-table>
          </div>
        </section>
        <pagination
          v-show="total > 0"
          :total="total"
          :page="form1.current"
          :limit="form1.size"
          @pagination="getPagination"
        ></pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      //===========
      loading: false,
      tableData: [],
      A1: "产品名称",
      A2: "备案编码",
      A3: "生产企业",
      types: 1,
      total: 0,
      options: [
        {
          value: 1,
          label: "国产化妆品",
        },
        {
          value: 2,
          label: "国产特殊化妆品",
        },
        {
          value: 3,
          label: "进口化妆品",
        },
        {
          value: 4,
          label: "进口特殊化妆品",
        },
      ],
      form1: {
        babm: "",
        cpmc: "",
        name: "",
        scqy: "",
        size: 10,
        current: 1,
      },
    };
  },
  mounted() {},
  created() {
    this.changeType(1);
  },
  methods: {
    //去内嵌页面
    toDetail(e) {
      let data = "";
      if (this.types == 1) {
        data = e.bah;
      } else if (this.types == 2) {
        data = e.zczh;
      } else if (this.types == 3) {
        data = e.bah;
      } else if (this.types == 4) {
        data = e.zczh;
      }
      //利用type区分三种档案
      //利用flag区分四种化妆品详情 然后分别调用不同的详情接口
      this.$router.push({
        path: `/cosmeticsDetail`,
        query: { type: 1, flag: this.types, data },
      });
    },
    //搜索
    searchList() {
      this.getData(this.types);
    },
    getPagination(e) {
      console.log(e);
      this.form1.current = e.page;
      this.form1.size = e.limit;
      this.chinaCosmetics();
    },
    //重置
    reset() {
      this.form1 = {
        babm: "",
        cpmc: "",
        name: "",
        scqy: "",
        size: 10,
        current: 1,
      };
    },
    //国产化妆品
    async chinaCosmetics() {
      this.loading = true;
      let msg1 = await this.$api.cosmetics.domesticList(this.form1);
      this.tableData = msg1.data.records;
      this.total = msg1.data.total;
      this.form1.size = msg1.data.size;
      this.form1.current = msg1.data.current;
      this.loading = false;
    },
    //国产特殊化妆品
    async chinaSpecialCosmetics() {
      this.loading = true;
      let msg1 = await this.$api.cosmetics.specialList(this.form1);
      this.tableData = msg1.data.records;
      this.total = msg1.data.total;
      this.form1.size = msg1.data.size;
      this.form1.current = msg1.data.current;
      this.loading = false;
    },
    //进口化妆品
    async importCosmetics() {
      this.loading = true;
      let msg1 = await this.$api.cosmetics.importList(this.form1);
      this.tableData = msg1.data.records;
      this.total = msg1.data.total;
      this.form1.size = msg1.data.size;
      this.form1.current = msg1.data.current;
      this.loading = false;
    },
    //进口特殊化妆品
    async importSpecialCosmetics() {
      this.loading = true;
      let msg1 = await this.$api.cosmetics.importSpecialList(this.form1);
      this.tableData = msg1.data.records;
      this.total = msg1.data.total;
      this.form1.size = msg1.data.size;
      this.form1.current = msg1.data.current;
      this.loading = false;
    },
    async getData(e) {
      if (e == 1) {
        this.A2 = "备案编码";
        this.A3 = "生产企业";
        this.chinaCosmetics();
      } else if (e == 2) {
        this.A2 = "批准日期";
        this.A3 = "省份";
        this.chinaSpecialCosmetics();
      } else if (e == 3) {
        this.A2 = "备案编码";
        this.A3 = "生产企业";
        this.importCosmetics();
      } else if (e == 4) {
        this.A2 = "批准日期";
        this.A3 = "省份";
        this.importSpecialCosmetics();
      }
    },
    async changeType(e) {
      this.reset();
      this.getData(e);
    },
  },
};
</script>


<style lang="scss" scoped>
::v-deep .el-select {
  width: 100% !important;
}
.container {
  height: 100%;
  // overflow: auto;
  background: #f2f2f2;

  .headerText {
    width: 100%;
    padding: 10px 20px;
    border-bottom: 1px solid #f2f3f5;
    color: #323233;
    font-size: 20px;
    font-weight: bold;
    .searchP {
      position: relative;
      cursor: pointer;
      &::before {
        content: "";
        width: 78px;
        height: 3px;
        background: #1349c5;
        position: absolute;
        bottom: -10px;
      }
    }
  }
  .tabs {
    width: 100%;
    height: 30%;
    background: #fff;
  }
}
//===================
::v-deep .el-button--medium {
  padding: 8px;
}
.footBox {
  width: 100%;
  text-align: center;
}
.tabsBottom {
  height: 70%;
  padding-top: 10px;
  .foot-main {
    height: 100%;
    // min-height: 600px;
    width: 100%;
    background: white;
  }
}
.exportBtn {
  padding: 10px 20px;
}
.table-box {
  padding: 0 20px;
  .table-item {
  }
}
.pagination {
  display: flex;
  justify-content: space-between;
  padding: 15px 20px;
}
</style>