<template>
  <el-card
    shadow="never"
    class="aui-card--fill"
  >
    <div class="mod-user__user}">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.company"
            placeholder="请输入单位名称"
            clearable
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-input
            v-model="dataForm.name"
            placeholder="请输入姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-cascader
            v-model="dataForm.area"
            placeholder="请选择所属市区级"
            :options="optionsOfLocation"
            @change="changearea"
            :props="props"
            clearable
          ></el-cascader>
        </el-form-item>
        <el-form-item>
          <el-select
            @change="changename"
            v-model="dataForm.committee"
            placeholder="请选择所属委员会"
            clearable
          >
            <el-option
              v-for="item in optionsOfCommittee"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>

        <el-form-item>
          <el-button
            v-if="$hasPermission('user:user:delete')"
            type="danger"
            @click="deleteHandle()"
          >{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('user:user:export')"
            type="info"
            @click="exportHandle()"
          >{{ $t('export') }}</el-button>
        </el-form-item>
        <!--    <el-form-item>
          <el-button
            type="info"
            @click="taozhuan()"
          >跳转页面测试按钮</el-button>
          <el-button
            type="info"
            @click="taozhuanDe()"
          >跳转详情测试按钮</el-button>
        </el-form-item> -->
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="company"
          label="单位"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="name"
          label="联系人"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="mobile"
          label="手机号"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="committeeName"
          label="委员会"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="areaName"
          label="所属市区"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="updateDate"
          label="创建时间"
          header-align="center"
          align="center"
        ></el-table-column>
        <!--    <el-table-column prop="id" label="用户ID" header-align="center" align="center"></el-table-column>
       
        <el-table-column prop="sex" label="性别；1,男;2,女" header-align="center" align="center"></el-table-column>
      
        <el-table-column prop="email" label="邮箱" header-align="center" align="center"></el-table-column>
    
        <el-table-column prop="position" label="所属职位" header-align="center" align="center"></el-table-column>
        <el-table-column prop="member" label="是否会员;1,是;2,否" header-align="center" align="center"></el-table-column>
      
        <el-table-column prop="ifCheck" label="是否审核;0,待审核1,已审核;2,审核未通过" header-align="center" align="center"></el-table-column>
        <el-table-column prop="openid" label="微信用户openId" header-align="center" align="center"></el-table-column>
        <el-table-column prop="creator" label="创建者" header-align="center" align="center"></el-table-column>
       
        <el-table-column prop="updateDate" label="更新时间" header-align="center" align="center"></el-table-column> -->
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPermission('user:user:update')"
              type="text"
              size="small"
              @click="taozhuan(scope.row.id)"
            >修改</el-button>
            <el-button
              type="text"
              size="small"
              @click="taozhuanDe(scope.row.id)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./user-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/user/user/page?check=1",
        getDataListIsPage: true,
        exportURL: "/user/user/export",
        deleteURL: "/user/user",
        deleteIsBatch: true,
      },
      props: {
        checkStrictly: true,
        value: "id",
        label: "name",
        children: "children",
      },
      dataForm: {
        company: "",
        name: "",
        area: "",
        committee: "",
      },
      optionsOfLocation: [
        /* {
          value: "ningbo",
          label: "宁波",
          children: [
            {
              value: "haishu",
              label: "海曙区",
            },
            {
              value: "yingzhou",
              label: "鄞州区",
            },
            {
              value: "beilun",
              label: "北仑区",
            },
            {
              value: "zhenhai",
              label: "镇海区",
            },
          ],
        }, */
      ],
      optionsOfCommittee: [
        /* {
          value: "网络安全协会",
          label: "网络安全协会",
        },
        {
          value: "网络安全协会1",
          label: "网络安全协会1",
        },
        {
          value: "网络安全协会2",
          label: "网络安全协会2",
        },
        {
          value: "网络安全协会3",
          label: "网络安全协会3",
        },
        {
          value: "网络安全协会4",
          label: "网络安全协会4",
        }, */
      ],
    };
  },
  created() {
    this.getInfo();
  },
  methods: {
    getInfo() {
      this.$http
        .get("/committee/committee/list")
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }

          this.optionsOfCommittee = res.data;
        })
        .catch(() => {});

      this.$http
        .get("/area/area/list")
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.optionsOfLocation = this.getTreeData(res.data);
        })
        .catch(() => {});
    },
    getTreeData(data) {
      // 循环遍历json数据
      for (var i = 0; i < data.length; i++) {
        if (data[i].children.length < 1) {
          // children若为空数组，则将children设为undefined
          data[i].children = undefined;
        } else {
          // children若不为空数组，则继续 递归调用 本方法
          this.getTreeData(data[i].children);
        }
      }
      return data;
    },
    changename(value) {
      /*  this.optionsOfCommittee.forEach((ele) => {
        if (value == ele.id) {
          this.dataForm.committeeName = ele.name;
        }
      }); */
      this.dataForm.committee = value;
    },
    changearea(value) {
      console.log(value);
      this.dataForm.area = value[value.length - 1];
    },
    taozhuan(id) {
      this.$router.push({
        path: "/memberManageExamine",
        query: { type: "xiugai", id: id },
      });
    },

    taozhuanDe(id) {
      this.$router.push({
        path: "/memberManageDetail",
        query: { type: "xiangqing", id: id },
      });
    },
  },
  components: {
    AddOrUpdate,
  },
};
</script>
