index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view>
  3. <view class="product-window"
  4. :class="(attr.cartAttr === true ? 'on' : '') + ' ' + (iSbnt ? 'join':'') + ' ' + (iScart ? 'joinCart':'')">
  5. <view class="textpic acea-row row-between-wrapper">
  6. <view class="pictrue">
  7. <image :src="attr.productSelect.picUrl"></image>
  8. </view>
  9. <view class="text">
  10. <view class="line1">
  11. {{ attr.productSelect.spuName }}
  12. </view>
  13. <view class="money font-color">
  14. ¥<text class="num">{{ fen2yuan(attr.productSelect.price) }}</text>
  15. <text class="stock" v-if='isShow'>库存: {{ attr.productSelect.stock }}</text>
  16. <text class='stock' v-if="attr.productSelect.limitCount > 0">限购: {{ attr.productSelect.limitCount }}</text>
  17. </view>
  18. </view>
  19. <view class="iconfont icon-guanbi" @click="close"></view>
  20. </view>
  21. <view class="rollTop">
  22. <!-- 属性 key + value 列表 -->
  23. <view class="productWinList">
  24. <view class="item" v-for="(property, propertyIndex) in attr.properties" :key="propertyIndex">
  25. <view class="title">{{ property.name }}</view>
  26. <view class="listn acea-row row-middle">
  27. <view class="itemn" :class="property.index === value.name ? 'on' : ''"
  28. v-for="(value, valueIndex) in property.values" :key="valueIndex"
  29. @click="clickProperty(propertyIndex, valueIndex)">
  30. {{ value.name }}
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="cart acea-row row-between-wrapper">
  36. <view class="title">数量</view>
  37. <view class="carnum acea-row row-left">
  38. <view class="item reduce" :class="attr.productSelect.cart_num <= 1 ? 'on' : ''"
  39. @click="CartNumDes">
  40. -
  41. </view>
  42. <view class='item num'>
  43. <input type="number" v-model="attr.productSelect.cart_num"
  44. data-name="productSelect.cart_num"
  45. @input="bindCode(attr.productSelect.cart_num)" />
  46. </view>
  47. <view v-if="iSplus" class="item plus" :class="attr.productSelect.cart_num >= attr.productSelect.stock ? 'on' : ''" @click="CartNumAdd">
  48. +
  49. </view>
  50. <view v-else class='item plus'
  51. :class='(attr.productSelect.cart_num >= attr.productSelect.stock)
  52. || (attr.productSelect.cart_num >= attr.productSelect.limitCount)
  53. ? "on":""'
  54. @click='CartNumAdd'>+</view>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- TODO 芋艿:拼团 -->
  59. <view class="joinBnt bg-color" v-if="iSbnt && attr.productSelect.stock > 0"
  60. @click="goCat">我要参团</view>
  61. <view class="joinBnt on"
  62. v-else-if="iSbnt && attr.productSelect.stock <= 0">已售罄</view>
  63. <!-- TODO 芋艿:购物车 -->
  64. <view class="joinBnt bg-color" v-if="iScart && attr.productSelect.stock"
  65. @click="goCat">确定</view>
  66. <view class="joinBnt on"
  67. v-else-if="(iScart && !attr.productSelect.stock)">已售罄</view>
  68. </view>
  69. <view class="mask" @touchmove.prevent :hidden="attr.cartAttr === false" @click="close"></view>
  70. </view>
  71. </template>
  72. <script>
  73. import * as Util from '@/utils/util.js';
  74. export default {
  75. props: {
  76. attr: {
  77. type: Object,
  78. default: () => {}
  79. },
  80. isShow: { // 是否展示库存
  81. type: Number,
  82. value: 0
  83. },
  84. iSbnt: { // 是否拼团商品
  85. type: Number,
  86. value: 0
  87. },
  88. iSplus: { // 是否允许 + - 操作
  89. type: Number,
  90. value: 0
  91. },
  92. iScart: { // 是否来自购物车界面
  93. type: Number,
  94. value: 0
  95. }
  96. },
  97. data() {
  98. return {};
  99. },
  100. mounted() {},
  101. methods: {
  102. goCat: function() {
  103. this.$emit('goCat');
  104. },
  105. /**
  106. * 购物车手动输入数量
  107. */
  108. bindCode: function(e) {
  109. // TODO 芋艿:【优化】方法名的处理;是否可去掉这个事件,统一处理
  110. this.$emit('iptCartNum', this.attr.productSelect.cart_num);
  111. },
  112. close: function() {
  113. this.$emit('close');
  114. },
  115. CartNumDes: function() {
  116. // TODO 芋艿:【优化】方法名的处理;是否可去掉这个事件,统一处理
  117. this.$emit('ChangeCartNum', false);
  118. },
  119. CartNumAdd: function() {
  120. // TODO 芋艿:【优化】方法名的处理;是否可去掉这个事件,统一处理
  121. this.$emit('ChangeCartNum', true);
  122. },
  123. /**
  124. * 选中某个规格属性
  125. *
  126. * @param propertyIndex properties 的下标
  127. * @param valueIndex values 的下标
  128. */
  129. clickProperty: function(propertyIndex, valueIndex) {
  130. this.$set(this.attr.properties[propertyIndex], 'index', this.attr.properties[propertyIndex].values[valueIndex].name);
  131. let newSkuKey = this.getCheckedValueNames().join(",");
  132. // TODO 芋艿:【优化】修改下 ChangeAttr 名字,改成 selectSku 更合适
  133. this.$emit("ChangeAttr", newSkuKey, propertyIndex, valueIndex);
  134. },
  135. /**
  136. * 获取被选中属性值的数组
  137. *
  138. * @returns {*[]} 例如说,['红色', '大']
  139. */
  140. getCheckedValueNames: function() {
  141. let properties = this.attr.properties;
  142. let valueNames = [];
  143. for (let i = 0; i < properties.length; i++) {
  144. for (let j = 0; j < properties[i].values.length; j++) {
  145. if (properties[i].index === properties[i].values[j].name) {
  146. valueNames.push(properties[i].values[j].name);
  147. }
  148. }
  149. }
  150. return valueNames;
  151. },
  152. fen2yuan(price) {
  153. return Util.fen2yuan(price)
  154. }
  155. }
  156. }
  157. </script>
  158. <style scoped lang="scss">
  159. .product-window {
  160. position: fixed;
  161. bottom: 0;
  162. width: 100%;
  163. left: 0;
  164. background-color: #fff;
  165. z-index: 77;
  166. border-radius: 16rpx 16rpx 0 0;
  167. padding-bottom: 140rpx;
  168. transform: translate3d(0, 100%, 0);
  169. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  170. }
  171. .product-window.on {
  172. transform: translate3d(0, 0, 0);
  173. }
  174. .product-window.join {
  175. padding-bottom: 30rpx;
  176. }
  177. .product-window.joinCart {
  178. padding-bottom: 30rpx;
  179. z-index: 999;
  180. }
  181. .product-window .textpic {
  182. padding: 0 130rpx 0 30rpx;
  183. margin-top: 29rpx;
  184. position: relative;
  185. }
  186. .product-window .textpic .pictrue {
  187. width: 150rpx;
  188. height: 150rpx;
  189. }
  190. .product-window .textpic .pictrue image {
  191. width: 100%;
  192. height: 100%;
  193. border-radius: 10rpx;
  194. }
  195. .product-window .textpic .text {
  196. width: 410rpx;
  197. font-size: 32rpx;
  198. color: #333333;
  199. }
  200. .product-window .textpic .text .money {
  201. font-size: 24rpx;
  202. margin-top: 40rpx;
  203. }
  204. .product-window .textpic .text .money .num {
  205. font-size: 36rpx;
  206. }
  207. .product-window .textpic .text .money .stock {
  208. color: #999;
  209. margin-left: 18rpx;
  210. }
  211. .product-window .textpic .iconfont {
  212. position: absolute;
  213. right: 30rpx;
  214. top: -5rpx;
  215. font-size: 35rpx;
  216. color: #8a8a8a;
  217. }
  218. .product-window .rollTop {
  219. max-height: 500rpx;
  220. overflow: auto;
  221. margin-top: 36rpx;
  222. }
  223. .product-window .productWinList .item~.item {
  224. margin-top: 36rpx;
  225. }
  226. .product-window .productWinList .item .title {
  227. font-size: 30rpx;
  228. color: #999;
  229. padding: 0 30rpx;
  230. }
  231. .product-window .productWinList .item .listn {
  232. padding: 0 30rpx 0 16rpx;
  233. }
  234. .product-window .productWinList .item .listn .itemn {
  235. border: 1px solid #F2F2F2;
  236. font-size: 26rpx;
  237. color: #282828;
  238. padding: 7rpx 33rpx;
  239. border-radius: 40rpx;
  240. margin: 20rpx 0 0 14rpx;
  241. background-color: #F2F2F2;
  242. }
  243. .product-window .productWinList .item .listn .itemn.on {
  244. color: $theme-color;
  245. background: rgba(255, 244, 243, 1);
  246. border-color: $theme-color;
  247. }
  248. .product-window .productWinList .item .listn .itemn.limit {
  249. color: #999;
  250. text-decoration: line-through;
  251. }
  252. .product-window .cart {
  253. margin-top: 36rpx;
  254. padding: 0 30rpx;
  255. }
  256. .product-window .cart .title {
  257. font-size: 30rpx;
  258. color: #999;
  259. }
  260. .product-window .cart .carnum {
  261. height: 54rpx;
  262. margin-top: 24rpx;
  263. }
  264. .product-window .cart .carnum view {
  265. // border: 1px solid #a4a4a4;
  266. width: 84rpx;
  267. text-align: center;
  268. height: 100%;
  269. line-height: 54rpx;
  270. color: #282828;
  271. font-size: 45rpx;
  272. }
  273. .product-window .cart .carnum .reduce {
  274. border-right: 0;
  275. border-radius: 6rpx 0 0 6rpx;
  276. line-height: 48rpx;
  277. }
  278. .product-window .cart .carnum .reduce.on {
  279. // border-color: #e3e3e3;
  280. color: #DEDEDE;
  281. font-size: 44rpx;
  282. }
  283. .product-window .cart .carnum .plus {
  284. border-left: 0;
  285. border-radius: 0 6rpx 6rpx 0;
  286. line-height: 46rpx;
  287. }
  288. .product-window .cart .carnum .plus.on {
  289. border-color: #e3e3e3;
  290. color: #dedede;
  291. }
  292. .product-window .cart .carnum .num {
  293. background: rgba(242, 242, 242, 1);
  294. color: #282828;
  295. font-size: 28rpx;
  296. border-radius: 12rpx;
  297. line-height: 29px;
  298. height: 54rpx;
  299. input {
  300. display: -webkit-inline-box;
  301. }
  302. }
  303. .product-window .joinBnt {
  304. font-size: 30rpx;
  305. width: 620rpx;
  306. height: 86rpx;
  307. border-radius: 50rpx;
  308. text-align: center;
  309. line-height: 86rpx;
  310. color: #fff;
  311. margin: 21rpx auto 0 auto;
  312. }
  313. .product-window .joinBnt.on {
  314. background-color: #bbb;
  315. color: #fff;
  316. }
  317. </style>