<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :option="option"
      :table-loading="loading"
      :data="infoData"
      v-model="form"
      :page.sync="infoPages"
      :permission="permissionList"
      @search-change="searchChange"
      @search-reset="resetChange"
      @refresh-change="refreshChange"
      @size-change="sizeChange"
      @current-change="currentChange"
    >
    </avue-crud>
  </basic-container>
</template>

<script>
import {getList, open, close, remove} from "@/api/manage/user";
import {mapGetters} from "vuex";
import {dateFormat} from "@/util/date";
import {confirmCount} from "@/api/report/report";

const pages = {total: 0, size: 10, currentPage: 1}
const baseOptions = {
  dateBtn: false,
  addBtn: false,
  viewBtn: true,
  editBtn: false,
  delBtn: false,
  height: "auto",
  reserveSelection: false,
  border: true,
  columnBtn: false,
  refreshBtn: false,
  menu: true,
  menuWidth: 120,
  tip: false,
  searchMenuSpan: 6,
  selection: false,
  headerAlign: 'center',
  align: 'center',
}
const sexLs = [
  {
    label: "男",
    value: 1,
  },
  {
    label: "女",
    value: 2,
  },
  {
    label: "不限",
    value: 3,
  }
]
const statusLs = [
  {
    label: "启用",
    value: 0,
  },
  {
    label: "停用",
    value: 1,
  },

]
export default {
  components: {},
  name: "manage_cuser",
  data() {
    return {
      form: {},
      selectionList: [],
      query: {},
      search: {},
      infoPages: Object.assign({}, pages),
      infoData: [],
      loading: false,
      checkDialog: false,
      delayDialog: false,
      finishDialog: false,
    };
  },
  created() {
    this.getData(this.query);
  },
  computed: {
    ...mapGetters(["userInfo", "permission"]),
    permissionList() {
      return {};
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids;
    },
    option() {
      // {
      //   "userId": "1298598161262571521",
      //   "cityId": -1,
      //   "sex": 1,
      //   "header": "",
      //   "nickName": "",
      //   "idNumber": "",
      //   "telphone": "17780870050",
      //   "email": "",
      //   "address": "",
      //   "birthday": "1985-02-28T00:00:00",
      //   "realName": "杜小彬",
      //   "localAddress": "",
      //   "createTime": "2020-08-26 20:28:23",
      //   "status": 0,
      //   "remarks": "",
      //   "nation": "",
      //   "politics": "",
      //   "tokenUser": "",
      //   "bankName": "",
      //   "cardNumber": "",
      //   "authValue": "",
      //   "bakValue": -1,
      //   "authCount": -1,
      //   "skillName": "维修电工,家电维修"
      // }
      return {
        ...baseOptions,
        column: [
          {
            label: "真实姓名",
            prop: "realName",
            search: true,
          },
          {
            label: "性别",
            prop: "sex",
            type: 'select',
            dicData: sexLs,
          },
          {
            label: "手机号",
            prop: "telphone",
            search: true,
          },
          {
            label: "身份证",
            prop: "idNumber",
            search: true,
          },
          {
            label: "年龄",
            prop: "age",
          },
          {
            label: "技能",
            prop: "skillName",
          },
          {
            label: "注册时间",
            prop: "createTime",
          },
          {
            label: "生日",
            prop: "birthday",
            hide: true,
          },
          {
            label: "户籍所在地",
            prop: "localAddress",
            hide: true,
          },
          {
            label: "身份证号码",
            prop: "idNumber",
            hide: true,
          },
          {
            label: "薪资",
            prop: "wage",
            hide: true,
          },
          {
            label: "工作地址",
            prop: "workplace",
            hide: true,
          }
        ],
      }
    }
  },
  methods: {
    refreshChange() {
      this.getData(this.search);
    },
    searchChange(values, done) {
      this.search = values;
      this.getData().then(() => done())
    },
    resetChange() {
      this.search = {}
      this.getData()
    },
    sizeChange(size) {
      this.infoPages.size = size
      this.getData()
    },
    currentChange(page) {
      this.infoPages.page = page
      this.getData()
    },
    getData(values) {
      return new Promise(async (resolve, reject) => {
        this.loading = true;
        let params = {
          ...this.search,
          size: this.infoPages.size,
          current: this.infoPages.currentPage,
        }
        // if( Array.isArray(this.search.date) &&  this.search.date.length ) {
        //   const [stime, etime] =  this.search.date
        //   params.stime = dateFormat(stime, "yyyy-MM-dd")
        //   params.etime = dateFormat(etime, "yyyy-MM-dd")
        //   delete params.date
        // }
        let resData = await getList(params)
        if (resData.data.code === 200) {
          const {records, current, total, size} = resData.data.data
          this.infoData = records
          this.infoPages = {...this.infoPages, currentPage: current, total, size}
          this.loading = false;
          resolve(records)
        } else {
          this.loading = false;
          reject()
        }
      })
    },
  },
};
</script>

<style>
</style>
