commodityManage.vue 13 KB

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