productManagement.vue 8.8 KB

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