list.vue 16 KB

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