<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="请输入用户名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="需求类型">
          <el-select
            v-model="searchForm.categoryId"
            clearable
            placeholder="请选择需求类型"
            size="medium"
          >
            <el-option
              v-for="item in typeList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <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 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"
              class="btn"
              round
              @click="edit(scope.row)"
              >编辑</el-button
            >
            <el-popconfirm title="确定删除此数据吗？" @confirm="del(scope.row)">
              <el-button type="warning" size="mini" round slot="reference"
                >删除</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </table-template>
    </div>

    <el-dialog title="编辑" :visible.sync="dialogVisible" width="30%">
      <el-form
        :model="dataForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="服务名称" prop="name">
          <el-input v-model="dataForm.name"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import TableTemplate from "@/components/Table";
import { helpList, categoryList, helpReview } from "@/api/livingCircle";

export default {
  components: { TableTemplate },

  data() {
    return {
      searchForm: {
        categoryId: "",
        name: "",
      },
      typeList: [],
      loading: false,
      tableData: [
        {
          name: "服务名称",
          type: "所属类型",
          icon: require("@/assets/1.png"),
          wx: "1",
        },
      ],
      tableColumns: [
        {
          key: "userName",
          label: "用户名称",
        },
        {
          key: "categoryName",
          label: "需求类型",
        },
        {
          key: "content",
          label: "需求描述",
          width: 220,
        },
        {
          key: "address",
          label: "详细地址",
          width: 220,
        },
        {
          key: "icon",
          label: "照片",
          type: "slot",
        },
        {
          key: "phone",
          label: "联系电话",
        },
        // {
        //   key: "wx",
        //   label: "微信号",
        // },
      ],
      pagination: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      rules: {
        name: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
      },
      dataForm: {},
      dialogVisible: false,
    };
  },
  watch: {
    dialogVisible(val) {
      if (!val) {
        this.$refs.ruleForm.resetFields();
      }
    },
  },
  created() {
    this.getCategoryList();
    this.init();
  },
  methods: {
    getCategoryList() {
      categoryList().then((res) => {
        if (res.code == 200) {
          this.typeList = res.data;
        }
      });
    },
    init() {
      let params = {
        address: "",
        categoryId: this.searchForm.categoryId,
        // state: "0",
        userName: this.searchForm.name,
        pageNum: this.pagination.currentPage,
        pageSize: this.pagination.pageSize,
      };
      helpList(params).then((res) => {
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.pagination.total = res.data.total;
        }
      });
    },
    onSubmit() {
      this.init();
    },
    jumpPage() {
      this.init();
    },
    view() {
      this.dialogVisible = true;
    },
    edit() {
      this.dialogVisible = true;
    },
    del() {},
    reviewHandle(row, state) {
      let params = {
        id: row.id,
        state: state,
        user: localStorage.getItem("userName"),
      };
      helpReview(params).then((res) => {
        if (res.code == 200) {
          this.$message.success("审核成功");
        }
      });
    },
  },
};
</script>

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