<template>
  <div class="app-container  row-container">
    <div class="connection-header collect-header">
      <div class="head-search">
        <date-range-picker v-model="blurryTime" class="date-item" />
        <rrOperation />
      </div>
      <crudOperation>
        <template v-slot:right>
          <el-button :loading="crud.downloadLoading" size="mini" :disabled="crud.selections.length === 0" @click="doExport(crud.selections)">
            <i class="iconfont icon-daochu" />
            导出
          </el-button>
        </template>
      </crudOperation>
    </div>
    <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" height="calc(100vh - 330px)" @selection-change="crud.selectionChangeHandler" @row-dblclick="handleDetail">
      <el-table-column type="selection" align="center" width="55" />
      <el-table-column prop="dept" label="申请部门" />
      <el-table-column prop="create_by" label="申请人" />
      <el-table-column prop="category" label="档案门类" />
      <el-table-column prop="fonds" label="所属全宗" />
      <el-table-column prop="approval" label="审批单" width="260" />
      <el-table-column prop="status" label="审批状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status===1" class="row-state end-state">已审批</span>
          <span v-else class="row-state ing-state">审批中</span>
        </template>
      </el-table-column>
      <el-table-column prop="create_time" label="申请时间">
        <template slot-scope="scope">
          <div>{{ scope.row.create_time | parseTime }}</div>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination v-if="crud.data.length !== 0" />
    <Detail ref="processDetail" :is-histroy="isHistroy" />
  </div>

</template>

<script>
// import crudConnection from '@/api/system/role'
import crudRoles from '@/api/system/role'
import CRUD, { presenter, header, crud } from '@crud/crud'
import DateRangePicker from '@/components/DateRangePicker'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
// import { exportFile } from '@/utils/index'
// import qs from 'qs'
import { mapGetters } from 'vuex'
import Detail from '@/views/system/processManage/runningProcess/module/detail'

const data = [
  {
    'id': '005E76FEC5A2AAB368CA1F',
    'dept': '档案室',
    'status': 1,
    'category': '文书档案（案卷）',
    'fonds': '全宗1',
    'approval': '归档审批流程-admin-2016-09-21',
    'create_time': 1687330805000,
    'create_by': 'admin'
  },
  {
    'id': '005E76FEC5A2AAB368CA1F',
    'dept': '档案室',
    'status': 0,
    'category': '文书档案（案卷）',
    'fonds': '全宗1',
    'approval': '归档审批流程-admin-2016-09-21',
    'create_time': 1687330805000,
    'create_by': 'admin'
  }
]

export default {
  name: 'FilingApprovalList',
  components: { Detail, DateRangePicker, rrOperation, crudOperation, pagination },
  cruds() {
    return [
      CRUD({
        title: '归档审批清单', url: 'api/role/initRoleList',
        crudMethod: { ...crudRoles },
        optShow: {
          add: false,
          edit: false,
          del: false,
          reset: true,
          download: false,
          group: false
        }
      })
    ]
  },
  mixins: [presenter(), header(), crud()],
  props: {
  },
  data() {
    return {
      blurryTime: null
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ])
  },
  created() {
  },
  mounted() {
  },
  methods: {
    [CRUD.HOOK.beforeRefresh]() {
      if (this.blurryTime) {
        this.crud.query.startTime = this.blurryTime[0]
        this.crud.query.endTime = this.blurryTime[1]
      }
    },
    [CRUD.HOOK.afterRefresh]() {
      this.crud.data = data
    },
    handleDetail(row) {
      this.$refs.processDetail.detailVisible = true
      this.$refs.processDetail.selectRow = row
      this.$refs.processDetail.activeIndex = 0
    },
    doExport(data) {
      crud.downloadLoading = true
      this.$confirm('此操作将导出所选数据' + '<span>你是否还要继续？</span>', '提示', {
        confirmButtonText: '继续',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        const ids = []
        data.forEach(val => {
          ids.push(val.id)
        })
        // const params = {
        //   'roleIds': ids
        // }
        // exportFile(this.baseApi + '/api/role/exportRole?' + qs.stringify(params, { indices: false }))
      }).catch(() => {
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/collect-reorganizi.scss";
.connection-header{
  padding: 0 !important;
}
</style>
