commodityManage.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <view>
  3. <!-- 顶部搜索加tab栏部分,点击批量打折是隐藏该部分 -->
  4. <view class="top-tab-search" v-if="!batch">
  5. <view class="search">
  6. <u--input
  7. v-model="keywords"
  8. placeholder="搜索商品名称"
  9. shape="circle"
  10. prefixIcon="search"
  11. prefixIconStyle="font-size: 22px;color: #909399"
  12. @change="search"
  13. ></u--input>
  14. <view class="screen" @click="openPopup">
  15. 筛选
  16. <image
  17. class="screen-icon"
  18. src="../../static/mine/334.png"
  19. mode=""
  20. ></image>
  21. </view>
  22. </view>
  23. <view class="tab">
  24. <view class="top-tab">
  25. <view
  26. :class="{ commodity: follow == '' }"
  27. class="tab"
  28. @click="tabSwitch('')"
  29. >
  30. 全部
  31. </view>
  32. <view
  33. :class="{ commodity: follow == 'normal' }"
  34. class="tab"
  35. @click="tabSwitch('normal')"
  36. >
  37. 已上架
  38. </view>
  39. <view
  40. :class="{ commodity: follow == 'down' }"
  41. class="tab"
  42. @click="tabSwitch('down')"
  43. >
  44. 已下架
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 顶部搜索加tab栏部分,点击批量打折是隐藏该部分 -->
  50. <!-- 内容 -->
  51. <view class="page">
  52. <u-checkbox-group
  53. v-model="selectedGoods"
  54. placement="column"
  55. @change="checkboxChange"
  56. >
  57. <view v-for="item in goodsList" :key="item.id">
  58. <view class="list">
  59. <view class="radio" v-if="batch">
  60. <u-checkbox
  61. :name="item.id"
  62. shape="circle"
  63. color="#f83224"
  64. activeColor="#f83224"
  65. :disabled="item.status == 'down'"
  66. >
  67. </u-checkbox>
  68. </view>
  69. <GoodsInformation
  70. :batch="batch"
  71. productAndCommodity="commodity"
  72. @openDiscountsPopup="openDiscountsPopup"
  73. :status="status"
  74. :itemInfo="item"
  75. @toDetail="toDetail"
  76. @deleteGoods="deleteGoods"
  77. @addAndRemove="addAndRemove"
  78. @cancelDiscount="cancelDiscount"
  79. />
  80. </view>
  81. </view>
  82. </u-checkbox-group>
  83. </view>
  84. <view class="footer" v-if="!batch">
  85. <view class="batch" @click="batchDiscount"> 批量打折 </view>
  86. <button class="btn-1" @click="toPlatform">上架平台商品</button>
  87. </view>
  88. <view class="footer" v-else>
  89. <view class="batch" @click="allSelect">
  90. <radio
  91. :checked="value"
  92. style="transform: scale(0.7)"
  93. color="#f83224"
  94. activeBackgroundColor="#f83224"
  95. ></radio>
  96. 全选
  97. </view>
  98. <view
  99. style="
  100. font-size: 26rpx;
  101. margin-left: 20rpx;
  102. color: rgba(54, 54, 54, 0.5);
  103. "
  104. @click="cancelBatchDiscount"
  105. >取消打折</view
  106. >
  107. <button class="btn" @click="wantDiscount">我要打折</button>
  108. </view>
  109. <!-- 筛选弹窗 -->
  110. <ScreenPopup :show="show" @close="close" :follow="follow" />
  111. <!-- 筛选弹窗 -->
  112. <!-- 打折弹窗 -->
  113. <DiscountsPopup
  114. :show="discountsShow"
  115. :selectGoodsInformation="selectGoodsInformation"
  116. @close="closeDiscountsPopup"
  117. />
  118. <!-- 打折弹窗 -->
  119. <!-- 批量打折 -->
  120. <BatchDiscountPopup
  121. :show="batchPopup"
  122. @close="closeDiscountsPopup"
  123. :selectGoodsInformation="selectGoodsInformation"
  124. />
  125. <agreePopup :agreeShow="agreeShow" :title="title" @close="closeDelete" />
  126. <u-toast ref="uToast"></u-toast>
  127. </view>
  128. </template>
  129. <script>
  130. import GoodsInformation from "./component/goodsInformation.vue";
  131. import ScreenPopup from "./component/screenPopup.vue";
  132. import DiscountsPopup from "./component/discountsPopup.vue";
  133. import BatchDiscountPopup from "./component/batchDiscountPopup.vue";
  134. import agreePopup from "../components/agreePopup";
  135. export default {
  136. components: {
  137. GoodsInformation,
  138. ScreenPopup,
  139. DiscountsPopup,
  140. BatchDiscountPopup,
  141. agreePopup,
  142. },
  143. data() {
  144. return {
  145. follow: "",
  146. status: "1",
  147. show: false,
  148. discountsShow: false,
  149. selectGoodsInformation: {},
  150. batch: false,
  151. value: false,
  152. batchPopup: false,
  153. goodsList: [],
  154. keywords: "", //搜索关键字
  155. source: "",
  156. selectedGoods: [],
  157. userId: "",
  158. agreeShow: false,
  159. needDeleteGoods: {},
  160. title: "",
  161. page: 1, //分页
  162. total: 0,
  163. limit: 10,
  164. };
  165. },
  166. computed: {
  167. i18n() {
  168. return this.$t("index");
  169. },
  170. //可选的商品数量,去掉下架的商品
  171. goodsLength() {
  172. let num = 0;
  173. this.goodsList.map((item) => {
  174. if (item.status != "down") {
  175. num++;
  176. }
  177. });
  178. return num;
  179. },
  180. },
  181. onLoad(options) {
  182. uni.getStorage({
  183. key: "user_info",
  184. success: ({ data }) => {
  185. this.userId = data.merchant.id;
  186. },
  187. });
  188. },
  189. watch: {
  190. selectedGoods(newVal) {
  191. if (this.goodsLength == newVal.length) {
  192. this.value = true;
  193. } else {
  194. this.value = false;
  195. }
  196. },
  197. },
  198. methods: {
  199. //删除商品
  200. deleteGoods(value) {
  201. console.log(value);
  202. this.agreeShow = true;
  203. this.title = "是否删除商品";
  204. this.needDeleteGoods = value;
  205. },
  206. //关闭确认弹窗
  207. closeDelete(value) {
  208. this.agreeShow = false;
  209. if (value) {
  210. if (this.title == "是否下架商品") {
  211. this.goodsApi(this.needDeleteGoods, "down");
  212. } else {
  213. uni.$u.http
  214. .post(`/api/goods/merchant_goods_del`, {
  215. merchant_goods_id: this.needDeleteGoods.id,
  216. })
  217. .then((res) => {
  218. this.getCommodityList(this.follow);
  219. uni.showToast({
  220. title: "商品已删除",
  221. icon: "none",
  222. });
  223. });
  224. }
  225. }
  226. },
  227. //取消打折
  228. cancelDiscount(item) {
  229. uni.$u.http
  230. .post(`/api/goods/cancel_discount`, {
  231. merchant_goods_id: item.id,
  232. })
  233. .then((res) => {
  234. this.getCommodityList();
  235. uni.showToast({
  236. title: "取消成功,商品初始折扣无法取消",
  237. icon: "none",
  238. });
  239. });
  240. },
  241. //商品上架 下架的接口调用
  242. goodsApi(item, value) {
  243. uni.$u.http
  244. .post(`/api/goods/modify_status`, {
  245. merchant_goods_id: item.id,
  246. status: value,
  247. })
  248. .then((res) => {
  249. uni.showToast({
  250. title: value == "down" ? "商品已下架" : "商品已上架",
  251. });
  252. this.getCommodityList(this.follow);
  253. });
  254. },
  255. //商品上架 or 下架
  256. addAndRemove(item, value) {
  257. if (value == "down") {
  258. this.title = "是否下架商品";
  259. this.agreeShow = true;
  260. // this.goodsApi(item, value);
  261. this.needDeleteGoods = item;
  262. } else {
  263. this.goodsApi(item, value);
  264. }
  265. },
  266. //切换横向tab栏
  267. tabSwitch(num) {
  268. this.follow = num;
  269. this.getCommodityList(num);
  270. },
  271. //跳转平台库商品
  272. toPlatform() {
  273. uni.navigateTo({
  274. url: `/pageD/platformProducts/platformProducts`,
  275. });
  276. },
  277. checkboxChange(e) {
  278. console.log(e);
  279. },
  280. //搜索
  281. search(e) {
  282. this.getCommodityList();
  283. },
  284. //打开筛选弹窗
  285. openPopup() {
  286. this.show = true;
  287. },
  288. //关闭筛选弹窗
  289. close(data) {
  290. this.show = false;
  291. if (data) {
  292. this.keywords = data.keywords;
  293. this.source = data.source;
  294. this.getCommodityList(data.status);
  295. } else {
  296. this.keywords = "";
  297. this.source = "";
  298. this.getCommodityList();
  299. }
  300. // this.follow = num;
  301. },
  302. //全选
  303. allSelect() {
  304. //判断是否已经全选
  305. if (this.selectedGoods.length == this.goodsLength) {
  306. this.selectedGoods = [];
  307. } else {
  308. this.goodsList.map((item) => {
  309. if (
  310. this.selectedGoods.indexOf(item.id) == -1 &&
  311. item.status != "down"
  312. ) {
  313. this.selectedGoods.push(item.id);
  314. }
  315. });
  316. }
  317. },
  318. //批量打折
  319. batchDiscount() {
  320. this.batch = !this.batch;
  321. uni.setNavigationBarTitle({
  322. title: "批量打折",
  323. });
  324. },
  325. cancelBatchDiscount() {
  326. this.batch = false;
  327. uni.setNavigationBarTitle({
  328. title: "商品管理",
  329. });
  330. this.selectedGoods = [];
  331. },
  332. //打开我要打折窗口
  333. wantDiscount() {
  334. if (this.selectedGoods == 0) {
  335. this.$refs.uToast.show({
  336. type: "default",
  337. title: "默认主题",
  338. message: "请选择至少一个商品",
  339. });
  340. return;
  341. }
  342. this.batchPopup = true;
  343. },
  344. //关闭折扣弹窗
  345. closeDiscountsPopup(value) {
  346. //判断是批量打折还是单个打折
  347. if (this.batchPopup) {
  348. this.batchPopup = false;
  349. if (value) {
  350. uni.$u.http
  351. //将选中商品的id使用","拼接
  352. .post(`/api/goods/discount`, {
  353. merchant_goods_id: this.selectedGoods.join(","),
  354. mer_discount: value,
  355. })
  356. .then((res) => {
  357. this.getCommodityList(this.follow);
  358. });
  359. this.batch = false;
  360. uni.setNavigationBarTitle({
  361. title: "商品管理",
  362. });
  363. }
  364. } else if (this.discountsShow) {
  365. this.discountsShow = false;
  366. if (value) {
  367. uni.$u.http
  368. .post(`/api/goods/discount`, {
  369. merchant_goods_id: this.selectGoodsInformation.id,
  370. mer_discount: value,
  371. })
  372. .then((res) => {
  373. this.getCommodityList(this.follow);
  374. });
  375. }
  376. }
  377. },
  378. //打开折扣弹窗
  379. openDiscountsPopup(value) {
  380. this.selectGoodsInformation = value;
  381. this.discountsShow = true;
  382. },
  383. toDetail(item) {
  384. uni.navigateTo({
  385. url: `/pageD/productDetails/productDetails?goodsId=${item.id}`,
  386. });
  387. },
  388. getCommodityList(status = "", value = "") {
  389. uni.$u.http
  390. .post(`/api/goods/merchant_goods`, {
  391. page: this.page,
  392. limit: 10,
  393. merchant_id: this.userId,
  394. status: status,
  395. keywords: this.keywords,
  396. source: this.source,
  397. })
  398. .then((res) => {
  399. if (!value) {
  400. this.goodsList = res.data;
  401. } else {
  402. this.goodsList = this.goodsList.concat(res.data);
  403. }
  404. this.total = res.total;
  405. });
  406. },
  407. },
  408. //触底加载
  409. onReachBottom() {
  410. if (this.goodsList.length < this.total) {
  411. this.page++;
  412. this.getCommodityList("", 1);
  413. }
  414. },
  415. mounted() {
  416. this.getCommodityList();
  417. uni.setNavigationBarTitle({
  418. title: "商品管理",
  419. });
  420. },
  421. };
  422. </script>
  423. <style lang="scss" scoped>
  424. .top-tab-search {
  425. background-color: #fff;
  426. padding: 10rpx 24rpx;
  427. z-index: 20174;
  428. .search {
  429. display: flex;
  430. align-items: center;
  431. .screen {
  432. display: flex;
  433. align-items: center;
  434. font-size: 26rpx;
  435. color: #333;
  436. margin-left: 20rpx;
  437. .screen-icon {
  438. width: 24rpx;
  439. height: 24rpx;
  440. margin-left: 5rpx;
  441. }
  442. }
  443. }
  444. .top-tab {
  445. margin-top: 10rpx;
  446. padding: 0 20rpx;
  447. display: flex;
  448. justify-content: space-between;
  449. .tab {
  450. font-size: 26rpx;
  451. color: rgba(34, 34, 34, 0.8);
  452. flex-shrink: 0;
  453. height: 44rpx;
  454. display: flex;
  455. align-items: flex-end;
  456. padding-bottom: 12rpx;
  457. }
  458. .commodity {
  459. position: relative;
  460. font-weight: 600;
  461. }
  462. .commodity::before {
  463. content: "";
  464. display: block;
  465. height: 4rpx;
  466. width: 50%;
  467. background: #f83224;
  468. position: absolute;
  469. bottom: -10rpx;
  470. opacity: 0.8;
  471. left: 50%;
  472. transform: translate(-50%, 50%);
  473. }
  474. }
  475. }
  476. .page {
  477. padding: 20rpx 24rpx;
  478. background-color: #fff;
  479. margin-bottom: 150rpx;
  480. .list {
  481. display: flex;
  482. flex-wrap: nowrap;
  483. align-items: center;
  484. .radio {
  485. margin-right: 20rpx;
  486. }
  487. }
  488. }
  489. .footer {
  490. position: fixed;
  491. display: flex;
  492. align-items: center;
  493. justify-content: space-between;
  494. bottom: 0;
  495. background-color: #fff;
  496. width: 93%;
  497. padding: 16rpx 24rpx 70rpx 24rpx;
  498. .batch {
  499. color: #333;
  500. font-size: 28rpx;
  501. margin-right: 50rpx;
  502. display: flex;
  503. align-items: center;
  504. }
  505. .btn-1 {
  506. width: 236rpx;
  507. height: 76rpx;
  508. border-radius: 52rpx;
  509. background-color: #fff;
  510. color: #f83224;
  511. border: 2rpx solid #f83224;
  512. padding: 0;
  513. margin: 0;
  514. font-size: 30rpx;
  515. }
  516. .btn {
  517. width: 236rpx;
  518. height: 76rpx;
  519. border-radius: 52rpx;
  520. background-color: #f83224;
  521. color: #fff;
  522. border: none;
  523. padding: 0;
  524. margin: 0;
  525. font-size: 30rpx;
  526. }
  527. }
  528. </style>