index.vue 9.2 KB

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