tm-cartCellListFood.vue 11 KB

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