productCenter.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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="aspectFit" />
  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 { data } = await productsList(params.value);
  121. goodsList.value = [...goodsList.value, ...data.list] || [];
  122. goodScroll.value = data.list.length >= params.value.limit;
  123. params.value.page++;
  124. } catch (err) {
  125. console.error(err);
  126. } finally {
  127. loading.value = false;
  128. }
  129. };
  130. function addProduct (obj){
  131. uni.navigateTo({
  132. url:`/pages/merchantCenter/releaseProduct?id=${obj.id}&isProductCenter=1`
  133. })
  134. }
  135. onReachBottom(() => {
  136. getGroomList();
  137. });
  138. </script>
  139. <style lang="scss" scoped>
  140. /* 搜索栏样式 */
  141. .search-bar {
  142. background: #fff;
  143. padding: 30rpx 30rpx 0;
  144. }
  145. .search-input {
  146. width: 100%;
  147. height: 60rpx;
  148. font-size: 28rpx;
  149. }
  150. /* 标签页样式 */
  151. .tabs {
  152. display: flex;
  153. background: white;
  154. border-radius: 10rpx;
  155. margin-bottom: 20rpx;
  156. }
  157. .tab {
  158. flex: 1;
  159. text-align: center;
  160. padding: 20rpx;
  161. font-size: 28rpx;
  162. color: #666;
  163. }
  164. .tab.active {
  165. color: #333;
  166. font-weight: bold;
  167. border-bottom: 4rpx solid #333;
  168. }
  169. .product-list{
  170. padding: 30rpx;
  171. box-sizing: border-box;
  172. }
  173. /* 商品卡片样式 */
  174. .product-card {
  175. background: #fff;
  176. border-radius: 16rpx;
  177. padding: 30rpx;
  178. margin-bottom: 20rpx;
  179. }
  180. .product-header {
  181. display: flex;
  182. margin-bottom: 20rpx;
  183. }
  184. .product-image {
  185. width: 120rpx;
  186. height: 120rpx;
  187. border-radius: 10rpx;
  188. margin-right: 20rpx;
  189. }
  190. .product-info {
  191. flex: 1;
  192. }
  193. .nameweight{
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. margin-bottom: 20rpx;
  198. }
  199. .product-name {
  200. font-size: 28rpx;
  201. color: #333;
  202. display: block;
  203. }
  204. .product-weight {
  205. background-color: rgba(197, 128, 3, 0.10);
  206. color: #C58003;
  207. font-size: 24rpx;
  208. padding: 8rpx 16rpx;
  209. border-radius: 8rpx;
  210. float: right;
  211. }
  212. .price-info {
  213. display: flex;
  214. justify-content: space-between;
  215. margin-bottom: 8rpx;
  216. }
  217. .label {
  218. font-size: 24rpx;
  219. color: #666666;
  220. }
  221. .value {
  222. color: #FD5F3C;
  223. font-size: 32rpx;
  224. .unit{
  225. font-size: 24rpx;
  226. }
  227. }
  228. /* 销售数据样式 */
  229. .product-stats {
  230. display: flex;
  231. margin-bottom: 20rpx;
  232. gap: 10rpx;
  233. }
  234. .stat {
  235. font-size: 24rpx;
  236. color: #666;
  237. padding: 10rpx;
  238. background-color: #F5F7FA;
  239. border-radius: 8rpx;
  240. }
  241. /* 操作按钮样式 */
  242. .action-buttons {
  243. display: flex;
  244. justify-content: space-between;
  245. gap: 30rpx;
  246. }
  247. .btn {
  248. flex: 1;
  249. height: 60rpx;
  250. line-height: 60rpx;
  251. border-radius: 8rpx;
  252. font-size: 28rpx;
  253. border: none;
  254. }
  255. .btn-offline {
  256. background: #F5F7FA;
  257. color: #333;
  258. }
  259. .btn-edit {
  260. background: #F8C008;
  261. color: #333;
  262. }
  263. .no-data {
  264. margin: 150rpx auto 0;
  265. text-align: center;
  266. img {
  267. width: 65%;
  268. height: auto;
  269. }
  270. }
  271. .mores-txt {
  272. width: 100%;
  273. align-items: center;
  274. justify-content: center;
  275. height: 70rpx;
  276. color: #999;
  277. font-size: 24rpx;
  278. .iconfont {
  279. margin-top: 2rpx;
  280. font-size: 20rpx;
  281. }
  282. }
  283. .search-bar-con {
  284. display: flex;
  285. align-items: center;
  286. background-color: #fff;
  287. border-bottom: 1rpx solid #eee;
  288. }
  289. .search-input-wrapper {
  290. flex: 1;
  291. position: relative;
  292. display: flex;
  293. align-items: center;
  294. background-color: #F9F7F0;
  295. border-radius: 16rpx;
  296. height: 72rpx;
  297. line-height: 72rpx;
  298. padding: 0 20rpx;
  299. box-sizing: border-box;
  300. }
  301. .search-icon {
  302. margin-right: 20rpx;
  303. }
  304. .search-input {
  305. flex: 1;
  306. height: 100%;
  307. font-size: 28rpx;
  308. color: #333;
  309. }
  310. .placeholder {
  311. color: #999;
  312. font-size: 28rpx;
  313. }
  314. .clear-btn {
  315. padding: 10rpx;
  316. margin-left: 10rpx;
  317. }
  318. </style>