tm-cartCellListFood.vue 10 KB

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