Shopping.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <!-- Shopping.vue -->
  2. <template>
  3. <uni-popup
  4. background-color="#fff"
  5. ref="isShowcartInfo"
  6. type="bottom"
  7. v-if="detailInfo"
  8. >
  9. <view class="div ui-add-shopping" :style="'height:'+(screenHeight*.7)+'px'" v-if="detailInfo">
  10. <view class="div shopping-info">
  11. <view class="div info-header">
  12. <image mode="aspectFit"
  13. v-bind:src="detailInfo.pgoods_image"
  14. class="img info-image"
  15. v-if="detailInfo.pgoods_image"
  16. />
  17. <view class="div">
  18. <text
  19. class="span header-price"
  20. >{{ detailInfo.pgoods_points }}积分</text
  21. >
  22. <text class="span">
  23. </text>
  24. <text class="span">库存{{ currentStock }}件</text>
  25. <text class="span">数量:{{ numbers }}</text>
  26. </view>
  27. <text class="span iconfont close" v-on:click="closeCartInfo(false)">&#xe65a;</text>
  28. </view>
  29. <view class="div goods-detail-properties">
  30. <view class="div info-body">
  31. <view class="p">数量</view>
  32. <view class="div ui-number">
  33. <view
  34. class="div reduce ui-common"
  35. @click.stop="reduceNumber()"
  36. v-bind:class="{ 'reduce-opacity': numbers <= 1 }"
  37. >
  38. -
  39. </view>
  40. <input
  41. type="number"
  42. min="1"
  43. class="number"
  44. value="1"
  45. v-model="numbers"
  46. readonly="true"
  47. />
  48. <view class="div add ui-common" @click.stop="addNumber()">+</view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="div info-footer">
  53. <view
  54. class="div footer-button active-cart"
  55. v-on:click="checkProduct(false)"
  56. >
  57. 加入购物车
  58. </view>
  59. <view
  60. class="div footer-button active-buy"
  61. v-on:click="checkProduct(true)"
  62. >
  63. 立即购买
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </uni-popup>
  69. </template>
  70. <script>
  71. import { urlencode } from '@/util/common'
  72. import { mapState, mapMutations } from 'vuex'
  73. import { cartAdd } from '../../../../api/memberPointscart'
  74. export default {
  75. data () {
  76. return {
  77. screenHeight:0,
  78. numbers: this.$store.state.pointsgoods.number > 0 ? this.$store.state.pointsgoods.number : 1, // todo 临时解决
  79. currentStock: this.$store.state.pointsgoods.detailInfo.pgoods_storage,
  80. productId: this.$store.state.pointsgoods.currentProductId,
  81. toastConfig: {
  82. message: '商品达到每单限购数量',
  83. position: 'middle'
  84. },
  85. ids: [],
  86. propertiPrice: 0,
  87. earlier: {}
  88. }
  89. },
  90. created () {
  91. },
  92. computed: {
  93. ...mapState({
  94. // 是否显示购物车浮层
  95. isShowcartInfo: state => state.goodsdetail.isShowcartInfo,
  96. isOnline: state => state.member.isOnline,
  97. detailInfo: state => state.pointsgoods.detailInfo,
  98. number: state => state.pointsgoods.number
  99. })
  100. },
  101. watch: {
  102. isShowcartInfo: function (value) {
  103. if(value){
  104. this.showPopup('isShowcartInfo')
  105. }else{
  106. this.hidePopup('isShowcartInfo')
  107. }
  108. },
  109. numbers: function (value) {
  110. if (value) {
  111. let pgoodsStorage = this.detailInfo.pgoods_storage
  112. if (value <= 0) {
  113. this.numbers = 1
  114. this.toastConfig.message = '受不了了,宝贝不能再少了'
  115. uni.showToast({icon:'none',title: this.toastConfig})
  116. } else if (value > pgoodsStorage) {
  117. this.toastConfig.message = '商品库存不足'
  118. uni.showToast({icon:'none',title: this.toastConfig})
  119. this.numbers = pgoodsStorage
  120. }
  121. this.saveNumber(this.numbers)
  122. }
  123. }
  124. },
  125. mounted () {
  126. const res = uni.getSystemInfoSync()
  127. this.screenWidth = res.windowWidth
  128. this.screenHeight = res.windowHeight
  129. },
  130. methods:{
  131. showPopup(id){
  132. this.$refs[id].open()
  133. },
  134. hidePopup(id){
  135. this.$refs[id].close()
  136. },
  137. ...mapMutations({
  138. saveCartState: 'saveCartState',
  139. saveNumber: 'saveNumber',
  140. }),
  141. // 关闭购物车浮层
  142. closeCartInfo (value) {
  143. this.saveCartState(value)
  144. },
  145. // 数量加
  146. addNumber () {
  147. if (this.detailInfo.pgoods_storage && this.numbers > this.detailInfo.pgoods_storage) {
  148. this.toastConfig.message = '商品库存不足'
  149. uni.showToast({icon:'none',title: this.toastConfig})
  150. this.numbers = this.detailInfo.pgoods_storage
  151. } else {
  152. this.numbers++
  153. }
  154. },
  155. // 数量减
  156. reduceNumber () {
  157. if (this.numbers > 1) {
  158. this.numbers--
  159. } else {
  160. this.numbers = 1
  161. this.toastConfig.message = '受不了了,宝贝不能再少了'
  162. uni.showToast({icon:'none',title: this.toastConfig})
  163. }
  164. },
  165. // 加入购物车
  166. checkProduct (checkout) {
  167. if (!this.isOnline) {
  168. uni.navigateTo({ url: '/pages/home/memberlogin/Login' })
  169. } else {
  170. if (checkout) { // 立即购买
  171. uni.navigateTo({ url: '/pages/member/pointsbuy/step1'+'?'+urlencode( { buy_now: 1, cart_id: this.detailInfo.pgoods_id + '|' + this.numbers } )})
  172. } else {
  173. cartAdd(this.detailInfo.pgoods_id, this.numbers).then(
  174. res => {
  175. uni.$emit('update-cart-num')
  176. uni.showToast({icon:'none',title: res.message})
  177. },
  178. error => {
  179. uni.showToast({icon:'none',title: error.message})
  180. }
  181. )
  182. }
  183. }
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. .mint-popup-bottom {
  190. overflow: initial;
  191. height: 70%;
  192. }
  193. .ui-add-shopping {
  194. /* position: fixed;
  195. top: 0;
  196. bottom: 0;
  197. left: 0;
  198. right: 0;
  199. width: 100%;
  200. height: 100%; */
  201. /* z-index: 200; */
  202. /* background:rgba(0,0,0, 0.4); */
  203. .shopping-info {
  204. background: rgba(255, 255, 255, 1);
  205. height: 100%;
  206. position: relative;
  207. width: -webkit-fill-available;
  208. /* bottom: 0; */
  209. z-index: 10;
  210. width: 100%;
  211. .info-header {
  212. padding: 0.75rem;
  213. display: flex;
  214. justify-content: flex-start;
  215. padding-bottom: 1.25rem;
  216. border-bottom: 0.5px solid rgba(232, 234, 237, 1);
  217. .img.info-image {
  218. width: 6rem;
  219. height: 6rem;
  220. border-radius: 1px;
  221. margin-top: -0.75rem;
  222. position: absolute;
  223. top: -0.65rem;
  224. }
  225. .div {
  226. padding-left: 6.75rem;
  227. width: 100%;
  228. .span {
  229. display: block;
  230. color: #999999;
  231. &.header-price {
  232. font-size:$h1;
  233. line-height: 1rem;
  234. padding-bottom: 0.6rem;
  235. color: $primaryColor;
  236. }
  237. &:nth-child(2) {
  238. .img {
  239. vertical-align: middle;
  240. padding-right: 0.5rem;
  241. width: 2.5rem;
  242. height: 1rem;
  243. }
  244. .span {
  245. display: inline;
  246. font-size:$subFontSize;
  247. line-height: 0.7rem;
  248. padding-bottom: 0.45rem;
  249. padding-top: 0.6rem;
  250. }
  251. }
  252. &:nth-child(3) {
  253. line-height: 1rem;
  254. font-size:$subFontSize;
  255. line-height: 1rem;
  256. width: 100%;
  257. overflow: hidden;
  258. text-overflow: ellipsis;
  259. white-space: nowrap;
  260. padding-right: 0.75rem;
  261. }
  262. &:last-child {
  263. line-height: 1rem;
  264. font-size:$subFontSize;
  265. line-height: 1rem;
  266. padding-top: 0.6rem;
  267. width: 100%;
  268. overflow: hidden;
  269. text-overflow: ellipsis;
  270. white-space: nowrap;
  271. padding-right: 0.75rem;
  272. }
  273. }
  274. }
  275. .img.close {
  276. position: absolute;
  277. top: 0.75rem;
  278. right: 0.75rem;
  279. width: 0.65rem;
  280. height: 0.65rem;
  281. cursor: pointer;
  282. opacity: 1;
  283. }
  284. }
  285. .div.goods-detail-properties {
  286. width: 100%;
  287. overflow: auto;
  288. height: auto;
  289. position: absolute;
  290. top: 11.2rem;
  291. bottom: 2.2rem;
  292. /* height: 100%; */
  293. }
  294. .div.goods-properties {
  295. padding: 0.75rem 0;
  296. .p {
  297. font-size:$h2;
  298. color: rgba(41, 43, 45, 1);
  299. line-height: 0.8rem;
  300. margin: 0;
  301. padding: 0 0.75rem;
  302. }
  303. .div.properties-list {
  304. .div {
  305. display: inline-block;
  306. margin-left: 0.75rem;
  307. .span {
  308. font-size:$subFontSize;
  309. color: rgba(78, 84, 93, 1);
  310. line-height: 0.7rem;
  311. display: inline-block;
  312. padding: 0.35rem 0.7rem;
  313. border: 1px solid #404245;
  314. border-radius: 0.1rem;
  315. cursor: pointer;
  316. margin-top: 0.75rem;
  317. &.active-properties {
  318. background: $primaryColor;
  319. color: rgba(255, 255, 255, 1);
  320. border: 1px solid $primaryColor;
  321. }
  322. &.disabled-properties {
  323. color: #b1b5bb;
  324. cursor: none;
  325. border: 1px solid #a2a6ad;
  326. }
  327. }
  328. /* &:nth-child(even) {
  329. margin-left: 0.75rem;
  330. } */
  331. }
  332. }
  333. }
  334. .info-body {
  335. padding: 0.75rem 0.75rem 1rem 0.75rem;
  336. .p {
  337. font-size:$h2;
  338. color: rgba(41, 43, 45, 1);
  339. line-height: 0.8rem;
  340. padding: 0;
  341. margin: 0;
  342. padding-bottom: 0.8rem;
  343. }
  344. .div.ui-number {
  345. height: 1.5rem;
  346. display: flex;
  347. border-radius: 0.15rem 0 0 0.15rem;
  348. input,
  349. .div {
  350. height: 1.4rem;
  351. line-height:1.4rem;
  352. text-align: center;
  353. color: #404245;
  354. display: inline-block;
  355. padding: 0;
  356. margin: 0;
  357. border: 0;
  358. outline-offset: 0;
  359. }
  360. .ui-common {
  361. line-height: 1.4rem;
  362. width: 1.4rem;
  363. height: 1.4rem;
  364. border: 1px solid #c7c7cd;
  365. cursor: pointer;
  366. }
  367. .reduce {
  368. border-right: 0;
  369. }
  370. .reduce-opacity {
  371. opacity: 0.4;
  372. }
  373. .add {
  374. border-left: 0;
  375. }
  376. .number {
  377. width: 2rem;
  378. border: 1px solid #c7c7cd;
  379. border-radius: 0;
  380. border-image-width: 0;
  381. box-shadow: 0;
  382. vertical-align: bottom;
  383. &:focus {
  384. outline: none;
  385. }
  386. }
  387. }
  388. }
  389. .info-footer {
  390. width: 100%;
  391. position: fixed;
  392. bottom: 0;
  393. display: flex;
  394. .footer-button {
  395. flex: 1;
  396. color: #ffffff;
  397. line-height: 2.2rem;
  398. text-align: center;
  399. font-size:$h2;
  400. height: 2.2rem;
  401. }
  402. .active-cart {
  403. background: $primaryColor;
  404. }
  405. .active-buy {
  406. background: #000;
  407. }
  408. }
  409. }
  410. }
  411. </style>