tm-cartCellListFood.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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)" 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 style="position: absolute;right: 20px;" v-if="typeclick==7">
  93. <view class="genghuan mr-10" @click="genghuan(mdata,1)">更换</view>
  94. </view>
  95. <view style="position: absolute;right: 20px;" v-if="typeclick==8">
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. </template>
  102. <script>
  103. /**
  104. * 餐饮购物商品列表
  105. * @property {Number} img-width = [] 默认:140,图片元素宽度,rpx单位。
  106. * @property {Number} cart-num = [] 默认:0,当前销售的数量,需要cartNum.sync。
  107. * @property {String} color = [] 默认:primary,主题色
  108. * @property {String} bg-color = [] 默认:white,背景主题色
  109. * @property {Boolean} dense = [ture|false] 默认:false,是否隐藏中间优惠和文字说明的结构,只保留标题和价格数量按钮。
  110. * @property {Number} action-size = [] 默认:34,增减按钮大小。单位rpx
  111. * @property {String} border = [top|bottom] 默认:top, 显示上边线还是下边线
  112. * @property {Boolean} black = [ture|false] 默认:null,是否暗黑主题
  113. * @property {Object} mdata = [] 默认:{},数据结构
  114. * @property {Object} key-map = [] 默认:{},mdata的字段映射,每个人数据格式都不一样,如果你的数据和默认字段不一致,需要映射下关键字段。
  115. * @property {Function} change 改变销售数量时触发,返回当前改变后的销售数量。
  116. */
  117. import tmSliderNav from "@/tm-vuetify/components/tm-sliderNav/tm-sliderNav.vue"
  118. import tmImages from "@/tm-vuetify/components/tm-images/tm-images.vue"
  119. import tmTags from "@/tm-vuetify/components/tm-tags/tm-tags.vue"
  120. export default {
  121. components: {
  122. tmSliderNav,
  123. tmImages,
  124. tmTags
  125. },
  126. name: "tm-cartCellListFood",
  127. props: {
  128. imgWidth: {
  129. type: Number,
  130. default: 140,
  131. },
  132. cartNum: {
  133. type: Number,
  134. default: 0
  135. },
  136. color: {
  137. type: String,
  138. default: 'primary'
  139. },
  140. bgColor: {
  141. type: String,
  142. default: 'white'
  143. },
  144. // 字段映射表,每个人的mdata的数据字段不一样。如果不同就映射下吧。
  145. keyMap: {
  146. type: Object,
  147. default: () => {
  148. return {
  149. img: 'img',
  150. title: 'title',
  151. label: 'label',
  152. price: 'price',
  153. salePrice: 'salePrice',
  154. saleLabel: 'saleLabel',
  155. unit: 'unit',
  156. buy: 'buy',
  157. size: 'size',
  158. orderStatus: 'orderStatus'
  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. goPay(data,type){
  242. console.log(data);
  243. },
  244. // 评价
  245. goEval(data,type){
  246. // console.log(data);
  247. uni.navigateTo({
  248. url:'/pages/pingjia/index?no='+data.orderNo
  249. })
  250. },
  251. // 确认收货
  252. goSure(data,type){
  253. console.log(data);
  254. },
  255. //购买
  256. goBuy(data,type){
  257. console.log(data);
  258. },
  259. jiaru(data) {
  260. this.$emit('jiaruFun', {
  261. data: data,
  262. type: 2
  263. });
  264. },
  265. genghuan(data, type) {
  266. if (type == 1) {
  267. this.$emit('genghuan', {
  268. data: data,
  269. type: type
  270. });
  271. } else if (type == 2) {
  272. this.$emit('genghuan', {
  273. data: data,
  274. type: type
  275. });
  276. }
  277. },
  278. quxq(data) {
  279. this.$emit('jiaruFun', {
  280. data: data,
  281. type: 1
  282. });
  283. },
  284. jian() {
  285. const buyNum = this.cNum;
  286. if (buyNum <= 0) {
  287. this.cart_num = 0;
  288. return
  289. }
  290. this.cart_num = buyNum - 1
  291. },
  292. jia() {
  293. const buyNum = this.cNum;
  294. this.cart_num = parseInt(buyNum) + 1
  295. },
  296. }
  297. }
  298. </script>
  299. <style lang="less">
  300. .jiarugouwuche image {
  301. width: 28px !important;
  302. height: 28px !important;
  303. }
  304. .qiangwang {
  305. width: 100px;
  306. height: 28px;
  307. background: #303440;
  308. border: 1px solid white;
  309. font-size: 13px;
  310. text-align: center;
  311. color: white;
  312. line-height: 28px;
  313. border-radius: 5px;
  314. margin-top: 30px;
  315. }
  316. .fukuan {
  317. color: white;
  318. font-size: 14px;
  319. background: #303440;
  320. padding: 4px 15px 4px 15px;
  321. border-radius: 40px;
  322. }
  323. .shanchu {
  324. width: 25px;
  325. height: 25px;
  326. float: right;
  327. }
  328. .genghuan {
  329. color: #EBEBEB;
  330. font-size: 14px;
  331. background: #303440;
  332. border-radius: 6px;
  333. width: 60px;
  334. height: 27px;
  335. border: 1px solid #EBEBEB;
  336. text-align: center;
  337. line-height: 27px;
  338. margin-top: 8px;
  339. }
  340. </style>