productManagement.vue 9.4 KB

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