index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. type="primary"
  10. @click="handleSearchList()"
  11. size="small">
  12. 查询搜索
  13. </el-button>
  14. <el-button
  15. style="float:right;margin-right: 15px"
  16. @click="handleResetSearch()"
  17. size="small">
  18. 重置
  19. </el-button>
  20. </div>
  21. <div style="margin-top: 15px">
  22. <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
  23. <el-form-item label="品牌名称:">
  24. <el-input v-model="listQuery.brandName" class="input-width" placeholder="品牌名称"></el-input>
  25. </el-form-item>
  26. <el-form-item label="推荐状态:">
  27. <el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
  28. <el-option v-for="item in recommendOptions"
  29. :key="item.value"
  30. :label="item.label"
  31. :value="item.value">
  32. </el-option>
  33. </el-select>
  34. </el-form-item>
  35. </el-form>
  36. </div>
  37. </el-card>
  38. <el-card class="operate-container" shadow="never">
  39. <i class="el-icon-tickets"></i>
  40. <span>数据列表</span>
  41. <el-button size="mini" class="btn-add" @click="handleSelectBrand()">选择品牌</el-button>
  42. </el-card>
  43. <div class="table-container">
  44. <el-table ref="homeBrandTable"
  45. :data="list"
  46. style="width: 100%;"
  47. @selection-change="handleSelectionChange"
  48. v-loading="listLoading" border>
  49. <el-table-column type="selection" width="60" align="center"></el-table-column>
  50. <el-table-column label="编号" width="120" align="center">
  51. <template slot-scope="scope">{{scope.row.id}}</template>
  52. </el-table-column>
  53. <el-table-column label="品牌名称" align="center">
  54. <template slot-scope="scope">{{scope.row.brandName}}</template>
  55. </el-table-column>
  56. <el-table-column label="是否推荐" width="200" align="center">
  57. <template slot-scope="scope">
  58. <el-switch
  59. @change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
  60. :active-value="1"
  61. :inactive-value="0"
  62. v-model="scope.row.recommendStatus">
  63. </el-switch>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="排序" width="160" align="center">
  67. <template slot-scope="scope">{{scope.row.sort}}</template>
  68. </el-table-column>
  69. <el-table-column label="状态" width="160" align="center">
  70. <template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
  71. </el-table-column>
  72. <el-table-column label="操作" width="180" align="center">
  73. <template slot-scope="scope">
  74. <el-button size="mini"
  75. type="text"
  76. @click="handleEditSort(scope.$index, scope.row)">设置排序
  77. </el-button>
  78. <el-button size="mini"
  79. type="text"
  80. @click="handleDelete(scope.$index, scope.row)">删除
  81. </el-button>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. </div>
  86. <div class="batch-operate-container">
  87. <el-select
  88. size="small"
  89. v-model="operateType" placeholder="批量操作">
  90. <el-option
  91. v-for="item in operates"
  92. :key="item.value"
  93. :label="item.label"
  94. :value="item.value">
  95. </el-option>
  96. </el-select>
  97. <el-button
  98. style="margin-left: 20px"
  99. class="search-button"
  100. @click="handleBatchOperate()"
  101. type="primary"
  102. size="small">
  103. 确定
  104. </el-button>
  105. </div>
  106. <div class="pagination-container">
  107. <el-pagination
  108. background
  109. @size-change="handleSizeChange"
  110. @current-change="handleCurrentChange"
  111. layout="total, sizes,prev, pager, next,jumper"
  112. :page-size="listQuery.pageSize"
  113. :page-sizes="[5,10,15]"
  114. :current-page.sync="listQuery.pageNum"
  115. :total="total">
  116. </el-pagination>
  117. </div>
  118. <el-dialog title="选择品牌" :visible.sync="selectDialogVisible" width="40%">
  119. <el-input v-model="dialogData.listQuery.keyword"
  120. style="width: 250px;margin-bottom: 20px"
  121. size="small"
  122. placeholder="品牌名称搜索">
  123. <el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
  124. </el-input>
  125. <el-table :data="dialogData.list"
  126. @selection-change="handleDialogSelectionChange" border>
  127. <el-table-column type="selection" width="60" align="center"></el-table-column>
  128. <el-table-column label="品牌名称"align="center">
  129. <template slot-scope="scope">{{scope.row.name}}</template>
  130. </el-table-column>
  131. <el-table-column label="相关" width="220" align="center">
  132. <template slot-scope="scope">
  133. 商品:<span class="color-main">{{scope.row.productCount}}</span>
  134. 评价:<span class="color-main">{{scope.row.productCommentCount}}</span>
  135. </template>
  136. </el-table-column>
  137. </el-table>
  138. <div class="pagination-container">
  139. <el-pagination
  140. background
  141. @size-change="handleDialogSizeChange"
  142. @current-change="handleDialogCurrentChange"
  143. layout="prev, pager, next"
  144. :current-page.sync="dialogData.listQuery.pageNum"
  145. :page-size="dialogData.listQuery.pageSize"
  146. :page-sizes="[5,10,15]"
  147. :total="dialogData.total">
  148. </el-pagination>
  149. </div>
  150. <div style="clear: both;"></div>
  151. <div slot="footer">
  152. <el-button size="small" @click="selectDialogVisible = false">取 消</el-button>
  153. <el-button size="small" type="primary" @click="handleSelectDialogConfirm()">确 定</el-button>
  154. </div>
  155. </el-dialog>
  156. <el-dialog title="设置排序"
  157. :visible.sync="sortDialogVisible"
  158. width="40%">
  159. <el-form :model="sortDialogData"
  160. label-width="150px">
  161. <el-form-item label="排序:">
  162. <el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
  163. </el-form-item>
  164. </el-form>
  165. <span slot="footer">
  166. <el-button @click="sortDialogVisible = false" size="small">取 消</el-button>
  167. <el-button type="primary" @click="handleUpdateSort" size="small">确 定</el-button>
  168. </span>
  169. </el-dialog>
  170. </div>
  171. </template>
  172. <script>
  173. import {fetchList,updateRecommendStatus,deleteHomeBrand,createHomeBrand,updateHomeBrandSort} from '@/api/homeBrand';
  174. import {fetchList as fetchBrandList} from '@/api/brand';
  175. const defaultListQuery = {
  176. pageNum: 1,
  177. pageSize: 5,
  178. brandName: null,
  179. recommendStatus: null
  180. };
  181. const defaultRecommendOptions = [
  182. {
  183. label: '未推荐',
  184. value: 0
  185. },
  186. {
  187. label: '推荐中',
  188. value: 1
  189. }
  190. ];
  191. export default {
  192. name: 'homeBrandList',
  193. data() {
  194. return {
  195. listQuery: Object.assign({}, defaultListQuery),
  196. recommendOptions: Object.assign({}, defaultRecommendOptions),
  197. list: null,
  198. total: null,
  199. listLoading: false,
  200. multipleSelection: [],
  201. operates: [
  202. {
  203. label: "设为推荐",
  204. value: 0
  205. },
  206. {
  207. label: "取消推荐",
  208. value: 1
  209. },
  210. {
  211. label: "删除",
  212. value: 2
  213. }
  214. ],
  215. operateType: null,
  216. selectDialogVisible:false,
  217. dialogData:{
  218. list: null,
  219. total: null,
  220. multipleSelection:[],
  221. listQuery:{
  222. keyword: null,
  223. pageNum: 1,
  224. pageSize: 5
  225. }
  226. },
  227. sortDialogVisible:false,
  228. sortDialogData:{sort:0,id:null}
  229. }
  230. },
  231. created() {
  232. this.getList();
  233. this.getDialogList();
  234. },
  235. filters:{
  236. formatRecommendStatus(status){
  237. if(status===1){
  238. return '推荐中';
  239. }else{
  240. return '未推荐';
  241. }
  242. }
  243. },
  244. methods: {
  245. handleResetSearch() {
  246. this.listQuery = Object.assign({}, defaultListQuery);
  247. },
  248. handleSearchList() {
  249. this.listQuery.pageNum = 1;
  250. this.getList();
  251. },
  252. handleSelectionChange(val){
  253. this.multipleSelection = val;
  254. },
  255. handleSizeChange(val) {
  256. this.listQuery.pageNum = 1;
  257. this.listQuery.pageSize = val;
  258. this.getList();
  259. },
  260. handleCurrentChange(val) {
  261. this.listQuery.pageNum = val;
  262. this.getList();
  263. },
  264. handleRecommendStatusStatusChange(index,row){
  265. this.updateRecommendStatusStatus(row.id,row.recommendStatus);
  266. },
  267. handleDelete(index,row){
  268. this.deleteBrand(row.id);
  269. },
  270. handleBatchOperate(){
  271. if (this.multipleSelection < 1) {
  272. this.$message({
  273. message: '请选择一条记录',
  274. type: 'warning',
  275. duration: 1000
  276. });
  277. return;
  278. }
  279. let ids = [];
  280. for (let i = 0; i < this.multipleSelection.length; i++) {
  281. ids.push(this.multipleSelection[i].id);
  282. }
  283. if (this.operateType === 0) {
  284. //设为推荐
  285. this.updateRecommendStatusStatus(ids,1);
  286. } else if (this.operateType === 1) {
  287. //取消推荐
  288. this.updateRecommendStatusStatus(ids,0);
  289. } else if(this.operateType===2){
  290. //删除
  291. this.deleteBrand(ids);
  292. }else {
  293. this.$message({
  294. message: '请选择批量操作类型',
  295. type: 'warning',
  296. duration: 1000
  297. });
  298. return;
  299. }
  300. },
  301. handleSelectBrand(){
  302. this.selectDialogVisible=true;
  303. },
  304. handleSelectSearch(){
  305. this.getDialogList();
  306. },
  307. handleDialogSizeChange(val) {
  308. this.dialogData.listQuery.pageNum = 1;
  309. this.dialogData.listQuery.pageSize = val;
  310. this.getDialogList();
  311. },
  312. handleDialogCurrentChange(val) {
  313. this.dialogData.listQuery.pageNum = val;
  314. this.getDialogList();
  315. },
  316. handleDialogSelectionChange(val){
  317. this.dialogData.multipleSelection = val;
  318. },
  319. handleSelectDialogConfirm(){
  320. if (this.dialogData.multipleSelection < 1) {
  321. this.$message({
  322. message: '请选择一条记录',
  323. type: 'warning',
  324. duration: 1000
  325. });
  326. return;
  327. }
  328. let selectBrands = [];
  329. for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
  330. selectBrands.push({
  331. brandId:this.dialogData.multipleSelection[i].id,
  332. brandName:this.dialogData.multipleSelection[i].name
  333. });
  334. }
  335. this.$confirm('使用要进行添加操作?', '提示', {
  336. confirmButtonText: '确定',
  337. cancelButtonText: '取消',
  338. type: 'warning'
  339. }).then(() => {
  340. createHomeBrand(selectBrands).then(response=>{
  341. this.selectDialogVisible=false;
  342. this.dialogData.multipleSelection=[];
  343. this.getList();
  344. this.$message({
  345. type: 'success',
  346. message: '添加成功!'
  347. });
  348. });
  349. });
  350. },
  351. handleEditSort(index,row){
  352. this.sortDialogVisible=true;
  353. this.sortDialogData.sort=row.sort;
  354. this.sortDialogData.id=row.id;
  355. },
  356. handleUpdateSort(){
  357. this.$confirm('是否要修改排序?', '提示', {
  358. confirmButtonText: '确定',
  359. cancelButtonText: '取消',
  360. type: 'warning'
  361. }).then(() => {
  362. updateHomeBrandSort(this.sortDialogData).then(response=>{
  363. this.sortDialogVisible=false;
  364. this.getList();
  365. this.$message({
  366. type: 'success',
  367. message: '删除成功!'
  368. });
  369. });
  370. })
  371. },
  372. getList() {
  373. this.listLoading = true;
  374. fetchList(this.listQuery).then(response => {
  375. this.listLoading = false;
  376. this.list = response.data.list;
  377. this.total = response.data.total;
  378. })
  379. },
  380. updateRecommendStatusStatus(ids,status){
  381. this.$confirm('是否要修改推荐状态?', '提示', {
  382. confirmButtonText: '确定',
  383. cancelButtonText: '取消',
  384. type: 'warning'
  385. }).then(() => {
  386. let params=new URLSearchParams();
  387. params.append("ids",ids);
  388. params.append("recommendStatus",status);
  389. updateRecommendStatus(params).then(response=>{
  390. this.getList();
  391. this.$message({
  392. type: 'success',
  393. message: '修改成功!'
  394. });
  395. });
  396. }).catch(() => {
  397. this.$message({
  398. type: 'success',
  399. message: '已取消操作!'
  400. });
  401. this.getList();
  402. });
  403. },
  404. deleteBrand(ids){
  405. this.$confirm('是否要删除该推荐?', '提示', {
  406. confirmButtonText: '确定',
  407. cancelButtonText: '取消',
  408. type: 'warning'
  409. }).then(() => {
  410. let params=new URLSearchParams();
  411. params.append("ids",ids);
  412. deleteHomeBrand(params).then(response=>{
  413. this.getList();
  414. this.$message({
  415. type: 'success',
  416. message: '删成功!'
  417. });
  418. });
  419. })
  420. },
  421. getDialogList(){
  422. fetchBrandList(this.dialogData.listQuery).then(response=>{
  423. this.dialogData.list=response.data.list;
  424. this.dialogData.total=response.data.total;
  425. })
  426. }
  427. }
  428. }
  429. </script>
  430. <style></style>