tm-cartCellListFood.vue 8.8 KB

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