index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template> 
  2. <div class="app-container">
  3. <el-card class="filter-container" shadow="never">
  4. <div>
  5. <i class="el-icon-search"></i>
  6. <span>筛选搜索</span>
  7. <el-button
  8. style="float: right"
  9. @click="searchBrandList()"
  10. type="primary"
  11. size="small">
  12. 查询结果
  13. </el-button>
  14. </div>
  15. <div style="margin-top: 15px">
  16. <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
  17. <el-form-item label="输入搜索:">
  18. <el-input style="width: 203px" v-model="listQuery.keyword" placeholder="品牌名称/关键字"></el-input>
  19. </el-form-item>
  20. </el-form>
  21. </div>
  22. </el-card>
  23. <el-card class="operate-container" shadow="never">
  24. <i class="el-icon-tickets"></i>
  25. <span>数据列表</span>
  26. <el-button
  27. v-if="createbrand"
  28. class="btn-add"
  29. @click="addBrand()"
  30. size="mini">
  31. 添加
  32. </el-button>
  33. </el-card>
  34. <div class="table-container">
  35. <el-table ref="brandTable"
  36. :data="list"
  37. style="width: 100%"
  38. @selection-change="handleSelectionChange"
  39. v-loading="listLoading"
  40. border>
  41. <el-table-column type="selection" width="60" align="center"></el-table-column>
  42. <el-table-column label="编号" width="100" align="center">
  43. <template slot-scope="scope">{{scope.row.id}}</template>
  44. </el-table-column>
  45. <el-table-column label="品牌名称" align="center">
  46. <template slot-scope="scope">{{scope.row.name}}</template>
  47. </el-table-column>
  48. <el-table-column label="品牌首字母" width="100" align="center">
  49. <template slot-scope="scope">{{scope.row.firstLetter}}</template>
  50. </el-table-column>
  51. <el-table-column label="排序" width="100" align="center">
  52. <template slot-scope="scope">{{scope.row.sort}}</template>
  53. </el-table-column>
  54. <el-table-column label="品牌制造商" width="100" align="center">
  55. <template slot-scope="scope">
  56. <el-switch
  57. @change="handleFactoryStatusChange(scope.$index, scope.row)"
  58. :active-value="1"
  59. :inactive-value="0"
  60. v-model="scope.row.factoryStatus">
  61. </el-switch>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="是否显示" width="100" align="center">
  65. <template slot-scope="scope">
  66. <el-switch
  67. @change="handleShowStatusChange(scope.$index, scope.row)"
  68. :active-value="1"
  69. :inactive-value="0"
  70. v-model="scope.row.showStatus">
  71. </el-switch>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="相关" width="220" align="center">
  75. <template slot-scope="scope">
  76. <span>商品:</span>
  77. <el-button
  78. size="mini"
  79. type="text"
  80. @click="getProductList(scope.$index, scope.row)">100
  81. </el-button>
  82. <span>评价:</span>
  83. <el-button
  84. size="mini"
  85. type="text"
  86. @click="getProductCommentList(scope.$index, scope.row)">1000
  87. </el-button>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="操作" width="200" align="center">
  91. <template slot-scope="scope">
  92. <el-button
  93. v-if="updatebrand"
  94. size="mini"
  95. @click="handleUpdate(scope.$index, scope.row)">编辑
  96. </el-button>
  97. <el-button
  98. v-if="deletebrand"
  99. size="mini"
  100. type="danger"
  101. @click="handleDelete(scope.$index, scope.row)">删除
  102. </el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. </div>
  107. <div class="batch-operate-container">
  108. <el-select
  109. size="small"
  110. v-model="operateType" placeholder="批量操作">
  111. <el-option
  112. v-for="item in operates"
  113. :key="item.value"
  114. :label="item.label"
  115. :value="item.value">
  116. </el-option>
  117. </el-select>
  118. <el-button
  119. style="margin-left: 20px"
  120. class="search-button"
  121. @click="handleBatchOperate()"
  122. type="primary"
  123. size="small">
  124. 确定
  125. </el-button>
  126. </div>
  127. <div class="pagination-container">
  128. <el-pagination
  129. background
  130. @size-change="handleSizeChange"
  131. @current-change="handleCurrentChange"
  132. layout="total, sizes,prev, pager, next,jumper"
  133. :page-size="listQuery.pageSize"
  134. :page-sizes="[5,10,15]"
  135. :current-page.sync="listQuery.pageNum"
  136. :total="total">
  137. </el-pagination>
  138. </div>
  139. </div>
  140. </template>
  141. <script>
  142. import {fetchList, updateShowStatus, updateFactoryStatus, deleteBrand} from '@/api/brand'
  143. import {createbrand,updatebrand,deletebrand} from '@/api/permissions'
  144. export default {
  145. name: 'brandList',
  146. data() {
  147. return {
  148. createbrand,
  149. updatebrand,
  150. deletebrand,
  151. operates: [
  152. {
  153. label: "显示品牌",
  154. value: "showBrand"
  155. },
  156. {
  157. label: "隐藏品牌",
  158. value: "hideBrand"
  159. }
  160. ],
  161. operateType: null,
  162. listQuery: {
  163. keyword: null,
  164. pageNum: 1,
  165. pageSize: 10
  166. },
  167. list: null,
  168. total: null,
  169. listLoading: true,
  170. multipleSelection: []
  171. }
  172. },
  173. created() {
  174. this.getList();
  175. },
  176. methods: {
  177. getList() {
  178. this.listLoading = true;
  179. fetchList(this.listQuery).then(response => {
  180. this.listLoading = false;
  181. this.list = response.data.list;
  182. this.total = response.data.total;
  183. this.totalPage = response.data.totalPage;
  184. this.pageSize = response.data.pageSize;
  185. });
  186. },
  187. handleSelectionChange(val) {
  188. this.multipleSelection = val;
  189. },
  190. handleUpdate(index, row) {
  191. this.$router.push({path: '/pms/updateBrand', query: {id: row.id}})
  192. },
  193. handleDelete(index, row) {
  194. this.$confirm('是否要删除该品牌', '提示', {
  195. confirmButtonText: '确定',
  196. cancelButtonText: '取消',
  197. type: 'warning'
  198. }).then(() => {
  199. deleteBrand(row.id).then(response => {
  200. this.$message({
  201. message: '删除成功',
  202. type: 'success',
  203. duration: 1000
  204. });
  205. this.getList();
  206. });
  207. });
  208. },
  209. getProductList(index, row) {
  210. console.log(index, row);
  211. },
  212. getProductCommentList(index, row) {
  213. console.log(index, row);
  214. },
  215. handleFactoryStatusChange(index, row) {
  216. var data = new URLSearchParams();
  217. data.append("ids", row.id);
  218. data.append("factoryStatus", row.factoryStatus);
  219. updateFactoryStatus(data).then(response => {
  220. this.$message({
  221. message: '修改成功',
  222. type: 'success',
  223. duration: 1000
  224. });
  225. }).catch(error => {
  226. if (row.factoryStatus === 0) {
  227. row.factoryStatus = 1;
  228. } else {
  229. row.factoryStatus = 0;
  230. }
  231. });
  232. },
  233. handleShowStatusChange(index, row) {
  234. let data = new URLSearchParams();
  235. ;
  236. data.append("ids", row.id);
  237. data.append("showStatus", row.showStatus);
  238. updateShowStatus(data).then(response => {
  239. this.$message({
  240. message: '修改成功',
  241. type: 'success',
  242. duration: 1000
  243. });
  244. }).catch(error => {
  245. if (row.showStatus === 0) {
  246. row.showStatus = 1;
  247. } else {
  248. row.showStatus = 0;
  249. }
  250. });
  251. },
  252. handleSizeChange(val) {
  253. this.listQuery.pageNum = 1;
  254. this.listQuery.pageSize = val;
  255. this.getList();
  256. },
  257. handleCurrentChange(val) {
  258. this.listQuery.pageNum = val;
  259. this.getList();
  260. },
  261. searchBrandList() {
  262. this.listQuery.pageNum = 1;
  263. this.getList();
  264. },
  265. handleBatchOperate() {
  266. console.log(this.multipleSelection);
  267. if (this.multipleSelection < 1) {
  268. this.$message({
  269. message: '请选择一条记录',
  270. type: 'warning',
  271. duration: 1000
  272. });
  273. return;
  274. }
  275. let showStatus = 0;
  276. if (this.operateType === 'showBrand') {
  277. showStatus = 1;
  278. } else if (this.operateType === 'hideBrand') {
  279. showStatus = 0;
  280. } else {
  281. this.$message({
  282. message: '请选择批量操作类型',
  283. type: 'warning',
  284. duration: 1000
  285. });
  286. return;
  287. }
  288. let ids = [];
  289. for (let i = 0; i < this.multipleSelection.length; i++) {
  290. ids.push(this.multipleSelection[i].id);
  291. }
  292. let data = new URLSearchParams();
  293. data.append("ids", ids);
  294. data.append("showStatus", showStatus);
  295. updateShowStatus(data).then(response => {
  296. this.getList();
  297. this.$message({
  298. message: '修改成功',
  299. type: 'success',
  300. duration: 1000
  301. });
  302. });
  303. },
  304. addBrand() {
  305. this.$router.push({path: '/pms/addBrand'})
  306. }
  307. }
  308. }
  309. </script>
  310. <style rel="stylesheet/scss" lang="scss" scoped>
  311. </style>