productManagement.vue 17 KB

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