tm-cartCellListFood.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. ]" @click.stop="goXiangQing(mdata)">
  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;"
  18. :class="[black_tmeme ? 'bk' : '',]" >
  19. {{mdata[keyMap['title']]}}
  20. <image v-if="typeclick==4" class="shanchu" src="/static/img/94.png" @click="shanchu(mdata)" ></image>
  21. </view>
  22. <view style="min-height: 64rpx;">
  23. <view v-if="!dense&&mdata[keyMap['label']]"
  24. class="tm-cartCellListFood-label text-size-s text-grey py-8">{{mdata[keyMap['label']]}}</view>
  25. <view v-if="!dense&&mdata[keyMap['label']]"
  26. class="tm-cartCellListFood-label text-size-s text-grey py-8 text-red">{{mdata[keyMap['size']]}}
  27. </view>
  28. <view v-if="mdata[keyMap['saleLabel']]&&!dense"
  29. class="tm-cartCellListFood-sale text-size-s text-grey">
  30. <block v-for="(item,index) in mdata[keyMap['saleLabel']]" :key="index">
  31. <tm-tags :black="black_tmeme" :color="color" v-if="index<4" size="xs">{{item}}</tm-tags>
  32. </block>
  33. </view>
  34. </view>
  35. <view class="tm-cartCellListFood-price flex-between">
  36. <view>
  37. <text class="text-size-xs text-red" v-if="typeclick!=7 && typeclick!=6 && typeclick!=8">¥</text>
  38. <text v-if="typeclick!=7 && typeclick!=6 && typeclick!=8"
  39. class="text-size-n text-red text-weight-b px-5">{{mdata[keyMap['price']]}}</text>
  40. <text v-if="mdata[keyMap['unit']]"
  41. class="text-size-xs text-grey pr-10">/{{mdata[keyMap['unit']]}}</text>
  42. <text v-if="mdata[keyMap['salePrice']]"
  43. class="text-delete text-size-xxs text-grey">¥{{mdata[keyMap['salePrice']]}}</text>
  44. </view>
  45. <view class="flex jiarugouwuche" v-if="typeclick==1" @click.stop="jiaru(mdata)">
  46. <image class="" src="/static/img/86.png"></image>
  47. </view>
  48. <view class="flex" v-if="typeclick==2">
  49. <block v-if="cNum>0">
  50. <view :style="{
  51. width:`${actionSize}rpx`,
  52. height:`${actionSize}rpx`,
  53. }" :class="[color,black_tmeme ? 'bk' : '',]" @click="jian"
  54. class="tm-cartCellListFood-actions rounded flex-center outlined">
  55. <text class="iconfont icon-minus text-size-xxs"></text>
  56. </view>
  57. <view class="px-12 text-size-n " :class="[black_tmeme ? 'bk' : '',]">{{cNum}}</view>
  58. </block>
  59. <view :style="{
  60. width:`${actionSize}rpx`,
  61. height:`${actionSize}rpx`,
  62. }" :class="[color,`border-${color}-a-1`,black_tmeme ? 'bk' : '',]" @click="jia"
  63. class="tm-cartCellListFood-actions rounded flex-center ">
  64. <text class="iconfont icon-plus text-size-xs"></text>
  65. </view>
  66. </view>
  67. <view class="flex" v-if="typeclick==3" @click="jiaru(mdata)">
  68. <view class="qiangwang">前往商城购买</view>
  69. </view>
  70. <view class="flex" v-if="typeclick==4">
  71. <view class="" v-if="mdata[keyMap['orderStatus']]==0">
  72. <view class="fukuan" @click="goPay(mdata,0)">去付款</view>
  73. </view>
  74. <view class="flex" v-if="mdata[keyMap['orderStatus']]==1 ||mdata[keyMap['orderStatus']]==2">
  75. <view class="fukuan mr-10" @click="goBuy(mdata,1)">再次购买</view>
  76. <view class="fukuan" @click="goSure(mdata,1)" v-if="mdata[keyMap['orderStatus']]==1">确认收货</view>
  77. <view class="fukuan" @click="goEval(mdata,2)"
  78. v-if="mdata[keyMap['orderStatus']]==2 && mdata[keyMap['isEval']]== 0 ">去评价</view>
  79. <!-- <view class="fukuan" @click="goEvalList(mdata,2)"
  80. v-if="mdata[keyMap['orderStatus']]==2 && mdata[keyMap['isEval']]== 1 ">我的评价</view> -->
  81. </view>
  82. </view>
  83. <view style="position: absolute;right: 20px;" v-if="typeclick==5">
  84. <view class="genghuan mr-10">出库</view>
  85. <!-- <view class="genghuan">取出</view> -->
  86. </view>
  87. <view style="position: absolute;right: 20px;" v-if="typeclick==6">
  88. <view class="genghuan mr-10" @click="genghuan(mdata,1)">更换</view>
  89. <view class="genghuan" @click="genghuan(mdata,2)">出库</view>
  90. </view>
  91. <view style="position: absolute;right: 20px;" v-if="typeclick==7">
  92. <view class="genghuan mr-10" @click="genghuan(mdata,1)">更换</view>
  93. </view>
  94. <view style="position: absolute;right: 20px;" v-if="typeclick==8">
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. </template>
  101. <script>
  102. /**
  103. * 餐饮购物商品列表
  104. * @property {Number} img-width = [] 默认:140,图片元素宽度,rpx单位。
  105. * @property {Number} cart-num = [] 默认:0,当前销售的数量,需要cartNum.sync。
  106. * @property {String} color = [] 默认:primary,主题色
  107. * @property {String} bg-color = [] 默认:white,背景主题色
  108. * @property {Boolean} dense = [ture|false] 默认:false,是否隐藏中间优惠和文字说明的结构,只保留标题和价格数量按钮。
  109. * @property {Number} action-size = [] 默认:34,增减按钮大小。单位rpx
  110. * @property {String} border = [top|bottom] 默认:top, 显示上边线还是下边线
  111. * @property {Boolean} black = [ture|false] 默认:null,是否暗黑主题
  112. * @property {Object} mdata = [] 默认:{},数据结构
  113. * @property {Object} key-map = [] 默认:{},mdata的字段映射,每个人数据格式都不一样,如果你的数据和默认字段不一致,需要映射下关键字段。
  114. * @property {Function} change 改变销售数量时触发,返回当前改变后的销售数量。
  115. */
  116. import tmSliderNav from "@/tm-vuetify/components/tm-sliderNav/tm-sliderNav.vue"
  117. import tmImages from "@/tm-vuetify/components/tm-images/tm-images.vue"
  118. import tmTags from "@/tm-vuetify/components/tm-tags/tm-tags.vue"
  119. export default {
  120. components: {
  121. tmSliderNav,
  122. tmImages,
  123. tmTags
  124. },
  125. name: "tm-cartCellListFood",
  126. props: {
  127. imgWidth: {
  128. type: Number,
  129. default: 140,
  130. },
  131. cartNum: {
  132. type: Number,
  133. default: 0
  134. },
  135. color: {
  136. type: String,
  137. default: 'primary'
  138. },
  139. bgColor: {
  140. type: String,
  141. default: 'white'
  142. },
  143. // 字段映射表,每个人的mdata的数据字段不一样。如果不同就映射下吧。
  144. keyMap: {
  145. type: Object,
  146. default: () => {
  147. return {
  148. img: 'img',
  149. title: 'title',
  150. label: 'label',
  151. price: 'price',
  152. salePrice: 'salePrice',
  153. saleLabel: 'saleLabel',
  154. unit: 'unit',
  155. buy: 'buy',
  156. size: 'size',
  157. orderStatus: 'orderStatus',
  158. isEval:'isEval'
  159. }
  160. }
  161. },
  162. // 精简后,不显示简介文字和优惠文字,只显示标题,价格和数量
  163. dense: {
  164. type: Boolean | String,
  165. default: false
  166. },
  167. //增减按钮大小。单位rpx
  168. actionSize: {
  169. type: Number,
  170. default: 38
  171. },
  172. // 显示上边线还是下边线。可选top / bottom
  173. border: {
  174. type: String,
  175. default: 'top'
  176. },
  177. black: {
  178. type: Boolean | String,
  179. default: null
  180. },
  181. mdata: {
  182. type: Object,
  183. default: () => {
  184. // return {
  185. // img:'https://picsum.photos/300?k=2',
  186. // title:'特色单人套餐(任选)',
  187. // label:'这个产品是只有几个融会',
  188. // price:36.2,
  189. // salePrice:76.4,
  190. // saleLabel:['7折优惠','首单减3元'],
  191. // unit:'/斤'
  192. // buy:0
  193. // }
  194. return {};
  195. }
  196. },
  197. typeclick: {
  198. type: Number,
  199. default: 0
  200. }
  201. },
  202. watch: {
  203. 'mdata.buy': function(val) {
  204. if (this.cart_num == val) return;
  205. this.cart_num = val;
  206. },
  207. },
  208. computed: {
  209. black_tmeme: function() {
  210. if (this.black !== null) return this.black;
  211. return this.$tm.vx.state().tmVuetify.black;
  212. },
  213. cart_num: {
  214. get: function() {
  215. return this.cNum;
  216. },
  217. set: function(val) {
  218. this.cNum = val;
  219. this.$emit("update:cartNum", val)
  220. // #ifdef H5
  221. this.$nextTick(function() {
  222. this.$emit("change", val)
  223. })
  224. // #endif
  225. // #ifndef H5
  226. this.$emit("change", val)
  227. // #endif
  228. }
  229. }
  230. },
  231. data() {
  232. return {
  233. cNum: 0,
  234. };
  235. },
  236. mounted() {
  237. this.cNum = this.mdata.buy;
  238. },
  239. methods: {
  240. // 点击详情
  241. goXiangQing(data){
  242. console.log(data,'详情数据');
  243. this.$emit('goXiangQing', {
  244. data: data
  245. });
  246. },
  247. // 删除订单
  248. shanchu(data){
  249. console.log(data,'3');
  250. this.$emit('shanchu', {
  251. data: data
  252. });
  253. },
  254. // 付款
  255. goPay(data,type){
  256. console.log(data);
  257. },
  258. // 评价
  259. goEval(data,type){
  260. console.log(data,type);
  261. this.$emit('Eval', {
  262. data: data,
  263. type: 2
  264. });
  265. },
  266. goEvalList(data,type){},
  267. // 确认收货
  268. goSure(data,type){
  269. console.log(data);
  270. this.$emit('sure', {
  271. data: data,
  272. type: 1
  273. });
  274. },
  275. //购买
  276. goBuy(data,type){
  277. console.log(data);
  278. },
  279. jiaru(data) {
  280. this.$emit('jiaruFun', {
  281. data: data,
  282. type: 2
  283. });
  284. },
  285. genghuan(data, type) {
  286. if (type == 1) {
  287. this.$emit('genghuan', {
  288. data: data,
  289. type: type
  290. });
  291. } else if (type == 2) {
  292. this.$emit('genghuan', {
  293. data: data,
  294. type: type
  295. });
  296. }
  297. },
  298. quxq(data) {
  299. this.$emit('jiaruFun', {
  300. data: data,
  301. type: 1
  302. });
  303. },
  304. jian() {
  305. const buyNum = this.cNum;
  306. if (buyNum <= 0) {
  307. this.cart_num = 0;
  308. return
  309. }
  310. this.cart_num = buyNum - 1
  311. },
  312. jia() {
  313. const buyNum = this.cNum;
  314. this.cart_num = parseInt(buyNum) + 1
  315. },
  316. }
  317. }
  318. </script>
  319. <style lang="less">
  320. .jiarugouwuche image {
  321. width: 28px !important;
  322. height: 28px !important;
  323. }
  324. .qiangwang {
  325. width: 100px;
  326. height: 28px;
  327. background: #303440;
  328. border: 1px solid white;
  329. font-size: 13px;
  330. text-align: center;
  331. color: white;
  332. line-height: 28px;
  333. border-radius: 5px;
  334. margin-top: 30px;
  335. }
  336. .fukuan {
  337. color: white;
  338. font-size: 14px;
  339. background: #303440;
  340. padding: 4px 15px 4px 15px;
  341. border-radius: 40px;
  342. }
  343. .shanchu {
  344. width: 25px;
  345. height: 25px;
  346. float: right;
  347. }
  348. .genghuan {
  349. color: #EBEBEB;
  350. font-size: 14px;
  351. background: #303440;
  352. border-radius: 6px;
  353. width: 60px;
  354. height: 27px;
  355. border: 1px solid #EBEBEB;
  356. text-align: center;
  357. line-height: 27px;
  358. margin-top: 8px;
  359. }
  360. </style>