index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. </div>
  157. </template>
  158. <script>
  159. import {fetchList,updateRecommendStatus,deleteHomeBrand,createHomeBrand} from '@/api/homeBrand';
  160. import {fetchList as fetchBrandList} from '@/api/brand';
  161. const defaultListQuery = {
  162. pageNum: 1,
  163. pageSize: 5,
  164. brandName: null,
  165. recommendStatus: null
  166. };
  167. const defaultRecommendOptions = [
  168. {
  169. label: '未推荐',
  170. value: 0
  171. },
  172. {
  173. label: '推荐中',
  174. value: 1
  175. }
  176. ];
  177. export default {
  178. name: 'homeBrandList',
  179. data() {
  180. return {
  181. listQuery: Object.assign({}, defaultListQuery),
  182. recommendOptions: Object.assign({}, defaultRecommendOptions),
  183. list: null,
  184. total: null,
  185. listLoading: false,
  186. multipleSelection: [],
  187. operates: [
  188. {
  189. label: "设为推荐",
  190. value: 0
  191. },
  192. {
  193. label: "取消推荐",
  194. value: 1
  195. },
  196. {
  197. label: "删除",
  198. value: 2
  199. }
  200. ],
  201. operateType: null,
  202. selectDialogVisible:false,
  203. dialogData:{
  204. list: null,
  205. total: null,
  206. multipleSelection:[],
  207. listQuery:{
  208. keyword: null,
  209. pageNum: 1,
  210. pageSize: 5
  211. }
  212. }
  213. }
  214. },
  215. created() {
  216. this.getList();
  217. this.getDialogList();
  218. },
  219. filters:{
  220. formatRecommendStatus(status){
  221. if(status===1){
  222. return '推荐中';
  223. }else{
  224. return '未推荐';
  225. }
  226. }
  227. },
  228. methods: {
  229. handleResetSearch() {
  230. this.listQuery = Object.assign({}, defaultListQuery);
  231. },
  232. handleSearchList() {
  233. this.listQuery.pageNum = 1;
  234. this.getList();
  235. },
  236. handleSelectionChange(val){
  237. this.multipleSelection = val;
  238. },
  239. handleSizeChange(val) {
  240. this.listQuery.pageNum = 1;
  241. this.listQuery.pageSize = val;
  242. this.getList();
  243. },
  244. handleCurrentChange(val) {
  245. this.listQuery.pageNum = val;
  246. this.getList();
  247. },
  248. handleRecommendStatusStatusChange(index,row){
  249. this.updateRecommendStatusStatus(row.id,row.recommendStatus);
  250. },
  251. handleDelete(index,row){
  252. this.deleteBrand(row.id);
  253. },
  254. handleBatchOperate(){
  255. if (this.multipleSelection < 1) {
  256. this.$message({
  257. message: '请选择一条记录',
  258. type: 'warning',
  259. duration: 1000
  260. });
  261. return;
  262. }
  263. let ids = [];
  264. for (let i = 0; i < this.multipleSelection.length; i++) {
  265. ids.push(this.multipleSelection[i].id);
  266. }
  267. if (this.operateType === 0) {
  268. //设为推荐
  269. this.updateRecommendStatusStatus(ids,1);
  270. } else if (this.operateType === 1) {
  271. //取消推荐
  272. this.updateRecommendStatusStatus(ids,0);
  273. } else if(this.operateType===2){
  274. //删除
  275. this.deleteBrand(ids);
  276. }else {
  277. this.$message({
  278. message: '请选择批量操作类型',
  279. type: 'warning',
  280. duration: 1000
  281. });
  282. return;
  283. }
  284. },
  285. handleSelectBrand(){
  286. this.selectDialogVisible=true;
  287. },
  288. handleSelectSearch(){
  289. this.getDialogList();
  290. },
  291. handleDialogSizeChange(val) {
  292. this.dialogData.listQuery.pageNum = 1;
  293. this.dialogData.listQuery.pageSize = val;
  294. this.getDialogList();
  295. },
  296. handleDialogCurrentChange(val) {
  297. this.dialogData.listQuery.pageNum = val;
  298. this.getDialogList();
  299. },
  300. handleDialogSelectionChange(val){
  301. this.dialogData.multipleSelection = val;
  302. },
  303. handleSelectDialogConfirm(){
  304. if (this.dialogData.multipleSelection < 1) {
  305. this.$message({
  306. message: '请选择一条记录',
  307. type: 'warning',
  308. duration: 1000
  309. });
  310. return;
  311. }
  312. let selectBrands = [];
  313. for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
  314. selectBrands.push({
  315. brandId:this.dialogData.multipleSelection[i].id,
  316. brandName:this.dialogData.multipleSelection[i].name
  317. });
  318. }
  319. this.$confirm('使用要进行添加操作?', '提示', {
  320. confirmButtonText: '确定',
  321. cancelButtonText: '取消',
  322. type: 'warning'
  323. }).then(() => {
  324. createHomeBrand(selectBrands).then(response=>{
  325. this.selectDialogVisible=false;
  326. this.dialogData.multipleSelection=[];
  327. this.getList();
  328. this.$message({
  329. type: 'success',
  330. message: '添加成功!'
  331. });
  332. });
  333. });
  334. },
  335. getList() {
  336. this.listLoading = true;
  337. fetchList(this.listQuery).then(response => {
  338. this.listLoading = false;
  339. this.list = response.data.list;
  340. this.total = response.data.total;
  341. })
  342. },
  343. updateRecommendStatusStatus(ids,status){
  344. this.$confirm('是否要修改推荐状态?', '提示', {
  345. confirmButtonText: '确定',
  346. cancelButtonText: '取消',
  347. type: 'warning'
  348. }).then(() => {
  349. let params=new URLSearchParams();
  350. params.append("ids",ids);
  351. params.append("recommendStatus",status);
  352. updateRecommendStatus(params).then(response=>{
  353. this.getList();
  354. this.$message({
  355. type: 'success',
  356. message: '修改成功!'
  357. });
  358. });
  359. })
  360. },
  361. deleteBrand(ids){
  362. this.$confirm('是否要删除该推荐?', '提示', {
  363. confirmButtonText: '确定',
  364. cancelButtonText: '取消',
  365. type: 'warning'
  366. }).then(() => {
  367. let params=new URLSearchParams();
  368. params.append("ids",ids);
  369. deleteHomeBrand(params).then(response=>{
  370. this.getList();
  371. this.$message({
  372. type: 'success',
  373. message: '删成功!'
  374. });
  375. });
  376. })
  377. },
  378. getDialogList(){
  379. fetchBrandList(this.dialogData.listQuery).then(response=>{
  380. this.dialogData.list=response.data.list;
  381. this.dialogData.total=response.data.total;
  382. })
  383. }
  384. }
  385. }
  386. </script>
  387. <style></style>