tm-cartCellListFood.vue 9.1 KB

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