list.vue 8.6 KB

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