cm-unit-popup.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. cursor-spacing="40"
  44. />
  45. <view
  46. class="iconfont icon-jiahao"
  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. isStock: false, //
  123. isQuantity: false,
  124. skuList: [],
  125. handleMinNumber: 1, // 规格起订量
  126. laddePopupShow: false,
  127. isBtnDisable: false,
  128. isIphoneX:this.$store.state.isIphoneX,
  129. }
  130. },
  131. created() {
  132. this.initData()
  133. },
  134. computed: {
  135. ...mapState(['hasLogin'])
  136. },
  137. methods: {
  138. async initData(data) {
  139. this.skuList = this.skuProduct.organizeSkus
  140. this.productCount = this.skuList[0].minBuyNumber
  141. this.handleMinNumber = this.skuList[0].minBuyNumber
  142. },
  143. //popup弹窗数量增加按钮
  144. changeCountAdd() {
  145. this.productCount++
  146. },
  147. //popup弹窗数量减按钮
  148. changeCountSub() {
  149. if (this.productCount <= this.handleMinNumber) {
  150. this.productCount = this.handleMinNumber
  151. this.isQuantity = true
  152. return
  153. } else {
  154. this.productCount--
  155. this.isQuantity = false
  156. }
  157. },
  158. changeNumber(e) {
  159. let _value = e.detail.value
  160. if (!this.$api.isNumber(_value)) {
  161. this.productCount = this.handleMinNumber
  162. } else if (_value < this.handleMinNumber) {
  163. this.productCount = this.handleMinNumber
  164. } else {
  165. this.productCount = e.detail.value
  166. }
  167. },
  168. handleConfirm(type) {
  169. if (this.hasLogin) {
  170. if (this.isBtnDisable || this.goodsData.disabled) {
  171. return
  172. }
  173. this.$emit('buyConfirm', { type: type, productCount: this.productCount })
  174. this.$parent.popupShow3 = false
  175. } else {
  176. this.handleNavLogin()
  177. }
  178. },
  179. handleNavLogin(){
  180. //未登录跳转
  181. const pages = getCurrentPages()
  182. const page = pages[pages.length - 1]
  183. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  184. this.$api.redirectTo('/pages/login/login')
  185. },
  186. handleBtnConfirm() {
  187. //确定加入购物车或立即购买
  188. if (this.isBtnDisable || this.goodsData.disabled) {
  189. return
  190. }
  191. this.$emit('buyConfirm', { type: this.btnType, productCount: this.productCount })
  192. this.$parent.popupShow3 = false
  193. },
  194. handleChoisSku(sku, index) {
  195. // 选择SKU
  196. this.skuIndex = index
  197. this.productCount = this.handleMinNumber = sku.minBuyNumber
  198. this.$emit('skuClick', sku)
  199. },
  200. hidePopup() {
  201. //隐藏
  202. this.$parent.popupShow3 = false
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss">
  208. .tui-shopping-main {
  209. width: 100%;
  210. .tui-sku-title {
  211. width: 100%;
  212. height: 136rpx;
  213. float: left;
  214. margin-bottom: 30rpx;
  215. .tui-sku-image {
  216. width: 138rpx;
  217. height: 138rpx;
  218. float: left;
  219. border-radius: 8rpx;
  220. margin-right: 30rpx;
  221. box-sizing: border-box;
  222. border: 1px dashed #e1e1e1;
  223. image {
  224. width: 134rpx;
  225. height: 134rpx;
  226. border-radius: 10rpx;
  227. }
  228. }
  229. .tui-sku-price {
  230. height: 136rpx;
  231. float: left;
  232. }
  233. }
  234. .tui-sku-unit {
  235. width: 100%;
  236. height: auto;
  237. float: left;
  238. .sku-unit-h1 {
  239. font-size: 28rpx;
  240. line-height: 40rpx;
  241. color: #333333;
  242. font-weight: bold;
  243. }
  244. .sku-unit-li {
  245. width: 100%;
  246. height: auto;
  247. .unit-li {
  248. padding: 0 24rpx;
  249. line-height: 48rpx;
  250. text-align: center;
  251. font-size: 24rpx;
  252. color: #666666;
  253. background: #f5f5f5;
  254. float: left;
  255. margin-right: 16rpx;
  256. margin-top: 12rpx;
  257. margin-bottom: 12rpx;
  258. border-radius: 24rpx;
  259. position: relative;
  260. box-sizing: border-box;
  261. border: 1px solid #f5f5f5;
  262. &.active {
  263. border-color: $color-system;
  264. background: #FFF8EF;
  265. color: $color-system;
  266. .tips {
  267. background: #FF5B00;
  268. }
  269. }
  270. .tips {
  271. padding: 0 10rpx;
  272. line-height: 32rpx;
  273. text-align: center;
  274. font-size: 22rpx;
  275. color: #ffffff;
  276. background: #cccccc;
  277. float: left;
  278. border-radius: 16rpx;
  279. position: absolute;
  280. right: -12rpx;
  281. top: -15rpx;
  282. }
  283. }
  284. }
  285. }
  286. .sku-unit-nunbox {
  287. justify-content: space-between;
  288. align-items: center;
  289. width: 100%;
  290. height: auto;
  291. float: left;
  292. margin-top: 30rpx;
  293. .sku-unit-nunbox-t {
  294. width: 100%;
  295. height: 44rpx;
  296. position: relative;
  297. margin-bottom: 10rpx;
  298. .text {
  299. font-size: $font-size-24;
  300. line-height: 48rpx;
  301. color: #999999;
  302. }
  303. .sku-unit-nunbox-text {
  304. line-height: 44rpx;
  305. font-size: $font-size-28;
  306. float: left;
  307. font-weight: bold;
  308. }
  309. .sku-unit-nunbox-num {
  310. float: right;
  311. .number-box {
  312. display: flex;
  313. justify-content: center;
  314. align-items: center;
  315. border: 2rpx solid #D5D5D5;
  316. border-radius: 30rpx;
  317. height: 48rpx;
  318. margin-left: 20rpx;
  319. .iconfont {
  320. font-size: $font-size-24;
  321. padding: 0 18rpx;
  322. color: #333333;
  323. text-align: center;
  324. line-height: 48rpx;
  325. font-weight: bold;
  326. background: #F7F7F7;
  327. &.icon-jianhao {
  328. border-radius: 30rpx 0 0 30rpx;
  329. &.disabled {
  330. background: #f5f5f5;
  331. }
  332. }
  333. &.icon-jiahao {
  334. border-radius: 0 30rpx 30rpx 0;
  335. &.disabled {
  336. background: #f5f5f5;
  337. }
  338. }
  339. }
  340. .btn-input {
  341. width: 62rpx;
  342. height: 48rpx;
  343. line-height: 48rpx;
  344. background: #ffffff;
  345. border-radius: 4rpx;
  346. text-align: center;
  347. font-size: $font-size-28;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. .sku-unit-ladel {
  354. width: 100%;
  355. height: 64rpx;
  356. line-height: 64rpx;
  357. float: left;
  358. margin-top: 20rpx;
  359. text-align: center;
  360. font-size: 24rpx;
  361. background: #FFF8EF;
  362. color: #F3B574;
  363. }
  364. }
  365. .tui-flex-1 {
  366. .tui-button {
  367. &.disabled {
  368. background: rgba(243,181,116,0.5);
  369. }
  370. }
  371. }
  372. .tui-modal-flex {
  373. width: 100%;
  374. height: 84rpx;
  375. margin-top: 40rpx;
  376. display: flex;
  377. .tui-modal-button {
  378. flex: 1;
  379. line-height: 84rpx;
  380. font-size: $font-size-28;
  381. text-align: center;
  382. border-radius: 42rpx;
  383. padding: 0;
  384. margin: 0 15rpx;
  385. box-sizing: border-box;
  386. &.cancel {
  387. background: #FFF4E6;
  388. color: #F3B574;
  389. &.disabled {
  390. background-color: #e1e1e1;
  391. color: #ffffff;
  392. }
  393. }
  394. &.confirm {
  395. background: $btn-confirm;
  396. color: #ffffff;
  397. &.disabled {
  398. background: rgba(243,181,116,0.5);
  399. }
  400. }
  401. }
  402. }
  403. </style>