productManagement.vue 9.2 KB

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