tm-cartCellListFood.vue 7.4 KB

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