123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- <template>
- <div>
- <el-row>
- <el-col :span="4">
- <el-form-item label="项目名称">
- <el-input
- v-model="filterProjects.name"
- placeholder="请输入项目名称"
- />
- </el-form-item>
- </el-col>
- <el-col
- :span="4"
- :offset="1"
- >
- <el-form-item label="立项时间">
- <el-date-picker
- v-model="filterProjects.time"
- type="month"
- placeholder="请选择立项时间"
- format="YYYY-MM"
- value-format="YYYY-MM"
- />
- </el-form-item>
- </el-col>
- <el-col
- :span="4"
- :offset="1"
- >
- <el-form-item label="项目状态">
- <el-select
- v-model="currentlyState"
- @change="changeState"
- >
- <el-option
- v-for="item in stateList"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col
- :span="5"
- style="margin-left: 40px"
- >
- <el-row justify="space-around">
- <el-button
- type="primary"
- :icon="Search"
- @click="queryProject"
- >查询
- </el-button>
- <el-button
- type="primary"
- :icon="DocumentCopy"
- @click="queryProject"
- >立项
- </el-button>
- <el-button
- type="primary"
- :icon="RefreshLeft"
- @click="listData(initialCondition)"
- >重置
- </el-button>
- </el-row>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="23">
- <el-row justify="space-between">
- <el-col :span="5">
- <div
- class="bg-white h-24"
- style="box-shadow: -7px 0 7px #e5e5e5"
- >
- <el-row
- style="height: 40%"
- align="middle"
- >
- <el-col :offset="2">
- <el-text
- style="font-family: 黑体;"
- >项目总数
- </el-text>
- </el-col>
- </el-row>
- <el-row
- style="height: 60%"
- align="middle"
- >
- <el-col :offset="2">
- <span class="dataStyle">{{ screenData.totalProject }}</span>
- </el-col>
- </el-row>
- </div>
- </el-col>
- <el-col :span="5">
- <div
- class="bg-white h-24"
- style="box-shadow: -7px 0 7px #e5e5e5"
- >
- <el-row
- style="height: 40%"
- align="middle"
- >
- <el-col :offset="2">
- <el-text
- style="font-family: 黑体;"
- >执行中项目
- </el-text>
- </el-col>
- </el-row>
- <el-row
- style="height: 60%"
- align="middle"
- >
- <el-col :offset="2">
- <span class="dataStyle">{{ screenData.unCompleteProject }}</span>
- </el-col>
- </el-row>
- </div>
- </el-col>
- <el-col :span="5">
- <div
- class="bg-white h-24"
- style="box-shadow: -7px 0 7px #e5e5e5"
- >
- <el-row
- style="height: 40%"
- align="middle"
- >
- <el-col :offset="2">
- <el-text
- style="font-family: 黑体;"
- >已完成项目
- </el-text>
- </el-col>
- </el-row>
- <el-row
- style="height: 60%"
- align="middle"
- >
- <el-col :offset="2">
- <span class="dataStyle">{{ screenData.completeProject }}</span>
- </el-col>
- </el-row>
- </div>
- </el-col>
- <el-col :span="5">
- <div
- class="bg-white h-24"
- style="box-shadow: -7px 0 7px #e5e5e5"
- >
- <el-row
- style="height: 40%"
- align="middle"
- >
- <el-col :offset="2">
- <el-text
- style="font-family: 黑体;"
- >项目总金额
- </el-text>
- </el-col>
- </el-row>
- <el-row
- style="height: 60%"
- align="middle"
- >
- <el-col :offset="2">
- <span class="dataStyle">{{ screenData.sum }}元</span>
- </el-col>
- </el-row>
- </div>
- </el-col>
- </el-row>
- </el-col>
- </el-row>
- <el-form>
- <el-row style="margin-top: 20px;">
- <el-col
- :span="23"
- >
- <el-table
- :data="projectListData"
- height="580"
- stripe
- >
- <el-table-column
- prop="code"
- label="项目编码"
- align="center"
- />
- <el-table-column
- prop="name"
- label="项目名称"
- align="center"
- />
- <el-table-column
- prop="principal"
- label="项目负责人"
- align="center"
- />
- <el-table-column
- prop="price"
- label="项目金额"
- align="center"
- />
- <el-table-column
- prop="CreatedAt"
- label="立项日期"
- align="center"
- />
- <el-table-column
- prop="state"
- label="状态"
- align="center"
- />
- <el-table-column
- label="项目操作"
- align="center"
- >
- <template #default="scope">
- <el-button
- @click="projectEdit(scope.$index, scope.row)"
- >
- 详情
- </el-button>
- <el-button
- type="danger"
- @click="projectDelete(scope.$index, scope.row)"
- >
- 删除
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- </el-form>
- <el-row>
- <el-col
- :span="23"
- style="display: flex;justify-content: end"
- >
- <el-pagination
- :page-size="10"
- background
- layout="prev, pager, next"
- :total="listTotal"
- @change="changePage"
- />
- </el-col>
- </el-row>
- </div>
- </template>
- <script setup>
- import { DocumentCopy, RefreshLeft, Search } from '@element-plus/icons-vue'
- import { getProjectList, projectDataScreen, deleteProject } from '@/api/project'
- import { reactive, ref, onMounted } from 'vue'
- import { ElMessage, ElMessageBox } from 'element-plus'
- defineOptions({
- name: 'ProjectList'
- })
- const screenData = reactive({})
- const projectListData = reactive([])
- const listTotal = ref(0)
- const stateList = [
- { label: '立项', value: 1 },
- { label: '施工', value: 2 },
- { label: '收款', value: 3 },
- { label: '完成', value: 4 },
- { label: '失效', value: 5 },
- ]
- const initialCondition = {
- pageInfo: {
- page: 1,
- pageSize: 10
- },
- name: '',
- time: '',
- state: 0
- }
- const filterProjects = reactive({
- pageInfo: {
- page: 1,
- pageSize: 10
- },
- name: '',
- time: '',
- state: 0
- }
- )
- const currentlyState = ref('')
- const changeState = (value) => {
- filterProjects.state = value
- stateList.forEach(item => {
- if (value === item.value) {
- currentlyState.value = item.label
- }
- })
- }
- const projectEdit = (index, row) => {
- }
- const projectDelete = (index, row) => {
- ElMessageBox.confirm(
- '确定要删除该项目吗?',
- '项目删除',
- {
- confirmButtonText: '确认',
- cancelButtonText: '取消',
- type: 'warning',
- }
- )
- .then(() => {
- deleteProject(row.code).then(res => {
- if (res.code === 0) {
- ElMessage({
- type: 'success',
- message: '删除成功',
- })
- listData(initialCondition)
- dataScreen()
- } else {
- ElMessage({
- type: 'error',
- message: res.msg,
- })
- }
- })
- })
- .catch(() => {
- ElMessage({
- type: 'info',
- message: '取消删除',
- })
- })
- }
- onMounted(() => {
- // 项目数据总览
- dataScreen()
- // 获取项目列表
- listData(initialCondition)
- })
- const listData = (condition) => {
- projectListData.length = 0
- getProjectList(condition).then(res => {
- if (res.code === 0 && res.data.total > 0) {
- const list = res.data.list
- list.forEach(item => {
- item.CreatedAt = formatDate(item.CreatedAt)
- item.state = projectState(item.state)
- })
- projectListData.push(...list)
- listTotal.value = res.data.total
- }
- })
- }
- const dataScreen = () => {
- projectDataScreen().then(res => {
- const obj = res.data
- Object.keys(obj).forEach(key => {
- screenData[key] = obj[key]
- })
- })
- }
- const formatDate = (dateString, locale = 'en-US', timezone = 'Asia/Shanghai') => {
- // 使用 Date 构造函数解析日期字符串
- const date = new Date(dateString)
- // 检查日期是否有效
- if (isNaN(date.getTime())) {
- throw new Error('Invalid date string')
- }
- // 使用 Date 对象的年份、月份和日期来构建新的日期字符串
- // 注意:JavaScript 中的月份是从 0 开始的,所以我们需要加 1
- const formattedDate = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).slice(-2)}-${('0' + date.getDate()).slice(-2)}`
- return formattedDate
- }
- const projectState = (state) => {
- const obj = {
- 1: '立项',
- 2: '施工',
- 3: '收款',
- 4: '完成',
- 5: '失效'
- }
- return obj[state]
- }
- const queryProject = () => {
- listData(filterProjects)
- }
- const changePage = (value) => {
- console.log(value)
- }
- </script>
- <style scoped lang="less">
- .dataStyle {
- font-size: 25px;
- font-weight: 500;
- }
- </style>
|