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:'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="item.id">
  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="aspectFill" />
  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(String(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. console.log(selectValue.value)
  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: 20rpx;
  452. margin: 10rpx 20rpx;
  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: 10rpx;
  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>