index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template> 
  2. <div class="app-container">
  3. <div class="filter-container container-frame">
  4. <div>
  5. <i class="el-icon-search" style="margin-top: 10px"></i>
  6. <span style="margin-top: 10px">筛选搜索</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: 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" style="margin-top: 5px"></i>
  27. <span style="margin-top: 5px">数据列表</span>
  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="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="220" align="center">
  91. <template slot-scope="scope">
  92. <el-button
  93. size="mini"
  94. @click="handleUpdate(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. handleUpdate(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. duration:1000
  198. });
  199. this.getList();
  200. });
  201. });
  202. },
  203. getProductList(index, row) {
  204. console.log(index, row);
  205. },
  206. getProductCommentList(index, row) {
  207. console.log(index, row);
  208. },
  209. handleFactoryStatusChange(index, row) {
  210. var data = new URLSearchParams();
  211. data.append("ids",row.id);
  212. data.append("factoryStatus",row.factoryStatus);
  213. updateFactoryStatus(data).then(response => {
  214. this.$message({
  215. message: '修改成功',
  216. type: 'success',
  217. duration:1000
  218. });
  219. }).catch(error => {
  220. if (row.factoryStatus === 0) {
  221. row.factoryStatus = 1;
  222. } else {
  223. row.factoryStatus = 0;
  224. }
  225. });
  226. },
  227. handleShowStatusChange(index, row) {
  228. let data = new URLSearchParams();;
  229. data.append("ids",row.id);
  230. data.append("showStatus",row.showStatus);
  231. updateShowStatus(data).then(response => {
  232. this.$message({
  233. message: '修改成功',
  234. type: 'success',
  235. duration:1000
  236. });
  237. }).catch(error => {
  238. if (row.showStatus === 0) {
  239. row.showStatus = 1;
  240. } else {
  241. row.showStatus = 0;
  242. }
  243. });
  244. },
  245. handleSizeChange(val) {
  246. this.listQuery.pageNum = 1;
  247. this.listQuery.pageSize = val;
  248. this.getList();
  249. },
  250. handleCurrentChange(val) {
  251. this.listQuery.pageNum = val;
  252. this.getList();
  253. },
  254. searchBrandList() {
  255. this.listQuery.pageNum = 1;
  256. this.getList();
  257. },
  258. handleBatchOperate() {
  259. if(this.multipleSelection<1){
  260. this.$message({
  261. message: '请选择一条记录',
  262. type: 'warning'
  263. });
  264. }
  265. let showStatus = 0;
  266. if(this.operateType==='showBrand'){
  267. showStatus = 1;
  268. }else if(this.operateType==='hideBrand'){
  269. showStatus = 0;
  270. }else{
  271. this.$message({
  272. message: '请选择批量操作类型',
  273. type: 'warning',
  274. duration:1000
  275. });
  276. return;
  277. }
  278. let ids = [];
  279. for(let i=0;i<this.multipleSelection.length;i++){
  280. ids.push(this.multipleSelection[i].id);
  281. }
  282. let data = new URLSearchParams();
  283. data.append("ids",ids);
  284. data.append("showStatus",showStatus);
  285. updateShowStatus(data).then(response => {
  286. this.getList();
  287. this.$message({
  288. message: '修改成功',
  289. type: 'success',
  290. duration:1000
  291. });
  292. });
  293. },
  294. addBrand() {
  295. this.$router.push({path: '/pms/addBrand'})
  296. }
  297. }
  298. }
  299. </script>
  300. <style rel="stylesheet/scss" lang="scss" scoped>
  301. .filter-container {
  302. }
  303. .operate-container {
  304. margin-top: 20px;
  305. }
  306. .operate-container .el-button {
  307. float: right;
  308. }
  309. .table-container {
  310. margin-top: 20px;
  311. }
  312. .batch-operate-container {
  313. display: inline-block;
  314. margin-top: 20px;
  315. }
  316. .pagination-container {
  317. display: inline-block;
  318. float: right;
  319. margin-top: 20px;
  320. }
  321. </style>