productItemSkline.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view
  3. class="product-list"
  4. >
  5. <view
  6. class="product-item"
  7. :style="{width:itemWidth+'px',marginTop:gap+'px'}"
  8. v-for="(item,index) in list"
  9. :key="item.id" >
  10. <view @click="viewPic(item.productImage)">
  11. <image mode="aspectFit" :src="item.productImage+'?x-oss-process=image/resize,p_30'" style="height: 140px;width: 100%;"></image>
  12. <view class="back-price" v-if="item.promoRuleValue">返<text>{{item.promoRuleValue}}</text>元</view>
  13. <view class="product-code"><text class="ellipsis-one" overflow="ellipsis">{{item.productCode}}</text></view>
  14. </view>
  15. <view>
  16. <view class="product-name">{{item.productName}}</view>
  17. <view class="product-guige"><text class="ellipsis-two" max-lines="2" overflow="ellipsis">{{item.productOrigCode}}</text></view>
  18. <view class="product-button">
  19. <view class="price-txt">¥<text>{{item.cost}}</text></view>
  20. <view>
  21. <button v-if="!item.checked" @click="addToCat(item)" size="mini" type="default" class="bg-0">
  22. <image style="width: 10px; height: 10px;" mode="aspectFit" src="../static/add.png"></image>
  23. </button>
  24. <button v-else @click="addToCat(item)" size="mini" type="primary" class="bg-1">
  25. <image style="width: 10px; height: 10px;" mode="aspectFit" src="../static/add.png"></image>
  26. {{item.qty}}
  27. </button>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. name: 'productItemSkline',
  37. props: {
  38. list: {
  39. type: Array,
  40. default: () => []
  41. },
  42. index:{
  43. type: [Number,String],
  44. default: 0
  45. },
  46. gap:{
  47. type: [Number,String],
  48. default: 10
  49. },
  50. itemWidth:{
  51. type: [Number,String],
  52. default: 0
  53. }
  54. },
  55. data() {
  56. return {
  57. }
  58. },
  59. methods: {
  60. addToCat(item){
  61. this.$emit('chooseProduct',item,this.index)
  62. },
  63. viewPic(img){
  64. uni.previewImage({
  65. urls: [img],
  66. longPressActions: {
  67. itemList: ['发送给朋友', '保存图片', '收藏'],
  68. success: function(data) {
  69. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  70. },
  71. fail: function(err) {
  72. console.log(err.errMsg);
  73. }
  74. }
  75. })
  76. }
  77. },
  78. }
  79. </script>
  80. <style lang="less">
  81. /* 显示一行省略号 */
  82. .ellipsis-one{
  83. white-space: nowrap;
  84. text-overflow: ellipsis;
  85. overflow: hidden;
  86. word-break: break-all;
  87. }
  88. /* 显示两行,省略号 */
  89. .ellipsis-two{
  90. overflow: hidden;
  91. text-overflow: ellipsis;
  92. display: -webkit-box;
  93. -webkit-line-clamp: 2;
  94. line-clamp: 2;
  95. -webkit-box-orient: vertical;
  96. }
  97. .product-list{
  98. display:flex;
  99. flex-wrap: wrap;
  100. justify-content: space-between;
  101. padding: 0 3%;
  102. }
  103. .product-item{
  104. background: #ffffff;
  105. border-radius: 10upx;
  106. box-shadow: 1px 1px 3px #EEEEEE;
  107. width: 48%;
  108. margin: 10px 0 0 0;
  109. display: flex;
  110. flex-direction: column;
  111. .price-txt{
  112. color: red;
  113. display: flex;
  114. align-items: center;
  115. text{
  116. font-size: 36rpx;
  117. }
  118. }
  119. > view{
  120. &:first-child{
  121. position: relative;
  122. overflow: hidden;
  123. .product-code{
  124. color: #666;
  125. position: absolute;
  126. width: 100%;
  127. left:0;
  128. bottom:0;
  129. background: rgba(255,255,255,0.7);
  130. text-align: center;
  131. }
  132. }
  133. &:last-child{
  134. position: relative;
  135. flex-grow: 1;
  136. padding: 10px 10px 40px;
  137. .product-name{
  138. font-size: 28rpx;
  139. font-weight: 900;
  140. color: #666;
  141. }
  142. .product-guige{
  143. margin: 10rpx 0;
  144. color: #2196F3;
  145. }
  146. }
  147. .product-button{
  148. position: absolute;
  149. left: 5%;
  150. bottom: 0;
  151. width: 90%;
  152. padding: 5px 0 10px;
  153. display: flex;
  154. justify-content: space-between;
  155. align-items: center;
  156. button{
  157. display: flex;
  158. align-items: center;
  159. text-align: center;
  160. justify-content: center;
  161. min-width:50rpx;
  162. height: 50rpx;
  163. font-size: 28rpx;
  164. border-radius: 25rpx;
  165. padding: 0 10rpx;
  166. color: #fff;
  167. &:active{
  168. background: #2abcff;
  169. }
  170. }
  171. .bg-0{
  172. background: #066cff;
  173. }
  174. .bg-1{
  175. background: #34aa0a;
  176. }
  177. }
  178. }
  179. .back-price{
  180. padding: 6rpx 65rpx;
  181. background: rgba(255 ,87 ,34 , 1);
  182. position: absolute;
  183. top: 18rpx;
  184. right: -45rpx;
  185. color: #fff;
  186. z-index: 2;
  187. font-size: 20rpx;
  188. text-align: center;
  189. transform: rotate(40deg);
  190. display: flex;
  191. align-items: center;
  192. text{
  193. font-size: 28rpx;
  194. margin: 0 5rpx;
  195. }
  196. }
  197. }
  198. </style>