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

<template>
  <div class="logList app-container">
   
    <div class="search">
        <div>

            <el-input
            v-model="query.userMobile"
            size="small"
            placeholder="用户手机号"
            class="item-width-200 "
            ></el-input>
                <el-date-picker
            v-model="date"
            size="small"
            value-format="yyyy-MM-dd"
            class="item-width-350 ml10"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
            </el-date-picker>
            <el-select
            v-model="query.status"
            size="small"
            clearable
            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>
            <el-button
        class="ml10"
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="handleSearch"
      >
        搜索
      </el-button>
        </div>
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column
        prop="userMobile"
        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.equityContent.icon" alt="">
        </template>
      </el-table-column>

      <el-table-column
        prop="createTime"
        align="center"
        label="权益名称"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
        {{scope.row.equityContent.equityName}}
        </template>
      </el-table-column>
       <el-table-column
        prop="mobile"
        align="center"
        label="权益到账手机号"
        show-overflow-tooltip
      >
      </el-table-column>
       <el-table-column
        prop="createTime"
        align="center"
        label="领取时间"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
        {{scope.row.createTime}}
        </template>
      </el-table-column>
       <el-table-column
        prop="createTime"
        align="center"
        label="状态"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
        {{scope.row.status == 1?'待充值':'已充值'}}
        </template>
      
      </el-table-column>

      <el-table-column align="center" label="操作">
        <template slot-scope="scope">

          <el-button type="text" size="small" v-if="scope.row.status == 1" @click="handleCommit(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 { getLogList,commitEquity } from "@/api/equity";
export default {
  name: "logList",
  data() {
    return {
        date:'',
      options: [
        {
          value: "1",
          label: "未使用",
        },
        {
          value: "2",
          label: "已使用",
        },
        {
          value: "3",
          label: "已失效",
        },
      ],
      tableData: [],
      loading: false,
      query: {
        userMobile:'',
        endDay:'',
        beginDay:'',
        status:'',
        currentPage: 1,
        pageSize: 10,
      },
      title: "",
      total: 0,
    };
  },
  watch: {
    date(val){
      if(val){
        this.query.beginDay = val[0]
        this.query.endDay = val[1]
      }else{
        this.query.beginDay = ''
        this.query.endDay = ''
      }
    }
  },
  methods: {
    handleSearch(){
        this.query.currentPage = 1
      this.getList();
    },

    handleCommit(couponLogId) {
      
      this.$confirm(`此操作将发放该条数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          commitEquity({couponLogId}).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
      let query = JSON.parse(JSON.stringify(this.query))
      if(!query.status){
        query.status = null
      }
      console.log(query);
      getLogList(query).then((res) => {
        this.loading = false
        if (res.state == "Success") {
          this.tableData = res.content.records;
          this.tableData.map(item =>{
            item.equityContent = JSON.parse(item.equityContent)
          })
          this.total = res.content.total
        }
      });
    },
  },
  created() {
    this.getList();
  },
};
</script>
  
<style lang="scss" >
.logList {
    .icon{
        width: 70px;
        height: 70px;
    }
}
</style>
  