tm-cartCellListFood.vue 9.7 KB

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