buyagain.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view class="container all-type-list-wrapper">
  3. <buyagain-list ref="productList" @operationConfim="hanldOperationConfim" @goCartPage="hanldToCartPage">
  4. </buyagain-list>
  5. <!--底部选择模态层弹窗组件 -->
  6. <view class="popup spec" :class="specClass" @touchmove.stop.prevent="discard" @tap="hideSpec">
  7. <!-- 遮罩层 -->
  8. <view class="mask"></view>
  9. <view
  10. class="layer"
  11. @tap.stop="discard"
  12. :style="{ paddingBottom: isIphoneX ? '68rpx' : '36rpx', bottom: isIphoneX ? '-352rpx' : '-320rpx' }"
  13. >
  14. <view class="content">
  15. <view class="layer-smimg"> <image :src="handleData.image" mode=""></image> </view>
  16. <view class="layer-nunbox">
  17. <view class="layer-nunbox-t">
  18. <view class="layer-nunbox-text">数量:</view>
  19. <view class="number-box">
  20. <view
  21. class="iconfont icon-jianhao"
  22. :class="[isQuantity == true ? 'disabled' : '']"
  23. @click="changeCountSub()"
  24. ></view>
  25. <input
  26. class="btn-input"
  27. type="number"
  28. v-model="number"
  29. maxlength="4"
  30. @blur="changeNumber($event)"
  31. />
  32. <view
  33. class="iconfont icon-jiahao"
  34. :class="[isStock == true ? 'disabled' : '']"
  35. @click="changeCountAdd()"
  36. ></view>
  37. </view>
  38. </view>
  39. <view class="layer-nunbox-b">
  40. <view class="text"
  41. >单价: <text class="p sm">¥</text>
  42. <text class="p bg">{{ buyRetailPrice.toFixed(2) }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="btn"> <view class="button add" @click="getAddProductCart">加入购物车</view> </view>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import buyagainList from '@/components/cm-module/listTemplate/buyagainList'
  54. export default {
  55. components: {
  56. buyagainList
  57. },
  58. data() {
  59. return {
  60. isIphoneX: this.$store.state.isIphoneX,
  61. clubID: '', //机构ID
  62. serviceProviderId: '', //协销ID
  63. serverUrl: '',
  64. emptyText: '',
  65. lastPageType: '',
  66. lastPageVal: '',
  67. specClass: '', //规格弹窗css类,控制开关动画
  68. handleData: {},
  69. isQuantity: false,
  70. isStock: false,
  71. minBuyNumber: 0,
  72. number: 1,
  73. buyRetailPrice: 0,
  74. buyRetailPriceStep: 1
  75. }
  76. },
  77. onLoad() {},
  78. methods: {
  79. getClubProductNum() {
  80. this.SellerService.GetSellerProductNum({
  81. clubId: this.clubID,
  82. serviceProviderId: this.serviceProviderId
  83. }).then(response => {
  84. this.$refs.productList.cartQuantity = response.data
  85. })
  86. },
  87. hanldOperationConfim(data) {
  88. //显示选择数量确认弹窗
  89. console.log(data)
  90. this.specClass = 'show'
  91. this.handleData = data
  92. this.minBuyNumber = data.minBuyNumber
  93. this.buyRetailPrice = data.price
  94. this.buyRetailPriceStep = data.step
  95. if (this.handleData.ladderPriceFlag == 1) {
  96. this.number = data.maxBuyNumber ? data.maxBuyNumber : 1
  97. } else {
  98. this.number = data.minBuyNumber ? data.minBuyNumber : 1
  99. }
  100. },
  101. hideSpec() {
  102. //关闭选择数量确认弹窗
  103. this.specClass = 'hide'
  104. setTimeout(() => {
  105. this.specClass = 'none'
  106. }, 200)
  107. },
  108. changeCountAdd() {
  109. //popup弹窗数量增加按钮
  110. if (this.buyRetailPriceStep == 2) {
  111. this.number += this.minBuyNumber
  112. } else {
  113. this.number++
  114. }
  115. this.calculatPerice()
  116. },
  117. changeCountSub() {
  118. //popup弹窗数量减按钮
  119. if (this.number <= this.minBuyNumber) {
  120. this.number = this.minBuyNumber
  121. this.isQuantity = true
  122. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`, 2000)
  123. return
  124. } else {
  125. if (this.buyRetailPriceStep == 2) {
  126. this.number -= this.minBuyNumber
  127. } else {
  128. this.number--
  129. }
  130. this.calculatPerice()
  131. this.isQuantity = false
  132. }
  133. },
  134. changeNumber(e) {
  135. let _value = e.detail.value
  136. if (!this.$api.isNumber(_value)) {
  137. this.number = this.minBuyNumber
  138. } else if (_value < this.minBuyNumber) {
  139. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`, 2000)
  140. this.number = this.minBuyNumber
  141. } else if (_value % this.minBuyNumber != 0) {
  142. this.$util.msg('购买量必须为起订量的整数倍', 2000)
  143. this.number = this.minBuyNumber
  144. } else {
  145. this.number = e.detail.value
  146. this.calculatPerice()
  147. }
  148. },
  149. calculatPerice() {
  150. //判断是否为阶梯价然后做计算价格处理
  151. if (this.handleData.ladderPriceFlag == 1) {
  152. this.handleData.ladderPrices.forEach((item, index) => {
  153. if (this.number >= item.buyNum) {
  154. this.buyRetailPrice = item.buyPrice
  155. }
  156. })
  157. } else {
  158. this.buyRetailPrice = this.handleData.retailPrice
  159. }
  160. },
  161. getAddProductCart() {
  162. //增加购物车成功和toast弹窗提示成功
  163. let params = {
  164. productId: this.handleData.productId,
  165. clubId: this.clubID,
  166. serviceProviderId: this.serviceProviderId,
  167. productCount: this.number,
  168. type:1
  169. }
  170. this.SellerService.ShoppingCartAddCart(params)
  171. .then(response => {
  172. this.specClass = 'hide'
  173. this.$util.msg('加入购物车成功', 1500, true, 'success')
  174. this.getClubProductNum()
  175. setTimeout(() => {
  176. this.specClass = 'none'
  177. }, 200)
  178. })
  179. .catch(error => {
  180. this.$util.msg(error.msg, 2000)
  181. })
  182. },
  183. hanldToCartPage() {
  184. this.$api.navigateTo('/pages/seller/cart/cart')
  185. },
  186. discard() {
  187. //丢弃
  188. }
  189. },
  190. onShow() {
  191. this.$api.getComStorage('orderUserInfo').then(resolve => {
  192. this.clubID = resolve.clubID
  193. })
  194. this.$api.getStorage().then(resolve => {
  195. this.serviceProviderId = resolve.serviceProviderId
  196. this.getClubProductNum()
  197. })
  198. }
  199. }
  200. </script>
  201. <style lang="scss">
  202. page {
  203. background: $sub-bg-color;
  204. .all-type-list-wrapper {
  205. display: flex;
  206. flex-direction: column;
  207. }
  208. }
  209. /* 加入购物模态层*/
  210. @keyframes showPopup {
  211. 0% {
  212. opacity: 0;
  213. }
  214. 100% {
  215. opacity: 1;
  216. }
  217. }
  218. @keyframes hidePopup {
  219. 0% {
  220. opacity: 1;
  221. }
  222. 100% {
  223. opacity: 0;
  224. }
  225. }
  226. @keyframes showLayer {
  227. 0% {
  228. transform: translateY(0);
  229. }
  230. 100% {
  231. transform: translateY(-100%);
  232. }
  233. }
  234. @keyframes hideLayer {
  235. 0% {
  236. transform: translateY(-100%);
  237. }
  238. 100% {
  239. transform: translateY(0);
  240. }
  241. }
  242. @keyframes showAmnation {
  243. 0% {
  244. top: -12rpx;
  245. opacity: 0;
  246. }
  247. 50% {
  248. top: -60rpx;
  249. opacity: 1;
  250. }
  251. 100% {
  252. top: -100rpx;
  253. opacity: 0;
  254. }
  255. }
  256. @keyframes hideAmnation {
  257. 0% {
  258. top: -100rpx;
  259. opacity: 0;
  260. }
  261. 100% {
  262. top: -12rpx;
  263. opacity: 0;
  264. }
  265. }
  266. .popup {
  267. position: fixed;
  268. top: 0;
  269. width: 100%;
  270. height: 100%;
  271. z-index: 999;
  272. display: none;
  273. .mask {
  274. position: fixed;
  275. top: 0;
  276. width: 100%;
  277. height: 100%;
  278. z-index: 21;
  279. background-color: rgba(0, 0, 0, 0.6);
  280. }
  281. .layer {
  282. position: fixed;
  283. z-index: 22;
  284. bottom: -294rpx;
  285. width: 702rpx;
  286. padding: 24rpx 24rpx 36rpx 24rpx;
  287. height: 260rpx;
  288. border-radius: 20rpx 20rpx 0 0;
  289. background-color: #fff;
  290. display: flex;
  291. flex-wrap: wrap;
  292. align-content: space-between;
  293. .content {
  294. width: 100%;
  295. }
  296. .btn {
  297. width: 100%;
  298. height: 88rpx;
  299. display: flex;
  300. .button {
  301. width: 702rpx;
  302. height: 88rpx;
  303. color: #fff;
  304. display: flex;
  305. align-items: center;
  306. justify-content: center;
  307. font-size: $font-size-28;
  308. border-radius: 44rpx;
  309. background: $btn-confirm;
  310. }
  311. }
  312. }
  313. &.show {
  314. display: block;
  315. .mask {
  316. animation: showPopup 0.2s linear both;
  317. }
  318. .layer {
  319. animation: showLayer 0.2s linear both;
  320. }
  321. }
  322. &.hide {
  323. display: block;
  324. .mask {
  325. animation: hidePopup 0.2s linear both;
  326. }
  327. .layer {
  328. animation: hideLayer 0.2s linear both;
  329. }
  330. }
  331. &.none {
  332. display: none;
  333. }
  334. &.service {
  335. .row {
  336. margin: 30upx 0;
  337. .title {
  338. font-size: 30upx;
  339. margin: 10upx 0;
  340. }
  341. .description {
  342. font-size: 28upx;
  343. color: #999;
  344. }
  345. }
  346. }
  347. .layer-smimg {
  348. width: 114rpx;
  349. height: 114rpx;
  350. float: left;
  351. border-radius: 10rpx;
  352. margin-right: 24rpx;
  353. image {
  354. width: 114rpx;
  355. height: 114rpx;
  356. border-radius: 10rpx;
  357. }
  358. }
  359. .layer-nunbox {
  360. justify-content: space-between;
  361. align-items: center;
  362. width: 536rpx;
  363. height: 88rpx;
  364. padding: 13rpx 0 0 0;
  365. float: left;
  366. .layer-nunbox-t {
  367. width: 100%;
  368. height: 44rpx;
  369. position: relative;
  370. display: flex;
  371. .layer-nunbox-text {
  372. line-height: 44rpx;
  373. font-size: $font-size-28;
  374. }
  375. .number-box {
  376. display: flex;
  377. justify-content: center;
  378. align-items: center;
  379. border: 2rpx solid #ffe6dc;
  380. border-radius: 30rpx;
  381. height: 48rpx;
  382. margin-left: 20rpx;
  383. .iconfont {
  384. font-size: $font-size-24;
  385. padding: 0 18rpx;
  386. color: #999999;
  387. text-align: center;
  388. line-height: 48rpx;
  389. font-weight: bold;
  390. background: #fef6f3;
  391. &.icon-jianhao {
  392. border-radius: 30rpx 0 0 30rpx;
  393. }
  394. &.icon-jiahao {
  395. border-radius: 0 30rpx 30rpx 0;
  396. }
  397. }
  398. .btn-input {
  399. width: 62rpx;
  400. height: 48rpx;
  401. line-height: 48rpx;
  402. background: #ffffff;
  403. border-radius: 4rpx;
  404. text-align: center;
  405. font-size: $font-size-28;
  406. }
  407. }
  408. .product-step {
  409. position: absolute;
  410. left: 45rpx;
  411. bottom: 0;
  412. height: 44rpx;
  413. background: #ffffff;
  414. }
  415. }
  416. .layer-nunbox-b {
  417. width: 100%;
  418. height: 44rpx;
  419. margin-top: 13rpx;
  420. }
  421. .text {
  422. line-height: 44rpx;
  423. font-size: $font-size-28;
  424. .p {
  425. color: #ff2a2a;
  426. }
  427. .p:first-child {
  428. margin-left: 30rpx;
  429. }
  430. .p.sm {
  431. font-size: $font-size-24;
  432. }
  433. }
  434. }
  435. }
  436. </style>