<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="openTime" slot-scope="{ row }">
        <div :style="{'color': (row.isExpiry===1?'red':'')}">{{ row.openTime ? dateFormat(new Date(row.openTime), "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%">
      <mission-view :model="view"></mission-view>
    </el-drawer>
  </div>
</template>

<script>
  import missionView from "@/views/util/mission-view";
  import {gatherList} from '@/api/workstation/task'
  import {dateFormat} from '@/util/date'


export default {
  name: "task",
  components: {missionView},
  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: false,
        selection: false,
        dialogType: "drawer",
        dialogWidth: "60%",
        delBtnText: "取消",
        dialogClickModal: false,
        column: [
          {
            label: "社区街道名称",
            prop: "companyName",
          },
          {
            label: "联系人",
            prop: "callName",
          },
          {
            label: "联系电话",
            prop: "callTel",
            display: false,
          },
          {
            label: "招聘中",
            prop: "recruitCount",
            display: false,
          },
          {
            label: "任务中",
            prop: "startCount",
            display: false,
          },
          {
            label: "已完成",
            prop: "completCount",
            display: false,
          },
          {
            label: "已失效",
            prop: "invalidCount",
          },
          {
            label: "审核未通过",
            prop: "rejectCount",
            display: false,
          },

          // {
          //   label: "待支付（人）",
          //   prop: "nonPaycount",
          //   display: false,
          // },
          // {
          //   label: "已支付",
          //   prop: "payCount",
          //   display: false,
          // },
          // {
          //   label: "已发放",
          //   prop: "userPayCount",
          //   display: false,
          // },
          // {
          //   label: "工资发放逾期",
          //   prop: "expiryCount",
          //   display: false,
          // },
          {
            label: "最新发布任务时间",
            prop: "openTime",
            slot: true,
            display: false
          }
        ]
      }
    }
  },
  methods: {
    dateFormat,
    rowView(row) {
      this.$emit('searchCompanyName', row.companyName)
    },
    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
      gatherList(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
      gatherList(params).then(res => {
        this.data = res.data.data.records
        this.page.total = res.data.data.total
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
