index_origin.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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.image"></image>
  8. </view>
  9. <view class="text">
  10. <view class="line1">
  11. {{ attr.productSelect.storeName }}
  12. </view>
  13. <view class="money font-color">
  14. ¥<text class="num">{{ attr.productSelect.storePrice }}</text>
  15. <text class="stock" v-if='isShow'>库存: {{ attr.productSelect.stock }}</text>
  16. <text class='stock' v-if="limitNum">限量: {{attr.productSelect.quota}}</text>
  17. </view>
  18. </view>
  19. <view class="iconfont icon-guanbi" @click="closeAttr"></view>
  20. </view>
  21. <view class="rollTop">
  22. <view class="productWinList">
  23. <view class="item" v-for="(item, indexw) in attr.productAttr" :key="indexw">
  24. <view class="title">{{ item.attrName }}</view>
  25. <view class="listn acea-row row-middle">
  26. <view class="itemn" :class="item.index === itemn ? 'on' : ''"
  27. v-for="(itemn, indexn) in item.attrValues" @click="tapAttr(indexw, indexn)"
  28. :key="indexn">
  29. {{ itemn }}
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="cart acea-row row-between-wrapper">
  35. <view class="title">数量</view>
  36. <view class="carnum acea-row row-left">
  37. <view class="item reduce" :class="attr.productSelect.cart_num <= 1 ? 'on' : ''"
  38. @click="CartNumDes">
  39. -
  40. </view>
  41. <view class='item num'>
  42. <input type="number" v-model="attr.productSelect.cart_num"
  43. data-name="productSelect.cart_num"
  44. @input="bindCode(attr.productSelect.cart_num)"></input>
  45. </view>
  46. <view
  47. v-if="iSplus"
  48. class="item plus"
  49. :class="attr.productSelect.cart_num >= attr.productSelect.stock ? 'on' : ''"
  50. @click="CartNumAdd">
  51. +
  52. </view>
  53. <view v-else class='item plus'
  54. :class='(attr.productSelect.cart_num >= attr.productSelect.quota) || (attr.productSelect.cart_num >= attr.productSelect.stock) || (attr.productSelect.cart_num >= attr.productSelect.num)? "on":""'
  55. @click='CartNumAdd'>+</view>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="joinBnt bg-color" v-if="iSbnt && attr.productSelect.stock>0 &&attr.productSelect.quota>0"
  60. @click="goCat">我要参团</view>
  61. <view class="joinBnt on"
  62. v-else-if="(iSbnt && attr.productSelect.quota<=0)||(iSbnt &&attr.productSelect.stock<=0)">已售罄</view>
  63. <view class="joinBnt bg-color" v-if="iScart && attr.productSelect.stock" @click="goCat">确定</view>
  64. <!-- <view class="joinBnt bg-color" v-if="iSbnt && attr.productSelect.stock && attr.productSelect.quota" @click="goCat">确定</view> -->
  65. <view class="joinBnt on" v-else-if="(iScart && !attr.productSelect.stock)">已售罄</view>
  66. </view>
  67. <view class="mask" @touchmove.prevent :hidden="attr.cartAttr === false" @click="closeAttr"></view>
  68. </view>
  69. </template>
  70. <script setup>
  71. import { toRefs } from 'vue'
  72. const props = defineProps({
  73. attr: {
  74. type: Object,
  75. default: () => ({})
  76. },
  77. limitNum: {
  78. type: Number,
  79. default: 0
  80. },
  81. isShow: {
  82. type: Number,
  83. default: 0
  84. },
  85. iSbnt: {
  86. type: Number,
  87. default: 0
  88. },
  89. iSplus: {
  90. type: Number,
  91. default: 0
  92. },
  93. iScart: {
  94. type: Number,
  95. default: 0
  96. }
  97. })
  98. const emit = defineEmits([
  99. 'goCat',
  100. 'iptCartNum',
  101. 'myevent',
  102. 'ChangeCartNum',
  103. 'attrVal',
  104. 'ChangeAttr'
  105. ])
  106. function goCat() {
  107. emit('goCat')
  108. }
  109. function bindCode() {
  110. emit('iptCartNum', props.attr.productSelect.cart_num)
  111. }
  112. function closeAttr() {
  113. emit('myevent')
  114. }
  115. function CartNumDes() {
  116. emit('ChangeCartNum', false)
  117. }
  118. function CartNumAdd() {
  119. emit('ChangeCartNum', true)
  120. }
  121. function tapAttr(indexw, indexn) {
  122. emit('attrVal', { indexw, indexn })
  123. // 直接修改 props 不推荐,建议父组件传递响应式对象
  124. if (props.attr.productAttr && props.attr.productAttr[indexw]) {
  125. props.attr.productAttr[indexw].index = props.attr.productAttr[indexw].attrValues[indexn]
  126. }
  127. const value = getCheckedValue().join(',')
  128. emit('ChangeAttr', value)
  129. }
  130. function getCheckedValue() {
  131. const productAttr = props.attr.productAttr || []
  132. const value = []
  133. for (let i = 0; i < productAttr.length; i++) {
  134. for (let j = 0; j < productAttr[i].attrValues.length; j++) {
  135. if (productAttr[i].index === productAttr[i].attrValues[j]) {
  136. value.push(productAttr[i].attrValues[j])
  137. }
  138. }
  139. }
  140. return value
  141. }
  142. </script>
  143. <style scoped lang="scss">
  144. .product-window {
  145. position: fixed;
  146. bottom: 0;
  147. width: 100%;
  148. left: 0;
  149. background-color: #fff;
  150. z-index: 276;
  151. border-radius: 16rpx 16rpx 0 0;
  152. padding-bottom: 140rpx;
  153. transform: translate3d(0, 100%, 0);
  154. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  155. }
  156. .mask {
  157. z-index: 275;
  158. }
  159. .product-window.on {
  160. transform: translate3d(0, 0, 0);
  161. }
  162. .product-window.join {
  163. padding-bottom: 30rpx;
  164. }
  165. .product-window.joinCart {
  166. padding-bottom: 30rpx;
  167. z-index: 999;
  168. }
  169. .product-window .textpic {
  170. padding: 0 130rpx 0 30rpx;
  171. margin-top: 29rpx;
  172. position: relative;
  173. }
  174. .product-window .textpic .pictrue {
  175. width: 150rpx;
  176. height: 150rpx;
  177. }
  178. .product-window .textpic .pictrue image {
  179. width: 100%;
  180. height: 100%;
  181. border-radius: 10rpx;
  182. }
  183. .product-window .textpic .text {
  184. width: 410rpx;
  185. font-size: 32rpx;
  186. color: #333333;
  187. }
  188. .product-window .textpic .text .money {
  189. font-size: 24rpx;
  190. margin-top: 40rpx;
  191. }
  192. .product-window .textpic .text .money .num {
  193. font-size: 36rpx;
  194. }
  195. .product-window .textpic .text .money .stock {
  196. color: #999;
  197. margin-left: 18rpx;
  198. }
  199. .product-window .textpic .iconfont {
  200. position: absolute;
  201. right: 30rpx;
  202. top: -5rpx;
  203. font-size: 35rpx;
  204. color: #8a8a8a;
  205. }
  206. .product-window .rollTop {
  207. max-height: 500rpx;
  208. overflow: auto;
  209. margin-top: 36rpx;
  210. }
  211. .product-window .productWinList .item~.item {
  212. margin-top: 36rpx;
  213. }
  214. .product-window .productWinList .item .title {
  215. font-size: 30rpx;
  216. color: #999;
  217. padding: 0 30rpx;
  218. }
  219. .product-window .productWinList .item .listn {
  220. padding: 0 30rpx 0 16rpx;
  221. }
  222. .product-window .productWinList .item .listn .itemn {
  223. border: 1px solid #F2F2F2;
  224. font-size: 26rpx;
  225. color: #282828;
  226. padding: 7rpx 33rpx;
  227. border-radius: 40rpx;
  228. margin: 20rpx 0 0 14rpx;
  229. background-color: #F2F2F2;
  230. }
  231. .product-window .productWinList .item .listn .itemn.on {
  232. color: $theme-color;
  233. background: rgba(255, 244, 243, 1);
  234. border-color: $theme-color;
  235. }
  236. .product-window .productWinList .item .listn .itemn.limit {
  237. color: #999;
  238. text-decoration: line-through;
  239. }
  240. .product-window .cart {
  241. margin-top: 36rpx;
  242. padding: 0 30rpx;
  243. }
  244. .product-window .cart .title {
  245. font-size: 30rpx;
  246. color: #999;
  247. }
  248. .product-window .cart .carnum {
  249. height: 54rpx;
  250. margin-top: 24rpx;
  251. }
  252. .product-window .cart .carnum view {
  253. // border: 1px solid #a4a4a4;
  254. width: 84rpx;
  255. text-align: center;
  256. height: 100%;
  257. line-height: 54rpx;
  258. color: #282828;
  259. font-size: 45rpx;
  260. }
  261. .product-window .cart .carnum .reduce {
  262. border-right: 0;
  263. border-radius: 6rpx 0 0 6rpx;
  264. line-height: 48rpx;
  265. }
  266. .product-window .cart .carnum .reduce.on {
  267. // border-color: #e3e3e3;
  268. color: #DEDEDE;
  269. font-size: 44rpx;
  270. }
  271. .product-window .cart .carnum .plus {
  272. border-left: 0;
  273. border-radius: 0 6rpx 6rpx 0;
  274. line-height: 46rpx;
  275. }
  276. .product-window .cart .carnum .plus.on {
  277. border-color: #e3e3e3;
  278. color: #dedede;
  279. }
  280. .product-window .cart .carnum .num {
  281. background: rgba(242, 242, 242, 1);
  282. color: #282828;
  283. font-size: 28rpx;
  284. border-radius: 12rpx;
  285. line-height: 29px;
  286. height: 54rpx;
  287. input {
  288. display: -webkit-inline-box;
  289. }
  290. }
  291. .product-window .joinBnt {
  292. font-size: 30rpx;
  293. width: 620rpx;
  294. height: 86rpx;
  295. border-radius: 50rpx;
  296. text-align: center;
  297. line-height: 86rpx;
  298. color: #fff;
  299. margin: 21rpx auto 0 auto;
  300. }
  301. .product-window .joinBnt.on {
  302. background-color: #bbb;
  303. color: #fff;
  304. }
  305. </style>