cm-unit-popup.vue 9.0 KB

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