
<template>
  <div class="goodsAudit app-container">
    <div class="search">
      <div>
        <el-input
          v-model="query.goodsName"
          size="small"
          placeholder="请输入商品名称"
          class="item-width-200"
        ></el-input>
        <el-select
          v-model="query.state"
          size="small"
          class="item-width-200 ml10"
          placeholder="请选择状态"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
     
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column
        align="center"
        label="商品名称"
        prop="goodsName"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="goodsType"
        align="center"
        label="类型"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
        {{scope.row.goodsType |filterType}}
       </template>
      </el-table-column>
      <el-table-column
        prop="discountContent"
        align="center"
        label="优惠内容"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="shopName"
        align="center"
        label="店铺名称"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="applyState"
        align="center"
        label="审核内容"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
        {{scope.row.applyState|filterState}}
       </template>
      </el-table-column>
      <el-table-column
        prop="applyTime"
        align="center"
        label="提交时间" 
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column prop="address" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" v-if="scope.row.applyState == 2" size="small" @click="handleDetail(scope.row)">查看</el-button>

          <el-button type="text" v-else size="small" @click="handleAudit(scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="query.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
  <script>
import { debounce } from "@/utils/index";
import {checkList} from '@/api/goods';
export default {
  name: "goodsAudit",
  data() {
    return {
      options: [
        {
          value: 1,
          label: "待审核",
        },
        // {
        //   value: 2,
        //   label: "审核通过",
        // },
        {
          value: 3,
          label: "已审核",
        },
        
      ],
      tableData: [],
      loading: false,
      query: {
        state: 1,
        goodsName: "",
        currentPage: 1,
        pageSize: 10,
      },
      title: "",
      total: 0,
    };
  },
  watch: {
    query: {
      handler: debounce(function (val) {
        this.checkList()
      }),
      deep: true,
    },
  },
   filters: {
    filterState: function(value) {
      // 1-待审核, 2-成功, 3-被驳回
        if (value == 1) {
          return '待审核'
        }
        else if (value == 2) {
          return '审核通过'
        }
        else if (value == 3) {
          return '被驳回'
        }
    },
    filterType:function(val){
      if(val== 1){
        return '优惠券'
      }else if(val == 6){
        return '研学'
      }else if(val == 5){
        return '商品'
      }
    }
  },
  methods: {
    handleDetail(row){
      this.$router.push({
        path:'/operationManage/goodsAudit/auditGoods',
        query:{
          id:row.goodsId,
          title:'审核详情',
          mode:'detail',
          shopId:row.shopId
        }
      })
    },
    // 点击审核
    handleAudit(row) {
      this.$router.push({
        path:'/operationManage/goodsAudit/auditGoods',
        query:{
          id:row.goodsId,
          mode:'edit',
          shopId:row.shopId
        }
      })

    },
    handleSizeChange(val) {
      this.query.currentPage = 1;
      this.query.pageSize = val;
    this.checkList()

    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
    this.checkList()

    },

    search() {
      this.query.currentPage = 1;
    this.checkList()

    },
    checkList(){
      this.loading = true
      checkList(this.query).then(res=>{
        this.loading = false
        if(res.state == 'Success'){
          this.tableData = res.content.records
          this.total = res.content.total
        }
      })
    }
  },
  created() {
    this.checkList()
  },
};
</script>
  
<style lang="scss" scoped>
.goodsAudit {
  .search{
    justify-content: space-between;
  }
}
</style>
  