<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"
        @row-update="rowUpdate"
        @size-change="sizeChange"
        class="customPage"
        :row-style="rowStyle"
      >
        <template slot="statusCop" slot-scope="{row}">
          <span>{{ statusLs.find((item) => item.value === row.status).label }}</span>
        </template>
      </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";

const page = {
  size: 10,
  currentPage: 1,
  total: 0,
}
const statusLs = [
  {label: "未处理", value: '0'},
  {label: "确认", value: '1'},
  {label: "忽略", value: '2'}
]
const baseOptions = {
  size: 'medium',
  dateBtn: false,
  addBtn: false,
  editBtn: true,
  viewBtn: false,
  delBtn: false,
  height: "auto",
  menuWidth: 130,
  reserveSelection: false,
  border: true,
  columnBtn: false,
  refreshBtn: false,
  menu: true,
  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: {},
      statusLs
    }
  },
  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: "name",
            display: false
          },
          {
            label: "身份证",
            prop: "idNumber",
            search: true,
            display: false
          },
          {
            label: '原属地名称',
            prop: 'nowOrg',
            display: false
          },
          {
            label: '现属地名称',
            prop: 'oldOrg',
            display: false
          },
          {
            label: '属地变更信息',
            prop: 'remark',
            display: false
          },
          {
            label: '状态',
            prop: 'statusCop',
            type: 'radio',
            slot: true,
            display: false,
            dicData: statusLs
          },
          {
            label: '状态',
            prop: 'status',
            type: 'radio',
            showColumn: false,
            dicData: [
              {label: "确认", value: '1'},
              {label: "忽略", value: '2'}
            ]
          },
        ],
      }
    },
  },
  created() {
    this.getDept()
    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.size = size;
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      const {releaseTimeRange} = params;
      let paramsed = {
        current: page.currentPage,
        size: page.size,
        ...this.query
      };
      this.loading = true;
      getTenantTalentsWarn(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,
        }
      });
    },
    rowUpdate(row, index, done) {
      updateTenantTalentsWarn({id: row.id, status: row.status}).then(
        () => {
          done();
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.refresh();
        },
        (error) => {
          window.console.log(error);
          done();
        }
      );
    }
  }
}

</script>

<style lang="scss" scoped>


</style>
