index.vue 5.4 KB

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