list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <template>
  2. <view class="app-content">
  3. <view class="input-wrap" >
  4. <view class="search-bar">
  5. <app-search-module v-model="searchText" placeholder="输入名称" @input="searchFn" />
  6. </view>
  7. <view style="padding-left:10upx;" class="button-group">
  8. <button class="admin-button-com middle blue filter-btn" style="margin-right:8upx;" @click.stop="openFilterPanel">
  9. 筛选
  10. <text v-if="hasActiveFilters" class="filter-dot"></text>
  11. </button>
  12. <button class="admin-button-com middle blue" @click="addGoods()">新增</button>
  13. </view>
  14. </view>
  15. <view class="app-middle">
  16. <scroll-view scroll-y scroll-with-animation class="tab-view" :scroll-top="scrollTop">
  17. <view v-for="(item,index) in tabbar" :key="index" class="tab-bar-item" :class="[currentTab==index ? 'active' : '']" :data-current="index" @tap.stop="swichTab($event ,item)" >
  18. <text>{{item.categoryName || ''}}</text>
  19. </view>
  20. </scroll-view>
  21. <block v-for="(item,index) in tabbar" :key="index">
  22. <scroll-view scroll-y class="right-box" v-if="currentTab==index" @scrolltolower="goBottom">
  23. <block v-if="!$util.isEmpty(list.data)">
  24. <view class="page-view">
  25. <view class="goods-list" v-for="(goodsItem, idx) in list.data" :key="idx">
  26. <view class="goods-list-top" @click="edit(goodsItem.id)">
  27. <view class="img-blo">
  28. <view v-if="goodsItem.stock <= 0 || goodsItem.status == 0" class="sold-out">
  29. <view class="sold-out-xj">
  30. 已下架
  31. <view v-if="goodsItem.stock != 0 && goodsItem.status == 0">(商城隐藏)</view>
  32. </view>
  33. </view>
  34. <img :src="goodsItem.smallCover" mode="aspectFit" />
  35. </view>
  36. <view class="goods-det">
  37. <view class="goods-det-top" style="margin-bottom:4upx;">
  38. <view class="goods-name" style="font-size:29upx;font-weight:bold; overflow: hidden;text-overflow: ellipsis;white-space: nowrap;width:350upx;">{{ goodsItem.name||'' }}</view>
  39. </view>
  40. <view class="operate-wrap" style="margin-bottom:15upx;">
  41. <view class="goods-price" style="font-size:26upx;" v-if="goodsItem.priceType == 1">¥{{ goodsItem.price?parseFloat(goodsItem.price):0 }}</view>
  42. <view class="goods-price" style="font-size:26upx;" v-else>---</view>
  43. </view>
  44. <view class="operate-wrap">
  45. <view style="font-size:23upx;">
  46. <text>库存</text> <text style="font-weight:bold;margin-left:8upx;">{{goodsItem.stock}}</text>
  47. <text style="margin-left:18upx;color:#CCCCCC;">已售 {{ goodsItem.actualSold }}</text>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="goods-list-bottom flex-center-between">
  53. <text @click.stop="moreToDo(goodsItem)">更多</text>
  54. <text @click.stop="getStockChange(goodsItem)">库存明细</text>
  55. <text @click.stop="editDesc(goodsItem)">编辑简介</text>
  56. </view>
  57. </view>
  58. </view>
  59. </block>
  60. <block v-else>
  61. <app-wrapper-empty title="暂无商品" :is-empty="$util.isEmpty(list.data)" />
  62. </block>
  63. </scroll-view>
  64. </block>
  65. </view>
  66. <!-- 筛选下拉面板 -->
  67. <view v-if="showFilterPanel" class="filter-overlay" @click="closeFilterPanel">
  68. <view class="filter-panel" @click.stop>
  69. <view class="filter-header">筛选商品</view>
  70. <!-- 价格筛选 -->
  71. <view class="filter-section">
  72. <view class="filter-title">价格</view>
  73. <view class="filter-options">
  74. <view
  75. v-for="(item, index) in priceOptions"
  76. :key="index"
  77. class="filter-option"
  78. :class="{ 'active': selectedPrice === item.value }"
  79. @click="selectPrice(item.value)"
  80. >
  81. {{ item.label }}
  82. </view>
  83. </view>
  84. </view>
  85. <!-- 库存筛选 -->
  86. <view class="filter-section">
  87. <view class="filter-title">库存</view>
  88. <view class="filter-options">
  89. <view
  90. v-for="(item, index) in stockOptions"
  91. :key="index"
  92. class="filter-option"
  93. :class="{ 'active': selectedStock === item.value }"
  94. @click="selectStock(item.value)"
  95. >
  96. {{ item.label }}
  97. </view>
  98. </view>
  99. </view>
  100. <!-- 支数筛选 -->
  101. <view class="filter-section">
  102. <view class="filter-title">支数</view>
  103. <view class="filter-options">
  104. <view
  105. v-for="(item, index) in flowerNumOptions"
  106. :key="index"
  107. class="filter-option"
  108. :class="{ 'active': selectedFlowerNum === item.value }"
  109. @click="selectFlowerNum(item.value)"
  110. >
  111. {{ item.label }}
  112. </view>
  113. </view>
  114. </view>
  115. <!-- 操作按钮 -->
  116. <view class="filter-actions">
  117. <button class="filter-action-btn clear-btn middle" @click="clearFilters">清空</button>
  118. <button class="filter-action-btn confirm-btn middle blue" @click="confirmFilters">确定</button>
  119. </view>
  120. </view>
  121. </view>
  122. </view>
  123. </template>
  124. <script>
  125. import AppSearchModule from "@/components/module/app-search"
  126. import AppWrapperEmpty from "@/components/app-wrapper-empty"
  127. import {categoryListInfo,getCategoryToGoods,print} from "@/api/goods"
  128. import { list } from "@/mixins"
  129. export default {
  130. name: "list",
  131. components: {
  132. AppWrapperEmpty,
  133. AppSearchModule
  134. },
  135. mixins: [list],
  136. data() {
  137. return {
  138. tabbar: [],
  139. currentTab: 0,
  140. scrollTop: 0,
  141. catId: "",
  142. flowerNum:0,
  143. searchText:'',
  144. lookStock:0, // 1:有库存 2:无库存
  145. lookPrice:0, // 1:有价格 2:无价格
  146. // 新增筛选相关数据
  147. showFilterPanel: false,
  148. selectedPrice: null, // 选中的价格筛选
  149. selectedStock: null, // 选中的库存筛选
  150. selectedFlowerNum: null, // 选中的支数筛选
  151. // 筛选选项配置
  152. priceOptions: [
  153. { label: '有价格', value: 1 },
  154. { label: '无价格', value: 2 }
  155. ],
  156. stockOptions: [
  157. { label: '有库存', value: 1 },
  158. { label: '无库存', value: 2 }
  159. ],
  160. flowerNumOptions: [
  161. { label: '6支', value: 6 },
  162. { label: '9支', value: 9 },
  163. { label: '11支', value: 11 },
  164. { label: '19支', value: 19 },
  165. { label: '33支', value: 33 },
  166. { label: '52支', value: 52 },
  167. { label: '66支', value: 66 },
  168. { label: '99支', value: 99 }
  169. ]
  170. };
  171. },
  172. computed: {
  173. // 检查是否有活跃的筛选条件
  174. hasActiveFilters() {
  175. return this.selectedPrice !== null || this.selectedStock !== null || this.selectedFlowerNum !== null;
  176. }
  177. },
  178. onShow() {
  179. // 检查是否需要刷新数据
  180. const shouldRefresh = uni.getStorageSync('goods_list_refresh');
  181. if (shouldRefresh) {
  182. uni.removeStorageSync('goods_list_refresh');
  183. this.resetList();
  184. this.getGoodsList();
  185. }
  186. },
  187. methods: {
  188. init(){
  189. this.getCategoryData()
  190. },
  191. // 新的筛选相关方法
  192. openFilterPanel() {
  193. this.showFilterPanel = true;
  194. },
  195. closeFilterPanel() {
  196. this.showFilterPanel = false;
  197. },
  198. selectPrice(value) {
  199. this.selectedPrice = this.selectedPrice === value ? null : value;
  200. },
  201. selectStock(value) {
  202. this.selectedStock = this.selectedStock === value ? null : value;
  203. },
  204. selectFlowerNum(value) {
  205. this.selectedFlowerNum = this.selectedFlowerNum === value ? null : value;
  206. },
  207. clearFilters() {
  208. this.selectedPrice = null;
  209. this.selectedStock = null;
  210. this.selectedFlowerNum = null;
  211. // 清空后立即更新筛选变量
  212. this.lookPrice = 0;
  213. this.lookStock = 0;
  214. this.flowerNum = 0;
  215. // 关闭筛选面板
  216. this.closeFilterPanel();
  217. // 触发搜索
  218. this.resetList();
  219. this.getGoodsList();
  220. },
  221. confirmFilters() {
  222. // 更新原有的筛选变量以保持兼容性
  223. this.lookPrice = this.selectedPrice || 0;
  224. this.lookStock = this.selectedStock || 0;
  225. this.flowerNum = this.selectedFlowerNum || 0;
  226. // 关闭筛选面板
  227. this.closeFilterPanel();
  228. // 重新加载数据
  229. this.resetList();
  230. this.getGoodsList();
  231. },
  232. // 保留原有方法以保持兼容性(暂时保留)
  233. // 兼容保留:旧筛选弹窗相关方法已不再使用
  234. moreToDo(item){
  235. let that=this;
  236. let doList = ['打1个标签', '打2个标签','打5个标签', '打10个标签', '销售记录', '设置为散花']
  237. let doNum = [1,2,5,10,20]
  238. uni.showActionSheet({
  239. itemList: doList,
  240. success: function (respond) {
  241. let index = respond.tapIndex
  242. if(index == 4){
  243. that.$msg('开发中')
  244. return
  245. }
  246. if(index == 5){
  247. that.$msg('开发中')
  248. return
  249. }
  250. let currentNum = Number(doNum[index])
  251. print({id:item.id,num:currentNum}).then(res=>{
  252. if(res.code == 1){
  253. that.$msg(res.msg)
  254. }
  255. })
  256. }
  257. })
  258. },
  259. getStockChange(item){
  260. this.$util.pageTo({url: "/admin/goods/stockChange?id="+item.id+'&name='+item.name})
  261. },
  262. editDesc(item){
  263. this.$util.pageTo({url: "/admin/goods/picTextAdd-Edit?gId="+item.id+'&name='+item.name})
  264. },
  265. goBottom(){
  266. if (!this.list.finished) {
  267. this.getGoodsList().then((res) => {
  268. uni.stopPullDownRefresh();
  269. });
  270. } else {
  271. uni.stopPullDownRefresh();
  272. }
  273. },
  274. addGoods(){
  275. this.$util.pageTo({url:"/admin/goods/add"})
  276. },
  277. edit(id){
  278. this.$util.pageTo({ url: "/admin/goods/detail", query: { id: id } })
  279. },
  280. getCategoryData() {
  281. categoryListInfo({flower:1}).then(res => {
  282. this.tabbar = res.data;
  283. if(this.tabbar && this.tabbar[0] && this.tabbar[0].id){
  284. this.catId = this.tabbar[0].id
  285. this.getGoodsList()
  286. }
  287. });
  288. },
  289. searchFn(){
  290. if (this.$util.isEmpty(this.searchText)){
  291. this.resetList()
  292. this.getGoodsList()
  293. }else{
  294. this.resetList()
  295. getCategoryToGoods({status:'',page:this.list.page,flower:1,searchText:this.searchText,flowerNum:this.flowerNum,lookPrice:this.lookPrice,lookStock:this.lookStock}).then(res => {
  296. this.completes(res)
  297. })
  298. }
  299. },
  300. getGoodsList() {
  301. return getCategoryToGoods({ status:'', page: this.list.page, catId:this.catId, flowerNum:this.flowerNum, lookPrice:this.lookPrice, lookStock:this.lookStock }).then(res => {
  302. this.completes(res)
  303. })
  304. },
  305. swichTab(e, item) {
  306. let cur = e.currentTarget.dataset.current;
  307. if (this.currentTab == cur) {
  308. return false;
  309. } else {
  310. this.currentTab = cur;
  311. this.catId = item.id;
  312. this.resetList();
  313. this.getGoodsList();
  314. }
  315. }
  316. }
  317. };
  318. </script>
  319. <style lang="scss" scoped>
  320. .app-content {
  321. min-height: calc(100vh - 80upx);
  322. background-color: #fff;
  323. }
  324. page {
  325. background: #fff;
  326. }
  327. ::-webkit-scrollbar {
  328. width: 0;
  329. height: 0;
  330. color: transparent;
  331. }
  332. .tab-view {
  333. height: 100vh;
  334. width: 200upx;
  335. position: fixed;
  336. left: 0;
  337. z-index: 10;
  338. background-color: #f0f2f6;
  339. padding-bottom:120upx;
  340. .tab-bar-item {
  341. width: 200upx;
  342. height: 100upx;
  343. box-sizing: border-box;
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. font-size: 26upx;
  348. color: #444;
  349. font-weight: 400;
  350. }
  351. .active {
  352. position: relative;
  353. color: $mainColor;
  354. font-size: 26upx;
  355. background: #fff;
  356. }
  357. .active::before {
  358. content: "";
  359. position: absolute;
  360. border-left: 8upx solid $mainColor;
  361. height: 100%;
  362. left: 0;
  363. }
  364. }
  365. .right-box {
  366. width: 100%;
  367. height:100vh;
  368. position: fixed;
  369. padding-left:220upx;
  370. padding-bottom:120upx;
  371. box-sizing: border-box;
  372. left: 0;
  373. .page-view {
  374. width: 100%;
  375. overflow: hidden;
  376. box-sizing: border-box;
  377. padding-bottom: env(safe-area-inset-bottom);
  378. .goods-list {
  379. margin: 40upx 0;
  380. .goods-list-top {
  381. position: relative;
  382. @include disFlex(flex-start, flex-start);
  383. }
  384. .goods-list-bottom {
  385. width: 96%;
  386. margin-top: 16upx;
  387. color: #bebebe;
  388. text{
  389. border:1px solid rgb(218, 216, 216);
  390. border-radius: 20upx;
  391. font-size:22upx;
  392. padding:9upx 25upx 9upx 25upx;
  393. }
  394. }
  395. .img-blo {
  396. width: 130upx;
  397. height: 130upx;
  398. margin-right: 20upx;
  399. & > img {
  400. height: 100%;
  401. width: 100%;
  402. }
  403. .sold-out{
  404. z-index:10;
  405. width:130upx;
  406. height:130upx;
  407. background-color:black;
  408. position:absolute;
  409. top:0;
  410. left:0;
  411. opacity: 0.5;
  412. color:white;
  413. text-align:center;
  414. .sold-out-xj{
  415. display: flex;
  416. flex-direction: column;
  417. justify-content: center;
  418. height: 130upx;
  419. font-size:24upx;
  420. }
  421. }
  422. }
  423. .goods-det {
  424. width: calc(100% - 150upx);
  425. font-size: 28upx;
  426. .operate-wrap {
  427. @include disFlex(flex-end, space-between);
  428. }
  429. .operate-icon-wrap {
  430. left: -20upx;
  431. }
  432. .goods-name {
  433. margin-bottom: 10upx;
  434. }
  435. .goods-sales {
  436. color: $fontColor3;
  437. font-size: 24upx;
  438. }
  439. .goods-price {
  440. color: #ff2842;
  441. font-weight: bold;
  442. }
  443. }
  444. }
  445. }
  446. }
  447. .app-footer {
  448. justify-content: space-between;
  449. .btn-list {
  450. width: 100%;
  451. &:first-child {
  452. border-left: 0;
  453. }
  454. .admin-button-com {
  455. width: 160upx;
  456. padding-top: 16upx;
  457. padding-bottom: 16upx;
  458. float:right;
  459. margin-right:30upx;
  460. }
  461. }
  462. .other-btn {
  463. color: $fontColor2;
  464. .iconfont {
  465. font-size: 24upx;
  466. color: $fontColor3;
  467. transform: scale(0.4);
  468. }
  469. }
  470. }
  471. .input-wrap {
  472. display: flex;
  473. padding: 22upx 20upx 22upx 13upx;
  474. .search-bar {
  475. flex: 1;
  476. }
  477. }
  478. /* 筛选按钮样式 */
  479. .filter-btn {
  480. position: relative;
  481. .filter-dot {
  482. position: absolute;
  483. top: 5upx;
  484. right: 5upx;
  485. width: 12upx;
  486. height: 12upx;
  487. background-color: #ff4757;
  488. border-radius: 50%;
  489. }
  490. }
  491. /* 筛选面板样式 */
  492. .filter-overlay {
  493. position: fixed;
  494. top: 0;
  495. left: 0;
  496. right: 0;
  497. bottom: 0;
  498. background-color: rgba(0, 0, 0, 0.5);
  499. z-index: 9999;
  500. display: flex;
  501. align-items: flex-start;
  502. justify-content: center;
  503. }
  504. .filter-panel {
  505. background-color: #fff;
  506. border-radius: 0 0 20upx 20upx; /* 只保留下边圆角 */
  507. width: 100%; /* 铺满宽度 */
  508. max-height: 80vh;
  509. overflow-y: auto;
  510. animation: slideDown 0.3s ease-out;
  511. }
  512. @keyframes slideDown {
  513. from {
  514. opacity: 0;
  515. transform: translateY(-50upx);
  516. }
  517. to {
  518. opacity: 1;
  519. transform: translateY(0);
  520. }
  521. }
  522. .filter-header {
  523. text-align: center;
  524. padding: 30upx 0;
  525. font-size: 32upx;
  526. font-weight: bold;
  527. border-bottom: 1upx solid #f0f0f0;
  528. color: #333;
  529. }
  530. .filter-section {
  531. padding: 30upx 40upx;
  532. border-bottom: 1upx solid #f0f0f0;
  533. &:last-child {
  534. border-bottom: none;
  535. }
  536. }
  537. .filter-title {
  538. font-size: 28upx;
  539. font-weight: 600;
  540. color: #333;
  541. margin-bottom: 20upx;
  542. }
  543. .filter-options {
  544. display: flex;
  545. flex-wrap: wrap;
  546. gap: 20upx;
  547. }
  548. .filter-option {
  549. padding: 16upx 32upx;
  550. border: 2upx solid #e0e0e0;
  551. border-radius: 25upx;
  552. font-size: 26upx;
  553. color: #666;
  554. background-color: #fff;
  555. text-align: center;
  556. min-width: 120upx;
  557. transition: all 0.3s ease;
  558. &.active {
  559. border-color: #52c41a;
  560. background-color: #f6ffed;
  561. color: #52c41a;
  562. font-weight: 600;
  563. }
  564. }
  565. .filter-actions {
  566. display: flex;
  567. padding: 30upx 40upx;
  568. gap: 20upx;
  569. }
  570. .filter-action-btn {
  571. flex: 1;
  572. padding: 14upx 0;
  573. border-radius: 12upx;
  574. font-size: 28upx;
  575. border: none;
  576. font-weight: 600;
  577. &.clear-btn {
  578. background-color: #f5f5f5;
  579. color: #666;
  580. }
  581. &.confirm-btn {
  582. background-color: #09C567;
  583. color: #fff;
  584. }
  585. }
  586. </style>