category.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
  4. <el-form-item label="分类名称" prop="categoryName">
  5. <el-input
  6. v-model="queryParams.categoryName"
  7. placeholder="请输入分类名称"
  8. clearable
  9. style="width: 240px"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态" prop="status">
  14. <el-select
  15. v-model="queryParams.status"
  16. placeholder="分类状态"
  17. clearable
  18. style="width: 240px">
  19. <el-option :key="0" label="正常" :value="0"/>
  20. <el-option :key="1" label="停用" :value="1"/>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" style="margin-bottom: 8px">
  29. <el-col :span="1.5">
  30. <el-button
  31. type="primary"
  32. plain
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. v-hasPermi="['task:category:add']"
  37. >新增
  38. </el-button>
  39. </el-col>
  40. </el-row>
  41. <el-table :data="categoryList"
  42. border
  43. stripe
  44. size="mini">
  45. <el-table-column label="分类编号" prop="id" width="100"/>
  46. <el-table-column label="分类名称" prop="categoryName" :show-overflow-tooltip="true"/>
  47. <el-table-column label="分类描述" prop="description" :show-overflow-tooltip="true"/>
  48. <el-table-column label="状态" align="center">
  49. <template slot-scope="scope">
  50. <el-tag type="success" size="small" v-if="scope.row.status==0">正常</el-tag>
  51. <el-tag type="info" size="small" v-else>停用</el-tag>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  55. <template slot-scope="scope">
  56. <span>{{ parseTime(scope.row.createTime) }}</span>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  60. <template slot-scope="scope">
  61. <el-button
  62. size="mini"
  63. type="text"
  64. icon="el-icon-edit"
  65. @click="handleUpdate(scope.row)"
  66. v-hasPermi="['task:category:edit']"
  67. >修改
  68. </el-button>
  69. <el-button
  70. size="mini"
  71. type="text"
  72. icon="el-icon-delete"
  73. @click="handleDelete(scope.row)"
  74. v-hasPermi="['task:category:delete']"
  75. >删除
  76. </el-button>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. <div style="margin-top: 10px;text-align: center">
  81. <el-pagination
  82. background
  83. @size-change="handleSizeChange"
  84. @current-change="handleCurrentChange"
  85. :current-page="queryParams.pageNum"
  86. :page-sizes="[10, 20, 50]"
  87. :page-size="queryParams.pageSize"
  88. layout="total, sizes, prev, pager, next, jumper"
  89. :total="total">
  90. </el-pagination>
  91. </div>
  92. <!-- 添加或修改分类配置对话框 -->
  93. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  94. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  95. <el-form-item label="分类名称" prop="categoryName">
  96. <el-input v-model="form.categoryName" placeholder="请输入分类名称"/>
  97. </el-form-item>
  98. <el-form-item label="状态" prop="status">
  99. <el-radio-group v-model="form.status">
  100. <el-radio label="0">正常</el-radio>
  101. <el-radio label="1">停用</el-radio>
  102. </el-radio-group>
  103. </el-form-item>
  104. <el-form-item label="分类描述" prop="description">
  105. <el-input v-model="form.description" type="textarea" placeholder="请输入内容"></el-input>
  106. </el-form-item>
  107. </el-form>
  108. <div slot="footer" class="dialog-footer">
  109. <el-button type="primary" @click="submitForm">确 定</el-button>
  110. <el-button @click="cancel">取 消</el-button>
  111. </div>
  112. </el-dialog>
  113. </div>
  114. </template>
  115. <script>
  116. import {
  117. listCategory,
  118. getCategory,
  119. delCategory,
  120. addCategory,
  121. updateCategory
  122. } from "@/api/task/category";
  123. export default {
  124. name: "Category",
  125. data() {
  126. return {
  127. // 总条数
  128. total: 0,
  129. // 分类表格数据
  130. categoryList: [],
  131. // 弹出层标题
  132. title: "",
  133. // 是否显示弹出层
  134. open: false,
  135. // 是否显示弹出层(数据权限)
  136. openDataScope: false,
  137. // 查询参数
  138. queryParams: {
  139. pageNum: 1,
  140. pageSize: 10,
  141. categoryName: undefined,
  142. description: undefined,
  143. status: undefined
  144. },
  145. // 表单参数
  146. form: {},
  147. // 表单校验
  148. rules: {
  149. categoryName: [
  150. {required: true, message: "分类名称不能为空", trigger: "blur"}
  151. ],
  152. }
  153. };
  154. },
  155. created() {
  156. this.getList();
  157. },
  158. methods: {
  159. /** 查询分类列表 */
  160. getList() {
  161. listCategory(this.queryParams).then(res => {
  162. this.categoryList = res.data.records;
  163. this.total = res.data.total;
  164. }
  165. );
  166. },
  167. // 取消按钮
  168. cancel() {
  169. this.open = false;
  170. this.reset();
  171. },
  172. // 取消按钮(数据权限)
  173. cancelDataScope() {
  174. this.openDataScope = false;
  175. this.reset();
  176. },
  177. // 表单重置
  178. reset() {
  179. this.form = {
  180. id: undefined,
  181. categoryName: undefined,
  182. description: undefined,
  183. status: "0",
  184. };
  185. this.resetForm("form");
  186. },
  187. /** 搜索按钮操作 */
  188. handleQuery() {
  189. this.queryParams.pageNum = 1;
  190. this.getList();
  191. },
  192. /** 重置按钮操作 */
  193. resetQuery() {
  194. this.resetForm("queryForm");
  195. this.handleQuery();
  196. },
  197. handleSizeChange(val) {
  198. this.pageSize = val;
  199. this.getList();
  200. },
  201. handleCurrentChange(val) {
  202. this.pageNum = val;
  203. this.getList();
  204. },
  205. /** 新增按钮操作 */
  206. handleAdd() {
  207. this.reset();
  208. this.open = true;
  209. this.title = "添加分类";
  210. },
  211. /** 修改按钮操作 */
  212. handleUpdate(row) {
  213. this.reset();
  214. getCategory(row.id).then(res => {
  215. this.form = res.data;
  216. this.open = true;
  217. this.title = "修改分类";
  218. });
  219. },
  220. /** 提交按钮 */
  221. submitForm() {
  222. this.$refs["form"].validate(valid => {
  223. if (valid) {
  224. if (this.form.id != undefined) {
  225. updateCategory(this.form).then(res => {
  226. this.$message.success("修改成功");
  227. this.open = false;
  228. this.getList();
  229. });
  230. } else {
  231. addCategory(this.form).then(res => {
  232. this.$message.success("新增成功");
  233. this.open = false;
  234. this.getList();
  235. });
  236. }
  237. }
  238. });
  239. },
  240. /** 删除按钮操作 */
  241. handleDelete(row) {
  242. this.$confirm('是否确认删除分类编号为"' + row.id + '"的数据项?').then(() => {
  243. return delCategory(row.id);
  244. }).then(() => {
  245. this.getList();
  246. this.$message.success("删除成功");
  247. }).catch(() => {
  248. });
  249. },
  250. }
  251. };
  252. </script>