index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. @click="handleSearchList()"
  10. type="primary"
  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 style="width: 203px" v-model="listQuery.keyword" placeholder="商品名称"></el-input>
  25. </el-form-item>
  26. <el-form-item label="商品货号:">
  27. <el-input style="width: 203px" v-model="listQuery.productSn" placeholder="商品货号"></el-input>
  28. </el-form-item>
  29. <el-form-item label="商品分类:">
  30. <el-cascader
  31. clearable
  32. v-model="selectProductCateValue"
  33. :options="productCateOptions">
  34. </el-cascader>
  35. </el-form-item>
  36. <el-form-item label="商品品牌:">
  37. <el-select v-model="listQuery.brandId" placeholder="请选择品牌" clearable>
  38. <el-option
  39. v-for="item in brandOptions"
  40. :key="item.value"
  41. :label="item.label"
  42. :value="item.value">
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="上架状态:">
  47. <el-select v-model="listQuery.publishStatus" placeholder="全部" clearable>
  48. <el-option
  49. v-for="item in publishStatusOptions"
  50. :key="item.value"
  51. :label="item.label"
  52. :value="item.value">
  53. </el-option>
  54. </el-select>
  55. </el-form-item>
  56. <el-form-item label="审核状态:">
  57. <el-select v-model="listQuery.verifyStatus" placeholder="全部" clearable>
  58. <el-option
  59. v-for="item in verifyStatusOptions"
  60. :key="item.value"
  61. :label="item.label"
  62. :value="item.value">
  63. </el-option>
  64. </el-select>
  65. </el-form-item>
  66. </el-form>
  67. </div>
  68. </el-card>
  69. <el-card class="operate-container" shadow="never">
  70. <i class="el-icon-tickets"></i>
  71. <span>数据列表</span>
  72. <el-button
  73. class="btn-add"
  74. @click="handleAddProduct()"
  75. size="mini">
  76. 添加
  77. </el-button>
  78. </el-card>
  79. <div class="table-container">
  80. <el-table ref="productTable"
  81. :data="list"
  82. style="width: 100%"
  83. @selection-change="handleSelectionChange"
  84. v-loading="listLoading"
  85. border>
  86. <el-table-column type="selection" width="60" align="center"></el-table-column>
  87. <el-table-column label="编号" width="100" align="center">
  88. <template slot-scope="scope">{{scope.row.id}}</template>
  89. </el-table-column>
  90. <el-table-column label="商品图片" width="120" align="center">
  91. <template slot-scope="scope"><img style="height: 80px" :src="scope.row.pic"></template>
  92. </el-table-column>
  93. <el-table-column label="商品名称" align="center">
  94. <template slot-scope="scope">
  95. <p>{{scope.row.name}}</p>
  96. <p>品牌:{{scope.row.brandName}}</p>
  97. </template>
  98. </el-table-column>
  99. <el-table-column label="价格/货号" width="120" align="center">
  100. <template slot-scope="scope">
  101. <p>价格:¥{{scope.row.price}}</p>
  102. <p>货号:{{scope.row.productSn}}</p>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="标签" width="140" align="center">
  106. <template slot-scope="scope">
  107. <p>上架:
  108. <el-switch
  109. @change="handlePublishStatusChange(scope.$index, scope.row)"
  110. :active-value="1"
  111. :inactive-value="0"
  112. v-model="scope.row.publishStatus">
  113. </el-switch>
  114. </p>
  115. <p>新品:
  116. <el-switch
  117. @change="handleNewStatusChange(scope.$index, scope.row)"
  118. :active-value="1"
  119. :inactive-value="0"
  120. v-model="scope.row.newStatus">
  121. </el-switch>
  122. </p>
  123. <p>推荐:
  124. <el-switch
  125. @change="handleRecommendStatusChange(scope.$index, scope.row)"
  126. :active-value="1"
  127. :inactive-value="0"
  128. v-model="scope.row.recommandStatus">
  129. </el-switch>
  130. </p>
  131. </template>
  132. </el-table-column>
  133. <el-table-column label="排序" width="100" align="center">
  134. <template slot-scope="scope">{{scope.row.sort}}</template>
  135. </el-table-column>
  136. <el-table-column label="SKU库存" width="100" align="center">
  137. <template slot-scope="scope">
  138. <el-button type="primary" icon="el-icon-edit" @click="handleShowSkuEditDialog(scope.$index, scope.row)" circle></el-button>
  139. </template>
  140. </el-table-column>
  141. <el-table-column label="销量" width="100" align="center">
  142. <template slot-scope="scope">{{scope.row.sale}}</template>
  143. </el-table-column>
  144. <el-table-column label="审核状态" width="100" align="center">
  145. <template slot-scope="scope">
  146. <p>{{scope.row.verifyStatus | verifyStatusFilter}}</p>
  147. <p>
  148. <el-button
  149. type="text"
  150. @click="handleShowVerifyDetail(scope.$index, scope.row)">审核详情
  151. </el-button>
  152. </p>
  153. </template>
  154. </el-table-column>
  155. <el-table-column label="操作" width="160" align="center">
  156. <template slot-scope="scope">
  157. <p>
  158. <el-button
  159. size="mini"
  160. @click="handleShowProduct(scope.$index, scope.row)">查看
  161. </el-button>
  162. <el-button
  163. size="mini"
  164. @click="handleUpdateProduct(scope.$index, scope.row)">编辑
  165. </el-button>
  166. </p>
  167. <p>
  168. <el-button
  169. size="mini"
  170. @click="handleShowLog(scope.$index, scope.row)">日志
  171. </el-button>
  172. <el-button
  173. size="mini"
  174. type="danger"
  175. @click="handleDelete(scope.$index, scope.row)">删除
  176. </el-button>
  177. </p>
  178. </template>
  179. </el-table-column>
  180. </el-table>
  181. </div>
  182. <div class="batch-operate-container">
  183. <el-select
  184. size="small"
  185. v-model="operateType" placeholder="批量操作">
  186. <el-option
  187. v-for="item in operates"
  188. :key="item.value"
  189. :label="item.label"
  190. :value="item.value">
  191. </el-option>
  192. </el-select>
  193. <el-button
  194. style="margin-left: 20px"
  195. class="search-button"
  196. @click="handleBatchOperate()"
  197. type="primary"
  198. size="small">
  199. 确定
  200. </el-button>
  201. </div>
  202. <div class="pagination-container">
  203. <el-pagination
  204. background
  205. @size-change="handleSizeChange"
  206. @current-change="handleCurrentChange"
  207. layout="total, sizes,prev, pager, next,jumper"
  208. :page-size="listQuery.pageSize"
  209. :page-sizes="[5,10,15]"
  210. :current-page.sync="listQuery.pageNum"
  211. :total="total">
  212. </el-pagination>
  213. </div>
  214. <el-dialog
  215. title="编辑货品信息"
  216. :visible.sync="editSkuInfo.dialogVisible"
  217. width="40%">
  218. <span>商品货号:</span>
  219. <span>{{editSkuInfo.productSn}}</span>
  220. <el-input placeholder="按sku编号搜索" v-model="editSkuInfo.keyword" size="small" style="width: 50%;margin-left: 20px">
  221. <el-button slot="append" icon="el-icon-search" @click="handleSearchEditSku"></el-button>
  222. </el-input>
  223. <el-table style="width: 100%;margin-top: 20px"
  224. :data="editSkuInfo.stockList"
  225. border>
  226. <el-table-column
  227. label="SKU编号"
  228. align="center">
  229. <template slot-scope="scope">
  230. <el-input v-model="scope.row.skuCode"></el-input>
  231. </template>
  232. </el-table-column>
  233. <el-table-column
  234. v-for="(item,index) in editSkuInfo.productAttr"
  235. :label="item.name"
  236. :key="item.id"
  237. align="center">
  238. <template slot-scope="scope">
  239. {{getProductSkuSp(scope.row,index)}}
  240. </template>
  241. </el-table-column>
  242. <el-table-column
  243. label="销售价格"
  244. width="80"
  245. align="center">
  246. <template slot-scope="scope">
  247. <el-input v-model="scope.row.price"></el-input>
  248. </template>
  249. </el-table-column>
  250. <el-table-column
  251. label="商品库存"
  252. width="80"
  253. align="center">
  254. <template slot-scope="scope">
  255. <el-input v-model="scope.row.stock"></el-input>
  256. </template>
  257. </el-table-column>
  258. <el-table-column
  259. label="库存预警值"
  260. width="100"
  261. align="center">
  262. <template slot-scope="scope">
  263. <el-input v-model="scope.row.lowStock"></el-input>
  264. </template>
  265. </el-table-column>
  266. </el-table>
  267. <span slot="footer" class="dialog-footer">
  268. <el-button @click="editSkuInfo.dialogVisible = false">取 消</el-button>
  269. <el-button type="primary" @click="handleEditSkuConfirm">确 定</el-button>
  270. </span>
  271. </el-dialog>
  272. </div>
  273. </template>
  274. <script>
  275. import {
  276. fetchList,
  277. updateDeleteStatus,
  278. updateNewStatus,
  279. updateRecommendStatus,
  280. updatePublishStatus
  281. } from '@/api/product'
  282. import {fetchList as fetchSkuStockList,update as updateSkuStockList} from '@/api/skuStock'
  283. import {fetchList as fetchProductAttrList} from '@/api/productAttr'
  284. import {fetchList as fetchBrandList} from '@/api/brand'
  285. import {fetchListWithChildren} from '@/api/productCate'
  286. const defaultListQuery = {
  287. keyword: null,
  288. pageNum: 1,
  289. pageSize: 5,
  290. publishStatus: null,
  291. verifyStatus: null,
  292. productSn: null,
  293. productCategoryId: null,
  294. brandId: null
  295. };
  296. export default {
  297. name: "productList",
  298. data() {
  299. return {
  300. editSkuInfo:{
  301. dialogVisible:false,
  302. productId:null,
  303. productSn:'',
  304. productAttributeCategoryId:null,
  305. stockList:[],
  306. productAttr:[],
  307. keyword:null
  308. },
  309. operates: [
  310. {
  311. label: "商品上架",
  312. value: "publishOn"
  313. },
  314. {
  315. label: "商品下架",
  316. value: "publishOff"
  317. },
  318. {
  319. label: "设为推荐",
  320. value: "recommendOn"
  321. },
  322. {
  323. label: "取消推荐",
  324. value: "recommendOff"
  325. },
  326. {
  327. label: "设为新品",
  328. value: "newOn"
  329. },
  330. {
  331. label: "取消新品",
  332. value: "newOff"
  333. },
  334. {
  335. label: "转移到分类",
  336. value: "transferCategory"
  337. },
  338. {
  339. label: "移入回收站",
  340. value: "recycle"
  341. }
  342. ],
  343. operateType: null,
  344. listQuery: Object.assign({}, defaultListQuery),
  345. list: null,
  346. total: null,
  347. listLoading: true,
  348. selectProductCateValue: null,
  349. multipleSelection: [],
  350. productCateOptions: [],
  351. brandOptions: [],
  352. publishStatusOptions: [{
  353. value: 1,
  354. label: '上架'
  355. }, {
  356. value: 0,
  357. label: '下架'
  358. }],
  359. verifyStatusOptions: [{
  360. value: 1,
  361. label: '审核通过'
  362. }, {
  363. value: 0,
  364. label: '未审核'
  365. }]
  366. }
  367. },
  368. created() {
  369. this.getList();
  370. this.getBrandList();
  371. this.getProductCateList();
  372. },
  373. watch: {
  374. selectProductCateValue: function (newValue) {
  375. if (newValue != null && newValue.length == 2) {
  376. this.listQuery.productCategoryId = newValue[1];
  377. } else {
  378. this.listQuery.productCategoryId = null;
  379. }
  380. }
  381. },
  382. filters: {
  383. verifyStatusFilter(value) {
  384. if (value === 1) {
  385. return '审核通过';
  386. } else {
  387. return '未审核';
  388. }
  389. }
  390. },
  391. methods: {
  392. getProductSkuSp(row, index) {
  393. if (index === 0) {
  394. return row.sp1;
  395. } else if (index === 1) {
  396. return row.sp2;
  397. } else {
  398. return row.sp3;
  399. }
  400. },
  401. getList() {
  402. this.listLoading = true;
  403. fetchList(this.listQuery).then(response => {
  404. this.listLoading = false;
  405. this.list = response.data.list;
  406. this.total = response.data.total;
  407. });
  408. },
  409. getBrandList() {
  410. fetchBrandList({pageNum: 1, pageSize: 100}).then(response => {
  411. this.brandOptions = [];
  412. let brandList = response.data.list;
  413. for (let i = 0; i < brandList.length; i++) {
  414. this.brandOptions.push({label: brandList[i].name, value: brandList[i].id});
  415. }
  416. });
  417. },
  418. getProductCateList() {
  419. fetchListWithChildren().then(response => {
  420. let list = response.data;
  421. this.productCateOptions = [];
  422. for (let i = 0; i < list.length; i++) {
  423. let children = [];
  424. if (list[i].children != null && list[i].children.length > 0) {
  425. for (let j = 0; j < list[i].children.length; j++) {
  426. children.push({label: list[i].children[j].name, value: list[i].children[j].id});
  427. }
  428. }
  429. this.productCateOptions.push({label: list[i].name, value: list[i].id, children: children});
  430. }
  431. });
  432. },
  433. handleShowSkuEditDialog(index,row){
  434. this.editSkuInfo.dialogVisible=true;
  435. this.editSkuInfo.productId=row.id;
  436. this.editSkuInfo.productSn=row.productSn;
  437. this.editSkuInfo.productAttributeCategoryId = row.productAttributeCategoryId;
  438. this.editSkuInfo.keyword=null;
  439. fetchSkuStockList(row.id,{keyword:this.editSkuInfo.keyword}).then(response=>{
  440. this.editSkuInfo.stockList=response.data;
  441. });
  442. if(row.productAttributeCategoryId!=null){
  443. fetchProductAttrList(row.productAttributeCategoryId,{type:0}).then(response=>{
  444. this.editSkuInfo.productAttr=response.data.list;
  445. });
  446. }
  447. },
  448. handleSearchEditSku(){
  449. fetchSkuStockList(this.editSkuInfo.productId,{keyword:this.editSkuInfo.keyword}).then(response=>{
  450. this.editSkuInfo.stockList=response.data;
  451. });
  452. },
  453. handleEditSkuConfirm(){
  454. if(this.editSkuInfo.stockList==null||this.editSkuInfo.stockList.length<=0){
  455. this.$message({
  456. message: '暂无sku信息',
  457. type: 'warning',
  458. duration: 1000
  459. });
  460. return
  461. }
  462. this.$confirm('是否要进行修改', '提示', {
  463. confirmButtonText: '确定',
  464. cancelButtonText: '取消',
  465. type: 'warning'
  466. }).then(()=>{
  467. updateSkuStockList(this.editSkuInfo.productId,this.editSkuInfo.stockList).then(response=>{
  468. this.$message({
  469. message: '修改成功',
  470. type: 'success',
  471. duration: 1000
  472. });
  473. this.editSkuInfo.dialogVisible=false;
  474. });
  475. });
  476. },
  477. handleSearchList() {
  478. this.listQuery.pageNum = 1;
  479. this.getList();
  480. },
  481. handleAddProduct() {
  482. this.$router.push({path:'/pms/addProduct'});
  483. },
  484. handleBatchOperate() {
  485. if(this.operateType==null){
  486. this.$message({
  487. message: '请选择操作类型',
  488. type: 'warning',
  489. duration: 1000
  490. });
  491. return;
  492. }
  493. if(this.multipleSelection==null||this.multipleSelection.length<1){
  494. this.$message({
  495. message: '请选择要操作的商品',
  496. type: 'warning',
  497. duration: 1000
  498. });
  499. return;
  500. }
  501. this.$confirm('是否要进行该批量操作?', '提示', {
  502. confirmButtonText: '确定',
  503. cancelButtonText: '取消',
  504. type: 'warning'
  505. }).then(() => {
  506. let ids=[];
  507. for(let i=0;i<this.multipleSelection.length;i++){
  508. ids.push(this.multipleSelection[i].id);
  509. }
  510. switch (this.operateType) {
  511. case this.operates[0].value:
  512. this.updatePublishStatus(1,ids);
  513. break;
  514. case this.operates[1].value:
  515. this.updatePublishStatus(0,ids);
  516. break;
  517. case this.operates[2].value:
  518. this.updateRecommendStatus(1,ids);
  519. break;
  520. case this.operates[3].value:
  521. this.updateRecommendStatus(0,ids);
  522. break;
  523. case this.operates[4].value:
  524. this.updateNewStatus(1,ids);
  525. break;
  526. case this.operates[5].value:
  527. this.updateNewStatus(0,ids);
  528. break;
  529. case this.operates[6].value:
  530. break;
  531. case this.operates[7].value:
  532. this.updateDeleteStatus(1,ids);
  533. break;
  534. default:
  535. break;
  536. }
  537. this.getList();
  538. });
  539. },
  540. handleSizeChange(val) {
  541. this.listQuery.pageNum = 1;
  542. this.listQuery.pageSize = val;
  543. this.getList();
  544. },
  545. handleCurrentChange(val) {
  546. this.listQuery.pageNum = val;
  547. this.getList();
  548. },
  549. handleSelectionChange(val) {
  550. this.multipleSelection = val;
  551. },
  552. handlePublishStatusChange(index, row) {
  553. let ids = [];
  554. ids.push(row.id);
  555. this.updatePublishStatus(row.publishStatus, ids);
  556. },
  557. handleNewStatusChange(index, row) {
  558. let ids = [];
  559. ids.push(row.id);
  560. this.updateNewStatus(row.newStatus, ids);
  561. },
  562. handleRecommendStatusChange(index, row) {
  563. let ids = [];
  564. ids.push(row.id);
  565. this.updateRecommendStatus(row.recommandStatus, ids);
  566. },
  567. handleResetSearch() {
  568. this.selectProductCateValue = [];
  569. this.listQuery = Object.assign({}, defaultListQuery);
  570. },
  571. handleDelete(index, row){
  572. this.$confirm('是否要进行删除操作?', '提示', {
  573. confirmButtonText: '确定',
  574. cancelButtonText: '取消',
  575. type: 'warning'
  576. }).then(() => {
  577. let ids = [];
  578. ids.push(row.id);
  579. this.updateDeleteStatus(1,ids);
  580. });
  581. },
  582. handleUpdateProduct(index,row){
  583. this.$router.push({path:'/pms/updateProduct',query:{id:row.id}});
  584. },
  585. handleShowProduct(index,row){
  586. console.log("handleShowProduct",row);
  587. },
  588. handleShowVerifyDetail(index,row){
  589. console.log("handleShowVerifyDetail",row);
  590. },
  591. handleShowLog(index,row){
  592. console.log("handleShowLog",row);
  593. },
  594. updatePublishStatus(publishStatus, ids) {
  595. let params = new URLSearchParams();
  596. params.append('ids', ids);
  597. params.append('publishStatus', publishStatus);
  598. updatePublishStatus(params).then(response => {
  599. this.$message({
  600. message: '修改成功',
  601. type: 'success',
  602. duration: 1000
  603. });
  604. });
  605. },
  606. updateNewStatus(newStatus, ids) {
  607. let params = new URLSearchParams();
  608. params.append('ids', ids);
  609. params.append('newStatus', newStatus);
  610. updateNewStatus(params).then(response => {
  611. this.$message({
  612. message: '修改成功',
  613. type: 'success',
  614. duration: 1000
  615. });
  616. });
  617. },
  618. updateRecommendStatus(recommendStatus, ids) {
  619. let params = new URLSearchParams();
  620. params.append('ids', ids);
  621. params.append('recommendStatus', recommendStatus);
  622. updateRecommendStatus(params).then(response => {
  623. this.$message({
  624. message: '修改成功',
  625. type: 'success',
  626. duration: 1000
  627. });
  628. });
  629. },
  630. updateDeleteStatus(deleteStatus, ids) {
  631. let params = new URLSearchParams();
  632. params.append('ids', ids);
  633. params.append('deleteStatus', deleteStatus);
  634. updateDeleteStatus(params).then(response => {
  635. this.$message({
  636. message: '删除成功',
  637. type: 'success',
  638. duration: 1000
  639. });
  640. });
  641. this.getList();
  642. }
  643. }
  644. }
  645. </script>
  646. <style></style>