<template>
  <div class="JNPF-common-layout">
    <div class="JNPF-common-layout-center JNPF-flex-main">
      <el-row class="JNPF-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="6">
            <el-form-item label="团队名称">
              <el-input
                v-model="listQuery.name"
                placeholder="团队名称"
                clearable
                @keyup.enter.native="getList()"
                @clear="getList()"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="组长">
              <el-input
                v-model="listQuery.leaderLabel"
                placeholder="组长名称"
                clearable
                @keyup.enter.native="getList()"
                @clear="getList()"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                @click="getList()"
              >
                {{ $t("common.search") }}</el-button
              >
              <el-button icon="el-icon-refresh-right" @click="reset()"
                >{{ $t("common.reset") }}
              </el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="JNPF-common-layout-main JNPF-flex-main">
        <div class="JNPF-common-head">
          <el-button type="primary" icon="el-icon-plus" @click="addTeam()"
            >新建</el-button
          >
          <div class="JNPF-common-head-right">
            <el-tooltip
              effect="dark"
              :content="$t('common.refresh')"
              placement="top"
            >
              <el-link
                icon="icon-ym icon-ym-Refresh JNPF-common-head-icon"
                :underline="false"
                @click="initData()"
              />
            </el-tooltip>
          </div>
        </div>
        <JNPF-table v-loading="listLoading" :data="tableData">
          <el-table-column prop="name" label="团队名称" />
          <el-table-column prop="leaderLabel" label="组长" />
          <el-table-column label="操作" width="150" fixed="right">
            <template slot-scope="scope">
              <tableOpts
                @edit="editTeam(scope.row, scope.row.id)"
                @del="deleteTeam(scope.row.id)"
              >
              </tableOpts>
            </template>
          </el-table-column>
        </JNPF-table>
        <pagination
          :total="total"
          :page.sync="listQuery.current"
          :limit.sync="listQuery.size"
          @pagination="getList"
        />
      </div>
    </div>
    <Form v-if="formVisible" ref="Form" @refreshDataList="getList" />
  </div>
</template>

<script>
import {
  getTeamAll,
  delSysTeam
} from "@/api/governmentCloud/serviceTeamManage/serviceTeamManage";

import Form from "./Form";

export default {
  name: "serviceTeam-manage",
  components: {
    Form
  },
  data() {
    return {
      tableData: [],
      listLoading: false,
      // organizeIdTree: [],
      listQuery: {
        leaderLabel: "",
        name: "",
        current: 1,
        size: 20
      },
      total: 0,
      formVisible: false
    };
  },
  watch: {},
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.listLoading = true;
      getTeamAll(this.listQuery)
        .then(res => {
          this.tableData = res.data.records;
          this.total = res.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    addTeam() {
      this.formVisible = true;
      this.$nextTick(() => {
        this.$refs.Form.init("1");
      });
    },
    editTeam(row, id) {
      this.formVisible = true;
      console.log(row);
      console.log(id);
      this.$nextTick(() => {
        this.$refs.Form.init("2", row, id);
      });
    },
    deleteTeam(id) {
      delSysTeam(id).then(res => {
        this.$message({
          message: "删除成功",
          type: "success",
          duration: 1500
        });
        this.listLoading = true;
        this.getList();
      });
    },
    reset() {
      this.listQuery.name = "";
      this.listQuery.leaderLabel = "";
      this.getList();
    }
  }
};
</script>
