<template>
  <page-view :avatar="avatar" :title="false">
    <div slot="headerContent">
      <div class="title">{{ timeFix }}，{{ user.realName }}<!--<span class="welcome-text">，{{ welcome }}</span>--></div>
      <!--      <div>前端工程师 | 蚂蚁金服 - 某某某事业群 - VUE平台</div>-->
    </div>
    <div slot="extra">
      <!--      <a-row class="more-info">-->
      <!--        <a-col :span="7">-->
      <!--          <head-info title="融资待还金额" content="526" :center="false" :bordered="false"/>-->
      <!--        </a-col>-->
      <!--        <a-col :span="7">-->
      <!--          <head-info title="投资待回金额" content="824" :center="false" :bordered="false"/>-->
      <!--        </a-col>-->
      <!--        <a-col :span="10">-->
      <!--          <head-info title="项目利润" content="2,223" :center="false" />-->
      <!--        </a-col>-->
      <!--      </a-row>-->
    </div>

    <a-card :bordered="false" v-show="dataFlag">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="业务内容">
                <a-input v-model="queryParam.content" placeholder="请输入业务内容"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="业务类型">
                <a-select v-model="queryParam.type" placeholder="请选择" >
                  <a-select-option key="-1" value="-1">暂无</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8 || 24" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        showPagination="auto"
      >
        <span slot="action" slot-scope="record">
          <template>
            <a @click="handle(record)">查看详情</a>
          <!--          <a-divider type="vertical" />-->
          <!--          <a v-if="$auth('workplace-backlogs-edit')" @click="handleEdit(record)">修改</a>-->
          <!--          <a-divider type="vertical" />-->
          <!--          <a-popconfirm v-if="$auth('workplace-backlogs-del')" title="是否要删除该条数据？" @confirm="batchDelete(record.id)">-->
          <!--            <a>删除</a>-->
          <!--          </a-popconfirm>-->
          </template>
        </span>
      </s-table>
    </a-card>
  </page-view>
</template>

<script>
import { timeFix } from '@/utils/util'
import { mapState } from 'vuex'
import { PageView } from '@/layouts'
import HeadInfo from '@/components/tools/HeadInfo'
import { Radar, STable } from '@/components'
import { getWorkplaceBacklogPage, updateWorkplaceBacklog } from '@/api/workplace/backlog'

export default {
  name: 'Workplace',
  components: {
    PageView,
    STable,
    HeadInfo,
    Radar
  },
  data () {
    return {
      // 查询参数
      queryParam: {
        status: 1
      },
      typeDict: {},
      leaderFlag: false,
      dataFlag: true,
      targetId: null,
      // 表头

      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          width: 50,
          customRender: (text, record, index) => {
            return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
          }
        },
        {
          title: '业务类型',
          dataIndex: 'type',
          width: 130,
          customRender: (text, record, index) => {
            return this.typeDict[text]
          }
        },
        {
          title: '业务内容',
          dataIndex: 'content',
          width: 400
        },
        {
          title: '任务创建时间',
          dataIndex: 'taskCreateTime',
          width: 150
        },
        {
          title: '操作',
          key: 'action',
          width: '80px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        parameter = {
          ...parameter,
          types: [99],
          ...this.queryParam,
          dataScope: {
            sortBy: 'desc',
            sortName: 'task_create_time'
          }
        }
        return getWorkplaceBacklogPage(Object.assign(parameter, this.queryParam))
          .then(res => {
            return res.data
          })
      },
      selectedRowKeys: [],
      selectedRows: [],

      options: {
        alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },
      optionAlertShow: false,

      timeFix: timeFix(),
      avatar: '',
      user: {},

      loading: true
    }
  },
  computed: {
    ...mapState({
      nickname: (state) => state.user.realName,
      welcome: (state) => state.user.welcome
    }),
    userInfo () {
      return this.$store.getters.userInfo
    }
  },
  created () {
    this.user = this.userInfo
    this.avatar = this.BaseTool.Constant.FILE_URL + this.userInfo.avatar
    this.getDict()
    this.tableOption()
  },
  mounted () {
    // this.getProjects()
    // this.getActivity()
    // this.getTeams()
    // this.initRadar()
  },
  methods: {
    tableOption () {
      this.options = {
        alert: false,
        rowSelection: null
      }
      this.optionAlertShow = false
    },
    handle (record) {
      if (record.type === 16) {
        this.leaderFlag = true
        this.updateStatus(record.id)
      } else {
        this.dataFlag = false
        this.targetId = record.targetId
      }
    },
    updateStatus (targetId) {
      updateWorkplaceBacklog({ id: targetId })
    },
    handleOk () {
      this.$refs.table.refresh()
    },
    resetSearchForm () {
      this.queryParam = {
        status: 1
      }
      this.$refs.table.refresh(true)
    },
    getDict () {
      this.typeDict = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.WORKPLACE_BACKLOG_TYPE)
    },
    back () {
      this.leaderFlag = false
      this.dataFlag = true
      this.$refs.table.refresh(true)
    }
  }
}
</script>

<style lang="less" scoped>
  .item-group {
    padding: 20px 0 8px 24px;
    font-size: 0;
    a {
      color: rgba(0, 0, 0, 0.65);
      display: inline-block;
      font-size: 14px;
      margin-bottom: 13px;
      width: 25%;
    }
  }

  .mobile {

    .project-list {

      .project-card-grid {
        width: 100%;
      }
    }

    .more-info {
      border: 0;
      padding-top: 16px;
      margin: 16px 0 16px;
    }

    .headerContent .title .welcome-text {
      display: none;
    }
  }

</style>
