<template>
  <div>
    <div class="search-wrapper">
      <el-form
        :inline="true"
        :model="searchForm"
        class="search_form"
        style="text-align: left"
      >
        <el-form-item label="入驻名称">
          <el-input
            v-model="searchForm.name"
            placeholder="请输入入驻名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="入驻名称">
          <el-input
            v-model="searchForm.categoryId"
            placeholder="请输入入驻名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
        <br />
        <el-form-item label="状态" style="margin-top: 10px">
          <el-radio-group v-model="searchForm.state" @change="onSubmit">
            <el-radio label="">全部</el-radio>

            <el-radio :label="0">未审核</el-radio>
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="4">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </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-popconfirm
              title="确定通过此申请吗？"
              style="margin-left: 10px"
              @confirm="reviewHandle('pass', scope.row)"
              v-if="scope.row.state == 0 && scope.row.state != 1"
            >
              <el-button type="success" size="mini" round slot="reference"
                >通过
              </el-button>
            </el-popconfirm>

            <el-popconfirm
              title="确定拒绝此申请吗？"
              @confirm="reviewHandle('refuse', scope.row)"
              v-if="scope.row.state == 0 && scope.row.state != 4"
              style="margin-left: 10px"
            >
              <el-button type="danger" size="mini" round slot="reference"
                >拒绝
              </el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </table-template>
    </div>
  </div>
</template>

<script>
import tableTemplate from "@/components/Table";
import { applyList, applyReview } from "@/api/livingCircle";
export default {
  name: "enter",
  components: { tableTemplate },
  data() {
    return {
      searchForm: {
        name: "",
        state: "",
      },
      // 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({
        name: this.searchForm.name,
        state: this.searchForm.state,
        type: 0,
        pageNum: this.pagination.currentPage,
        pageSize: this.pagination.pageSize,
      }).then((res) => {
        this.tableData = res.data.list ? res.data.list : [];
        this.pagination.total = res.data.total;
      });
    },

    reviewHandle(type, row) {
      let params = {};
      if (type === "pass") {
        params = {
          id: row.id,
          state: 1,
          user: this.userName,
        };
      } else {
        params = {
          id: row.id,
          state: 4,
          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();
    },
    onSubmit() {
      this.init();
    },
  },
};
</script>

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