productCenter.vue 8.8 KB

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