tm-cartCellListFood.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="tm-cartCellListFood px-20 py-32 flex-top-start" :class="[
  3. bgColor,
  4. black_tmeme ? 'grey-darken-4' : '',
  5. black_tmeme ? 'bk' : '',
  6. border === 'top' ? 'border-t-1' : '',
  7. border === 'bottom' ? 'border-b-1' : '',
  8. ]">
  9. <view v-if="mdata[keyMap['img']]" class="tm-cartCellListFood-img" :style="{
  10. width:imgWidth+'rpx',
  11. height:imgWidth+'rpx'
  12. }">
  13. <tm-images :width="imgWidth" :height="imgWidth" :round="3" :src="mdata[keyMap['img']]"></tm-images>
  14. </view>
  15. <view class="tm-cartCellListFood-r fulled ">
  16. <view class="pl-15">
  17. <view class="title text-size-s text-weight-b text-overflow-2" style="line-height: 32rpx;" :class="[black_tmeme ? 'bk' : '',]">
  18. {{mdata[keyMap['title']]}}
  19. </view>
  20. <view style="min-height: 64rpx;" >
  21. <view v-if="!dense&&mdata[keyMap['label']]" class="tm-cartCellListFood-label text-size-s text-grey py-8">{{mdata[keyMap['label']]}}</view>
  22. <view v-if="mdata[keyMap['saleLabel']]&&!dense" class="tm-cartCellListFood-sale text-size-s text-grey">
  23. <block v-for="(item,index) in mdata[keyMap['saleLabel']]" :key="index">
  24. <tm-tags :black="black_tmeme" :color="color" v-if="index<4" size="xs">{{item}}</tm-tags>
  25. </block>
  26. </view>
  27. </view>
  28. <view class="tm-cartCellListFood-price flex-between">
  29. <view>
  30. <text class="text-size-xs text-red">¥</text>
  31. <text class="text-size-n text-red text-weight-b px-5">{{mdata[keyMap['price']]}}</text>
  32. <text v-if="mdata[keyMap['unit']]" class="text-size-xs text-grey pr-10">/{{mdata[keyMap['unit']]}}</text>
  33. <text v-if="mdata[keyMap['salePrice']]" class="text-delete text-size-xxs text-grey">¥{{mdata[keyMap['salePrice']]}}</text>
  34. </view>
  35. <view class="flex">
  36. <block v-if="cNum>0">
  37. <view :style="{
  38. width:`${actionSize}rpx`,
  39. height:`${actionSize}rpx`,
  40. }" :class="[color,black_tmeme ? 'bk' : '',]" @click="jian" class="tm-cartCellListFood-actions rounded flex-center outlined">
  41. <text class="iconfont icon-minus text-size-xxs"></text>
  42. </view>
  43. <view class="px-12 text-size-n " :class="[black_tmeme ? 'bk' : '',]">{{cNum}}</view>
  44. </block>
  45. <view :style="{
  46. width:`${actionSize}rpx`,
  47. height:`${actionSize}rpx`,
  48. }" :class="[color,`border-${color}-a-1`,black_tmeme ? 'bk' : '',]" @click="jia" class="tm-cartCellListFood-actions rounded flex-center ">
  49. <text class="iconfont icon-plus text-size-xs"></text>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. /**
  59. * 餐饮购物商品列表
  60. * @property {Number} img-width = [] 默认:140,图片元素宽度,rpx单位。
  61. * @property {Number} cart-num = [] 默认:0,当前销售的数量,需要cartNum.sync。
  62. * @property {String} color = [] 默认:primary,主题色
  63. * @property {String} bg-color = [] 默认:white,背景主题色
  64. * @property {Boolean} dense = [ture|false] 默认:false,是否隐藏中间优惠和文字说明的结构,只保留标题和价格数量按钮。
  65. * @property {Number} action-size = [] 默认:34,增减按钮大小。单位rpx
  66. * @property {String} border = [top|bottom] 默认:top, 显示上边线还是下边线
  67. * @property {Boolean} black = [ture|false] 默认:null,是否暗黑主题
  68. * @property {Object} mdata = [] 默认:{},数据结构
  69. * @property {Object} key-map = [] 默认:{},mdata的字段映射,每个人数据格式都不一样,如果你的数据和默认字段不一致,需要映射下关键字段。
  70. * @property {Function} change 改变销售数量时触发,返回当前改变后的销售数量。
  71. */
  72. import tmSliderNav from "@/tm-vuetify/components/tm-sliderNav/tm-sliderNav.vue"
  73. import tmImages from "@/tm-vuetify/components/tm-images/tm-images.vue"
  74. import tmTags from "@/tm-vuetify/components/tm-tags/tm-tags.vue"
  75. export default {
  76. components:{tmSliderNav,tmImages,tmTags},
  77. name:"tm-cartCellListFood",
  78. props:{
  79. imgWidth:{
  80. type:Number,
  81. default:140,
  82. },
  83. cartNum:{
  84. type:Number,
  85. default:0
  86. },
  87. color:{
  88. type:String,
  89. default:'primary'
  90. },
  91. bgColor:{
  92. type:String,
  93. default:'white'
  94. },
  95. // 字段映射表,每个人的mdata的数据字段不一样。如果不同就映射下吧。
  96. keyMap:{
  97. type:Object,
  98. default:()=>{
  99. return {
  100. img:'img',
  101. title:'title',
  102. label:'label',
  103. price:'price',
  104. salePrice:'salePrice',
  105. saleLabel:'saleLabel',
  106. unit:'unit',
  107. buy:'buy'
  108. }
  109. }
  110. },
  111. // 精简后,不显示简介文字和优惠文字,只显示标题,价格和数量
  112. dense:{
  113. type:Boolean|String,
  114. default:false
  115. },
  116. //增减按钮大小。单位rpx
  117. actionSize:{
  118. type:Number,
  119. default:38
  120. },
  121. // 显示上边线还是下边线。可选top / bottom
  122. border: {
  123. type: String,
  124. default: 'top'
  125. },
  126. black:{
  127. type:Boolean|String,
  128. default:null
  129. },
  130. mdata:{
  131. type:Object,
  132. default:()=>{
  133. // return {
  134. // img:'https://picsum.photos/300?k=2',
  135. // title:'特色单人套餐(任选)',
  136. // label:'这个产品是只有几个融会',
  137. // price:36.2,
  138. // salePrice:76.4,
  139. // saleLabel:['7折优惠','首单减3元'],
  140. // unit:'/斤'
  141. // buy:0
  142. // }
  143. return {};
  144. }
  145. }
  146. },
  147. watch:{
  148. 'mdata.buy':function(val){
  149. if(this.cart_num==val) return;
  150. this.cart_num = val;
  151. },
  152. },
  153. computed:{
  154. black_tmeme: function() {
  155. if (this.black !== null) return this.black;
  156. return this.$tm.vx.state().tmVuetify.black;
  157. },
  158. cart_num:{
  159. get:function(){
  160. return this.cNum;
  161. },
  162. set:function(val){
  163. this.cNum = val;
  164. this.$emit("update:cartNum",val)
  165. // #ifdef H5
  166. this.$nextTick(function(){
  167. this.$emit("change",val)
  168. })
  169. // #endif
  170. // #ifndef H5
  171. this.$emit("change",val)
  172. // #endif
  173. }
  174. }
  175. },
  176. data() {
  177. return {
  178. cNum:0,
  179. };
  180. },
  181. mounted() {
  182. this.cNum = this.mdata.buy;
  183. },
  184. methods:{
  185. jian(){
  186. const buyNum = this.cNum;
  187. if(buyNum<=0) {
  188. this.cart_num = 0;
  189. return
  190. }
  191. this.cart_num = buyNum-1
  192. },
  193. jia(){
  194. const buyNum = this.cNum;
  195. this.cart_num = parseInt(buyNum) + 1
  196. },
  197. }
  198. }
  199. </script>
  200. <style lang="less">
  201. </style>