Newer
Older
xc-metering-front / src / views / tested / MeasurementBusiness / satisfaction / index.vue
liyaguang on 14 Jan 4 KB 首页看板问题修改
<!-- 委托方满意度调查表 -->
<script lang="ts" setup name="ClientSatisfactionSurveyForm">
import { reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { getListPage } from '@/api/eqpt/MeasurementBusiness/satisfaction'
import { keepSearchParams } from '@/utils/keepQuery'
const { proxy } = getCurrentInstance() as any
const listQuery = reactive({
  sendTimeStart: '',
  writeStatus: '',
  sendTimeEnd: '',
  offset: 1,
  limit: 20,
  draft: '',
})
onBeforeRouteLeave((to: any) => {
  keepSearchParams(to.path, 'ClientSatisfactionSurveyForm')
})
// 证书有效期开始结束时间
const datetimerange = ref()
watch(() => datetimerange.value, (newVal) => {
  listQuery.sendTimeStart = ''
  listQuery.sendTimeEnd = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.sendTimeStart = `${newVal[0]} 00:00:00`
      listQuery.sendTimeEnd = `${newVal[1]} 23:59:59`
    }
  }
})
const columns = ref([
  {
    text: '文件编号',
    value: 'questionnaireNo',
    align: 'center',
  },
  {
    text: '填写单位',
    value: 'customerName',
    align: 'center',
  },
  {
    text: '发送人',
    value: 'senderName',
    align: 'center',
  },
  {
    text: '发送时间',
    value: 'sendTime',
    align: 'center',
  },
  {
    text: '填写状态',
    value: 'writeStatus',
    align: 'center',
  },
])
const list = ref([])
const total = ref(0)
const listLoading = ref(true)

// 获取数据
const fetchData = (isNowPage = true) => {
  listLoading.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.offset = 1
  }
  getListPage(listQuery).then((response) => {
    list.value = response.data.rows
    total.value = parseInt(response.data.total)
    listLoading.value = false
  })
}
fetchData()
// 查询数据
const search = () => {
  fetchData(false)
}
// 重置
const reset = () => {
  datetimerange.value = []
  listQuery.sendTimeStart = ''
  listQuery.writeStatus = ''
  listQuery.sendTimeEnd = ''
  listQuery.draft = ''
  listQuery.offset = 1
  listQuery.limit = 20
  search()
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size: number; page: number }) => {
  if (val && val.size) {
    listQuery.limit = val.size
  }
  if (val && val.page) {
    listQuery.offset = val.page
  }
  fetchData()
}
const $router = useRouter()
// 新建编辑操作
const handler = (row: any, type: string) => {
  $router.push({
    path: `/satisfaction/${type}`,
    query: {
      row: JSON.stringify(row),
      id: row.id,
    },
  })
}

onActivated(() => {
  // 从编辑或者新增页面回来需要重新获取列表数据
  // $router.options.history.state.forward 上一次路由地址
  if (!($router.options.history.state.forward as string || '').includes('detail')) {
    console.log('需要重新获取列表')
    fetchData(false)
  }
})
</script>

<template>
  <app-container>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="search" @clear="reset">
      <search-item>
        <el-date-picker
          v-model="datetimerange" type="daterange" value-format="YYYY-MM-DD"
          format="YYYY-MM-DD" range-separator="至" start-placeholder="发送开始时间" end-placeholder="发送结束时间"
          clearable
        />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.draft" filterable placeholder="填写状态" style="width: 192px;">
          <el-option label="已提交" value="2" />
          <el-option label="未提交" value="1" />
        </el-select>
        <!-- <el-input v-model.trim="listQuery.writeStatus" placeholder="填写状态" clearable /> -->
      </search-item>
    </search-area>
    <table-container>
      <!-- <template #btns-right>
        <icon-button v-if="proxy.hasPerm('/tested/business/satisfaction/add')" icon="icon-add" title="新增" @click="handler({}, 'create')" />
      </template> -->
      <!-- 普通表格 -->
      <normal-table
        :data="list" :total="total" :columns="columns as any" :query="listQuery" :list-loading="listLoading"
        :is-showmulti-select="true" @change="changePage"
      >
        <template #columns>
          <el-table-column label="操作" width="120" align="center">
            <template #default="scope">
              <el-button link type="primary" size="small" @click="handler(scope.row, 'detail')">
                查看
              </el-button>
              <el-button v-if="proxy.hasPerm('/tested/business/satisfaction/edit') && (String(scope.row.draft) === '1' || String(scope.row.draft) === '')" link type="primary" size="small" @click="handler(scope.row, 'update')">
                编辑
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>