productCenter.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view class="container">
  3. <!-- 搜索栏 -->
  4. <view class="search-bar">
  5. <view class="search-bar-con">
  6. <view class="search-input-wrapper">
  7. <uni-icons class="search-icon" type="search" size="18" color="#999"></uni-icons>
  8. <input
  9. class="search-input"
  10. v-model="searchVal"
  11. placeholder="请输入搜索内容"
  12. placeholder-class="placeholder"
  13. @input="onSearch"
  14. @confirm="onSearch"
  15. :focus="isFocus"
  16. />
  17. <view v-if="searchVal" class="clear-btn" @click="onClear">
  18. <uni-icons type="clear" size="18" color="#999"></uni-icons>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 商品列表 -->
  24. <view class="product-list">
  25. <view class="product-card" v-for="(item, index) in goodsList" :key="index">
  26. <view class="product-header">
  27. <image class="product-image" :src="item.image" mode="aspectFill" />
  28. <view class="product-info">
  29. <view class="nameweight">
  30. <text class="product-name">{{ item.storeName }}</text>
  31. <text class="product-weight">{{ item.weight }}g</text>
  32. </view>
  33. <view class="nameweight">
  34. <view class="price-info">
  35. <text class="label">工费</text>
  36. <view class="value"><text class="unit">¥</text>{{ item.totalLaborCost }}<text class="unit">/g</text></view>
  37. </view>
  38. <view class="price-info">
  39. <text class="label">附加费</text>
  40. <view class="value"><text class="unit">¥</text>{{ item.additionalAmount }}</view>
  41. </view>
  42. </view>
  43. <view class="product-stats">
  44. <text class="stat">销量:{{ Number(item.sales || 0) + Number(item.ficti || 0) }}</text>
  45. <text class="stat">库存:{{ item.stock }}</text>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="action-buttons">
  50. <button class="btn btn-edit" @click="addProduct(item)">添加商品</button>
  51. </view>
  52. </view>
  53. <view class="loadingicon acea-row row-center-wrapper" v-if="goodScroll">
  54. <text
  55. class="loading iconfont icon-jiazai"
  56. :hidden="loading == false"
  57. ></text>
  58. </view>
  59. <view class="no-data" v-if="isNoDataState">
  60. <image
  61. src="https://my-go-easy-im.oss-cn-shenzhen.aliyuncs.com/goeasy-im-%E6%B0%B4%E8%B4%9D%E5%95%86%E5%9F%8E/zhanwu_20250827104005_1720_6.png"
  62. />
  63. </view>
  64. <view class="mores-txt flex" v-if="!goodScroll && !isNoDataState">
  65. <text>我是有底线的</text>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script setup>
  71. import {computed, ref} from 'vue'
  72. import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
  73. import { productsList,productPutOnShell,productOffShell } from "@/api/merchant.js";
  74. import { useAppStore } from "@/stores/app";
  75. const appStore = useAppStore();
  76. const tabList = ref([
  77. {name:'销售中',code:1},
  78. {name:'已下架',code:0}
  79. ])
  80. const searchVal = ref('')
  81. const goodsList = ref([]);
  82. const goodType = ref(1);
  83. // Pagination
  84. const params = ref({
  85. page: 1,
  86. limit: 10,
  87. isShow:1,
  88. });
  89. const loading = ref(false);
  90. const goodScroll = ref(true);
  91. const merchantInfo = ref({})
  92. const isFocus = ref(false)
  93. const isNoDataState = computed(() => {
  94. return goodsList.value.length === 0 && !loading.value;
  95. });
  96. onShow(() => {
  97. merchantInfo.value = appStore.userInfo.merchant;
  98. getGroomList()
  99. })
  100. const onSearch = () => {
  101. goodsList.value = [];
  102. loading.value = false;
  103. goodScroll.value = true;
  104. params.value.page = 1;
  105. getGroomList();
  106. }
  107. // 清除搜索内容
  108. const onClear = () => {
  109. console.log('清除搜索内容');
  110. searchVal.value = ''; // 手动清空关键词
  111. // 如果需要清除后立即刷新列表,可以调用搜索
  112. onSearch();
  113. }
  114. const getGroomList = async () => {
  115. if (!goodScroll.value) return;
  116. try {
  117. loading.value = true;
  118. // params.value.merchantId = merchantInfo.value.id;
  119. params.value.keyword = searchVal.value;
  120. const id = merchantInfo.value.id;
  121. const { data } = await productsList(params.value);
  122. goodsList.value = [...goodsList.value, ...data.list] || [];
  123. goodScroll.value = data.list.length >= params.value.limit;
  124. params.value.page++;
  125. } catch (err) {
  126. console.error(err);
  127. } finally {
  128. loading.value = false;
  129. }
  130. };
  131. function addProduct (obj){
  132. uni.navigateTo({
  133. url:`/pages/merchantCenters/releaseProduct?id=${obj.id}&isProductCenter=1`
  134. })
  135. }
  136. onReachBottom(() => {
  137. getGroomList();
  138. });
  139. </script>
  140. <style lang="scss" scoped>
  141. /* 搜索栏样式 */
  142. .search-bar {
  143. background: #fff;
  144. padding: 20rpx;
  145. }
  146. .search-input {
  147. width: 100%;
  148. height: 60rpx;
  149. font-size: 28rpx;
  150. }
  151. /* 标签页样式 */
  152. .tabs {
  153. display: flex;
  154. background: white;
  155. border-radius: 10rpx;
  156. margin-bottom: 20rpx;
  157. }
  158. .tab {
  159. flex: 1;
  160. text-align: center;
  161. padding: 20rpx;
  162. font-size: 28rpx;
  163. color: #666;
  164. }
  165. .tab.active {
  166. color: #333;
  167. font-weight: bold;
  168. border-bottom: 4rpx solid #333;
  169. }
  170. .product-list{
  171. padding: 20rpx;
  172. box-sizing: border-box;
  173. }
  174. /* 商品卡片样式 */
  175. .product-card {
  176. background: #fff;
  177. border-radius: 16rpx;
  178. padding: 30rpx;
  179. margin-bottom: 20rpx;
  180. }
  181. .product-header {
  182. display: flex;
  183. margin-bottom: 20rpx;
  184. }
  185. .product-image {
  186. width: 120rpx;
  187. height: 120rpx;
  188. border-radius: 10rpx;
  189. margin-right: 20rpx;
  190. }
  191. .product-info {
  192. flex: 1;
  193. }
  194. .nameweight{
  195. display: flex;
  196. justify-content: space-between;
  197. align-items: center;
  198. margin-bottom: 20rpx;
  199. }
  200. .product-name {
  201. font-size: 28rpx;
  202. color: #333;
  203. display: block;
  204. }
  205. .product-weight {
  206. background-color: rgba(197, 128, 3, 0.10);
  207. color: #C58003;
  208. font-size: 24rpx;
  209. padding: 8rpx 16rpx;
  210. border-radius: 8rpx;
  211. float: right;
  212. }
  213. .price-info {
  214. display: flex;
  215. justify-content: space-between;
  216. margin-bottom: 8rpx;
  217. }
  218. .label {
  219. font-size: 24rpx;
  220. color: #666666;
  221. }
  222. .value {
  223. color: #FD5F3C;
  224. font-size: 32rpx;
  225. .unit{
  226. font-size: 24rpx;
  227. }
  228. }
  229. /* 销售数据样式 */
  230. .product-stats {
  231. display: flex;
  232. margin-bottom: 20rpx;
  233. gap: 10rpx;
  234. }
  235. .stat {
  236. font-size: 24rpx;
  237. color: #666;
  238. padding: 10rpx;
  239. background-color: #F5F7FA;
  240. border-radius: 8rpx;
  241. }
  242. /* 操作按钮样式 */
  243. .action-buttons {
  244. display: flex;
  245. justify-content: space-between;
  246. gap: 30rpx;
  247. }
  248. .btn {
  249. flex: 1;
  250. height: 60rpx;
  251. line-height: 60rpx;
  252. border-radius: 8rpx;
  253. font-size: 28rpx;
  254. border: none;
  255. }
  256. .btn-offline {
  257. background: #F5F7FA;
  258. color: #333;
  259. }
  260. .btn-edit {
  261. background: #F8C008;
  262. color: #333;
  263. }
  264. .no-data {
  265. margin: 150rpx auto 0;
  266. text-align: center;
  267. img {
  268. width: 65%;
  269. height: auto;
  270. }
  271. }
  272. .mores-txt {
  273. width: 100%;
  274. align-items: center;
  275. justify-content: center;
  276. height: 70rpx;
  277. color: #999;
  278. font-size: 24rpx;
  279. .iconfont {
  280. margin-top: 2rpx;
  281. font-size: 20rpx;
  282. }
  283. }
  284. .search-bar-con {
  285. display: flex;
  286. align-items: center;
  287. background-color: #fff;
  288. border-bottom: 1rpx solid #eee;
  289. }
  290. .search-input-wrapper {
  291. flex: 1;
  292. position: relative;
  293. display: flex;
  294. align-items: center;
  295. background-color: #F9F7F0;
  296. border-radius: 16rpx;
  297. height: 72rpx;
  298. line-height: 72rpx;
  299. padding: 0 20rpx;
  300. box-sizing: border-box;
  301. }
  302. .search-icon {
  303. margin-right: 20rpx;
  304. }
  305. .search-input {
  306. flex: 1;
  307. height: 100%;
  308. font-size: 28rpx;
  309. color: #333;
  310. }
  311. .placeholder {
  312. color: #999;
  313. font-size: 28rpx;
  314. }
  315. .clear-btn {
  316. padding: 10rpx;
  317. margin-left: 10rpx;
  318. }
  319. </style>