productManagement.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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:'36px',
  31. }"
  32. :activeStyle="{
  33. color: '#F8C008',
  34. fontWeight: 'bold',
  35. transform: 'scale(1.05)'
  36. }"
  37. :inactiveStyle="{
  38. color: '#333333',
  39. transform: 'scale(1)'
  40. }"></up-tabs>
  41. <!-- 管理按钮 -->
  42. <view v-if="goodsList.length" class='nav acea-row row-between-wrapper'>
  43. <view>共 <text class='num font-color'>{{ goodsList.length }}</text>件商品</view>
  44. <view class='administrate acea-row row-center-wrapper' @click='manage'>
  45. {{ footerswitch ? '管理' : '取消' }}
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 商品列表 -->
  50. <view class="product-list">
  51. <up-checkbox-group shape="circle" @change="checkboxChange" class="centent" activeColor="#F8C008">
  52. <view class="product-card" v-for="(item, index) in goodsList" :key="index">
  53. <view class="product-header">
  54. <!-- 多选框 -->
  55. <up-checkbox
  56. :name="item.id.toString()"
  57. :checked="item.checked"
  58. v-if="!footerswitch"
  59. style="margin-right: 10rpx;"
  60. activeColor="#F8C008"
  61. />
  62. <image class="product-image" :src="item.image" mode="aspectFit" />
  63. <view class="product-info">
  64. <view class="nameweight">
  65. <text class="product-name">{{ item.storeName }}</text>
  66. <text class="product-weight">{{ item.weight }}g</text>
  67. </view>
  68. <view class="nameweight">
  69. <view class="price-info">
  70. <text class="label">工费</text>
  71. <view class="value"><text class="unit">¥</text>{{ item.totalLaborCost }}<text class="unit">/g</text></view>
  72. </view>
  73. <view class="price-info">
  74. <text class="label">附加费</text>
  75. <view class="value"><text class="unit">¥</text>{{ item.additionalAmount }}</view>
  76. </view>
  77. </view>
  78. <view class="product-stats">
  79. <text class="stat">销量:{{ Number(item.sales || 0) + Number(item.ficti || 0) }}</text>
  80. <text class="stat">库存:{{ item.stock }}</text>
  81. </view>
  82. </view>
  83. </view>
  84. <view class="action-buttons">
  85. <button class="btn btn-delete" @click="deleteFn(item,index)">删除</button>
  86. <button class="btn btn-offline" v-show="params.isShow==1" @click="OffShellFn(item,index)">下架</button>
  87. <button class="btn btn-offline" v-show="params.isShow==0" @click="PutOnShellFn(item,index)">上架</button>
  88. <button class="btn btn-edit" v-show="params.isShow==0" @click="toEditProduct(item)">编辑</button>
  89. </view>
  90. </view>
  91. </up-checkbox-group>
  92. <view class="loadingicon acea-row row-center-wrapper" v-if="goodScroll">
  93. <text
  94. class="loading iconfont icon-jiazai"
  95. :hidden="loading == false"
  96. ></text>
  97. </view>
  98. <view class="no-data" v-if="isNoDataState">
  99. <image
  100. 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"
  101. />
  102. </view>
  103. <view class="mores-txt flex" v-if="!goodScroll && !isNoDataState">
  104. <text>我是有底线的</text>
  105. </view>
  106. </view>
  107. <!-- 底部操作栏 -->
  108. <view v-if="!footerswitch" class='footer acea-row row-between-wrapper'>
  109. <view>
  110. <up-checkbox-group shape="circle" @change="checkboxAllChange">
  111. <up-checkbox value="all" :checked="!!isAllSelect" activeColor="#F8C008" />
  112. <text class='checkAll'>全选</text>
  113. </up-checkbox-group>
  114. </view>
  115. <view class='button acea-row row-middle'>
  116. <button v-if="params.isShow==1" class='bnt' @click="batchOffShell">批量下架</button>
  117. <button v-if="params.isShow==0" class='bnt' @click="batchPutOnShell">批量上架</button>
  118. <!-- <button class='bnt cart-color delete-btn' @click="batchDelete">批量删除</button>-->
  119. </view>
  120. </view>
  121. </view>
  122. </template>
  123. <script setup>
  124. import {computed, ref,watch} from 'vue'
  125. import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
  126. import { productsList, productPutOnShell, productOffShell, productDelete, batchStatus } from "@/api/merchant.js";
  127. import { useAppStore } from "@/stores/app";
  128. const appStore = useAppStore();
  129. // 管理相关状态
  130. const footerswitch = ref(true); // true: 显示正常模式, false: 显示管理模式
  131. const isAllSelect = ref(false); // 是否全选
  132. const selectValue = ref([]); // 选中的商品ID数组
  133. const tabList = ref([
  134. {name:'销售中',code:1},
  135. {name:'已下架',code:0}
  136. ])
  137. const searchVal = ref('')
  138. const goodsList = ref([]);
  139. const goodType = ref(1);
  140. // Pagination
  141. const params = ref({
  142. page: 1,
  143. limit: 10,
  144. isShow:1,
  145. });
  146. const loading = ref(false);
  147. const goodScroll = ref(true);
  148. const merchantInfo = ref({})
  149. const isFocus = ref(false)
  150. const isNoDataState = computed(() => {
  151. return goodsList.value.length === 0 && !loading.value;
  152. });
  153. onShow(() => {
  154. merchantInfo.value = appStore.userInfo.merchant;
  155. getGroomList()
  156. })
  157. // 切换管理状态
  158. const manage = () => {
  159. footerswitch.value = !footerswitch.value;
  160. // 退出管理状态时,清空选择
  161. if (footerswitch.value) {
  162. resetSelection();
  163. }
  164. }
  165. // 重置选择状态
  166. const resetSelection = () => {
  167. goodsList.value.forEach(item => {
  168. item.checked = false;
  169. });
  170. isAllSelect.value = false;
  171. selectValue.value = [];
  172. }
  173. // 多选框变化
  174. const checkboxChange = (values) => {
  175. goodsList.value.forEach(item => {
  176. item.checked = values.includes(item.id.toString());
  177. });
  178. selectValue.value = values;
  179. isAllSelect.value = goodsList.value.length === values.length;
  180. };
  181. // 全选变化
  182. const checkboxAllChange = (event) => {
  183. if (event.length > 0) {
  184. setAllSelectValue(1);
  185. } else {
  186. setAllSelectValue(0);
  187. }
  188. };
  189. // 设置全选状态
  190. const setAllSelectValue = (status) => {
  191. const selectValues = [];
  192. goodsList.value.forEach(item => {
  193. if (status) {
  194. item.checked = true;
  195. selectValues.push(item.id);
  196. isAllSelect.value = true;
  197. } else {
  198. item.checked = false;
  199. isAllSelect.value = false;
  200. }
  201. });
  202. selectValue.value = selectValues;
  203. console.log(selectValue.value)
  204. };
  205. // 检查是否有选中商品
  206. const checkHasSelected = () => {
  207. if (!selectValue.value || selectValue.value.length === 0) {
  208. uni.showToast({ title: '请先选择商品', icon: 'none' });
  209. return false;
  210. }
  211. return true;
  212. }
  213. // 批量下架
  214. const batchOffShell = async () => {
  215. if (!checkHasSelected()) return;
  216. uni.showModal({
  217. title: '提示',
  218. content: `确定要下架选中的${selectValue.value.length}件商品吗?`,
  219. success: async (res) => {
  220. if (res.confirm) {
  221. try {
  222. const { code, message } = await batchStatus({ ids: selectValue.value, status:0 });
  223. if (code === 200) {
  224. uni.showToast({ title: '批量下架成功', icon: 'success' });
  225. // 从列表中移除下架的商品
  226. goodsList.value = goodsList.value.filter(item => !selectValue.value.includes(item.id.toString()));
  227. resetSelection();
  228. footerswitch.value = true; // 退出管理模式
  229. } else {
  230. uni.showToast({ title: message || '操作失败', icon: 'none' });
  231. }
  232. } catch (err) {
  233. uni.showToast({ title: err.message || '操作失败', icon: 'none' });
  234. }
  235. }
  236. }
  237. });
  238. }
  239. // 批量上架
  240. const batchPutOnShell = async () => {
  241. if (!checkHasSelected()) return;
  242. uni.showModal({
  243. title: '提示',
  244. content: `确定要上架选中的${selectValue.value.length}件商品吗?`,
  245. success: async (res) => {
  246. if (res.confirm) {
  247. try {
  248. const { code, message } = await batchStatus({ ids: selectValue.value,status:1 });
  249. if (code === 200) {
  250. uni.showToast({ title: '批量上架成功', icon: 'success' });
  251. // 从列表中移除上架的商品
  252. goodsList.value = goodsList.value.filter(item => !selectValue.value.includes(item.id.toString()));
  253. resetSelection();
  254. footerswitch.value = true; // 退出管理模式
  255. } else {
  256. uni.showToast({ title: message || '操作失败', icon: 'none' });
  257. }
  258. } catch (err) {
  259. uni.showToast({ title: err.message || '操作失败', icon: 'none' });
  260. }
  261. }
  262. }
  263. });
  264. }
  265. // 批量删除
  266. // const batchDelete = async () => {
  267. // if (!checkHasSelected()) return;
  268. //
  269. // uni.showModal({
  270. // title: '警告',
  271. // content: `确定要删除选中的${selectValue.value.length}件商品吗?此操作不可恢复!`,
  272. // success: async (res) => {
  273. // if (res.confirm) {
  274. // try {
  275. // const { code, message } = await batchDeleteApi({ ids: selectValue.value.join(',') });
  276. // if (code === 200) {
  277. // uni.showToast({ title: '批量删除成功', icon: 'success' });
  278. // // 从列表中移除删除的商品
  279. // goodsList.value = goodsList.value.filter(item => !selectValue.value.includes(item.id.toString()));
  280. // resetSelection();
  281. // footerswitch.value = true; // 退出管理模式
  282. // } else {
  283. // uni.showToast({ title: message || '操作失败', icon: 'none' });
  284. // }
  285. // } catch (err) {
  286. // uni.showToast({ title: err.message || '操作失败', icon: 'none' });
  287. // }
  288. // }
  289. // }
  290. // });
  291. // }
  292. const tabChange = (item) => {
  293. console.log('item',item)
  294. goodsList.value = [];
  295. loading.value = false;
  296. goodScroll.value = true;
  297. params.value.isShow = item.code;
  298. params.value.page = 1;
  299. getGroomList();
  300. // 切换标签时退出管理模式
  301. footerswitch.value = true;
  302. resetSelection();
  303. }
  304. const onSearch = () => {
  305. goodsList.value = [];
  306. loading.value = false;
  307. goodScroll.value = true;
  308. params.value.page = 1;
  309. getGroomList();
  310. // 搜索时退出管理模式
  311. footerswitch.value = true;
  312. resetSelection();
  313. }
  314. // 清除搜索内容
  315. const onClear = () => {
  316. console.log('清除搜索内容');
  317. searchVal.value = '';
  318. onSearch();
  319. }
  320. const getGroomList = async () => {
  321. if (!goodScroll.value) return;
  322. try {
  323. loading.value = true;
  324. params.value.merchantId = merchantInfo.value.id;
  325. params.value.keyword = searchVal.value;
  326. const { data } = await productsList(params.value);
  327. // 初始化选择状态
  328. const newList = data.list || [];
  329. newList.forEach(item => {
  330. item.checked = false;
  331. });
  332. goodsList.value = [...goodsList.value, ...newList];
  333. goodScroll.value = data.list.length >= params.value.limit;
  334. params.value.page++;
  335. } catch (err) {
  336. console.error(err);
  337. } finally {
  338. loading.value = false;
  339. }
  340. };
  341. async function OffShellFn(obj,index) {
  342. const {code} = await productOffShell(obj.id);
  343. if(code == 200){
  344. uni.showToast({ title: "操作成功", icon: "none" });
  345. goodsList.value.splice(index,1);
  346. }
  347. }
  348. async function PutOnShellFn(obj,index) {
  349. const {code} = await productPutOnShell(obj.id);
  350. if(code == 200){
  351. uni.showToast({ title: "操作成功", icon: "none" });
  352. goodsList.value.splice(index,1);
  353. }
  354. }
  355. function toEditProduct (obj){
  356. uni.navigateTo({
  357. url:`/pages/merchantCenters/releaseProduct?id=${obj.id}`
  358. })
  359. }
  360. async function deleteFn(obj,index){
  361. uni.showModal({
  362. title: '警告',
  363. content: '确定要删除此商品吗?此操作不可恢复!',
  364. success: async (res) => {
  365. if (res.confirm) {
  366. const {code} = await productDelete(obj.id);
  367. if(code == 200){
  368. uni.showToast({ title: "操作成功", icon: "none" });
  369. goodsList.value.splice(index,1);
  370. }
  371. }
  372. }
  373. });
  374. }
  375. onReachBottom(() => {
  376. getGroomList();
  377. });
  378. </script>
  379. <style scoped>
  380. /* 管理栏样式 */
  381. .nav {
  382. width: 100%;
  383. height: 90rpx;
  384. background-color: #fff;
  385. padding: 0 30rpx;
  386. box-sizing: border-box;
  387. font-size: 28rpx;
  388. color: #282828;
  389. border-top: 1px solid #f0f0f0;
  390. border-bottom: 1px solid #f0f0f0;
  391. margin-top: 20rpx;
  392. }
  393. .nav .administrate {
  394. width: 120rpx;
  395. height: 50rpx;
  396. border-radius: 8rpx;
  397. border: 1px solid #F8C008;
  398. color: #F8C008;
  399. font-size: 24rpx;
  400. }
  401. .num {
  402. color: #F8C008;
  403. font-weight: bold;
  404. margin: 0 4rpx;
  405. }
  406. /* 底部操作栏样式 */
  407. .footer {
  408. z-index: 9;
  409. width: 100%;
  410. height: 96rpx;
  411. background-color: #fff;
  412. position: fixed;
  413. padding: 0 30rpx;
  414. box-sizing: border-box;
  415. border-top: 1rpx solid #eee;
  416. border-bottom: 1px solid #EEEEEE;
  417. bottom: 0rpx;
  418. }
  419. .footer .checkAll {
  420. font-size: 28rpx;
  421. color: #282828;
  422. margin-left: 16rpx;
  423. line-height: 56rpx;
  424. }
  425. .footer .button {
  426. display: flex;
  427. gap: 20rpx;
  428. }
  429. .footer .button .bnt {
  430. font-size: 28rpx;
  431. color: #333333;
  432. border-radius: 8rpx;
  433. background-color: #F8C008;
  434. width: 180rpx;
  435. height: 60rpx;
  436. line-height: 60rpx;
  437. text-align: center;
  438. border: none;
  439. }
  440. .footer .button .delete-btn {
  441. color:#F52929;
  442. background-color: #FEEAEA;
  443. }
  444. /* 商品卡片调整 */
  445. .product-card {
  446. width: 100%;
  447. position: relative;
  448. background-color: #fff;
  449. border-radius: 16rpx;
  450. padding: 20rpx;
  451. margin: 10rpx 20rpx;
  452. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  453. }
  454. .product-header {
  455. display: flex;
  456. align-items: flex-start;
  457. margin-bottom: 20rpx;
  458. }
  459. .product-image {
  460. width: 180rpx;
  461. height: 180rpx;
  462. border-radius: 12rpx;
  463. margin-right: 20rpx;
  464. }
  465. .product-info {
  466. flex: 1;
  467. }
  468. .nameweight {
  469. display: flex;
  470. justify-content: space-between;
  471. align-items: center;
  472. margin-bottom: 20rpx;
  473. }
  474. .product-name {
  475. font-size: 28rpx;
  476. font-weight: bold;
  477. color: #333;
  478. flex: 1;
  479. margin-right: 20rpx;
  480. }
  481. .product-weight {
  482. font-size: 24rpx;
  483. color: #999;
  484. background: #f5f5f5;
  485. padding: 4rpx 12rpx;
  486. border-radius: 8rpx;
  487. }
  488. .price-info {
  489. display: flex;
  490. align-items: center;
  491. margin-bottom: 10rpx;
  492. }
  493. .price-info .label {
  494. font-size: 24rpx;
  495. color: #666;
  496. margin-right: 10rpx;
  497. min-width: 60rpx;
  498. }
  499. .price-info .value {
  500. font-size: 28rpx;
  501. color: #e64340;
  502. font-weight: bold;
  503. }
  504. .price-info .unit {
  505. font-size: 20rpx;
  506. }
  507. .product-stats {
  508. display: flex;
  509. gap: 30rpx;
  510. margin-top: 10rpx;
  511. }
  512. .product-stats .stat {
  513. font-size: 24rpx;
  514. color: #999;
  515. }
  516. .action-buttons {
  517. display: flex;
  518. justify-content: flex-start;
  519. align-items: center;
  520. gap: 20rpx;
  521. padding-top: 10rpx;
  522. //border-top: 1rpx solid #f0f0f0;
  523. }
  524. .btn {
  525. font-size: 28rpx;
  526. border-radius: 8rpx;
  527. background: transparent;
  528. flex: 1;
  529. height: 60rpx;
  530. line-height: 60rpx;
  531. }
  532. .btn-delete {
  533. color: #F52929;
  534. background-color: #FEEAEA;
  535. }
  536. .btn-offline {
  537. color: #333333;
  538. background-color: #F5F7FA;
  539. }
  540. .btn-edit {
  541. color: #333333;
  542. background-color: #F8C008;
  543. }
  544. /* 搜索栏样式 */
  545. .search-bar {
  546. background-color: #fff;
  547. position: sticky;
  548. top: 0;
  549. z-index: 100;
  550. padding: 20rpx 30rpx 0;
  551. }
  552. .search-bar-con {
  553. padding-bottom: 20rpx;
  554. }
  555. .search-input-wrapper {
  556. display: flex;
  557. align-items: center;
  558. background-color: #f5f5f5;
  559. border-radius: 50rpx;
  560. padding: 0 20rpx;
  561. height: 70rpx;
  562. }
  563. .search-icon {
  564. margin-right: 10rpx;
  565. }
  566. .search-input {
  567. flex: 1;
  568. height: 100%;
  569. font-size: 28rpx;
  570. color: #333;
  571. }
  572. .placeholder {
  573. color: #999;
  574. font-size: 28rpx;
  575. }
  576. .clear-btn {
  577. width: 40rpx;
  578. height: 40rpx;
  579. border-radius: 50%;
  580. background: #e0e0e0;
  581. display: flex;
  582. align-items: center;
  583. justify-content: center;
  584. margin-left: 10rpx;
  585. }
  586. /* 加载状态 */
  587. .loadingicon {
  588. text-align: center;
  589. color: #999;
  590. font-size: 24rpx;
  591. padding: 30rpx 0;
  592. }
  593. /* 无数据状态 */
  594. .no-data {
  595. display: flex;
  596. justify-content: center;
  597. padding: 100rpx 0;
  598. }
  599. .no-data image {
  600. width: 300rpx;
  601. height: 300rpx;
  602. }
  603. .mores-txt {
  604. text-align: center;
  605. color: #999;
  606. font-size: 24rpx;
  607. padding: 30rpx 0 60rpx;
  608. border-top: 1rpx solid #f0f0f0;
  609. margin-top: 20rpx;
  610. align-items: center;
  611. justify-content: center;
  612. }
  613. </style>