<template>
  <div>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane
        :label="`我的待办 ( ${taskData.myTask} )`"
        name="1"
      ></el-tab-pane>
      <el-tab-pane
        :label="`我的已办 ( ${taskData.finishedTask} )`"
        name="2"
      ></el-tab-pane>
      <el-tab-pane
        :label="`所有任务 ( ${taskData.allTask} )`"
        name="3"
      ></el-tab-pane>
    </el-tabs>

    <div class="table-wrapper">
      <table-template
        :tableData="tableData"
        :tableColumns="tableColumns"
        :loading="loading"
        :pagination="pagination"
        @Jump="jumpPage"
      >
        <el-table-column slot="icon" label="照片" align="center">
          <template slot-scope="scope">
            <el-image
              style="width: 30px; height: 30px"
              :src="scope.row.icon"
              :preview-src-list="[scope.row.icon]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column slot="url" label="营业执照" align="center">
          <template slot-scope="scope">
            <el-image
              style="width: 30px; height: 30px"
              :src="scope.row.url"
              :preview-src-list="[scope.row.url]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column slot="url1" label="身份证照片" align="center">
          <template slot-scope="scope">
            <el-image
              style="width: 30px; height: 30px"
              :src="scope.row.icon"
              :preview-src-list="[scope.row.url1]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="350" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" round @click="view(scope.row)"
              >查看</el-button
            >
            <el-button
              type="success"
              size="mini"
              round
              @click="pass(scope.row)"
              class="btn"
              >通过
            </el-button>

            <el-popconfirm
              title="确定拒绝此申请吗？"
              @confirm="deny(scope.row)"
            >
              <el-button type="danger" size="mini" round slot="reference"
                >拒绝
              </el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </table-template>
    </div>
  </div>
</template>

<script>
import { applyList, applyReview } from "@/api/livingCircle";

import tableTemplate from "@/components/Table";
export default {
  name: "enter",
  components: { tableTemplate },
  data() {
    return {
      taskData: {
        myTask: 1,
        finishedTask: 2,
        allTask: 3,
      },
      activeName: "1",
      loading: false,
      tableData: [
        {
          name: "服务名称",
          type: "所属类型",
          icon: require("@/assets/1.png"),
          wx: "1",
        },
      ],
      tableColumns: [
        {
          key: "name",
          label: "商家名称",
        },
        {
          key: "category",
          label: "经营类型",
        },

        {
          key: "address",
          label: "详细地址",
        },
        {
          key: "icon",
          label: "照片",
          type: "slot",
        },
        {
          key: "phone",
          label: "联系电话",
        },
        {
          key: "url",
          label: "营业执照",
          type: "slot",
        },
        {
          key: "url1",
          label: "身份证",
          type: "slot",
        },
      ],
      pagination: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      rules: {
        name: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
      },
      userName: "",
    };
  },
  mounted() {
    this.userName = localStorage.getItem("userName");

    this.init();
  },
  methods: {
    init() {
      applyList({
        // state:'',
        type: 1,
        pageNum: this.pagination.currentPage,
        pageSize: this.pagination.pageSize,
      }).then((res) => {
        this.tableData = res.data.list;
        this.pagination.total = res.data.total;
      });
    },

    reviewHandle(type, row) {
      let params = {};
      if (type === "pass") {
        params = {
          id: row.id,
          state: 0,
          user: this.userName,
        };
      } else {
        params = {
          id: row.id,
          state: 1,
          user: this.userName,
        };
      }
      applyReview(params).then((res) => {
        if (res.code == 200) {
          this.$message.success("审核成功");
          this.init();
        }
      });
    },
    view() {},
    handleClick() {
      this.loading = true;
      this.init();
      this.loading = false;
      console.log("this.init();--->", this.activeName);
    },
    jumpPage() {
      this.init();
    },
  },
};
</script>

<style lang="stylus" scoped>
@import '~@/stylus/common';
.btn{
    margin-right 10px
}
</style>
