projectList.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :span="4">
  5. <el-form-item label="项目名称">
  6. <el-input
  7. v-model="filterProjects.name"
  8. placeholder="请输入项目名称"
  9. />
  10. </el-form-item>
  11. </el-col>
  12. <el-col
  13. :span="4"
  14. :offset="1"
  15. >
  16. <el-form-item label="立项时间">
  17. <el-date-picker
  18. v-model="filterProjects.time"
  19. type="month"
  20. placeholder="请选择立项时间"
  21. format="YYYY-MM"
  22. value-format="YYYY-MM"
  23. />
  24. </el-form-item>
  25. </el-col>
  26. <el-col
  27. :span="4"
  28. :offset="1"
  29. >
  30. <el-form-item label="项目状态">
  31. <el-select
  32. v-model="currentlyState"
  33. @change="changeState"
  34. >
  35. <el-option
  36. v-for="item in stateList"
  37. :key="item.value"
  38. :label="item.label"
  39. :value="item.value"
  40. />
  41. </el-select>
  42. </el-form-item>
  43. </el-col>
  44. <el-col
  45. :span="5"
  46. style="margin-left: 40px"
  47. >
  48. <el-row justify="space-around">
  49. <el-button
  50. type="primary"
  51. :icon="Search"
  52. @click="queryProject"
  53. >查询
  54. </el-button>
  55. <el-button
  56. type="primary"
  57. :icon="DocumentCopy"
  58. @click="queryProject"
  59. >立项
  60. </el-button>
  61. <el-button
  62. type="primary"
  63. :icon="RefreshLeft"
  64. @click="listData(initialCondition)"
  65. >重置
  66. </el-button>
  67. </el-row>
  68. </el-col>
  69. </el-row>
  70. <el-row>
  71. <el-col :span="23">
  72. <el-row justify="space-between">
  73. <el-col :span="5">
  74. <div
  75. class="bg-white h-24"
  76. style="box-shadow: -7px 0 7px #e5e5e5"
  77. >
  78. <el-row
  79. style="height: 40%"
  80. align="middle"
  81. >
  82. <el-col :offset="2">
  83. <el-text
  84. style="font-family: 黑体;"
  85. >项目总数
  86. </el-text>
  87. </el-col>
  88. </el-row>
  89. <el-row
  90. style="height: 60%"
  91. align="middle"
  92. >
  93. <el-col :offset="2">
  94. <span class="dataStyle">{{ screenData.totalProject }}</span>
  95. </el-col>
  96. </el-row>
  97. </div>
  98. </el-col>
  99. <el-col :span="5">
  100. <div
  101. class="bg-white h-24"
  102. style="box-shadow: -7px 0 7px #e5e5e5"
  103. >
  104. <el-row
  105. style="height: 40%"
  106. align="middle"
  107. >
  108. <el-col :offset="2">
  109. <el-text
  110. style="font-family: 黑体;"
  111. >执行中项目
  112. </el-text>
  113. </el-col>
  114. </el-row>
  115. <el-row
  116. style="height: 60%"
  117. align="middle"
  118. >
  119. <el-col :offset="2">
  120. <span class="dataStyle">{{ screenData.unCompleteProject }}</span>
  121. </el-col>
  122. </el-row>
  123. </div>
  124. </el-col>
  125. <el-col :span="5">
  126. <div
  127. class="bg-white h-24"
  128. style="box-shadow: -7px 0 7px #e5e5e5"
  129. >
  130. <el-row
  131. style="height: 40%"
  132. align="middle"
  133. >
  134. <el-col :offset="2">
  135. <el-text
  136. style="font-family: 黑体;"
  137. >已完成项目
  138. </el-text>
  139. </el-col>
  140. </el-row>
  141. <el-row
  142. style="height: 60%"
  143. align="middle"
  144. >
  145. <el-col :offset="2">
  146. <span class="dataStyle">{{ screenData.completeProject }}</span>
  147. </el-col>
  148. </el-row>
  149. </div>
  150. </el-col>
  151. <el-col :span="5">
  152. <div
  153. class="bg-white h-24"
  154. style="box-shadow: -7px 0 7px #e5e5e5"
  155. >
  156. <el-row
  157. style="height: 40%"
  158. align="middle"
  159. >
  160. <el-col :offset="2">
  161. <el-text
  162. style="font-family: 黑体;"
  163. >项目总金额
  164. </el-text>
  165. </el-col>
  166. </el-row>
  167. <el-row
  168. style="height: 60%"
  169. align="middle"
  170. >
  171. <el-col :offset="2">
  172. <span class="dataStyle">{{ screenData.sum }}元</span>
  173. </el-col>
  174. </el-row>
  175. </div>
  176. </el-col>
  177. </el-row>
  178. </el-col>
  179. </el-row>
  180. <el-form>
  181. <el-row style="margin-top: 20px;">
  182. <el-col
  183. :span="23"
  184. >
  185. <el-table
  186. :data="projectListData"
  187. height="580"
  188. stripe
  189. >
  190. <el-table-column
  191. prop="code"
  192. label="项目编码"
  193. align="center"
  194. />
  195. <el-table-column
  196. prop="name"
  197. label="项目名称"
  198. align="center"
  199. />
  200. <el-table-column
  201. prop="principal"
  202. label="项目负责人"
  203. align="center"
  204. />
  205. <el-table-column
  206. prop="price"
  207. label="项目金额"
  208. align="center"
  209. />
  210. <el-table-column
  211. prop="CreatedAt"
  212. label="立项日期"
  213. align="center"
  214. />
  215. <el-table-column
  216. prop="state"
  217. label="状态"
  218. align="center"
  219. />
  220. <el-table-column
  221. label="项目操作"
  222. align="center"
  223. >
  224. <template #default="scope">
  225. <el-button
  226. @click="projectEdit(scope.$index, scope.row)"
  227. >
  228. 详情
  229. </el-button>
  230. <el-button
  231. type="danger"
  232. @click="projectDelete(scope.$index, scope.row)"
  233. >
  234. 删除
  235. </el-button>
  236. </template>
  237. </el-table-column>
  238. </el-table>
  239. </el-col>
  240. </el-row>
  241. </el-form>
  242. <el-row>
  243. <el-col
  244. :span="23"
  245. style="display: flex;justify-content: end"
  246. >
  247. <el-pagination
  248. :page-size="10"
  249. background
  250. layout="prev, pager, next"
  251. :total="listTotal"
  252. @change="changePage"
  253. />
  254. </el-col>
  255. </el-row>
  256. </div>
  257. </template>
  258. <script setup>
  259. import { DocumentCopy, RefreshLeft, Search } from '@element-plus/icons-vue'
  260. import { getProjectList, projectDataScreen, deleteProject } from '@/api/project'
  261. import { reactive, ref, onMounted } from 'vue'
  262. import { ElMessage, ElMessageBox } from 'element-plus'
  263. defineOptions({
  264. name: 'ProjectList'
  265. })
  266. const screenData = reactive({})
  267. const projectListData = reactive([])
  268. const listTotal = ref(0)
  269. const stateList = [
  270. { label: '立项', value: 1 },
  271. { label: '施工', value: 2 },
  272. { label: '收款', value: 3 },
  273. { label: '完成', value: 4 },
  274. { label: '失效', value: 5 },
  275. ]
  276. const initialCondition = {
  277. pageInfo: {
  278. page: 1,
  279. pageSize: 10
  280. },
  281. name: '',
  282. time: '',
  283. state: 0
  284. }
  285. const filterProjects = reactive({
  286. pageInfo: {
  287. page: 1,
  288. pageSize: 10
  289. },
  290. name: '',
  291. time: '',
  292. state: 0
  293. }
  294. )
  295. const currentlyState = ref('')
  296. const changeState = (value) => {
  297. filterProjects.state = value
  298. stateList.forEach(item => {
  299. if (value === item.value) {
  300. currentlyState.value = item.label
  301. }
  302. })
  303. }
  304. const projectEdit = (index, row) => {
  305. }
  306. const projectDelete = (index, row) => {
  307. ElMessageBox.confirm(
  308. '确定要删除该项目吗?',
  309. '项目删除',
  310. {
  311. confirmButtonText: '确认',
  312. cancelButtonText: '取消',
  313. type: 'warning',
  314. }
  315. )
  316. .then(() => {
  317. deleteProject(row.code).then(res => {
  318. if (res.code === 0) {
  319. ElMessage({
  320. type: 'success',
  321. message: '删除成功',
  322. })
  323. listData(initialCondition)
  324. dataScreen()
  325. } else {
  326. ElMessage({
  327. type: 'error',
  328. message: res.msg,
  329. })
  330. }
  331. })
  332. })
  333. .catch(() => {
  334. ElMessage({
  335. type: 'info',
  336. message: '取消删除',
  337. })
  338. })
  339. }
  340. onMounted(() => {
  341. // 项目数据总览
  342. dataScreen()
  343. // 获取项目列表
  344. listData(initialCondition)
  345. })
  346. const listData = (condition) => {
  347. projectListData.length = 0
  348. getProjectList(condition).then(res => {
  349. if (res.code === 0 && res.data.total > 0) {
  350. const list = res.data.list
  351. list.forEach(item => {
  352. item.CreatedAt = formatDate(item.CreatedAt)
  353. item.state = projectState(item.state)
  354. })
  355. projectListData.push(...list)
  356. listTotal.value = res.data.total
  357. }
  358. })
  359. }
  360. const dataScreen = () => {
  361. projectDataScreen().then(res => {
  362. const obj = res.data
  363. Object.keys(obj).forEach(key => {
  364. screenData[key] = obj[key]
  365. })
  366. })
  367. }
  368. const formatDate = (dateString, locale = 'en-US', timezone = 'Asia/Shanghai') => {
  369. // 使用 Date 构造函数解析日期字符串
  370. const date = new Date(dateString)
  371. // 检查日期是否有效
  372. if (isNaN(date.getTime())) {
  373. throw new Error('Invalid date string')
  374. }
  375. // 使用 Date 对象的年份、月份和日期来构建新的日期字符串
  376. // 注意:JavaScript 中的月份是从 0 开始的,所以我们需要加 1
  377. const formattedDate = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).slice(-2)}-${('0' + date.getDate()).slice(-2)}`
  378. return formattedDate
  379. }
  380. const projectState = (state) => {
  381. const obj = {
  382. 1: '立项',
  383. 2: '施工',
  384. 3: '收款',
  385. 4: '完成',
  386. 5: '失效'
  387. }
  388. return obj[state]
  389. }
  390. const queryProject = () => {
  391. listData(filterProjects)
  392. }
  393. const changePage = (value) => {
  394. console.log(value)
  395. }
  396. </script>
  397. <style scoped lang="less">
  398. .dataStyle {
  399. font-size: 25px;
  400. font-weight: 500;
  401. }
  402. </style>