<template>
  <div>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
    >
      <template slot="status" slot-scope="{ row }">
        <div>{{ row.status | jobStatus}}</div>
      </template>
      <template slot="wage" slot-scope="{ row }">
        <div>{{ row.wage}}元/人/天</div>
      </template>
      <template slot="etimePub" slot-scope="{ row }">
        <div>{{ dateFormat(new Date(row.etimePub), "yyyy/MM/dd")}}</div>
      </template>
      <template slot="etime" slot-scope="{ row }">
        <div>{{ dateFormat(new Date(row.etime), "yyyy/MM/dd")}}</div>
      </template>
      <template slot="stime" slot-scope="{ row }">
        <div>{{ dateFormat(new Date(row.stime), "yyyy/MM/dd")}}</div>
      </template>
      <template slot="expiryTime" slot-scope="{ row }">
        <div>{{ dateFormat(new Date(row.expiryTime), "yyyy/MM/dd")}}</div>
      </template>
      <!--自定义操作栏-->
      <div slot="menu" slot-scope="{ size, type, row }">
        <el-button
          icon="el-icon-view"
          :size="size"
          :type="type"
          @click.stop="rowView(row)"
        >查看</el-button>
      </div>
    </avue-crud>
    <el-drawer title="详情" :visible.sync="viewDrawer" size="60%">
      <post-view :model="view"></post-view>
    </el-drawer>
  </div>
</template>

<script>
  import {
    getDetail,
  } from "@/api/workstation/post";
  import postView from "@/views/util/post-view.vue";
  import {detailList, stationExport} from '@/api/workstation/post'
  import { missionState,companyPostState } from "@/common/dic";
  import {dateFormat} from '@/util/date'
  // import {download} from '@/util/util'

export default {
  name: "post",
  components: {postView},
  filters: {
    jobStatus (v) {
      switch (v) {
        case 1:
          return '招聘中'
        case 2:
          return '任务中'
        case 3:
          return '已完成'
        case 4:
          return '已失效'
        case 9:
          return '未发布'
      }
    }
  },
  data () {
    return {
      viewDrawer: false,
      loading: false,
      view: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 100,
      },
      query: {},
      data: [],
      option: {
        height: "400",
        calcHeight: 40,
        menuWidth: 120,
        align: "center",
        menuAlign: "center",
        indexLabel: "序号",
        menu:true,
        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: "jobName",
          },
          {
            label: "岗位编码",
            prop: "missionNo",
            display: false,
          },
          {
            label: "机构名称",
            prop: "companyName",
          },
          {
            label: "岗位状态",
            prop: "jobStatus",
            dicData: companyPostState,
            slot: true
          },
          {
            label: "招聘人数",
            prop: "peopleNum",
            display: false,
          },
          {
            label: "申请人数",
            prop: "applyCount",
            display: false,
          },
          {
            label: "录用人数",
            prop: "employedCount",
          },
          // {
          //   label: "发工资人数",
          //   prop: "userPayCount",
          // },

          {
            label: "参考工资",
            prop: "wage",
            slot: true
          },
          // {
          //   label: "报名截止日期",
          //   prop: "etimePub",
          //   slot: true,
          //   display: false,
          // },
          {
            label: "开始时间",
            prop: "stime",
            slot: true,
            display: false,
          },
          {
            label: "结束时间",
            prop: "etime",
            slot: true,
            display: false,
          }
        ]
      }
    }
  },
  methods: {
    dateFormat,
    rowView(row) {
      getDetail(row.missionNo).then((resp) => {
        this.viewDrawer = true;
        this.view = resp.data.data;
      });
    },
    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
      detailList(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
      detailList(params).then(res => {
        this.data = res.data.data.records
        this.page.total = res.data.data.total
        this.loading = false
      })
    },
    // 导出
    taskOut(search){
      this.query = search
      var query = this.query
      window.open(
        stationExport(
          query.status,
          query.companyName,
          query.missionNo,
          query.missionTitle,
          query.reviewState,
          query.stime,
          query.etime,
          this.page.currentPage,
          this.page.pageSize
        )
      )
    }
  }
}
</script>

<style scoped>

</style>
