cm-unit-popup.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template name="cm-parameter">
  2. <!-- 相关规格 -->
  3. <view>
  4. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  5. <view class="tui-popup-box clearfix">
  6. <view class="tui-shopping-main" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
  7. <view class="tui-sku-title">
  8. <view class="tui-sku-image"> <image :src="skuProduct.mainImage" mode=""></image> </view>
  9. <view class="tui-sku-price">
  10. <cmUnitPrice :skuProduct="skuProduct" />
  11. </view>
  12. </view>
  13. <view class="tui-sku-unit">
  14. <view class="sku-unit-h1">规格:</view>
  15. <view class="sku-unit-li">
  16. <view
  17. class="unit-li"
  18. v-for="(sku, index) in skuList"
  19. @click="handleChoisSku(sku, index)"
  20. :key="index"
  21. :class="skuIndex === index ? 'active' : ''"
  22. >
  23. {{ sku.unit }}
  24. </view>
  25. </view>
  26. </view>
  27. <view class="sku-unit-nunbox">
  28. <view class="sku-unit-nunbox-t">
  29. <view class="sku-unit-nunbox-text">购买数量:</view>
  30. <view class="sku-unit-nunbox-num">
  31. <view class="number-box">
  32. <view
  33. class="iconfont icon-jianhao"
  34. :class="[isQuantity == true ? 'disabled' : '']"
  35. @click="changeCountSub"
  36. ></view>
  37. <input
  38. class="btn-input"
  39. type="number"
  40. v-model="productCount"
  41. maxlength="4"
  42. @blur="changeNumber($event)"
  43. />
  44. <view
  45. class="iconfont icon-jiahao"
  46. :class="[isStock == true ? 'disabled' : '']"
  47. @click="changeCountAdd"
  48. ></view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view
  55. class="tui-right-flex tui-popup-btn"
  56. :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }"
  57. >
  58. <view class="tui-flex-1" v-if="type === 1">
  59. <view
  60. class="tui-button"
  61. :class="[goodsData.disabled ? 'disabled' : '', isBtnDisable ? 'disabled' : '']"
  62. @click="handleBtnConfirm"
  63. >确定</view
  64. >
  65. </view>
  66. <view class="tui-modal-flex" v-else>
  67. <button
  68. class="tui-modal-button cancel"
  69. :disabled="goodsData.disabled"
  70. :class="[goodsData.disabled ? 'disabled' : '', isBtnDisable ? 'disabled' : '']"
  71. @click="handleConfirm('add')"
  72. >
  73. 加入购物车
  74. </button>
  75. <button
  76. class="tui-modal-button confirm"
  77. :disabled="goodsData.disabled"
  78. :class="[goodsData.disabled ? 'disabled' : '', isBtnDisable ? 'disabled' : '']"
  79. @click="handleConfirm('buy')"
  80. >
  81. 立即购买
  82. </button>
  83. </view>
  84. </view>
  85. </view>
  86. </tui-bottom-popup>
  87. </view>
  88. </template>
  89. <script>
  90. import { mapState, mapMutations } from 'vuex'
  91. import uniGrader from '@/components/uni-grade/uni-grade.vue'
  92. import cmUnitPrice from './cm-unit-price.vue'
  93. export default {
  94. name: 'cm-unit-popup',
  95. components: {
  96. uniGrader,
  97. cmUnitPrice,
  98. },
  99. props: {
  100. skuProduct: {
  101. type: Object
  102. },
  103. goodsData: {
  104. type: Object
  105. },
  106. popupShow: {
  107. type: Boolean,
  108. default: false
  109. },
  110. type: {
  111. type: Number,
  112. default: 1
  113. },
  114. btnType: {
  115. type: String
  116. }
  117. },
  118. data() {
  119. return {
  120. skuIndex: 0,
  121. productCount: 0,
  122. ladderPriceList: [],
  123. isStock: false, //
  124. isQuantity: false,
  125. skuList: [],
  126. handleStock: 0, // 规格库存
  127. handleMinNumber: 1, // 规格起订量
  128. isShowLadder: false,
  129. laddePopupShow: false,
  130. isBtnDisable: false
  131. }
  132. },
  133. created() {
  134. this.initData()
  135. },
  136. computed: {
  137. ...mapState(['hasLogin'])
  138. },
  139. methods: {
  140. async initData(data) {
  141. this.skuList = this.skuProduct.organizeSkus
  142. this.productCount = this.skuList[0].minBuyNumber
  143. this.handleMinNumber = this.skuList[0].minBuyNumber
  144. this.handleStock = this.skuList[0].stock
  145. },
  146. //popup弹窗数量增加按钮
  147. changeCountAdd() {
  148. if (this.productCount === this.handleStock) {
  149. this.isStock = true
  150. return
  151. }
  152. this.productCount++
  153. },
  154. //popup弹窗数量减按钮
  155. changeCountSub() {
  156. if (this.productCount <= this.handleMinNumber) {
  157. this.productCount = this.handleMinNumber
  158. this.isQuantity = true
  159. return
  160. } else {
  161. this.productCount--
  162. this.isQuantity = false
  163. }
  164. },
  165. changeNumber(e) {
  166. let _value = e.detail.value
  167. if (!this.$api.isNumber(_value)) {
  168. this.productCount = this.handleMinNumber
  169. } else if (_value < this.handleMinNumber) {
  170. this.productCount = this.handleMinNumber
  171. } else if (_value > this.handleStock) {
  172. this.productCount = this.handleStock
  173. } else {
  174. this.productCount = e.detail.value
  175. }
  176. },
  177. handleConfirm(type) {
  178. if (this.hasLogin) {
  179. if (this.isBtnDisable || this.goodsData.disabled) {
  180. return
  181. }
  182. this.$emit('buyConfirm', { type: type, productCount: this.productCount })
  183. this.$parent.popupShow3 = false
  184. } else {
  185. this.handleNavLogin()
  186. }
  187. },
  188. handleNavLogin(){
  189. //未登录跳转
  190. const pages = getCurrentPages()
  191. const page = pages[pages.length - 1]
  192. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  193. this.$api.redirectTo('/pages/login/login')
  194. },
  195. handleBtnConfirm() {
  196. //确定加入购物车或立即购买
  197. if (this.isBtnDisable || this.goodsData.disabled) {
  198. return
  199. }
  200. this.$emit('buyConfirm', { type: this.btnType, productCount: this.productCount })
  201. this.$parent.popupShow3 = false
  202. },
  203. handleChoisSku(sku, index) {
  204. // 选择SKU
  205. this.skuIndex = index
  206. this.productCount = this.handleMinNumber = sku.minBuyNumber
  207. this.handleStock = sku.stock
  208. this.isBtnDisable = sku.stock === 0
  209. this.ladderPriceList = sku.ladderPriceList
  210. this.isShowLadder = sku.ladderPriceList ? true : false
  211. this.$emit('skuClick', sku)
  212. },
  213. showLaddePopup() {
  214. // 点击显示阶梯价
  215. this.laddePopupShow = true
  216. },
  217. hidePopup() {
  218. //隐藏
  219. this.$parent.popupShow3 = false
  220. }
  221. }
  222. }
  223. </script>
  224. <style lang="scss">
  225. .tui-shopping-main {
  226. width: 100%;
  227. .tui-sku-title {
  228. width: 100%;
  229. height: 136rpx;
  230. float: left;
  231. margin-bottom: 30rpx;
  232. .tui-sku-image {
  233. width: 138rpx;
  234. height: 138rpx;
  235. float: left;
  236. border-radius: 8rpx;
  237. margin-right: 30rpx;
  238. box-sizing: border-box;
  239. border: 1px dashed #e1e1e1;
  240. image {
  241. width: 134rpx;
  242. height: 134rpx;
  243. border-radius: 10rpx;
  244. }
  245. }
  246. .tui-sku-price {
  247. height: 136rpx;
  248. float: left;
  249. }
  250. }
  251. .tui-sku-unit {
  252. width: 100%;
  253. height: auto;
  254. float: left;
  255. .sku-unit-h1 {
  256. font-size: 28rpx;
  257. line-height: 40rpx;
  258. color: #333333;
  259. font-weight: bold;
  260. }
  261. .sku-unit-li {
  262. width: 100%;
  263. height: auto;
  264. .unit-li {
  265. padding: 0 24rpx;
  266. line-height: 48rpx;
  267. text-align: center;
  268. font-size: 24rpx;
  269. color: #666666;
  270. background: #f5f5f5;
  271. float: left;
  272. margin-right: 16rpx;
  273. margin-top: 12rpx;
  274. margin-bottom: 12rpx;
  275. border-radius: 24rpx;
  276. position: relative;
  277. box-sizing: border-box;
  278. border: 1px solid #f5f5f5;
  279. &.active {
  280. border-color: $color-system;
  281. background: #FFF8EF;
  282. color: $color-system;
  283. .tips {
  284. background: #FF5B00;
  285. }
  286. }
  287. .tips {
  288. padding: 0 10rpx;
  289. line-height: 32rpx;
  290. text-align: center;
  291. font-size: 22rpx;
  292. color: #ffffff;
  293. background: #cccccc;
  294. float: left;
  295. border-radius: 16rpx;
  296. position: absolute;
  297. right: -12rpx;
  298. top: -15rpx;
  299. }
  300. }
  301. }
  302. }
  303. .sku-unit-nunbox {
  304. justify-content: space-between;
  305. align-items: center;
  306. width: 100%;
  307. height: auto;
  308. float: left;
  309. margin-top: 30rpx;
  310. .sku-unit-nunbox-t {
  311. width: 100%;
  312. height: 44rpx;
  313. position: relative;
  314. margin-bottom: 10rpx;
  315. .text {
  316. font-size: $font-size-24;
  317. line-height: 48rpx;
  318. color: #999999;
  319. }
  320. .sku-unit-nunbox-text {
  321. line-height: 44rpx;
  322. font-size: $font-size-28;
  323. float: left;
  324. font-weight: bold;
  325. }
  326. .sku-unit-nunbox-num {
  327. float: right;
  328. .number-box {
  329. display: flex;
  330. justify-content: center;
  331. align-items: center;
  332. border: 2rpx solid #D5D5D5;
  333. border-radius: 30rpx;
  334. height: 48rpx;
  335. margin-left: 20rpx;
  336. .iconfont {
  337. font-size: $font-size-24;
  338. padding: 0 18rpx;
  339. color: #333333;
  340. text-align: center;
  341. line-height: 48rpx;
  342. font-weight: bold;
  343. background: #F7F7F7;
  344. &.icon-jianhao {
  345. border-radius: 30rpx 0 0 30rpx;
  346. &.disabled {
  347. background: #f5f5f5;
  348. }
  349. }
  350. &.icon-jiahao {
  351. border-radius: 0 30rpx 30rpx 0;
  352. &.disabled {
  353. background: #f5f5f5;
  354. }
  355. }
  356. }
  357. .btn-input {
  358. width: 62rpx;
  359. height: 48rpx;
  360. line-height: 48rpx;
  361. background: #ffffff;
  362. border-radius: 4rpx;
  363. text-align: center;
  364. font-size: $font-size-28;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. .sku-unit-ladel {
  371. width: 100%;
  372. height: 64rpx;
  373. line-height: 64rpx;
  374. float: left;
  375. margin-top: 20rpx;
  376. text-align: center;
  377. font-size: 24rpx;
  378. background: #FFF8EF;
  379. color: #F3B574;
  380. }
  381. }
  382. .tui-flex-1 {
  383. .tui-button {
  384. &.disabled {
  385. background: rgba(243,181,116,0.5);
  386. }
  387. }
  388. }
  389. .tui-modal-flex {
  390. width: 100%;
  391. height: 84rpx;
  392. margin-top: 40rpx;
  393. display: flex;
  394. .tui-modal-button {
  395. flex: 1;
  396. line-height: 84rpx;
  397. font-size: $font-size-28;
  398. text-align: center;
  399. border-radius: 42rpx;
  400. padding: 0;
  401. margin: 0 15rpx;
  402. box-sizing: border-box;
  403. &.cancel {
  404. background: #FFF4E6;
  405. color: #F3B574;
  406. &.disabled {
  407. background-color: #e1e1e1;
  408. color: #ffffff;
  409. }
  410. }
  411. &.confirm {
  412. background: $btn-confirm;
  413. color: #ffffff;
  414. &.disabled {
  415. background: rgba(243,181,116,0.5);
  416. }
  417. }
  418. }
  419. }
  420. </style>