index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. <template>
  2. <view class="goods-list">
  3. <!-- #ifdef MP || APP-PLUS -->
  4. <view class="accountTitle">
  5. <view :style="{height:getHeight.barTop+'px'}"></view>
  6. <view class="sysTitle acea-row row-center-wrapper" :style="{height:getHeight.barHeight+'px'}">
  7. <view>商品管理</view>
  8. <text class="iconfont icon-ic_leftarrow" @click="goarrow"></text>
  9. </view>
  10. </view>
  11. <view :style="{height:(getHeight.barTop+getHeight.barHeight)+'px'}"></view>
  12. <!-- #endif -->
  13. <view class="searchCon acea-row row-between-wrapper">
  14. <view class="search acea-row row-middle">
  15. <text class="iconfont icon-ic_search"></text>
  16. <input class="inputs" placeholder='请输入商品名称/ID' placeholder-class='placeholder' confirm-type='search' name="search"
  17. v-model="keyword" @confirm="searchSubmit"></input>
  18. </view>
  19. <view @click="manageTap" v-if="administer">取消</view>
  20. <view class="edit acea-row row-center-wrapper" @click="manageTap" v-else>
  21. <text class="iconfont icon-ic_batch"></text>
  22. </view>
  23. </view>
  24. <view class="nav acea-row row-middle">
  25. <view class="item" :class="current == index?'on':''" v-for="(item, index) in navList" :key="index" @click="navTap(item,index)">
  26. {{item.name}}
  27. <image src="../static/adorn.png" v-if="current == index"></image>
  28. </view>
  29. </view>
  30. <view class="list" v-if="goodsList.length">
  31. <checkbox-group @change="checkboxChange">
  32. <view class="acea-row row-middle" v-for="(item, index) in goodsList" :key="index">
  33. <!-- #ifndef MP -->
  34. <checkbox class="checkbox" v-if="administer" :value="(item.id).toString()" :checked="item.checked" />
  35. <!-- #endif -->
  36. <!-- #ifdef MP -->
  37. <checkbox class="checkbox" v-if="administer" :value="item.id" :checked="item.checked" />
  38. <!-- #endif -->
  39. <view class="item">
  40. <view class="top acea-row row-center-wrapper" @tap="goDetail(item)">
  41. <view class="pictrue">
  42. <image :src="item.image"></image>
  43. </view>
  44. <view class="text">
  45. <view class="name line1">{{item.store_name}}</view>
  46. <view class="info">
  47. <text>销量: {{item.sales}}</text>
  48. <text>库存: {{item.stock}}</text>
  49. <text>评分: {{item.star}}</text>
  50. </view>
  51. <baseMoney
  52. :money="item.price"
  53. symbolSize="20"
  54. integerSize="32"
  55. decimalSize="20"
  56. color="#FF7E00"
  57. ></baseMoney>
  58. </view>
  59. </view>
  60. <view class="bottom acea-row row-right" v-if="!administer">
  61. <view class="bnt acea-row row-center-wrapper" :class="item.is_show?'':'up'" @click="setShow(item,0)">{{item.is_show?'下架':'上架'}}</view>
  62. <view class="bnt on acea-row row-center-wrapper" @tap="openDrawer(item)">编辑</view>
  63. </view>
  64. </view>
  65. </view>
  66. </checkbox-group>
  67. </view>
  68. <view class="empty-box" v-if="goodsList.length == 0 && !loading">
  69. <emptyPage title="暂无商品~" src="/statics/images/empty-box.gif"></emptyPage>
  70. </view>
  71. <Loading :loaded="loadend" :loading="loading"></Loading>
  72. <view class="footerH"></view>
  73. <view class="footer acea-row row-between-wrapper" v-if="administer">
  74. <checkbox-group @change="checkboxAllChange">
  75. <checkbox value="all" :checked="isAllSelect" />
  76. <text class='checkAll'>全选({{getIds().length}})</text>
  77. </checkbox-group>
  78. <view class="acea-row row-middle">
  79. <view class="bnt acea-row row-center-wrapper" v-if="storeNum" @click="editLabels">添加标签</view>
  80. <view class="bnt acea-row row-center-wrapper" @click="editClass">修改分类</view>
  81. <view class="bnt acea-row row-center-wrapper" v-if="type == 1" @click="setShow('',1,0)">下架</view>
  82. <view class="bnt acea-row row-center-wrapper" v-else-if="type == 2" @click="setShow('',1,1)">上架</view>
  83. </view>
  84. </view>
  85. <footer-page :isWork='storeNum'></footer-page>
  86. <base-drawer mode="bottom" :visible="visible" background-color="transparent" mask maskClosable @close="closeDrawer">
  87. <view class="edit-list rd-t-40rpx">
  88. <view class="item" v-if="!storeNum && goodsInfo.pid==0" @tap="editInfo(0)">修改价格</view>
  89. <view class="item" v-if="!storeNum" @tap="editInfo(4)">修改库存</view>
  90. <view class="item" v-if="storeNum" @tap="editInfo(0)">修改价格/库存</view>
  91. <view class="item" @tap="editInfo(1)">商品分类</view>
  92. <view class="item" v-if="goodsInfo.pid==0" @tap="editInfo(2)">商品标签</view>
  93. </view>
  94. </base-drawer>
  95. <edit-price :visible='visiblePrice' :goodsInfo='goodsInfo' :storeNum='storeNum' @closeDrawer='priceCloseDrawer' @successChange='successChange'></edit-price>
  96. <edit-stock :visible='visibleStock' :goodsInfo='goodsInfo' @closeDrawer='stockCloseDrawer' @successChange='successChange'></edit-stock>
  97. <edit-lable ref="lable" :visible='visibleLable' :storeNum='storeNum' @closeDrawer='lableCloseDrawer' @successChange='successChange'></edit-lable>
  98. <classify ref="classify" :visible='visibleClass' :storeNum='storeNum' @closeDrawer='classCloseDrawer' @successChange='successChange'></classify>
  99. </view>
  100. </template>
  101. <script>
  102. import Loading from '@/components/Loading/index';
  103. import emptyPage from '@/components/emptyPage.vue';
  104. import footerPage from '../components/footerPage/index.vue';
  105. import editPrice from './components/editPrice/index.vue';
  106. import editStock from './components/editStock/index.vue';
  107. import editLable from './components/label/index.vue';
  108. import classify from './components/classify/index.vue';
  109. import { goShopDetail } from '@/libs/order.js';
  110. import {
  111. storeProductList,
  112. adminProductList,
  113. storeProductSetShow,
  114. productSetShow
  115. } from "@/api/admin";
  116. import {
  117. mapGetters
  118. } from "vuex";
  119. export default {
  120. components: {
  121. editPrice,
  122. editStock,
  123. editLable,
  124. classify,
  125. footerPage,
  126. emptyPage,
  127. Loading
  128. },
  129. computed: mapGetters(["storeNum"]),
  130. data() {
  131. return {
  132. getHeight: this.$util.getWXStatusHeight(),
  133. navList:[
  134. {
  135. name:'全部',
  136. type:''
  137. },
  138. {
  139. name:'出售中',
  140. type:1
  141. },
  142. {
  143. name:'仓库中',
  144. type:2
  145. },
  146. {
  147. name:'已售罄',
  148. type:4
  149. },
  150. {
  151. name:'库存警告',
  152. type:5
  153. }
  154. ],
  155. editList:[
  156. {
  157. name:'修改价格',
  158. num:3
  159. },
  160. {
  161. name:'修改库存',
  162. num:4
  163. },
  164. {
  165. name:'修改价格/库存',
  166. num:0
  167. },
  168. {
  169. name:'商品分类',
  170. num:1
  171. },
  172. {
  173. name:'商品标签',
  174. num:2
  175. },
  176. ],
  177. current:0,
  178. administer:0,
  179. isAllSelect: false,
  180. goodsList:[],
  181. goodsInfo:{},
  182. visible:false,
  183. visiblePrice:false, //价格库存是否显示
  184. visibleStock:false, //库存是否显示
  185. visibleLable:false, //标签是否显示
  186. loadTitle: '加载更多',
  187. loading: false,
  188. loadend: false,
  189. limit: 20,
  190. page: 1,
  191. keyword:'', //搜索字段
  192. type:'', //商品状态
  193. visibleClass:false
  194. }
  195. },
  196. onShow() {
  197. },
  198. onLoad(option) {
  199. this.type = option.type || '';
  200. for (let i = 0; i < this.navList.length; i++) {
  201. if (this.navList[i].type == this.type) {
  202. this.current = i;
  203. break;
  204. }
  205. }
  206. this.productList();
  207. },
  208. methods: {
  209. // 去详情页
  210. goDetail(item) {
  211. if(!item.is_show){
  212. this.$util.Tips({
  213. title: '商品未上架'
  214. });
  215. return
  216. }
  217. goShopDetail(item, this.$store.state.app.uid).catch(res => {
  218. uni.navigateTo({
  219. url: `/pages/goods_details/index?id=${item.id}`
  220. });
  221. });
  222. },
  223. goarrow(){
  224. uni.navigateBack()
  225. },
  226. editClass(){
  227. if(!this.getIds().length){
  228. this.$util.Tips({
  229. title: '请选择商品'
  230. });
  231. return
  232. }
  233. this.$refs.classify.category(this.getIds(),'');
  234. let that = this;
  235. setTimeout(function(){
  236. that.visibleClass = true
  237. },200)
  238. },
  239. classCloseDrawer(){
  240. this.visibleClass = false
  241. },
  242. successChange(){
  243. this.visibleClass = false
  244. this.visibleLable = false
  245. this.visiblePrice = false
  246. this.visibleStock = false
  247. this.init();
  248. },
  249. //批量编辑标签
  250. editLabels(){
  251. if(!this.getIds().length){
  252. this.$util.Tips({
  253. title: '请选择商品'
  254. });
  255. return
  256. }
  257. this.visibleLable = true
  258. this.$refs.lable.productLabel({},1,this.getIds());
  259. },
  260. //批量获取id集合
  261. getIds(){
  262. let ids = []
  263. this.goodsList.forEach(item=>{
  264. if(item.checked){
  265. ids.push(item.id)
  266. }
  267. })
  268. ids.slice(0, 100)
  269. return ids
  270. },
  271. setShow(item,num,type){
  272. let data = {}
  273. if(num){
  274. if(!this.getIds().length){
  275. this.$util.Tips({
  276. title: '请选择商品'
  277. });
  278. return
  279. }
  280. data = {
  281. id:this.getIds(),
  282. is_show:type
  283. }
  284. }else{
  285. data = {
  286. id:item.id,
  287. is_show:item.is_show?0:1
  288. }
  289. }
  290. let funApi = '';
  291. if(this.storeNum){
  292. funApi = productSetShow;
  293. }else{
  294. funApi = storeProductSetShow;
  295. }
  296. funApi(data).then(res=>{
  297. this.$util.Tips({
  298. title: res.msg
  299. });
  300. this.init();
  301. }).catch(err=>{
  302. this.$util.Tips({
  303. title: err
  304. });
  305. })
  306. },
  307. init(){
  308. this.goodsList = [];
  309. this.page = 1;
  310. this.loadend = false;
  311. this.loading = false;
  312. this.productList();
  313. },
  314. searchSubmit(){
  315. this.init();
  316. },
  317. productList(){
  318. let that = this;
  319. if (this.loading) return;
  320. if (this.loadend) return;
  321. that.loading = true;
  322. that.loadTitle = "";
  323. let funApi = '';
  324. if(this.storeNum){
  325. funApi = adminProductList;
  326. }else{
  327. funApi = storeProductList;
  328. }
  329. funApi({
  330. page: that.page,
  331. limit: that.limit,
  332. store_name: that.keyword,
  333. type: that.type
  334. }).then(res=>{
  335. let goodsList = res.data.list;
  336. goodsList.forEach(item => {
  337. item.checked = false;
  338. })
  339. this.isAllSelect = false
  340. let loadend = goodsList.length < that.limit;
  341. that.goodsList = that.$util.SplitArray(goodsList, that.goodsList);
  342. that.$set(that, 'goodsList', that.goodsList);
  343. that.loadend = loadend;
  344. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  345. that.page = that.page + 1;
  346. that.loading = false;
  347. }).catch(err=>{
  348. that.loading = false;
  349. that.loadTitle = "加载更多";
  350. })
  351. },
  352. editInfo(index){
  353. switch (index) {
  354. case 0:
  355. this.visible = false
  356. if(this.goodsInfo.spec_type){
  357. uni.navigateTo({
  358. url: '/pages/admin/goods/specs?id='+this.goodsInfo.id + '&storeNum='+this.storeNum
  359. })
  360. }else{
  361. this.visiblePrice = true
  362. }
  363. break;
  364. case 1:
  365. this.visible = false
  366. this.visibleClass = true
  367. break;
  368. case 2:
  369. this.visibleLable = true
  370. this.visible = false
  371. break;
  372. case 4:
  373. this.visible = false
  374. if(this.goodsInfo.spec_type){
  375. uni.navigateTo({
  376. url: '/pages/admin/goods/specsStock?id='+this.goodsInfo.id + '&storeNum='+this.storeNum
  377. })
  378. }else{
  379. this.visibleStock = true
  380. }
  381. break;
  382. }
  383. },
  384. lableCloseDrawer(){
  385. this.visibleLable = false
  386. },
  387. priceCloseDrawer(){
  388. this.visiblePrice = false
  389. },
  390. stockCloseDrawer(){
  391. this.visibleStock = false
  392. },
  393. openDrawer(item){
  394. this.visible = true
  395. this.goodsInfo = JSON.parse(JSON.stringify(item))
  396. this.$refs.lable.productLabel(this.goodsInfo,0,[]);
  397. this.$refs.classify.category(item.id,item.cate_id);
  398. },
  399. closeDrawer(){
  400. this.visible = false
  401. },
  402. manageTap() {
  403. this.administer = !this.administer;
  404. },
  405. navTap(item,index){
  406. this.current = index;
  407. if (this.type != item.type) {
  408. this.type = item.type;
  409. this.init();
  410. }
  411. },
  412. checkboxChange(event) {
  413. let idList = event.detail.value;
  414. this.goodsList.forEach((item) => {
  415. if (idList.indexOf(item.id + '') !== -1) {
  416. item.checked = true;
  417. } else {
  418. item.checked = false;
  419. }
  420. })
  421. if (idList.length == this.goodsList.length) {
  422. this.isAllSelect = true;
  423. } else {
  424. this.isAllSelect = false;
  425. }
  426. },
  427. forGoods(val) {
  428. let that = this;
  429. if (!that.goodsList.length) return
  430. that.goodsList.forEach((item) => {
  431. if (val) {
  432. item.checked = true;
  433. } else {
  434. item.checked = false;
  435. }
  436. })
  437. },
  438. checkboxAllChange(event) {
  439. let value = event.detail.value;
  440. if (value.length) {
  441. if(this.goodsList.length>100){
  442. this.$util.Tips({
  443. title: '每次最多只提交100条数据'
  444. });
  445. }
  446. this.isAllSelect = true;
  447. this.forGoods(1)
  448. } else {
  449. this.isAllSelect = false;
  450. this.forGoods(0)
  451. }
  452. },
  453. },
  454. onReachBottom(){
  455. this.productList();
  456. }
  457. }
  458. </script>
  459. <style lang="scss" scoped>
  460. /deep/checkbox .uni-checkbox-input.uni-checkbox-input-checked {
  461. border-color: #2A7EFB !important;
  462. background-color: #2A7EFB !important;
  463. }
  464. /deep/checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  465. border: 1px solid #2A7EFB !important;
  466. background-color: #2A7EFB !important;
  467. }
  468. /deep/uni-checkbox .uni-checkbox-input{
  469. margin-top: -4rpx;
  470. }
  471. /deep/checkbox:not([disabled]) .uni-checkbox-input:hover {
  472. border-color: #d1d1d1 !important;
  473. }
  474. .empty-box{
  475. padding: 0 20rpx;
  476. }
  477. .accountTitle{
  478. background: #F5F5F5;
  479. position: fixed;
  480. left:0;
  481. top:0;
  482. width: 100%;
  483. z-index: 99;
  484. padding-bottom: 6rpx;
  485. .sysTitle{
  486. width: 100%;
  487. position: relative;
  488. font-weight: 500;
  489. color: #333333;
  490. font-size: 30rpx;
  491. .iconfont{
  492. position: absolute;
  493. font-size: 42rpx;
  494. left:20rpx;
  495. width: 60rpx;
  496. font-weight: 500;
  497. }
  498. }
  499. }
  500. .goods-list{
  501. padding-top: 20rpx;
  502. .searchCon{
  503. padding: 0 20rpx;
  504. .search{
  505. width: 618rpx;
  506. height: 72rpx;
  507. background: #FFFFFF;
  508. border-radius: 50rpx;
  509. padding: 0 34rpx;
  510. .iconfont{
  511. color: #999;
  512. font-size: 32rpx;
  513. margin-right: 16rpx;
  514. }
  515. .inputs{
  516. font-size: 28rpx;
  517. width: 100%;
  518. height: 100%;
  519. flex: 1;
  520. }
  521. .placeholder{
  522. color: #ccc;
  523. }
  524. }
  525. .edit{
  526. width: 72rpx;
  527. height: 72rpx;
  528. background: #FFFFFF;
  529. border-radius: 50%;
  530. .iconfont {
  531. color: #666;
  532. font-size: 36rpx;
  533. }
  534. }
  535. }
  536. .nav{
  537. padding: 20rpx 20rpx 18rpx 34rpx;
  538. position: sticky;
  539. top:0;
  540. left:0;
  541. width: 100%;
  542. background-color: #F5F5F5;
  543. z-index: 9;
  544. .item{
  545. font-weight: 400;
  546. font-size: 26rpx;
  547. color: #333333;
  548. padding: 10rpx 0;
  549. position: relative;
  550. &~.item{
  551. margin-left: 72rpx;
  552. }
  553. &.on{
  554. font-weight: 500;
  555. color: #2A7EFB;
  556. font-size: 30rpx;
  557. font-family: PingFang SC, PingFang SC;
  558. }
  559. image {
  560. width: 14rpx;
  561. height: 14rpx;
  562. display: block;
  563. position: absolute;
  564. bottom: 0;
  565. right: -4rpx;
  566. }
  567. }
  568. }
  569. .list{
  570. padding-bottom: 20rpx;
  571. padding: 0 20rpx 20rpx 20rpx;
  572. /deep/uni-checkbox .uni-checkbox-input{
  573. background-color: #f5f5f5;
  574. margin: 0 20rpx 20rpx 0;
  575. }
  576. /deep/wx-checkbox .wx-checkbox-input{
  577. background-color: #f5f5f5;
  578. margin: 0 20rpx 20rpx 0;
  579. }
  580. .item {
  581. width: 100%;
  582. background-color: #fff;
  583. padding: 24rpx;
  584. box-sizing: border-box;
  585. margin-bottom: 20rpx;
  586. border-radius: 24rpx;
  587. flex: 1;
  588. overflow: hidden;
  589. .top{
  590. .checkbox{
  591. margin-right: 10rpx;
  592. }
  593. .pictrue{
  594. width: 136rpx;
  595. height: 136rpx;
  596. margin-right: 20rpx;
  597. image {
  598. width: 100%;
  599. height: 100%;
  600. border-radius: 16rpx;
  601. }
  602. }
  603. .text{
  604. flex: 1;
  605. overflow: hidden;
  606. .name {
  607. font-size: 28rpx;
  608. font-weight: 400;
  609. color: #333333;
  610. }
  611. .info {
  612. font-size: 24rpx;
  613. font-weight: 400;
  614. color: #666666;
  615. margin: 10rpx 0 18rpx 0;
  616. text {
  617. margin-right: 40rpx;
  618. }
  619. }
  620. }
  621. }
  622. .bottom{
  623. margin-top: 26rpx;
  624. .bnt{
  625. width: 144rpx;
  626. height: 56rpx;
  627. border:1px solid #ccc;
  628. font-size: 24rpx;
  629. font-family: PingFang SC, PingFang SC;
  630. font-weight: 400;
  631. color: #333333;
  632. border-radius: 50rpx;
  633. &~.bnt{
  634. margin-left: 16rpx;
  635. }
  636. &.on{
  637. border-color: #2A7EFB;
  638. background-color: #2A7EFB;
  639. color: #fff;
  640. }
  641. &.up{
  642. border-color: #FF7E00;
  643. color: #FF7E00;
  644. }
  645. }
  646. }
  647. }
  648. }
  649. .footerH {
  650. height: 110rpx;
  651. height: calc(110rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  652. height: calc(110rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  653. }
  654. .footer {
  655. box-sizing: border-box;
  656. padding: 0 32rpx;
  657. width: 100%;
  658. height: 96rpx;
  659. background-color: #fff;
  660. position: fixed;
  661. bottom: 0;
  662. z-index: 30;
  663. height: calc(96rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  664. height: calc(96rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  665. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  666. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  667. width: 100%;
  668. left: 0;
  669. .bnt {
  670. width: 160rpx;
  671. height: 64rpx;
  672. border-radius: 50rpx;
  673. border: 1rpx solid #2A7EFB;
  674. color: #2A7EFB;
  675. font-size: 24rpx;
  676. font-family: PingFang SC, PingFang SC;
  677. font-weight: 500;
  678. &~.bnt{
  679. margin-left: 16rpx;
  680. }
  681. }
  682. }
  683. .edit-list{
  684. background-color: #fff;
  685. padding: 45rpx 34rpx;
  686. .item{
  687. font-family: PingFang SC, PingFang SC;
  688. font-weight: 400;
  689. color: #333333;
  690. font-size: 32rpx;
  691. text-align: center;
  692. height: 106rpx;
  693. line-height: 106rpx;
  694. }
  695. }
  696. }
  697. </style>