tm-cartBarFood.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view class="tm-cartBarFood">
  3. <view
  4. @touchmove.stop.prevent="stopMove"
  5. @click.stop="openList=!openList"
  6. class="tm-cartBarFood-bg absolute"
  7. v-if="openList"
  8. :style="{
  9. height: sywi + 'px'
  10. }"
  11. ></view>
  12. <view
  13. :style="{
  14. width: position != 'static' ? wininfo.windowWidth - offsetLeft * 2 + 'px' : 'auto',
  15. left: position != 'static' ? offsetLeft + 'px' : '0px',
  16. top: position == 'top' ? top_px + 'px' : 'auto',
  17. bottom: position == 'bottom' ? bottom_px + 'px' : 'auto'
  18. }"
  19. class="tm-cartBarFood-body "
  20. :class="[
  21. position,
  22. border === 'top' ? 'border-t-1' : '',
  23. border === 'bottom' ? 'border-b-1' : '',
  24. 'sheetIDX'
  25. ]"
  26. >
  27. <view class="tm-cartBarFood-list white "
  28. :class="[
  29. black_tmeme ? 'grey-darken-5' : '',
  30. black_tmeme ? 'bk' : '',
  31. ]"
  32. >
  33. <!-- :cartNum.sync="test" -->
  34. <view v-show="openList" class="pb-32">
  35. <view @touchmove.stop.prevent="stopMove" class="flex-between px-32 py-24">
  36. <text class="text-size-s text-weight-b">已选商品</text>
  37. <view @click="clearEmpty" class="text-size-s text-grey">
  38. <tm-icons color="grey" size="20" name="icon-delete-fill"></tm-icons>
  39. 清空购物车
  40. </view>
  41. </view>
  42. <block v-if="listData.length <= 0"><tm-empty label="没有商品,快去选购吧" model="listEmpty"></tm-empty></block>
  43. <view class="tm-cartBarFood-list-srcoll" >
  44. <block v-for="(item, index) in listData" :key="index">
  45. <tm-cartCellListFood :black="black_tmeme" :key="index" @change="listAddChange($event, index)" :mdata="item" :cartNum.sync="item.buy" :color="color" dense ></tm-cartCellListFood>
  46. </block>
  47. </view>
  48. <!-- #ifndef H5 -->
  49. <view style="height:100upx;"></view>
  50. <!-- #endif -->
  51. <!-- #ifdef H5 -->
  52. <view style="height:50upx;"></view>
  53. <!-- #endif -->
  54. </view>
  55. </view>
  56. <view :style="{ background: bgColor }" :class="[
  57. 'on',
  58. black_tmeme ? 'grey-darken-5' : '',
  59. black_tmeme ? 'bk' : '',
  60. 'round-' + round,
  61. bgTheme,
  62. ]" class=" flex-between tm-cartBarFood-wk">
  63. <view class="flex-start">
  64. <view @click="openlistfun" class="tm-cartBarFood-body px-32">
  65. <tm-badges :offset="[10,-5]" v-if="sum.num > 0" :dot="false" :label="sum.num"></tm-badges>
  66. <view :class="[openList?'ani':'']">
  67. <tm-icons :black="black_tmeme" :color="list.length > 0&&disabled==false ? color : colorGrey" :size="60" name="icon-shopping-cart-fill"></tm-icons>
  68. </view>
  69. </view>
  70. <view class="flex flex-col">
  71. <view class="text-weight-b" :class="[`text-${color}`]">
  72. <text class="text-size-xs">¥</text>
  73. <text class="text-size-lg">{{ sum.price }}</text>
  74. </view>
  75. <view v-if="label!=''&&label.length>0&&label!=true&&label!='true'" class="text-size-xs text-grey">{{label}}</view>
  76. </view>
  77. </view>
  78. <view class="pr-16"><tm-button :black="black_tmeme" @click="confirm" size="n" :theme="list.length > 0&&disabled==false ? btnColor : colorGrey" font-color="white" round="24">{{btnText}}</tm-button></view>
  79. </view>
  80. <!-- 安全区域的高度。 -->
  81. <view v-if="safe" class="safe--hei " :class="[
  82. black_tmeme ? 'grey-darken-5' : 'white',
  83. black_tmeme ? 'bk' : '',
  84. ]"></view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. /**
  90. * 底部餐饮结算工具条
  91. * @property {Array} list = [] 默认:[],当前购物车产品列表,
  92. * @property {String} bg-theme = [] 默认:"white",背景颜色主题名称
  93. * @property {String | Boolean} black = [true|false] 默认:null,暗黑模式。
  94. * @property {String} bg-color = [] 默认:'',自定义背景颜色。
  95. * @property {String} color = [] 默认:primary,文字默认激活色。
  96. * @property {String} btn-color = [] 默认:primary,默认按激活主题色。
  97. * @property {String} color-grey = [] 默认:gret,购物车为空时主题色。
  98. * @property {String} btnT-text = [] 默认:确认商品,确认按钮上的文字。
  99. * @property {String} position = [bottom|top|static] 默认:bottom,可选位置:bottom|top|static
  100. * @property {Number|String} top = [] 默认:0,距离顶部的距离:只有在position=='top'使用
  101. * @property {Number|String} bottom = [] 默认:0,距离底部的距离:只有在position=='bottom'使用
  102. * @property {String} border = [top|bottom] 默认:top,显示上边线还是下边线。可选top / bottom
  103. * @property {String|Number} offset-left = [] 默认:0,偏移量。即离左边的间距。如果提供,自动居中出现两边间隙。
  104. * @property {String|Boolean} safe = [true|false] 默认:true,// 是否开启底部安全区域。
  105. * @property {Number} round = [] 默认:0,圆角
  106. * @property {String} label = [] 默认:注意选择的超市哦,价格正文的文字说明。
  107. * @property {Function} change 购物车增减商品时触发{num,index}。
  108. * @property {Function} confirm 确认提交按钮时触发
  109. *
  110. */
  111. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  112. import tmEmpty from "@/tm-vuetify/components/tm-empty/tm-empty.vue"
  113. import tmButton from "@/tm-vuetify/components/tm-button/tm-button.vue"
  114. import tmBadges from "@/tm-vuetify/components/tm-badges/tm-badges.vue"
  115. import tmCartCellListFood from "@/tm-vuetify/components/tm-cartCellListFood/tm-cartCellListFood.vue"
  116. export default {
  117. components:{tmIcons,tmEmpty,tmButton,tmCartCellListFood,tmBadges},
  118. name: 'tm-cartBarFood',
  119. props: {
  120. list: {
  121. Array,
  122. default: () => {
  123. return [];
  124. }
  125. },
  126. // 背景颜色主题名称
  127. bgTheme: {
  128. type: String,
  129. default: 'white'
  130. },
  131. // 是否启用暗黑主题。
  132. black: {
  133. type: String | Boolean,
  134. default: null
  135. },
  136. // 背景颜色,自定义。
  137. bgColor: {
  138. type: String,
  139. default: ''
  140. },
  141. // 自定义项目文字默认激活色。
  142. color: {
  143. type: String,
  144. default: 'primary'
  145. },
  146. btnColor: {
  147. type: String,
  148. default: 'primary'
  149. },
  150. btnText:{
  151. type:String,
  152. default:'确认商品'
  153. },
  154. // 自定义项目文字默认失去焦点色。
  155. colorGrey: {
  156. type: String,
  157. default: 'grey'
  158. },
  159. // 可选bootom / top / static
  160. position: {
  161. type: String,
  162. default: 'bottom'
  163. },
  164. // 距离顶部的距离。默认是0,只有在position=='top'使用
  165. top: {
  166. type: Number | String,
  167. default: 0
  168. },
  169. // 距离顶部的距离。默认是0,只有在position=='bottom'使用
  170. bottom: {
  171. type: Number | String,
  172. default: 0
  173. },
  174. // 显示上边线还是下边线。可选top / bottom
  175. border: {
  176. type: String,
  177. default: ''
  178. },
  179. // 只支持圆角主题。如round-5
  180. round: {
  181. type: String | Number,
  182. default: 0
  183. },
  184. // 偏移量。即离左边的间距。如果提供,整个navbar的宽度会是100% - offsetLeft*2。
  185. offsetLeft: {
  186. type: String | Number,
  187. default: 0
  188. },
  189. // 是否开启底部安全区域。
  190. safe: {
  191. type: String | Boolean,
  192. default: true
  193. },
  194. disabled: {
  195. type: String | Boolean,
  196. default: false
  197. },
  198. // 是否开启点按动画,默认开启。
  199. ani: {
  200. type: String | Boolean,
  201. default: true
  202. },
  203. //价格下方的说明。
  204. label:{
  205. type:String,
  206. default:'注意选择的超市哦'
  207. }
  208. },
  209. watch: {
  210. list:{
  211. deep:true,
  212. handler(){
  213. this.listData = uni.$tm.deepClone(this.list)
  214. }
  215. }
  216. },
  217. computed: {
  218. black_tmeme: function() {
  219. if (this.black !== null) return this.black;
  220. return this.$tm.vx.state().tmVuetify.black;
  221. },
  222. top_px: function() {
  223. return this.top;
  224. },
  225. bottom_px: function() {
  226. return this.bottom;
  227. },
  228. wininfo: function() {
  229. return uni.getSystemInfoSync();
  230. },
  231. listLen: function() {
  232. return this.listData.length;
  233. },
  234. sum:function(){
  235. let t = this;
  236. let pr = 0;
  237. let num =0;
  238. this.listData.forEach(item => {
  239. pr += item.price * item.buy;
  240. num += item.buy;
  241. });
  242. return {
  243. price:pr<=0?0:pr.toFixed(2),
  244. num:num
  245. }
  246. }
  247. },
  248. data() {
  249. return {
  250. safeBottomeHeight: '0',
  251. sywi: 0,
  252. openList: false,
  253. listData:[]
  254. };
  255. },
  256. mounted() {
  257. let t = this;
  258. this.sywi = uni.getSystemInfoSync().windowHeight;
  259. // t.safeBottomeHeight = uni.getSystemInfoSync().safeAreaInsets.bottom;
  260. this.listData = uni.$tm.deepClone(this.list)
  261. },
  262. methods: {
  263. openlistfun(){
  264. if(this.disabled) return;
  265. this.openList = !this.openList;
  266. },
  267. listAddChange(e,index) {
  268. this.$nextTick(function(){
  269. this.$emit('change',{num:e,index:index})
  270. })
  271. },
  272. clearEmpty() {
  273. this.$emit('clear')
  274. },
  275. getlist() {
  276. if(this.list.length<=0) return;
  277. let rlist = {
  278. priceTotal:this.sum.price,
  279. numTotal:this.sum.num,
  280. list:this.list
  281. };
  282. return rlist;
  283. },
  284. confirm() {
  285. if(this.list.length<=0||this.disabled) return;
  286. let rlist = {
  287. priceTotal:this.sum.price,
  288. numTotal:this.sum.num,
  289. list:this.list
  290. };
  291. this.$emit('confirm',rlist);
  292. return rlist;
  293. },
  294. stopMove(){
  295. return false;
  296. }
  297. }
  298. };
  299. </script>
  300. <style lang="scss" scoped>
  301. .safe--hei{
  302. height: var(--status-bar-height);
  303. }
  304. .tm-cartBarFood {
  305. .tm-cartBarFood-bg {
  306. top: 0;
  307. left: 0;
  308. width: 100%;
  309. background-color: rgba(0, 0, 0, 0.3);
  310. }
  311. .tm-cartBarFood-wk{
  312. height: 100rpx;
  313. position: relative;
  314. z-index: 15;
  315. &.on{
  316. box-shadow: 0 -5px 10px rgba(0,0,0,0.05);
  317. }
  318. }
  319. .tm-cartBarFood-body {
  320. animation: scalse 0.4s linear;
  321. .tm-cartBarFood-list {
  322. position: absolute;
  323. bottom: 40rpx;
  324. width: 100%;
  325. z-index: 10;
  326. .tm-cartBarFood-list-srcoll{
  327. max-height: 600rpx;
  328. overflow-y: scroll;
  329. }
  330. }
  331. &.bottom {
  332. position: fixed;
  333. bottom: 0;
  334. left: 0;
  335. z-index: 400;
  336. }
  337. &.top {
  338. position: fixed;
  339. z-index: 400;
  340. top: 0;
  341. left: 0;
  342. }
  343. }
  344. }
  345. .ani {
  346. animation: scalse 0.4s linear;
  347. }
  348. @keyframes scalse {
  349. 0% {
  350. transform: scale(0.9);
  351. }
  352. 50% {
  353. transform: scale(1.1);
  354. }
  355. 100% {
  356. transform: scale(1);
  357. }
  358. }
  359. </style>