index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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="status">
  13. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
  14. <el-option
  15. v-for="dict in statusOptions"
  16. :key="dict.dictValue"
  17. :label="dict.dictLabel"
  18. :value="dict.dictValue"
  19. />
  20. </el-select>
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  24. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  25. </el-form-item>
  26. </el-form>
  27. <el-row :gutter="10" class="mb8">
  28. <el-col :span="1.5">
  29. <el-button
  30. type="primary"
  31. plain
  32. icon="el-icon-plus"
  33. size="mini"
  34. @click="handleAdd"
  35. v-hasPermi="['todo:todoItems:add']"
  36. >新增</el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button
  40. type="success"
  41. plain
  42. icon="el-icon-edit"
  43. size="mini"
  44. :disabled="single"
  45. @click="handleUpdate"
  46. v-hasPermi="['todo:todoItems:edit']"
  47. >修改</el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="danger"
  52. plain
  53. icon="el-icon-delete"
  54. size="mini"
  55. :disabled="multiple"
  56. @click="handleDelete"
  57. v-hasPermi="['todo:todoItems:remove']"
  58. >删除</el-button>
  59. </el-col>
  60. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  61. </el-row>
  62. <el-table v-loading="loading" :data="todoItemsList" @selection-change="handleSelectionChange">
  63. <el-table-column type="selection" width="55" align="center" />
  64. <el-table-column label="ID" align="center" prop="id" />
  65. <el-table-column label="标题" align="center" prop="title" />
  66. <el-table-column label="描述" align="center" prop="description" show-overflow-tooltip />
  67. <el-table-column label="状态" align="center" prop="status">
  68. <template slot-scope="scope">
  69. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="优先级" align="center" prop="priority">
  73. <template slot-scope="scope">
  74. <dict-tag :options="priorityOptions" :value="scope.row.priority"/>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="截止时间" align="center" prop="dueDate" width="180">
  78. <template slot-scope="scope">
  79. <span>{{ parseTime(scope.row.dueDate, '{y}-{m}-{d}') }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  83. <template slot-scope="scope">
  84. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  88. <template slot-scope="scope">
  89. <el-button
  90. size="mini"
  91. type="text"
  92. icon="el-icon-edit"
  93. @click="handleUpdate(scope.row)"
  94. v-hasPermi="['todo:todoItems:edit']"
  95. >修改</el-button>
  96. <el-button
  97. size="mini"
  98. type="text"
  99. icon="el-icon-check"
  100. @click="handleUpdateStatus(scope.row)"
  101. v-hasPermi="['todo:todoItems:edit']"
  102. >更新状态</el-button>
  103. <el-button
  104. size="mini"
  105. type="text"
  106. icon="el-icon-delete"
  107. @click="handleDelete(scope.row)"
  108. v-hasPermi="['todo:todoItems:remove']"
  109. >删除</el-button>
  110. </template>
  111. </el-table-column>
  112. </el-table>
  113. <pagination
  114. v-show="total>0"
  115. :total="total"
  116. :page.sync="queryParams.pageNum"
  117. :limit.sync="queryParams.pageSize"
  118. @pagination="getList"
  119. />
  120. <!-- 添加或修改待办事项对话框 -->
  121. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  122. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  123. <el-form-item label="标题" prop="title">
  124. <el-input v-model="form.title" placeholder="请输入待办事项标题" />
  125. </el-form-item>
  126. <el-form-item label="描述" prop="description">
  127. <el-input v-model="form.description" type="textarea" placeholder="请输入描述" />
  128. </el-form-item>
  129. <el-form-item label="状态" prop="status">
  130. <el-select v-model="form.status" placeholder="请选择状态" default-first-option>
  131. <el-option
  132. v-for="dict in statusOptions"
  133. :key="dict.dictValue"
  134. :label="dict.dictLabel"
  135. :value="dict.dictValue"
  136. />
  137. </el-select>
  138. </el-form-item>
  139. <el-form-item label="优先级" prop="priority">
  140. <el-select v-model="form.priority" placeholder="请选择优先级">
  141. <el-option
  142. v-for="dict in priorityOptions"
  143. :key="dict.dictValue"
  144. :label="dict.dictLabel"
  145. :value="dict.dictValue"
  146. ></el-option>
  147. </el-select>
  148. </el-form-item>
  149. <el-form-item label="截止时间" prop="dueDate">
  150. <el-date-picker clearable
  151. v-model="form.dueDate"
  152. type="date"
  153. value-format="yyyy-MM-dd"
  154. placeholder="请选择截止时间">
  155. </el-date-picker>
  156. </el-form-item>
  157. </el-form>
  158. <div slot="footer" class="dialog-footer">
  159. <el-button type="primary" @click="submitForm">确 定</el-button>
  160. <el-button @click="cancel">取 消</el-button>
  161. </div>
  162. </el-dialog>
  163. <!-- 更新状态对话框 -->
  164. <el-dialog title="更新状态" :visible.sync="statusOpen" width="300px" append-to-body>
  165. <el-form ref="statusForm" :model="statusForm" label-width="80px">
  166. <el-form-item label="状态" prop="status">
  167. <el-select v-model="statusForm.status" placeholder="请选择状态">
  168. <el-option
  169. v-for="dict in statusOptions"
  170. :key="dict.dictValue"
  171. :label="dict.dictLabel"
  172. :value="dict.dictValue"
  173. ></el-option>
  174. </el-select>
  175. </el-form-item>
  176. </el-form>
  177. <div slot="footer" class="dialog-footer">
  178. <el-button type="primary" @click="submitStatusForm">确 定</el-button>
  179. <el-button @click="cancelStatus">取 消</el-button>
  180. </div>
  181. </el-dialog>
  182. </div>
  183. </template>
  184. <script>
  185. import { listTodoItems, getTodoItems, delTodoItems, addTodoItems, updateTodoItems, updateTodoItemsStatus } from "@/api/todo/todoItems";
  186. export default {
  187. name: "TodoItems",
  188. data() {
  189. return {
  190. // 遮罩层
  191. loading: true,
  192. // 选中数组
  193. ids: [],
  194. // 非单个禁用
  195. single: true,
  196. // 非多个禁用
  197. multiple: true,
  198. // 显示搜索条件
  199. showSearch: true,
  200. // 总条数
  201. total: 0,
  202. // 待办事项表格数据
  203. todoItemsList: [],
  204. // 弹出层标题
  205. title: "",
  206. // 是否显示弹出层
  207. open: false,
  208. // 是否显示状态更新弹出层
  209. statusOpen: false,
  210. // 状态选项
  211. statusOptions: [],
  212. // 优先级选项
  213. priorityOptions: [],
  214. todoItemTypeOptions: [],
  215. // 查询参数
  216. queryParams: {
  217. pageNum: 1,
  218. pageSize: 10,
  219. title: null,
  220. status: null
  221. },
  222. // 表单参数
  223. form: {
  224. status: 0
  225. },
  226. // 状态表单参数
  227. statusForm: {},
  228. // 表单校验
  229. rules: {
  230. title: [
  231. { required: true, message: "标题不能为空", trigger: "blur" }
  232. ],
  233. status: [
  234. { required: true, message: "状态不能为空", trigger: "change" }
  235. ]
  236. }
  237. };
  238. },
  239. created() {
  240. this.getList();
  241. this.getDicts("todo_status").then(response => {
  242. this.statusOptions = response.data;
  243. });
  244. this.getDicts("todo_priority").then(response => {
  245. this.priorityOptions = response.data;
  246. });
  247. this.getDicts("todo_item_type").then(response => {
  248. this.todoItemTypeOptions = response.data;
  249. });
  250. },
  251. methods: {
  252. /** 查询待办事项列表 */
  253. getList() {
  254. this.loading = true;
  255. listTodoItems(this.queryParams).then(response => {
  256. this.todoItemsList = response.data.list;
  257. this.total = response.data.total;
  258. this.loading = false;
  259. });
  260. },
  261. // 取消按钮
  262. cancel() {
  263. this.open = false;
  264. this.reset();
  265. },
  266. // 取消状态更新
  267. cancelStatus() {
  268. this.statusOpen = false;
  269. this.statusForm = {};
  270. },
  271. // 表单重置
  272. reset() {
  273. this.form = {
  274. id: null,
  275. title: null,
  276. description: null,
  277. status: null,
  278. priority: null,
  279. dueDate: null
  280. };
  281. this.resetForm("form");
  282. },
  283. /** 搜索按钮操作 */
  284. handleQuery() {
  285. this.queryParams.pageNum = 1;
  286. this.getList();
  287. },
  288. /** 重置按钮操作 */
  289. resetQuery() {
  290. this.resetForm("queryForm");
  291. this.handleQuery();
  292. },
  293. // 多选框选中数据
  294. handleSelectionChange(selection) {
  295. this.ids = selection.map(item => item.id)
  296. this.single = selection.length!==1
  297. this.multiple = !selection.length
  298. },
  299. /** 新增按钮操作 */
  300. handleAdd() {
  301. this.reset();
  302. this.open = true;
  303. this.title = "添加待办事项";
  304. },
  305. /** 修改按钮操作 */
  306. handleUpdate(row) {
  307. this.reset();
  308. const id = row.id || this.ids
  309. getTodoItems(id).then(response => {
  310. this.form = response.data;
  311. // 确保数据类型匹配
  312. if (this.form.status !== null && this.form.status !== undefined) {
  313. this.form.status = String(this.form.status);
  314. }
  315. if (this.form.priority !== null && this.form.priority !== undefined) {
  316. this.form.priority = String(this.form.priority);
  317. }
  318. this.open = true;
  319. this.title = "修改待办事项";
  320. });
  321. },
  322. /** 更新状态按钮操作 */
  323. handleUpdateStatus(row) {
  324. this.statusForm = {
  325. id: row.id,
  326. status: String(row.status)
  327. };
  328. this.statusOpen = true;
  329. },
  330. /** 提交按钮 */
  331. submitForm() {
  332. this.$refs["form"].validate(valid => {
  333. if (valid) {
  334. if (this.form.id != null) {
  335. updateTodoItems(this.form).then(response => {
  336. this.$message.success("修改成功");
  337. this.open = false;
  338. this.getList();
  339. });
  340. } else {
  341. addTodoItems(this.form).then(response => {
  342. this.$message.success("新增成功");
  343. this.open = false;
  344. this.getList();
  345. });
  346. }
  347. }
  348. });
  349. },
  350. /** 提交状态更新 */
  351. submitStatusForm() {
  352. updateTodoItemsStatus(this.statusForm.id, this.statusForm.status).then(response => {
  353. this.$message.success("状态更新成功");
  354. this.statusOpen = false;
  355. this.getList();
  356. });
  357. },
  358. /** 删除按钮操作 */
  359. handleDelete(row) {
  360. const ids = row.id || this.ids;
  361. this.$confirm('是否确认删除待办事项编号为"' + ids + '"的数据项?').then(function() {
  362. return delTodoItems(ids);
  363. }).then(() => {
  364. this.getList();
  365. this.$message.success("删除成功");
  366. }).catch(() => {});
  367. }
  368. }
  369. }
  370. </script>
  371. <style scoped>
  372. .mb8 {
  373. margin-bottom: 8px;
  374. }
  375. .fixed-width {
  376. width: 100px;
  377. }
  378. </style>