index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="app-container">
  3. <!-- <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. :inline="true"
  7. v-show="showSearch"
  8. label-width="90px"
  9. >
  10. <el-form-item label="位置">
  11. <el-select
  12. v-model="queryParams.location"
  13. placeholder="请选择位置"
  14. clearable
  15. @change="queryParams.pageNum = 1;getList()"
  16. >
  17. <el-option
  18. :label="item.dictLabel"
  19. :value="item.dictValue"
  20. v-for="(item, index) in bannerLocationList"
  21. :key="index"
  22. />
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button
  27. type="primary"
  28. icon="el-icon-search"
  29. size="mini"
  30. @click="handleQuery"
  31. >搜索</el-button
  32. >
  33. <el-button icon="el-icon-refresh" size="mini" @click="getList(true)"
  34. >重置</el-button
  35. >
  36. </el-form-item>
  37. </el-form> -->
  38. <el-row :gutter="10" class="mb8">
  39. <el-col :span="1.5">
  40. <el-button
  41. type="primary"
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="['business:category:add']"
  46. >添加分类</el-button
  47. >
  48. </el-col>
  49. <right-toolbar
  50. :showSearch.sync="showSearch"
  51. @queryTable="getList()"
  52. ></right-toolbar>
  53. </el-row>
  54. <!-- 列表 -->
  55. <el-table ref="table" v-loading="loading" :data="list">
  56. <el-table-column label="分类名称" prop="name" />
  57. <el-table-column label="分类图片">
  58. <div slot-scope="{ row }">
  59. <el-image
  60. style="width: 100px; height: 100px"
  61. :src="row.picUrl"
  62. :preview-src-list="[row.picUrl]"
  63. />
  64. </div>
  65. </el-table-column>
  66. <el-table-column label="排序" align="center">
  67. <template slot-scope="{ row }">
  68. <div>{{ row.sort }}</div>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="状态" prop="status" align="center">
  72. <template slot-scope="{ row }">
  73. <el-tag :type="row.isShow === 1 ? 'success' : 'info'">{{
  74. row.isShow === 1 ? "显示" : "不显示"
  75. }}</el-tag>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="操作" align="center">
  79. <template slot-scope="{ row }">
  80. <div>
  81. <el-button
  82. v-hasPermi="['business:category:edit']"
  83. type="text"
  84. @click="edit(row)"
  85. >编辑</el-button
  86. >
  87. <el-button
  88. v-hasPermi="['business:category:remove']"
  89. type="text"
  90. class="del"
  91. @click="del(row)"
  92. >删除</el-button
  93. >
  94. </div>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. <!-- 分页 -->
  99. <pagination
  100. v-show="total > 0"
  101. :total="total"
  102. :page.sync="pageParams.pageNum"
  103. :limit.sync="pageParams.pageSize"
  104. @pagination="getList"
  105. />
  106. <category-create
  107. v-if="createShow"
  108. :category-id="categoryId"
  109. :dialog-show="createShow"
  110. @close="close"
  111. />
  112. </div>
  113. </template>
  114. <script>
  115. import { publicFileGetUrl } from "@/api/common";
  116. import {
  117. goodsCategoryList,
  118. goodsCategoryRemove,
  119. } from "@/api/business/category";
  120. import CategoryCreate from "./components/CategoryCreate";
  121. export default {
  122. name: "ListCate",
  123. components: {
  124. CategoryCreate,
  125. },
  126. data() {
  127. return {
  128. loading: false,
  129. showSearch: true,
  130. queryParams: {},
  131. pageParams: {
  132. pageNum: 1,
  133. pageSize: 10,
  134. },
  135. // 总条数
  136. total: 0,
  137. list: [],
  138. createShow: false,
  139. categoryId: '',
  140. };
  141. },
  142. created() {
  143. this.getList();
  144. },
  145. methods: {
  146. getList() {
  147. this.loading = true;
  148. goodsCategoryList(
  149. "pageNum=" +
  150. this.pageParams.pageNum +
  151. "&pageSize=" +
  152. this.pageParams.pageSize +
  153. "&",
  154. this.queryParams
  155. )
  156. .then((res) => {
  157. this.loading = false;
  158. if (res.code == 0) {
  159. res.rows.forEach((item) => {
  160. item.picUrl = publicFileGetUrl + item.picUrl.split(",")[0];
  161. });
  162. this.total = res.total;
  163. this.list = res.rows;
  164. }
  165. })
  166. .catch(() => {
  167. this.loading = false;
  168. });
  169. },
  170. del(item) {
  171. this.$confirm(`确认删除分类 “${item.name}” 吗?`, "删除分类", {
  172. confirmButtonText: "确定",
  173. cancelButtonText: "取消",
  174. type: "warning",
  175. }).then(() => {
  176. goodsCategoryRemove({ categoryId: item.categoryId }).then((res) => {
  177. if (res.code === 0) {
  178. this.$message.success("操作已完成!");
  179. this.getList();
  180. }
  181. });
  182. });
  183. },
  184. edit(item){
  185. this.categoryId = item.categoryId
  186. this.createShow = true;
  187. },
  188. // 重置
  189. resetQuery() {
  190. this.pageParams.pageNum = 1
  191. this.getList();
  192. },
  193. handleAdd() {
  194. this.createShow = true;
  195. },
  196. // 关闭弹框
  197. close() {
  198. this.createShow = false;
  199. this.categoryId = ''
  200. this.getList();
  201. },
  202. },
  203. };
  204. </script>
  205. <style>
  206. </style>