tm-cartCellListFood.vue 6.7 KB

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