list.vue 8.5 KB

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