tm-cartCellListFood.vue 8.3 KB

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