index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" >
  4. <el-form-item label="标题" prop="title">
  5. <el-input
  6. v-model="queryParams.title"
  7. placeholder="请输入待办事项标题"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="公司名称" prop="companyName">
  13. <el-input
  14. v-model="queryParams.companyName"
  15. placeholder="请输入公司名称"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="状态" prop="status">
  21. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
  22. <el-option
  23. v-for="dict in statusOptions"
  24. :key="dict.dictValue"
  25. :label="dict.dictLabel"
  26. :value="dict.dictValue"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  32. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  33. </el-form-item>
  34. </el-form>
  35. <el-row :gutter="10" class="mb8">
  36. <el-col :span="1.5">
  37. <el-button
  38. type="primary"
  39. plain
  40. icon="el-icon-plus"
  41. size="mini"
  42. @click="handleAdd"
  43. v-hasPermi="['todo:todoItems:add']"
  44. >新增</el-button>
  45. </el-col>
  46. <el-col :span="1.5">
  47. <el-button
  48. type="success"
  49. plain
  50. icon="el-icon-edit"
  51. size="mini"
  52. :disabled="single"
  53. @click="handleUpdate"
  54. v-hasPermi="['todo:todoItems:edit']"
  55. >修改</el-button>
  56. </el-col>
  57. <el-col :span="1.5">
  58. <el-button
  59. type="danger"
  60. plain
  61. icon="el-icon-delete"
  62. size="mini"
  63. :disabled="multiple"
  64. @click="handleDelete"
  65. v-hasPermi="['todo:todoItems:remove']"
  66. >删除</el-button>
  67. </el-col>
  68. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  69. </el-row>
  70. <el-table
  71. v-loading="loading"
  72. :data="todoItemsList"
  73. @selection-change="handleSelectionChange"
  74. >
  75. <el-table-column type="selection" width="55" align="center" />
  76. <el-table-column label="ID" align="center" prop="id" />
  77. <el-table-column label="标题" align="center" prop="title" />
  78. <el-table-column label="分配者" align="center" prop="creatorName" />
  79. <el-table-column label="执行人" align="center" prop="assigneeName" />
  80. <el-table-column label="描述" align="center" prop="description" show-overflow-tooltip />
  81. <el-table-column label="状态" align="center" prop="status">
  82. <template slot-scope="scope">
  83. <el-tag :type="getStatusType(scope.row.status)" size="small">
  84. {{ getStatusLabel(scope.row.status) }}
  85. </el-tag>
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="优先级" align="center" prop="priority">
  89. <template slot-scope="scope">
  90. <el-tag :type="getPriorityType(scope.row.priority)" size="small">
  91. {{ getPriorityLabel(scope.row.priority) }}
  92. </el-tag>
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="截止时间" align="center" prop="dueDate" width="180">
  96. <template slot-scope="scope">
  97. <span>{{ parseTime(scope.row.dueDate, '{y}-{m}-{d}') }}</span>
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  101. <template slot-scope="scope">
  102. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
  106. <template slot-scope="scope">
  107. <el-button
  108. size="mini"
  109. type="text"
  110. icon="el-icon-edit"
  111. @click="handleUpdate(scope.row)"
  112. v-hasPermi="['todo:todoItems:edit']"
  113. >修改</el-button>
  114. <!-- <el-button-->
  115. <!-- size="mini"-->
  116. <!-- type="text"-->
  117. <!-- icon="el-icon-check"-->
  118. <!-- @click="handleUpdateStatus(scope.row)"-->
  119. <!-- v-hasPermi="['todo:todoItems:edit']"-->
  120. <!-- >更新状态</el-button>-->
  121. <el-button
  122. size="mini"
  123. type="text"
  124. icon="el-icon-user"
  125. @click="handleAssignExecutor(scope.row)"
  126. v-hasPermi="['todo:todoItems:edit']"
  127. class="assign-executor-btn"
  128. >分配执行者</el-button>
  129. <el-button
  130. size="mini"
  131. type="text"
  132. icon="el-icon-delete"
  133. @click="handleDelete(scope.row)"
  134. v-hasPermi="['todo:todoItems:remove']"
  135. >删除</el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <div class="pagination-wrapper">
  140. <pagination
  141. v-show="total>0"
  142. :total="total"
  143. :page.sync="queryParams.pageNum"
  144. :limit.sync="queryParams.pageSize"
  145. @pagination="getList"
  146. />
  147. </div>
  148. <!-- 添加或修改待办事项对话框 -->
  149. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  150. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  151. <el-form-item label="标题" prop="title">
  152. <el-input v-model="form.title" placeholder="请输入待办事项标题" />
  153. </el-form-item>
  154. <el-form-item label="描述" prop="description">
  155. <el-input v-model="form.description" type="textarea" placeholder="请输入描述" />
  156. </el-form-item>
  157. <el-form-item label="状态" prop="status">
  158. <el-select v-model="form.status" placeholder="请选择状态" default-first-option>
  159. <el-option
  160. v-for="dict in statusOptions"
  161. :key="dict.dictValue"
  162. :label="dict.dictLabel"
  163. :value="dict.dictValue"
  164. />
  165. </el-select>
  166. </el-form-item>
  167. <el-form-item label="优先级" prop="priority">
  168. <el-select v-model="form.priority" placeholder="请选择优先级">
  169. <el-option
  170. v-for="dict in priorityOptions"
  171. :key="dict.dictValue"
  172. :label="dict.dictLabel"
  173. :value="dict.dictValue"
  174. ></el-option>
  175. </el-select>
  176. </el-form-item>
  177. <el-form-item label="截止时间" prop="dueDate">
  178. <el-date-picker clearable
  179. v-model="form.dueDate"
  180. type="date"
  181. value-format="yyyy-MM-dd"
  182. placeholder="请选择截止时间">
  183. </el-date-picker>
  184. </el-form-item>
  185. </el-form>
  186. <div slot="footer" class="dialog-footer">
  187. <el-button type="primary" @click="submitForm">确 定</el-button>
  188. <el-button @click="cancel">取 消</el-button>
  189. </div>
  190. </el-dialog>
  191. <!-- 更新状态对话框 -->
  192. <el-dialog title="更新状态" :visible.sync="statusOpen" width="300px" append-to-body>
  193. <el-form ref="statusForm" :model="statusForm" label-width="80px">
  194. <el-form-item label="状态" prop="status">
  195. <el-select v-model="statusForm.status" placeholder="请选择状态">
  196. <el-option
  197. v-for="dict in statusOptions"
  198. :key="dict.dictValue"
  199. :label="dict.dictLabel"
  200. :value="dict.dictValue"
  201. ></el-option>
  202. </el-select>
  203. </el-form-item>
  204. </el-form>
  205. <div slot="footer" class="dialog-footer">
  206. <el-button type="primary" @click="submitStatusForm">确 定</el-button>
  207. <el-button @click="cancelStatus">取 消</el-button>
  208. </div>
  209. </el-dialog>
  210. <!-- 分配执行者对话框 -->
  211. <el-dialog title="分配执行者" :visible.sync="assignOpen" width="500px" append-to-body>
  212. <el-form ref="assignForm" :model="assignForm" :rules="assignRules" label-width="80px">
  213. <el-form-item label="待办事项" prop="title">
  214. <el-input v-model="assignForm.title" disabled />
  215. </el-form-item>
  216. <el-form-item label="执行者" prop="executorId">
  217. <el-select v-model="assignForm.executorId" placeholder="请选择执行者" filterable class="executor-select">
  218. <el-option
  219. v-for="executor in executorList"
  220. :key="executor.userId"
  221. :label="executor.userName"
  222. :value="executor.userId"
  223. ></el-option>
  224. </el-select>
  225. <div class="el-form-item__tip">
  226. <small>执行者列表会根据搜索条件中的公司名称进行过滤</small>
  227. </div>
  228. </el-form-item>
  229. </el-form>
  230. <div slot="footer" class="dialog-footer">
  231. <el-button type="primary" @click="submitAssignForm">确 定</el-button>
  232. <el-button @click="cancelAssign">取 消</el-button>
  233. </div>
  234. </el-dialog>
  235. </div>
  236. </template>
  237. <script>
  238. import { listTodoItems, getTodoItems, delTodoItems, addTodoItems, updateTodoItems, updateTodoItemsStatus, assignExecutor, getExecutorList, getUserList } from "@/api/todo/todoItems";
  239. import {parseTime} from "../../../utils/common";
  240. export default {
  241. name: "TodoItems",
  242. data() {
  243. return {
  244. // 遮罩层
  245. loading: true,
  246. // 选中数组
  247. ids: [],
  248. // 非单个禁用
  249. single: true,
  250. // 非多个禁用
  251. multiple: true,
  252. // 显示搜索条件
  253. showSearch: true,
  254. // 总条数
  255. total: 0,
  256. // 待办事项表格数据
  257. todoItemsList: [],
  258. // 弹出层标题
  259. title: "",
  260. // 是否显示弹出层
  261. open: false,
  262. // 是否显示状态更新弹出层
  263. statusOpen: false,
  264. // 是否显示分配执行者弹出层
  265. assignOpen: false,
  266. // 状态选项
  267. statusOptions: [],
  268. // 优先级选项
  269. priorityOptions: [],
  270. todoItemTypeOptions: [],
  271. // 执行者列表
  272. executorList: [],
  273. // 查询参数
  274. queryParams: {
  275. pageNum: 1,
  276. pageSize: 10,
  277. title: null,
  278. companyName: null,
  279. status: null
  280. },
  281. // 表单参数
  282. form: {
  283. status: 0
  284. },
  285. // 状态表单参数
  286. statusForm: {},
  287. // 分配执行者表单参数
  288. assignForm: {
  289. id: null,
  290. title: '',
  291. executorId: null,
  292. remark: ''
  293. },
  294. // 表单校验
  295. rules: {
  296. title: [
  297. { required: true, message: "标题不能为空", trigger: "blur" }
  298. ],
  299. status: [
  300. { required: true, message: "状态不能为空", trigger: "change" }
  301. ]
  302. },
  303. // 分配执行者表单校验
  304. assignRules: {
  305. executorId: [
  306. { required: true, message: "请选择执行者", trigger: "change" }
  307. ]
  308. }
  309. };
  310. },
  311. created() {
  312. this.getList();
  313. this.getDicts("todo_status").then(response => {
  314. this.statusOptions = response.data;
  315. });
  316. this.getDicts("todo_priority").then(response => {
  317. this.priorityOptions = response.data;
  318. });
  319. this.getDicts("todo_item_type").then(response => {
  320. this.todoItemTypeOptions = response.data;
  321. });
  322. // 获取执行者列表
  323. this.getExecutorList();
  324. },
  325. methods: {
  326. parseTime,
  327. /** 查询待办事项列表 */
  328. getList() {
  329. this.loading = true;
  330. listTodoItems(this.queryParams).then(response => {
  331. this.todoItemsList = response.data.list;
  332. this.total = response.data.total;
  333. this.loading = false;
  334. });
  335. },
  336. /** 获取执行者列表 */
  337. getExecutorList() {
  338. const params = {
  339. companyName: this.queryParams.companyName || '',
  340. companyId: null,
  341. pageNum: 1,
  342. pageSize: 10 // 获取足够多的执行者供选择
  343. };
  344. getUserList(params).then(response => {
  345. if (response.code === 200) {
  346. this.executorList = response.data || [];
  347. }
  348. });
  349. },
  350. /** 获取状态标签 */
  351. getStatusLabel(status) {
  352. const statusOption = this.statusOptions.find(option => option.dictValue === String(status));
  353. return statusOption ? statusOption.dictLabel : '未知';
  354. },
  355. /** 获取状态标签类型(颜色) */
  356. getStatusType(status) {
  357. const statusMap = {
  358. '0': 'info', // 待处理 - 蓝色
  359. '1': 'warning', // 进行中 - 橙色
  360. '2': 'success', // 已完成 - 绿色
  361. '3': 'danger' // 已取消 - 红色
  362. };
  363. return statusMap[String(status)] || 'info';
  364. },
  365. /** 获取优先级标签 */
  366. getPriorityLabel(priority) {
  367. const priorityOption = this.priorityOptions.find(option => option.dictValue === String(priority));
  368. return priorityOption ? priorityOption.dictLabel : '未知';
  369. },
  370. /** 获取优先级标签类型(颜色) */
  371. getPriorityType(priority) {
  372. const priorityMap = {
  373. '0': 'info', // 低 - 蓝色
  374. '1': 'success', // 中 - 绿色
  375. '2': 'warning', // 高 - 橙色
  376. '3': 'danger' // 紧急 - 红色
  377. };
  378. return priorityMap[String(priority)] || 'info';
  379. },
  380. // 取消按钮
  381. cancel() {
  382. this.open = false;
  383. this.reset();
  384. },
  385. // 取消状态更新
  386. cancelStatus() {
  387. this.statusOpen = false;
  388. this.statusForm = {};
  389. },
  390. // 表单重置
  391. reset() {
  392. this.form = {
  393. id: null,
  394. title: null,
  395. description: null,
  396. status: null,
  397. priority: null,
  398. dueDate: null
  399. };
  400. this.resetForm("form");
  401. },
  402. /** 搜索按钮操作 */
  403. handleQuery() {
  404. this.queryParams.pageNum = 1;
  405. this.getList();
  406. // 更新执行者列表
  407. this.getExecutorList();
  408. },
  409. /** 重置按钮操作 */
  410. resetQuery() {
  411. this.resetForm("queryForm");
  412. this.handleQuery();
  413. // 重置后更新执行者列表
  414. this.getExecutorList();
  415. },
  416. // 多选框选中数据
  417. handleSelectionChange(selection) {
  418. this.ids = selection.map(item => item.id)
  419. this.single = selection.length!==1
  420. this.multiple = !selection.length
  421. },
  422. /** 新增按钮操作 */
  423. handleAdd() {
  424. this.reset();
  425. this.open = true;
  426. this.title = "添加待办事项";
  427. },
  428. /** 修改按钮操作 */
  429. handleUpdate(row) {
  430. this.reset();
  431. const id = row.id || this.ids
  432. // 确保id是单个值,如果是数组则取第一个
  433. const todoId = Array.isArray(id) ? id[0] : id;
  434. getTodoItems(todoId).then(response => {
  435. this.form = response.data;
  436. // 确保数据类型匹配
  437. if (this.form.status !== null && this.form.status !== undefined) {
  438. this.form.status = String(this.form.status);
  439. }
  440. if (this.form.priority !== null && this.form.priority !== undefined) {
  441. this.form.priority = String(this.form.priority);
  442. }
  443. this.open = true;
  444. this.title = "修改待办事项";
  445. });
  446. },
  447. /** 更新状态按钮操作 */
  448. handleUpdateStatus(row) {
  449. this.statusForm = {
  450. id: row.id,
  451. status: String(row.status)
  452. };
  453. this.statusOpen = true;
  454. },
  455. /** 分配执行者按钮操作 */
  456. handleAssignExecutor(row) {
  457. this.assignForm = {
  458. id: row.id,
  459. title: row.title,
  460. executorId: row.executorId || null,
  461. remark: ''
  462. };
  463. this.assignOpen = true;
  464. },
  465. /** 提交按钮 */
  466. submitForm() {
  467. this.$refs["form"].validate(valid => {
  468. if (valid) {
  469. if (this.form.id != null) {
  470. updateTodoItems(this.form).then(response => {
  471. this.$message.success("修改成功");
  472. this.open = false;
  473. this.getList();
  474. });
  475. } else {
  476. addTodoItems(this.form).then(response => {
  477. this.$message.success("新增成功");
  478. this.open = false;
  479. this.getList();
  480. });
  481. }
  482. }
  483. });
  484. },
  485. /** 提交状态更新 */
  486. submitStatusForm() {
  487. updateTodoItemsStatus(this.statusForm.id, this.statusForm.status).then(response => {
  488. this.$message.success("状态更新成功");
  489. this.statusOpen = false;
  490. this.getList();
  491. });
  492. },
  493. /** 提交分配执行者 */
  494. submitAssignForm() {
  495. this.$refs["assignForm"].validate(valid => {
  496. if (valid) {
  497. assignExecutor(this.assignForm).then(response => {
  498. this.$message.success("执行者分配成功");
  499. this.assignOpen = false;
  500. this.getList();
  501. });
  502. }
  503. });
  504. },
  505. /** 取消分配执行者 */
  506. cancelAssign() {
  507. this.assignOpen = false;
  508. this.assignForm = {
  509. id: null,
  510. title: '',
  511. executorId: null,
  512. remark: ''
  513. };
  514. },
  515. /** 删除按钮操作 */
  516. handleDelete(row) {
  517. const ids = row.id || this.ids;
  518. this.$confirm('是否确认删除待办事项编号为"' + ids + '"的数据项?').then(function() {
  519. return delTodoItems(ids);
  520. }).then(() => {
  521. this.getList();
  522. this.$message.success("删除成功");
  523. }).catch(() => {});
  524. }
  525. }
  526. }
  527. </script>
  528. <style scoped>
  529. .mb8 {
  530. margin-bottom: 8px;
  531. }
  532. .fixed-width {
  533. width: 100px;
  534. }
  535. .assign-executor-btn {
  536. margin-left: 5px;
  537. }
  538. .executor-select {
  539. width: 100%;
  540. }
  541. .el-form-item__tip {
  542. margin-top: 5px;
  543. color: #909399;
  544. font-size: 12px;
  545. }
  546. /* 标签样式优化 */
  547. .el-tag {
  548. border-radius: 12px;
  549. font-weight: 500;
  550. padding: 4px 12px;
  551. border: none;
  552. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  553. }
  554. /* 分页样式 */
  555. .pagination-wrapper {
  556. margin-top: 20px;
  557. }
  558. .el-pagination {
  559. text-align: center;
  560. padding: 20px;
  561. background: #fff;
  562. border-radius: 8px;
  563. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  564. }
  565. /* 对话框样式 */
  566. .el-dialog {
  567. border-radius: 12px;
  568. overflow: hidden;
  569. }
  570. .el-dialog__header {
  571. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  572. color: white;
  573. padding: 20px;
  574. }
  575. .el-dialog__title {
  576. color: white;
  577. font-weight: 600;
  578. }
  579. .el-dialog__body {
  580. padding: 30px;
  581. }
  582. .el-dialog__footer {
  583. padding: 20px;
  584. border-top: 1px solid #ebeef5;
  585. background: #f8f9fa;
  586. }
  587. </style>