index.vue 8.61 KB
<template>
  <div class="app-container">
    <div>
      <!-- 搜索区域 -->
      <div class="from-Card">
        <el-form ref="queryRef" size="small" :model="queryParams" :inline="true" label-position="top">
          <el-row style="width: 100%;">
            <el-col :span="4">
              <el-form-item label="缴费编号" prop="name">
                <el-input
                  v-model.trim="queryParams.name"
                  placeholder="缴费编号"
                  clearable
                  style="width: 100%"
                  @keyup.enter="searchFN"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="display: flex">
              <el-form-item style="width: 100%;" label="确认时间" prop="commitTime">
                <el-date-picker
                  v-model="commitTime[0]" type="date" value-format="YYYY-MM-DD HH:mm:ss"
                  placeholder="开始时间" style="width: 100%;"
                />
              </el-form-item>
              <el-form-item style="width: 100%;" label="确认时间" prop="commitTime">
                <el-date-picker
                  v-model="commitTime[1]" type="date" value-format="YYYY-MM-DD HH:mm:ss"
                  placeholder="结束时间" style="width: 100%;"
                  :default-time="defaultTime"
                />
              </el-form-item>
            </el-col>
            <div class="po-r-btns">
              <el-button size="small" type="primary" icon="Search" @click="searchFN()">查询</el-button>
              <el-button size="small" icon="Refresh" @click="reset">重置</el-button>
              <el-button size="small" type="warning" icon="" @click="handeData">导出</el-button>
            </div>

          </el-row>

        </el-form>
        <el-row justify="space-between">
          <div>
            <router-link class="router" to="/rank/batchAddDuan">
              <el-button type="primary" icon="Plus">添加段位 </el-button>
            </router-link>
          </div>
        </el-row>
      </div>
      <!-- 表格数据 -->
      <div class="table">
        <el-table v-loading="loading" :data="list" :row-class-name="tableRowClassName" border style="width: 100%">
          <el-table-column align="center" label="序号" type="index" width="55" />
          <el-table-column
            label="编号"
            align="center"
            prop="name"
            min-width="140"
            :show-overflow-tooltip="true"
          />

          <el-table-column
            label="状态"
            align="center"
            prop="status"
            min-width="100"
          >
            <template #default="props">
              <div v-if="props.row.status==0"> 待确认</div>
              <div v-if="props.row.status==1">已确认</div>
            </template>
          </el-table-column>

          <el-table-column
            label="确认时间"
            align="center"
            prop="commitTime"
            min-width="100"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.commitTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="附件"
            align="center"
            width="100"
          >
            <template #default="{row}">
              <el-button v-if="row.status==1" :disabled="!row.fileUrl" type="primary" link @click="handelDowen(row)">下载</el-button>
              <el-button v-else type="primary" link @click="handelDowenUpdated(row)">编辑</el-button>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            fixed="right"
            width="350"
          >
            <template #default="scope">
              <el-button type="primary" @click="handleInfo(scope.row)">查看</el-button>
              <el-button :disabled="scope.row.status==1" color="#13B5B1" style="--el-color-black:#fff;" @click="commitFN(scope.row)">确认</el-button>
              <el-button :disabled="scope.row.status==1" type="warning" @click="handleEdit(scope.row)">编辑</el-button>
              <el-button type="danger" @click="handleDelete(scope.row)">删除</el-button>
              <!--              <el-button v-if="scope.row.status==1" type="danger" @click="handleDel(scope.row)">撤回</el-button>-->
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          :total="total"
          @pagination="initData"
        />
      </div>
      <View ref="viewRef" />
      <Error ref="errorRef" />
      <el-link v-show="false" ref="linkRef" :href="fillImgUrl(url)" :underline="false" target="_blank" />
      <upload ref="uploadRef" @success="initData" />
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { reactive } from '@vue/runtime-core'
import { ref, toRefs, onMounted, getCurrentInstance, nextTick } from 'vue'
import { apiList, confirm, voidDuanInfoRange, duanInputDeltel } from '@/api/exam/addDuan'
import View from './view.vue'
import upload from './upload.vue'
import Error from './error.vue'

const { proxy } = getCurrentInstance()
const rotuer = useRouter()
const total = ref(0)
const list = ref([])
const url = ref(null)
const loading = ref(false)
const defaultTime = ref(new Date(0, 0, 0, 23, 59, 59))
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10
  }

})
const commitTime = ref([null, null])
const rowData = ref()
const { queryParams } = toRefs(data)

onMounted(() => {
  initData()
})

// 背景色
const tableRowClassName = ({
  row,
  rowIndex
}) => {
  if (row.status == 2) {
    return 'success-row'
  }
}

function searchFN() {
  queryParams.value.pageNum = 1
  initData()
}

// 获取赛会列表
async function initData() {
  if ((commitTime.value[0] == null && commitTime.value[1] != null) || (commitTime.value[1] == null && commitTime.value[0] != null)) return proxy.$modal.msgError('请完善提交日期范围')
  queryParams.value.commitTimeRange = commitTime.value[0] != null ? commitTime.value.toString() : null
  loading.value = true
  const res = await apiList(queryParams.value)
  list.value = res.rows
  for (const v of list.value) {
    if (v.fileUrl)v.fileUrl = JSON.parse(v.fileUrl)
  }
  loading.value = false
  total.value = res.total
}

// 重置
function reset() {
  queryParams.value = {
    pageNum: 1,
    pageSize: 10
  }
  commitTime.value = [null, null]
  initData()
}

// 查看
function handleInfo(row) {
  rowData.value = row
  proxy.$refs['viewRef'].open(row, row.status == 1)
}

// 确认
async function commitFN(row) {
  if (!row.fileUrl) return proxy.$modal.confirm('请上传附件!')
  const res = await confirm({ ids: row.id })
  if (res.data.finishFlag) {
    proxy.$modal.msgSuccess('提交成功!')
  } else {
    proxy.$refs['errorRef'].open(res.data)
  }
  await initData()
}

function handleEdit(row) {
  rotuer.push({
    path: '/rank/batchAddDuan',
    query: { rangeId: row.id, fileUrl: row.fileUrl ? JSON.stringify(row.fileUrl) : null }
  })
}

// 删除
async function handleDelete(row) {
  let text
  if (row.status == 1) {
    // 已确认
    text = `编号为${row.name}的数据已确认,是否确认删除该数据项?`
  } else {
    text = `是否确认删除编号为${row.name}数据项?`
  }
  await proxy.$modal.confirm(text)
  await duanInputDeltel(row.id)
  await proxy.$modal.msgSuccess('操作成功')
  await initData()
}

async function handleDel(row) {
  await proxy.$modal.confirm('是否确认撤回该数据项?')
  await voidDuanInfoRange({ ids: row.id })
  await proxy.$modal.msgSuccess('操作成功')
  await initData()
}

function handeData() {
  if ((commitTime.value[0] == null && commitTime.value[1] != null) || (commitTime.value[1] == null && commitTime.value[0] != null)) return proxy.$modal.msgError('请完善提交日期范围')
  queryParams.value.commitTimeRange = commitTime.value[0] != null ? commitTime.value.toString() : null
  proxy.download('/system/duanInput/export', {
    commitTimeRang: queryParams.value.commitTimeRange,
    rangeName: queryParams.value.name
  }, `批次添加段位${new Date().getTime()}.xlsx`)
}

function handelDowen(row) {
  url.value = row.fileUrl?.[0]?.url
  nextTick(() => {
    proxy.$refs['linkRef'].$el.click()
  })
}

function handelDowenUpdated(row) {
  proxy.$refs['uploadRef'].open({ id: row.id, fileUrl: row.fileUrl })
}
</script>

<style lang="scss" scoped>
.router {
  margin-right: 20px;
}
:deep(.el-button--info){
  background-color: #920f20;
  border:1px solid #920f20
}


</style>