<template>
  <el-card
    shadow="never"
    class="aui-card--fill"
  >
    <div class="mod-fhjw__user}">
      <el-form
        :inline="true"
        :model="dataForm"
        :rules="dataRule"
        @keyup.enter.native="getDataList()"
      >
        <!-- <el-form-item>
          <el-input
            v-model="dataForm.username"
            placeholder="用户名"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item prop="mobile">
          <el-input
            v-model="dataForm.mobile"
            placeholder="手机号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getCheck()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('fhjw:user:save')"
            type="primary"
            @click="addOrUpdateHandle()"
          >{{ $t('add') }}</el-button>
        </el-form-item>
        <!-- <el-form-item>
          <el-upload
            class="upload-demo"
            ref="upload"
            action=""
            :http-request="afterRead"
            accept=".pdf,.doc,.docx,.xls,.xlsx"
            :file-list="datalist"
          >
            <el-button type="warning">导入</el-button>
          </el-upload>

        </el-form-item> -->

        <!-- <el-form-item>
          <el-button
            v-if="$hasPermission('fhjw:user:delete')"
            type="danger"
            @click="deleteHandle()"
          >{{ $t('deleteBatch') }}</el-button>
        </el-form-item> -->
        <!-- <el-form-item>
          <a href="">点击此处下载导入模板</a>
        </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="username"
          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="userIdno"
          label="身份证号"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="identity"
          label="身份"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="gender"
          :label="$t('user.gender')"
          sortable="custom"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <!-- {{ $getDictLabel("gender", scope.row.gender) }} -->
            <span>{{genderText(scope.row.gender)}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="userRole"
          label="所属权限"
          header-align="center"
          align="center"
        ></el-table-column>
        <!--  <el-table-column
          prop="caseId"
          label="案件ID"
          header-align="center"
          align="center"
        ></el-table-column> -->

        <el-table-column
          prop="createDate"
          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('fhjw:user:update')"
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row.id)"
            >{{ $t('update') }}</el-button>
            <el-button
              v-if="$hasPermission('fhjw:user:delete')"
              type="text"
              size="small"
              @click="deleteHandle(scope.row.id)"
            >{{ $t('delete') }}</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";
import { isEmail, isNumber } from "@/utils/validate";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/fhjw/user/page",
        getDataListIsPage: true,
        exportURL: "/fhjw/user/export",
        deleteURL: "/fhjw/user",
        deleteIsBatch: true,
      },
      datalist: [],
      flag: true,
      dataForm: {
        id: "",
        mobile: "",
      },
    };
  },
  computed: {
    dataRule() {
      var validateMobile = (rule, value, callback) => {
        this.flag = true;
        if (value && !isNumber(value)) {
          console.log("88888");
          this.flag = false;
          return callback(
            new Error(
              this.$t("validate.format", { attr: this.$t("user.mobile") })
            )
          );
        } else {
          console.log("99999");
        }
        callback();
      };
      return {
        mobile: [
          { required: true, validator: validateMobile, trigger: "blur" },
        ],
      };
    },
  },
  components: {
    AddOrUpdate,
  },
  methods: {
    getCheck() {
      if (this.flag) {
        this.getDataList();
      }
    },
    genderText(gender) {
      return ["男", "女"][gender];
    },
    //上传附件
    afterRead(file) {
      let data = new FormData();
      data.append("file", file.file);
      console.log(file);
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      setTimeout(() => {
        loading.close();
      }, 2000);
      //  console.log("file", data);
      /* getfileUploader(data).then((res) => {
        if (res.data.code == 0) {
          this.datalist.push({
            docId: res.data.data.docId,
            name: res.data.data.fileName,
            filePath: res.data.data.url,
            createDate: currentDate,
          });
          //     console.log("上传完的dataform", this.dataForm);
        }
        this.dataForm.woWorkorderDocumentDTOList = this.datalist;
      }); */
    },
  },
};
</script>
<style lang="less" scoped>
/deep/.el-upload-list {
  display: none;
}
</style>
