<!--
 * @Author: wenjie 1454560336@qq.com
 * @Date: 2024-07-11 13:51:26
 * @LastEditors: wenjie 1454560336@qq.com
 * @LastEditTime: 2024-07-24 18:15:43
 * @FilePath: \admin-manage\src\views\operationManage\equitiesManage\index.vue
 * @Description: 
 * 
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
-->

<template>
  <div class="equitiesManage app-container">
    <el-tabs v-model="query.equityType">
    <el-tab-pane label="基础权益" name="1"></el-tab-pane>
    <el-tab-pane label="专属权益" name="2"></el-tab-pane>
  </el-tabs>
    <div class="search">
      <el-button class="add-btn" type="primary" size="small" @click="handleAdd"
        >添加</el-button
      >
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column
        prop="equityName"
        align="center"
        label="权益名称"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="setMealDetail"
        align="center"
        label="权益图标"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
          <img class="icon" :src="scope.row.equityImg" alt="">
        </template>
      </el-table-column>
      <el-table-column
        prop="equityDetail"
        align="center"
        label="权益描述"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="创建时间"
        show-overflow-tooltip
      >
      </el-table-column>
       <el-table-column
        prop="createTime"
        align="center"
        label="是否显示在用户端"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
          <span :class="[scope.row.showType == 1?'green':'red']">{{ scope.row.showType == 1 ? "展示" : "不展示"}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="状态"
        v-if="query.equityType == 2"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span :class="[scope.row.status == 1?'green':'red']">{{ scope.row.status == 1 ? "启用" : "禁用"}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            v-if="query.equityType == 2"
            @click="handle(scope.row)"
            >{{ scope.row.status == 1 ? "禁用" : "启用" }}</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="handleShow(scope.row)"
            >{{ scope.row.showType == 1 ? "不展示" : "展示" }}</el-button
          >

          <el-button type="text" size="small" @click="handleEdit(scope.row.id)"
            >修改</el-button
          >
          <el-button type="text" size="small" @click="handleDel(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="query.currentPage"
        :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 { equityList,enableEquity,delEquity,showEquity } from "@/api/equity";
export default {
  name: "equitiesManage",
  data() {
    return {
      options: [
        {
          value: "0",
          label: "全部状态",
        },
        {
          value: "1",
          label: "已完成",
        },
        {
          value: "2",
          label: "进行中",
        },
        {
          value: "3",
          label: "失败",
        },
      ],
      tableData: [],
      loading: false,
      query: {
        setMealCode:'',
        equityName:'',
        equityType:'1',
        status:'',
        currentPage: 1,
        pageSize: 10,
      },
      title: "",
      total: 0,
    };
  },
  watch: {
    'query.equityType'(newValue) {
      this.query.currentPage =1
      this.getList()
    }
  },
  methods: {

    handle(row){
       this.$confirm(`此操作将${row.status == 1?'禁用':'启用'}该条数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          enableEquity({equityId:row.id,status:row.status == 1?2:1}).then(res=>{
            if (res.state == "Success") {
              this.$notify({
                title: '提示',
                message: '操作成功',
                type: 'success'
              });
              this.getList()
            }
          })
         
        })
      
    },
    handleShow(row){
       this.$confirm(`此操作将${row.showType == 1?'不展示':'展示'}该条数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          showEquity({equityId:row.id,showType:row.showType == 1?2:1}).then(res=>{
            if (res.state == "Success") {
              this.$notify({
                title: '提示',
                message: '操作成功',
                type: 'success'
              });
              this.getList()
            }
          })
         
        })
      
    },
    handleEdit(id){
      this.$router.push({
        path:"/operationManage/equitiesManage/addEquities",
        query:{
          id,
          equityType:this.query.equityType,
          setMealCode:this.$route.query.id
        }
      });
    },
    handleAdd() {
      this.$router.push({
        path:"/operationManage/equitiesManage/addEquities",
        query:{
          equityType:this.query.equityType,
          setMealCode:this.$route.query.id

        }
      });
    },
    handleDel(equityId) {
      
      this.$confirm(`此操作将永久删除该条数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delEquity({equityId}).then(res=>{
            if (res.state == "Success") {
              this.$notify({
                title: '提示',
                message: '操作成功',
                type: 'success'
              });
              this.getList()
            }
          })
         
        })
    },
    handleSizeChange(val) {
      this.query.currentPage = 1;
      this.query.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
      this.getList();
    },

    search() {
      this.query.currentPage = 1;
      this.getList();
    },
    getList() {
      this.loading = true
      equityList(this.query).then((res) => {
        this.loading = false
        if (res.state == "Success") {
          this.tableData = res.content.records;
          this.total = res.content.total
        }
      });
    },
  },
  created() {
    this.query.setMealCode = this.$route.query.id
    this.getList();
  },
};
</script>
  
<style lang="scss" >
.equitiesManage {
    .icon{
        width: 70px;
        height: 70px;
    }
}
</style>
  