<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="商品名称" prop="productName">
        <el-input

          v-model="queryParams.productName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属分类" prop="tuiCateId">
        <el-select   v-model="queryParams.tuiCateId" placeholder="请选择分类" clearable size="small" >
         <el-option
                v-for="item in productTuiCateOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table  height="500" border v-loading="loading" :data="storeProductList" >
      <el-table-column label="ID" align="center" prop="productId" />
      <el-table-column label="商品编码" show-overflow-tooltip align="center" prop="barCode" />
      <el-table-column label="商品图片" align="center" width="120">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="hover"
          >
            <img slot="reference" :src="scope.row.image" width="100">
            <img :src="scope.row.image" style="max-width: 150px;">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="商品名称" show-overflow-tooltip align="center" prop="productName" />
      <el-table-column label="SKU" show-overflow-tooltip align="center" prop="sku" />
      <el-table-column label="分类" align="center" prop="tuiCateId" >
          <template slot-scope="scope">
              <el-tag prop="tuiCateId" v-for="(item, index) in productTuiCateOptions"    v-if="scope.row.tuiCateId==item.dictValue">{{item.dictLabel}}</el-tag>
          </template>
      </el-table-column>
      <el-table-column label="售价" align="center" prop="price" >
          <template slot-scope="scope" >
              <span v-if="scope.row.price!=null">{{scope.row.price.toFixed(2)}}</span>
          </template>
      </el-table-column>
      <el-table-column label="原价" align="center" prop="otPrice" >
          <template slot-scope="scope" >
              <span v-if="scope.row.otPrice!=null">{{scope.row.otPrice.toFixed(2)}}</span>
          </template>
      </el-table-column>
      <el-table-column label="一级分佣" align="center" prop="brokerage" >
          <template slot-scope="scope" >
              <span v-if="scope.row.brokerage!=null">{{scope.row.brokerage.toFixed(2)}}</span>
          </template>
      </el-table-column>
      <el-table-column label="二级分佣" align="center" prop="brokerageTwo" >
          <template slot-scope="scope" >
              <span v-if="scope.row.brokerageTwo!=null">{{scope.row.brokerageTwo.toFixed(2)}}</span>
          </template>
      </el-table-column>
      <el-table-column label="三级分佣" align="center" prop="brokerageThree" >
          <template slot-scope="scope" >
              <span v-if="scope.row.brokerageTwo!=null">{{scope.row.brokerageThree.toFixed(2)}}</span>
          </template>
      </el-table-column>
      <el-table-column label="库存" show-overflow-tooltip align="center" prop="stock" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {getStoreTuiProductAttrValueList} from "@/api/hisStore/storeProduct";


export default {
  name: "HisTuiList",
  data() {
    return {
      productTuiCateOptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品表格数据
      storeProductList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productName: null,
        tuiCateId: null,
      },
    };
  },
  created() {
    this.getDicts("store_product_tui_cate").then((response) => {
      this.productTuiCateOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询商品列表 */
    getList() {
      this.loading = true;
      getStoreTuiProductAttrValueList(this.queryParams).then(response => {
        this.storeProductList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
