<template>
  <div>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      ref="crud"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
    >
      <template slot="insuranceOn" slot-scope="{ row }">
        <div>{{ row.insuranceOn | insuranceOn}}</div>
      </template>
      <template slot="trialOn" slot-scope="{ row }">
        <div>{{ row.trialOn | trialOn}}</div>
      </template>
      <template slot="contractOn" slot-scope="{ row }">
        <div>{{ row.contractOn | insuranceOn}}</div>
      </template>
      <template slot="isSign" slot-scope="{ row }">
        <div>{{ row.isSign | isSign}}</div>
      </template>
      <template slot="serveCost" slot-scope="{ row }">
        <div>{{ moneyFormat(negativeTurnZero(row.serveCost))}}</div>
      </template>
    </avue-crud>
  </div>
</template>

<script>
  import {getCompanyStateVOList} from '@/api/workstation/enterprise'
  import { moneyFormat } from "@/util/money";
  import { negativeTurnZero } from "@/util/validate";
export default {
  name: "examine",
  props: {
  },
  data () {
    return {
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 100,
      },
      query: {},
      data: [],
      option: {
        height: "400",
        calcHeight: 40,
        menuWidth: 420,
        align: "center",
        menuAlign: "center",
        indexLabel: "序号",
        menu:false,
        tip: false,
        addBtn: false,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        excelBtn: false,
        columnBtn: false,
        searchBtn: false,
        searchShow: false,
        border: true,
        index: true,
        selection: false,
        dialogType: "drawer",
        dialogWidth: "60%",
        delBtnText: "取消",
        dialogClickModal: false,
        column: [
          {
            label: "用工单位",
            prop: "companyName",
            display: false
          },
          {
            label: "联系人",
            prop: "name",
            display: false,
          },
          {
            label: "联系电话",
            prop: "phone",
            display: false
          },
          {
            label: "商保",
            prop: "insuranceOn",
            slot: true,
            display: false,
          },
          {
            label: "保证金",
            prop: "trialOn",
            slot: true,
            display: false,
          },
          {
            label: "电子合同",
            prop: "contractOn",
            slot: true,
            display: false,
          },
          {
            label: "服务费",
            prop: "serveCost",
            slot: true,
          },

          {
            label: "服务协议",
            prop: "isSign",
            slot: true,
          },
          {
            label: "邀请码",
            prop: "inviteCode",
            display: false,
          },
          {
            label: "注册时间",
            prop: "createTime",
            display: false,
          }
        ]
      }
    }
  },
  filters: {
    insuranceOn(v){
      if (v === 0) {
        return '停用'
      } else if (v === 1) {
        return '启用'
      }
    },
    // 0：已缴费，1：未缴，2：免缴
    trialOn(v){
      if (v === 0) {
        return '已缴'
      } else if (v === 1) {
        return '未缴'
      } else if (v === 2) {
        return '免缴'
      }
    },
    // 0未签；1：已签
    isSign(v){
      if (v === 0) {
        return '未签'
      } else if (v === 1) {
        return '已签'
      }
    },
  },
  methods: {
    negativeTurnZero,
    moneyFormat,
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.listInit(this.query)
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.listInit(this.query)
    },
    /*刷新本页 带搜索参数*/
    refreshChange() {
      this.init(this.query)
    },
    init(search){
      this.page.currentPage = 1;
      this.query = search
      var params = {
        ...search,
        current: this.page.currentPage,
        size: this.page.pageSize
      }
      this.loading = true
      getCompanyStateVOList(params).then(res => {
        this.data = res.data.data.records
        this.page.total = res.data.data.total
        this.loading = false
      })
    },
    listInit(search){
      this.query = search
      var params = {
        ...search,
        current: this.page.currentPage,
        size: this.page.pageSize
      }
      this.loading = true
      getCompanyStateVOList(params).then(res => {
        this.data = res.data.data.records
        this.page.total = res.data.data.total
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
