
<template>
  <div class="comboManage app-container">
    <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="createTime"
        align="center"
        label="套餐图片"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <img :src="scope.row.imgUrl" alt="" class="icon">
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="套餐code"
        prop="setMealCode"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="setMealName"
        align="center"
        label="套餐名字"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="setMealDetail"
        align="center"
        label="套餐说明"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="count"
        align="center"
        label="累计套餐订购人数"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
          <span>{{ scope.row.count || 0 }}</span>
        </template>
      </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.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"
            @click="handle(scope.row)"
            >{{ scope.row.status == 1 ? "禁用" : "启用" }}</el-button
          >

          <el-button type="text" size="small" @click="handleEdit(scope.row.id)"
            >修改</el-button
          >
          <el-button type="text" size="small" @click="handleEditEquities(scope.row.setMealCode)"
            >权益配置</el-button
          >
          <el-button type="text" size="small" @click="handleDel(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.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 { getList,operate,delMeal } from "@/api/common";
export default {
  name: "comboManage",
  data() {
    return {
      options: [
        {
          value: "0",
          label: "全部状态",
        },
        {
          value: "1",
          label: "已完成",
        },
        {
          value: "2",
          label: "进行中",
        },
        {
          value: "3",
          label: "失败",
        },
      ],
      tableData: [],
      loading: false,
      query: {
        currentPage: 1,
        pageSize: 10,
      },
      title: "",
      total: 0,
    };
  },
  watch: {
    query: {
      handler: debounce(function (val) {
          this.getList()

      }),
      deep: true,
    },
  },
  methods: {
    handle(row){
       this.$confirm(`此操作将${row.status == 1?'禁用':'启用'}该条数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          operate({setMealId:row.id,status:row.status == 1?2:1}).then(res=>{
            if (res.state == "Success") {
              this.$notify({
                title: '提示',
                message: '操作成功',
                type: 'success'
              });
              this.query.currentPage = 1
              this.getList()
            }
          })
         
        })
      
    },
    handleEdit(id){
      this.$router.push({
        path:"/operationManage/comboManage/editCombo",
        query:{
          id
        }
      });
    },
    handleEditEquities(id){
      this.$router.push({
        path:"/operationManage/equitiesManage/index",
        query:{
          id
        }
      });
    },
    handleAdd() {
       this.$router.push({
        path:"/operationManage/comboManage/editCombo",
        query:{
          title:'添加套餐'
        }
      });
    },
    handleDel(row) {
      this.$confirm(`此操作将删除该条数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delMeal({setMealId:row.id}).then(res=>{
            if (res.state == "Success") {
              this.$notify({
                title: '提示',
                message: '操作成功',
                type: 'success'
              });
              this.query.currentPage = 1
              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
      getList(this.query).then((res) => {
        this.loading = false
        if (res.state == "Success") {
          this.tableData = res.content.records;
          this.total = res.content.total
        }
      });
    },
  },
  created() {
    this.getList();
  },
};
</script>
  
<style lang="scss" >
.comboManage {
  .icon{
    width: 80px;
  }
}
</style>
  