<template>
  <d2-container>
    <div class="providerOrderList-container">
      <div class="filter-box">
        <div class="filter-item">
          <div class="spana">产品名称：</div>
          <el-input v-model="conditionCollection.name"
                    placeholder="请输入"></el-input>
        </div>
        <div class="filter-item">
          <div class="spana">产品类型：</div>
          <el-select v-model="conditionCollection.type"
                     placeholder="全部">
            <el-option v-for="item in typeList"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="filter-item">
          <div class="spana">产品型号：</div>
          <el-input v-model="conditionCollection.model"
                    placeholder="请输入"></el-input>
        </div>

        <div class="filter-btn">
          <el-button type="primary"
                     size=""
                     @click="queryData()">查询</el-button>
          <el-button type=""
                     size=""
                     @click="reset()">重置</el-button>
          <el-button type="success"
                     icon="el-icon-circle-plus-outline"
                     @click="addBusiness()">新建产品</el-button>
        </div>
      </div>
      <div>
        <el-table :data="dataList"
                  size="medium"
                  style="width: 100%; text-align: center;"
                  :key="tablekey"
                  v-loading="loadings">
          <!-- <el-table-column prop="userCode" label="序号"> </el-table-column> -->
          <el-table-column prop="id"
                           label="产品ID"> </el-table-column>
          <el-table-column prop="name"
                           label="产品名称"></el-table-column>
          <el-table-column prop="typeValue"
                           label="产品类型"> </el-table-column>
          <el-table-column prop="model"
                           label="产品型号"> </el-table-column>
          <el-table-column prop="searchPrefix"
                           label="搜索前缀"></el-table-column>
          <el-table-column prop="updateTime"
                           label="创建时间"> </el-table-column>
          <el-table-column prop="remark"
                           label="备注"> </el-table-column>
          <el-table-column fixed="right"
                           label="操作"
                           width="120">
            <template slot-scope="scope">
              <!-- 编辑 -->
              <!-- <el-button type="text"
                         style="font-size: 14px; margin-left: 0px"
                         @click="detils(scope.row.openId)">查看详情</el-button> -->

              <el-button type="text"
                         style="font-size: 14px; margin-left: 10px"
                         @click="enable(scope.row.openId)">编辑</el-button>

            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination">
        <pagination v-show="total >= 0"
                    :total="total"
                    :page.sync="searchCriteria.pageNow"
                    :limit.sync="searchCriteria.pageSize"
                    @pagination="pagingEvent" />
      </div>
    </div>
  </d2-container>
</template>

<script>
import {
  getProduct,
  getProductType,
} from "@/libs/common/constant";
import { selectListALL } from "@/utils/json";
export default {
  data() {
    return {
      conditionCollection: {
        name: "",
        type: "",
        model: "",
      },
      dataList: [],
      searchCriteria: {
        pageNow: 1,
        pageSize: 10,
      },
      total: 0,
      tablekey: "",
      loadings: true,
      isLoadProvinceId: true,
      // 产品 类型
      typeList: [],

      determineQueryData: {},
    };
  },
  async created() {
    // 获取 字典 数据
    await this.getConstant();
    // 获取 初始 数据
    await this.queryData();
  },
  methods: {
    // 查询
    async queryData() {
      this.determineQueryData = this.conditionCollection;
      var data = this.conditionCollection;
      data.currentPage = this.searchCriteria.pageNow;
      data.pageSize = this.searchCriteria.pageSize;
      await this.getListData(data);
    },
    //  重置
    reset() {
      var obj = this.conditionCollection;
      for (const key in obj) {
        obj[key] = "";
      }
    },
    // 获取 列表 参数
    async getListData(data) {
      this.loadings = true;
      const dataList = await this.getProduct(data);
      console.log(dataList);
      this.total = dataList.total;
      this.dataList = dataList.list;
      this.loadings = false;
    },

    async getProduct(data) {
      const res = await this.$api.GET(`${getProduct.url}`, data);
      return res;
    },
    async pagingEvent() {
      // await this.queryData();
      var data = this.determineQueryData;
      data.currentPage = this.searchCriteria.pageNow;
      data.pageSize = this.searchCriteria.pageSize;
      await this.getListData(data);
    },

    // 添加 产品
    addBusiness() {
      this.$router.push({
        path: "/addProduct",
      });
    },

    // 查看详情
    detils(openId) {
      this.$router.push({
        path: `/detailsBusiness/${openId}`,
      });
    },
    selectListALL(myJson) {
      return selectListALL(myJson);
    },
    // 获取 常量
    async getConstant() {
      await this.getProductType();
    },

    // 获取 产品类型
    async getProductType() {
      const res = await this.$api.GET(`${getProductType.url}`);
      this.typeList = this.selectListALL(res);
    },
    // 编辑产品
    async enable(openId) {
      this.$router.push({
        path: `/editProduct/${openId}`,
      });
    },

  },
};
</script>

<style lang="scss" scoped>
</style>
