index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="分组名" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入分组名"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="创建者ID" prop="createUserId">
  14. <el-input
  15. v-model="queryParams.createUserId"
  16. placeholder="请输入创建者ID"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="创建者ID" prop="isDel">
  23. <el-input
  24. v-model="queryParams.isDel"
  25. placeholder="请输入创建者ID"
  26. clearable
  27. size="small"
  28. @keyup.enter.native="handleQuery"
  29. />
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  33. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  34. </el-form-item>
  35. </el-form>
  36. <el-row :gutter="10" class="mb8">
  37. <el-col :span="1.5">
  38. <el-button
  39. type="primary"
  40. icon="el-icon-plus"
  41. size="mini"
  42. @click="handleAdd"
  43. v-hasPermi="['store:materialGroup:add']"
  44. >新增</el-button>
  45. </el-col>
  46. <el-col :span="1.5">
  47. <el-button
  48. type="success"
  49. icon="el-icon-edit"
  50. size="mini"
  51. :disabled="single"
  52. @click="handleUpdate"
  53. v-hasPermi="['store:materialGroup:edit']"
  54. >修改</el-button>
  55. </el-col>
  56. <el-col :span="1.5">
  57. <el-button
  58. type="danger"
  59. icon="el-icon-delete"
  60. size="mini"
  61. :disabled="multiple"
  62. @click="handleDelete"
  63. v-hasPermi="['store:materialGroup:remove']"
  64. >删除</el-button>
  65. </el-col>
  66. <el-col :span="1.5">
  67. <el-button
  68. type="warning"
  69. icon="el-icon-download"
  70. size="mini"
  71. @click="handleExport"
  72. v-hasPermi="['store:materialGroup:export']"
  73. >导出</el-button>
  74. </el-col>
  75. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  76. </el-row>
  77. <el-table v-loading="loading" :data="materialGroupList" @selection-change="handleSelectionChange" border>
  78. <el-table-column type="selection" width="55" align="center" />
  79. <el-table-column label="PK" align="center" prop="groupId" />
  80. <el-table-column label="分组名" align="center" prop="name" />
  81. <el-table-column label="创建者ID" align="center" prop="createUserId" />
  82. <el-table-column label="创建者ID" align="center" prop="isDel" />
  83. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  84. <template slot-scope="scope">
  85. <el-button
  86. size="mini"
  87. type="text"
  88. icon="el-icon-edit"
  89. @click="handleUpdate(scope.row)"
  90. v-hasPermi="['store:materialGroup:edit']"
  91. >修改</el-button>
  92. <el-button
  93. size="mini"
  94. type="text"
  95. icon="el-icon-delete"
  96. @click="handleDelete(scope.row)"
  97. v-hasPermi="['store:materialGroup:remove']"
  98. >删除</el-button>
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. <pagination
  103. v-show="total>0"
  104. :total="total"
  105. :page.sync="queryParams.pageNum"
  106. :limit.sync="queryParams.pageSize"
  107. @pagination="getList"
  108. />
  109. <!-- 添加或修改素材分组对话框 -->
  110. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  111. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  112. <el-form-item label="分组名" prop="name">
  113. <el-input v-model="form.name" placeholder="请输入分组名" />
  114. </el-form-item>
  115. <el-form-item label="创建者ID" prop="createUserId">
  116. <el-input v-model="form.createUserId" placeholder="请输入创建者ID" />
  117. </el-form-item>
  118. <el-form-item label="创建者ID" prop="isDel">
  119. <el-input v-model="form.isDel" placeholder="请输入创建者ID" />
  120. </el-form-item>
  121. </el-form>
  122. <div slot="footer" class="dialog-footer">
  123. <el-button type="primary" @click="submitForm">确 定</el-button>
  124. <el-button @click="cancel">取 消</el-button>
  125. </div>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import { listMaterialGroup, getMaterialGroup, delMaterialGroup, addMaterialGroup, updateMaterialGroup, exportMaterialGroup } from "@/api/store/materialGroup";
  131. export default {
  132. name: "MaterialGroup",
  133. data() {
  134. return {
  135. // 遮罩层
  136. loading: true,
  137. // 选中数组
  138. ids: [],
  139. // 非单个禁用
  140. single: true,
  141. // 非多个禁用
  142. multiple: true,
  143. // 显示搜索条件
  144. showSearch: true,
  145. // 总条数
  146. total: 0,
  147. // 素材分组表格数据
  148. materialGroupList: [],
  149. // 弹出层标题
  150. title: "",
  151. // 是否显示弹出层
  152. open: false,
  153. // 查询参数
  154. queryParams: {
  155. pageNum: 1,
  156. pageSize: 10,
  157. name: null,
  158. createUserId: null,
  159. isDel: null
  160. },
  161. // 表单参数
  162. form: {},
  163. // 表单校验
  164. rules: {
  165. name: [
  166. { required: true, message: "分组名不能为空", trigger: "blur" }
  167. ],
  168. createTime: [
  169. { required: true, message: "创建时间不能为空", trigger: "blur" }
  170. ],
  171. }
  172. };
  173. },
  174. created() {
  175. this.getList();
  176. },
  177. methods: {
  178. /** 查询素材分组列表 */
  179. getList() {
  180. this.loading = true;
  181. listMaterialGroup(this.queryParams).then(response => {
  182. this.materialGroupList = response.rows;
  183. this.total = response.total;
  184. this.loading = false;
  185. });
  186. },
  187. // 取消按钮
  188. cancel() {
  189. this.open = false;
  190. this.reset();
  191. },
  192. // 表单重置
  193. reset() {
  194. this.form = {
  195. groupId: null,
  196. name: null,
  197. createTime: null,
  198. updateTime: null,
  199. createUserId: null,
  200. isDel: null
  201. };
  202. this.resetForm("form");
  203. },
  204. /** 搜索按钮操作 */
  205. handleQuery() {
  206. this.queryParams.pageNum = 1;
  207. this.getList();
  208. },
  209. /** 重置按钮操作 */
  210. resetQuery() {
  211. this.resetForm("queryForm");
  212. this.handleQuery();
  213. },
  214. // 多选框选中数据
  215. handleSelectionChange(selection) {
  216. this.ids = selection.map(item => item.groupId)
  217. this.single = selection.length!==1
  218. this.multiple = !selection.length
  219. },
  220. /** 新增按钮操作 */
  221. handleAdd() {
  222. this.reset();
  223. this.open = true;
  224. this.title = "添加素材分组";
  225. },
  226. /** 修改按钮操作 */
  227. handleUpdate(row) {
  228. this.reset();
  229. const groupId = row.groupId || this.ids
  230. getMaterialGroup(groupId).then(response => {
  231. this.form = response.data;
  232. this.open = true;
  233. this.title = "修改素材分组";
  234. });
  235. },
  236. /** 提交按钮 */
  237. submitForm() {
  238. this.$refs["form"].validate(valid => {
  239. if (valid) {
  240. if (this.form.groupId != null) {
  241. updateMaterialGroup(this.form).then(response => {
  242. if (response.code === 200) {
  243. this.msgSuccess("修改成功");
  244. this.open = false;
  245. this.getList();
  246. }
  247. });
  248. } else {
  249. addMaterialGroup(this.form).then(response => {
  250. if (response.code === 200) {
  251. this.msgSuccess("新增成功");
  252. this.open = false;
  253. this.getList();
  254. }
  255. });
  256. }
  257. }
  258. });
  259. },
  260. /** 删除按钮操作 */
  261. handleDelete(row) {
  262. const groupIds = row.groupId || this.ids;
  263. this.$confirm('是否确认删除素材分组编号为"' + groupIds + '"的数据项?', "警告", {
  264. confirmButtonText: "确定",
  265. cancelButtonText: "取消",
  266. type: "warning"
  267. }).then(function() {
  268. return delMaterialGroup(groupIds);
  269. }).then(() => {
  270. this.getList();
  271. this.msgSuccess("删除成功");
  272. }).catch(function() {});
  273. },
  274. /** 导出按钮操作 */
  275. handleExport() {
  276. const queryParams = this.queryParams;
  277. this.$confirm('是否确认导出所有素材分组数据项?', "警告", {
  278. confirmButtonText: "确定",
  279. cancelButtonText: "取消",
  280. type: "warning"
  281. }).then(function() {
  282. return exportMaterialGroup(queryParams);
  283. }).then(response => {
  284. this.download(response.msg);
  285. }).catch(function() {});
  286. }
  287. }
  288. };
  289. </script>