<template>
  <el-row>
    <basic-container>
      <avue-crud
        :option="option"
        :table-loading="loading"
        :data="dataSource"
        :page.sync="page"
        ref="crud"
        v-model="crudValues"
        :permission="permissionList"
        @search-change="searchChange"
        @search-reset="searchReset"
        @current-change="currentChange"
        @size-change="sizeChange"
        class="customPage"
        :row-style="rowStyle"
      >
      </avue-crud>
    </basic-container>
  </el-row>
</template>

<script>
import {mapGetters} from "vuex";
import {getList} from "@/api/tenant/personnelserve";
import {isvalidatemobile} from "@/util/validate";
import {detail, getDept, getDeptMyTree, talentsDetail} from "@/api/tenant/talents";
import {addServeLog, getMainServeUserLog, removeServeLog, updateServeLog} from "@/api/tenant/serve";
import {getTenantTalentsWarn, tenantTalentsWarn, updateTenantTalentsWarn} from "@/api/tenant/LocalWarningDisposal";
import {getServeLogList} from '@/api/tenant/serverRecords'

const page = {
  size: 10,
  currentPage: 1,
  total: 0,
}
const baseOptions = {
  size: 'medium',
  dateBtn: false,
  addBtn: false,
  editBtn: false,
  viewBtn: false,
  delBtn: false,
  height: "auto",
  menuWidth: 130,
  reserveSelection: false,
  border: true,
  columnBtn: false,
  refreshBtn: false,
  menu: false,
  tip: false,
  selection: false,
  align: 'center',
  searchMenuSpan: 6,
  // dialogType: "drawer",
  searchLabelWidth: 60,
}
export default {
  filters: {
    ellipsis(value) {
      if (!value) return "";
      if (value.length > 15) {
        return value.slice(0, 14) + "...";
      }
      return value;
    },
  },
  data() {
    return {
      loading: false,
      dataSource: [],
      crudValues: {},
      depTree: [],
      page: Object.assign({}, page),
      logPage: Object.assign({}, page),
      logDataSource: [],
      loadingLog: false,
      innerDrawerLog: false,
      innerDrawerAddLog: false,
      logValues: {},
      query: {}
    }
  },
  computed: {
    ...mapGetters(["permission", "userInfo"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.tenant_main_talents_latent_index_add, false),
        viewBtn: true,
        delBtn: this.vaildData(this.permission.tenant_main_talents_latent_index_del, false),
        editBtn: this.vaildData(this.permission.tenant_main_talents_latent_index_edit, false),
      };
    },
    option() {
      const self = this;
      const IdCardNo = (rule, value, callback) => {
        // if (check18IdCardNo(value)) {
        callback();
        // } else {
        //   callback(new Error("身份证格式不正确"));
        // }
      };
      const validateTel = (rule, value, callback) => {
        if (isvalidatemobile(value)[0]) {
          callback(new Error(isvalidatemobile(value)[1]));
        } else {
          callback();
        }
      };
      return {
        ...baseOptions,
        column: [
          {
            label: "所属机构",
            prop: "deptId",
            type: "tree",
            multiple: false,
            hide: true,
            search: true,
            dicData: this.depTree,
            props: {
              label: "title",
              value: 'value'
            },
            searchSpan: 8,
            searchLabelWidth: 100,
          },
          {
            label: "姓名",
            prop: "name",
            display: false
          },
          {
            label: "身份证",
            prop: "idNumber",
            search: true,
            display: false,
            searchSpan: 8,
          },
          {
            label: '机构名称',
            prop: 'deptName',
            display: false
          },
          {
            label: '服务主题',
            prop: 'serveTheme',
            display: false
          },
          {
            label: '服务时间',
            prop: 'time',
            display: false
          },
          {
            label: "开始时间",
            prop: "stime",
            type: "date",
            placeholder: "请选开始日期",
            search: true,
            hide: true,
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            searchLabelWidth: 100,
            searchValue: this.getdate(),
            searchSpan: 8,
          },
          {
            label: "结束时间",
            prop: "etime",
            type: "date",
            placeholder: "请选择结束日期",
            search: true,
            hide: true,
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            searchLabelWidth: 100,
            searchSpan: 8,
          },
        ]
      }
    },
  },
  created() {
    this.getDept()
    this.query = {...this.query, stime: this.getdate()}
    this.onLoad(this.page, this.query)

  },
  activated() {
    this.$nextTick(() => {
      this.$refs.crud.refreshTable()
    })
  },
  methods: {
    rowStyle(column) {
      if (column.row.status == "0") {
        this.option.editBtn = true;
      } else {
        this.option.editBtn = false;
      }
    },
    async getDept() {
      let params = {
        tenantId: '000000'
      }
      let resData = await getDeptMyTree(params)
      if (resData.data.code === 200) {
        this.depTree = resData.data.data
      }
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page, this.query);
    },
    sizeChange(size) {
      this.page.pageSize = size;
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      const {releaseTimeRange} = params;
      let paramsed = {
        current: page.currentPage,
        size: page.pageSize,
        ...params
      };
      console.log(this.query, paramsed)

      this.loading = true;
      getServeLogList(paramsed).then((res) => {
        const {total, size, current, records, page} = res.data.data
        this.dataSource = records;
        this.loading = false;
        this.page = {
          size: size,
          currentPage: current,
          total: total,
        }
      });
    },
    getdate() {
      let time = new Date();
      let day = ("0" + time.getDate()).slice(-2);
      let month = ("0" + (time.getMonth() + 1)).slice(-2);
      let today = time.getFullYear() + "-" + month + "-" + day;
      return today;

    },
  }
}

</script>

<style lang="scss" scoped>


</style>
