
<template>
  <div class="subscribeManage app-container">
    <div class="search">
      <el-date-picker
        v-model="date"
        size="small"
        class="item-width-350"
        value-format="yyyy-MM-dd"
        type="datetimerange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      >
      </el-date-picker>
      <el-button
        class="ml10"
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="handleSearch"
      >
        搜索
      </el-button>

    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column
        align="center"
        label="用户ID"
        prop="userId"
        show-overflow-tooltip
        width="230px"
      >
      </el-table-column>
      <el-table-column
        prop="name"
        align="center"
        label="联系人"
        show-overflow-tooltip
        width="100px"

      >
      </el-table-column>
      <el-table-column
        prop="phone"
        align="center"
        label="联系电话"
        show-overflow-tooltip
      >
      </el-table-column>
        <el-table-column
        prop="reservationTime"
        align="center"
        label="预约时间"
        show-overflow-tooltip
      >
      </el-table-column>
        <el-table-column
        prop="goodsName"
        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="createTime"
        align="center"
        label="提交时间"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column prop="address" align="center" label="状态">
        <template slot-scope="scope">
            <el-tag :type="scope.row.status == 1 ?'':'success'"  @click="handleState(scope.row.id, scope.row.status == 1 ? 2 : 1)">{{ scope.row.status == 1 ? "未联系" : "已联系" }}</el-tag>
        </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 { reservationLog, reservationOperate} from "@/api/study";
export default {
  name: "subscribeManage",
  data() {
    return {
      date: "", //时间
      tableData: [],
      loading: false,
      query: {
        currentPage: 1,
        pageSize: 10,
        startDate: "",
        endDate: "",
      },
      total: 0,
      
    };
  },
  watch: {
    // query: {
    //   handler: debounce(function (val) {
    //     this.reservationLog();
    //   }),
    //   deep: true,
    // },
    date(val) {
      if (val) {
        this.query.startDate = val[0];
        this.query.endDate = val[1];
      } else {
        this.query.startDate = "";
        this.query.endDate = "";
      }
    },
  },

  methods: {
    handleSearch(){
      this.query.currentPage = 1
      this.reservationLog();

    },
    handleState(id) {
    
      this.$confirm(`此操作将修改该数据状态, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        reservationOperate({ id }).then((res) => {
          if (res.state == "Success") {
            this.$notify({
              title: "成功",
              message: "操作成功",
              type: "success",
            });
            this.reservationLog();
          }
        });
      });
    },
    
    handleSizeChange(val) {
      this.query.currentPage = 1;
      this.query.pageSize = val;
      this.reservationLog();
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
      this.reservationLog();
    },

    search() {
      this.query.currentPage = 1;
      this.reservationLog();
    },
    reservationLog() {
      this.loading = true;
      reservationLog(this.query).then((res) => {
        this.loading = false;
        if (res.state == "Success") {
          this.tableData = res.content.records;
          this.total = res.content.total;
        }
      });
    },
    
  },
  created() {
    this.reservationLog();
  },
};
</script>
  
<style lang="scss" scoped>
.subscribeManage {
  .search {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
  