index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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.productName" 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="handleSelectProduct()">选择商品</el-button>
  42. </el-card>
  43. <div class="table-container">
  44. <el-table ref="newProductTable"
  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.productName}}</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="50%">
  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="160" align="center">
  132. <template slot-scope="scope">NO.{{scope.row.productSn}}</template>
  133. </el-table-column>
  134. <el-table-column label="价格" width="120" align="center">
  135. <template slot-scope="scope">¥{{scope.row.price}}</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,deleteNewProduct,createNewProduct,updateNewProductSort} from '@/api/newProduct';
  174. import {fetchList as fetchProductList} from '@/api/product';
  175. const defaultListQuery = {
  176. pageNum: 1,
  177. pageSize: 5,
  178. productName: 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: 'newProductList',
  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. },
  234. filters:{
  235. formatRecommendStatus(status){
  236. if(status===1){
  237. return '推荐中';
  238. }else{
  239. return '未推荐';
  240. }
  241. }
  242. },
  243. methods: {
  244. handleResetSearch() {
  245. this.listQuery = Object.assign({}, defaultListQuery);
  246. },
  247. handleSearchList() {
  248. this.listQuery.pageNum = 1;
  249. this.getList();
  250. },
  251. handleSelectionChange(val){
  252. this.multipleSelection = val;
  253. },
  254. handleSizeChange(val) {
  255. this.listQuery.pageNum = 1;
  256. this.listQuery.pageSize = val;
  257. this.getList();
  258. },
  259. handleCurrentChange(val) {
  260. this.listQuery.pageNum = val;
  261. this.getList();
  262. },
  263. handleRecommendStatusStatusChange(index,row){
  264. this.updateRecommendStatusStatus(row.id,row.recommendStatus);
  265. },
  266. handleDelete(index,row){
  267. this.deleteProduct(row.id);
  268. },
  269. handleBatchOperate(){
  270. if (this.multipleSelection < 1) {
  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. if (this.operateType === 0) {
  283. //设为推荐
  284. this.updateRecommendStatusStatus(ids,1);
  285. } else if (this.operateType === 1) {
  286. //取消推荐
  287. this.updateRecommendStatusStatus(ids,0);
  288. } else if(this.operateType===2){
  289. //删除
  290. this.deleteProduct(ids);
  291. }else {
  292. this.$message({
  293. message: '请选择批量操作类型',
  294. type: 'warning',
  295. duration: 1000
  296. });
  297. }
  298. },
  299. handleSelectProduct(){
  300. this.selectDialogVisible=true;
  301. this.getDialogList();
  302. },
  303. handleSelectSearch(){
  304. this.getDialogList();
  305. },
  306. handleDialogSizeChange(val) {
  307. this.dialogData.listQuery.pageNum = 1;
  308. this.dialogData.listQuery.pageSize = val;
  309. this.getDialogList();
  310. },
  311. handleDialogCurrentChange(val) {
  312. this.dialogData.listQuery.pageNum = val;
  313. this.getDialogList();
  314. },
  315. handleDialogSelectionChange(val){
  316. this.dialogData.multipleSelection = val;
  317. },
  318. handleSelectDialogConfirm(){
  319. if (this.dialogData.multipleSelection < 1) {
  320. this.$message({
  321. message: '请选择一条记录',
  322. type: 'warning',
  323. duration: 1000
  324. });
  325. return;
  326. }
  327. let selectProducts = [];
  328. for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
  329. selectProducts.push({
  330. productId:this.dialogData.multipleSelection[i].id,
  331. productName:this.dialogData.multipleSelection[i].name
  332. });
  333. }
  334. this.$confirm('使用要进行添加操作?', '提示', {
  335. confirmButtonText: '确定',
  336. cancelButtonText: '取消',
  337. type: 'warning'
  338. }).then(() => {
  339. createNewProduct(selectProducts).then(response=>{
  340. this.selectDialogVisible=false;
  341. this.dialogData.multipleSelection=[];
  342. this.getList();
  343. this.$message({
  344. type: 'success',
  345. message: '添加成功!'
  346. });
  347. });
  348. });
  349. },
  350. handleEditSort(index,row){
  351. this.sortDialogVisible=true;
  352. this.sortDialogData.sort=row.sort;
  353. this.sortDialogData.id=row.id;
  354. },
  355. handleUpdateSort(){
  356. this.$confirm('是否要修改排序?', '提示', {
  357. confirmButtonText: '确定',
  358. cancelButtonText: '取消',
  359. type: 'warning'
  360. }).then(() => {
  361. updateNewProductSort(this.sortDialogData).then(response=>{
  362. this.sortDialogVisible=false;
  363. this.getList();
  364. this.$message({
  365. type: 'success',
  366. message: '删除成功!'
  367. });
  368. });
  369. })
  370. },
  371. getList() {
  372. this.listLoading = true;
  373. fetchList(this.listQuery).then(response => {
  374. this.listLoading = false;
  375. this.list = response.data.list;
  376. this.total = response.data.total;
  377. })
  378. },
  379. updateRecommendStatusStatus(ids,status){
  380. this.$confirm('是否要修改推荐状态?', '提示', {
  381. confirmButtonText: '确定',
  382. cancelButtonText: '取消',
  383. type: 'warning'
  384. }).then(() => {
  385. let params=new URLSearchParams();
  386. params.append("ids",ids);
  387. params.append("recommendStatus",status);
  388. updateRecommendStatus(params).then(response=>{
  389. this.getList();
  390. this.$message({
  391. type: 'success',
  392. message: '修改成功!'
  393. });
  394. });
  395. }).catch(() => {
  396. this.$message({
  397. type: 'success',
  398. message: '已取消操作!'
  399. });
  400. this.getList();
  401. });
  402. },
  403. deleteProduct(ids){
  404. this.$confirm('是否要删除该推荐?', '提示', {
  405. confirmButtonText: '确定',
  406. cancelButtonText: '取消',
  407. type: 'warning'
  408. }).then(() => {
  409. let params=new URLSearchParams();
  410. params.append("ids",ids);
  411. deleteNewProduct(params).then(response=>{
  412. this.getList();
  413. this.$message({
  414. type: 'success',
  415. message: '删除成功!'
  416. });
  417. });
  418. })
  419. },
  420. getDialogList(){
  421. fetchProductList(this.dialogData.listQuery).then(response=>{
  422. this.dialogData.list=response.data.list;
  423. this.dialogData.total=response.data.total;
  424. })
  425. }
  426. }
  427. }
  428. </script>
  429. <style></style>