
<template>
  <div class="memberManage app-container">
    <div class="search">
      <div>
        <el-input
          v-model="query.userIdOrPhone"
          size="small"
          placeholder="请输入用户ID或手机号"
          class="item-width-200"
        ></el-input>
        <el-select
          v-model="query.setMealId"
          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-select
          v-model="query.platformType"
          size="small"
          class="item-width-200 ml10"
          placeholder="请选择注册平台"
        >
          <el-option
            v-for="item in options1"
            :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
        align="center"
        label="用户ID"
        prop="userId"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="phone"
        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.platformType == 1?'慧研学惠生活':'印象贵大' }}
        </template>
      
      </el-table-column>
      <el-table-column
        prop="setMealId"
        align="center"
        label="套餐情况"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.setMealCode | filterMeal(that) }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="useMoney"
        label="消费金额（元）"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="createTime"
        label="注册时间"
        show-overflow-tooltip
      >
      </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 { userList } from "@/api/user";
import { getSetMealNameAndId } from "@/api/common";
export default {
  name: "memberManage",
  data() {
    return {
      that: this,
      tableData: [],
      options: [],
      options1: [
        {
          label:'慧研学惠生活',
          value:1
        },
        {
          label:'印象贵大',
          value:2
        },
        {
          label:'中数未来生活宝',
          value:3
        }
      ],
      loading: false,
      query: {
        platformType:1,
        setMealId: "",
        userIdOrPhone: "",
        currentPage: 1,
        pageSize: 10,
      },
      title: "",
      total: 0,
    };
  },
  // watch: {
  //   query: {
  //     handler: debounce(function (val) {
  //       this.getList();

  //       console.log(1);
  //     }),
  //     deep: true,
  //   },
  // },
  filters: {
    filterMeal: function (val, that) {
      let msg;
      that.options.map((item) => {
        if (val == item.value) {
          msg = item.label;
        }
      });
      return msg || "无套餐";
    },
  },
  methods: {
    handleSearch(){
      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();
    },
    getList() {
      this.loading = true;
      userList(this.query).then((res) => {
        this.loading = false;
        if (res.state == "Success") {
          this.tableData = res.content.records;
          this.total = res.content.total;
        }
      });
    },
    getMeal() {
      getSetMealNameAndId().then((res) => {
        if (res.state == "Success") {
          for (const key in res.content) {
            if (Object.hasOwnProperty.call(res.content, key)) {
              this.options.push({
                label: res.content[key],
                value: key,
              });
            }
          }
        }
      });
    },
  },
  created() {
    this.getList();
    this.getMeal();
  },
};
</script>
  
<style lang="scss" scoped>
.memberManage {
  .search {
    justify-content: space-between;
    .add-btn {
      // margin-right: 20px;
    }
  }
}
</style>
  