home.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view class="w-full">
  3. <view>
  4. <u-row justify="space-between" customStyle="margin-bottom: 10px">
  5. <u-col span="3">
  6. <view class="icon-container-l" @click="onOrder">
  7. <uni-badge size="normal" :text="txts" absolute="rightTop">
  8. <u-icon :name="iconCooking" label="自提" labelPos="bottom" size="32"></u-icon>
  9. </uni-badge>
  10. </view>
  11. </u-col>
  12. <view class="container">
  13. <u-tag plain :text="cList.openState ? '营业中' : '离线'" :type="cList.openState ? 'success' : 'error'"
  14. size="mini"></u-tag>
  15. <view>
  16. <!-- <text>{{cList.name}}</text> -->
  17. <u-icon :label="cList.name" labelPos="left" @click="btnIc" size="16" name="arrow-down"></u-icon>
  18. </view>
  19. </view>
  20. <u-col span="3">
  21. <view class="icon-container-r" @click="onMyInfo">
  22. <u-icon label="我的" labelPos="bottom" size="32" :name="iconPeople"></u-icon>
  23. </view>
  24. </u-col>
  25. </u-row>
  26. </view>
  27. <view class="w-full dflex-b padding-xs box-sizing-b dflex-wrap-w">
  28. <view class="goods-item margin-bottom-sm" v-for="(item, gindex) in goods" :key="gindex">
  29. <view class="img dflex-c" @click="toDetial(item)">
  30. <image mode="aspectFit" :src="item.imgList[0].url"></image>
  31. </view>
  32. <view class="title">{{item.spuName}}</view>
  33. <view class="dflex padding-bottom-xs">
  34. <u-tag plain text="销量: 199" borderColor="#FF6D20" color="#FF6D20" size="mini"></u-tag>
  35. </view>
  36. <view class="w-full dflex-b">
  37. <view class="price">{{item.minPrice ? item.minPrice : '无'}}</view>
  38. <view>
  39. <u-button type="primary" shape="circle" size="small"
  40. color="linear-gradient(to right, #F54319, #FF6D20)" @click="goCart(item)">
  41. <u-icon name="shopping-cart-fill" size="28" color="#fff"></u-icon>
  42. </u-button>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <my-gap :height="10" />
  48. <specPopup class='spec-box' ref="specPopup" :cardMsg="cardMsg" @update-shopmsg="handleUpdateShopMsg"
  49. @onSuccess="carListMeg">
  50. </specPopup>
  51. <view class="cart-bottom padding-sm dflex-b">
  52. <view class="cart padding-lr">
  53. <uni-badge size="small" :text="buyCount" absolute="rightTop">
  54. <u-icon name="shopping-cart-fill" size="28" color="#FF873D" @click="showCart"></u-icon>
  55. </uni-badge>
  56. <text class="cart-total">总计:¥{{total}}</text>
  57. </view>
  58. <view class="balance dflex-c background-gradient" @click="toBuy">去结算</view>
  59. </view>
  60. <cartPopupVue ref="cartPopup" @selected-changed="handleSelectedChanged" @cartChange="cartChange" />
  61. </view>
  62. </template>
  63. <script>
  64. import cartPopupVue from '../../components/cartPopup.vue'
  65. import specPopup from '@/components/specPopup.vue'
  66. import iconCooking from '../../static/cooking.png'
  67. import iconPeople from '../../static/people.png'
  68. import shoppingCart from '../../static/shoppingCart.png'
  69. export default {
  70. components: {
  71. cartPopupVue,
  72. specPopup
  73. },
  74. data() {
  75. return {
  76. onIndex: 0,
  77. show: false,
  78. iconCooking: iconCooking,
  79. iconPeople: iconPeople,
  80. shoppingCart: shoppingCart,
  81. tags: 1,
  82. txts: 1,
  83. carList: {},
  84. goods: [],
  85. total: 0,
  86. cList: {},
  87. cardMsg: {},
  88. selectedList: [],
  89. buyCount: 0
  90. }
  91. },
  92. onLoad() {
  93. // this.carListMeg()
  94. },
  95. onShow(){
  96. const e = uni.getStorageSync('carl')
  97. this.cList = e
  98. this.fatchDate()
  99. this.carListMeg()
  100. },
  101. methods: {
  102. // 加购
  103. goCart(e) {
  104. this.cardMsg = e
  105. // this.$nextTick(() => {
  106. // this.$refs.specPopup.open();
  107. // });
  108. this.$refs.specPopup.open();
  109. this.$refs.specPopup.setData(e.spuId);
  110. this.$refs.specPopup.setType(0)
  111. },
  112. handleSelectedChanged(selectedItems) {
  113. console.log('选中的数据:', selectedItems)
  114. this.carList = selectedItems
  115. this.carListMeg()
  116. this.totalPrice()
  117. },
  118. //计算selected为true的
  119. totalPrice() {
  120. let total = 0;
  121. for (let i = 0; i < this.carList.length; i++) {
  122. // 检查商品是否有 selected 属性
  123. // if (this.carList[i].hasOwnProperty('selected')) {
  124. // // 如果 selected 属性存在,只有当它为 true 时才计算
  125. // if (this.carList[i].selected) {
  126. // let priceInCents = Math.round(this.carList[i].price * 100);
  127. // let quant = this.carList[i].quantity;
  128. // total += priceInCents * quant;
  129. // }
  130. // } else {
  131. // 如果 selected 属性不存在,直接计算所有商品
  132. let priceInCents = Math.round(this.carList[i].price * 100);
  133. let quant = this.carList[i].quantity;
  134. total += priceInCents * quant;
  135. // }
  136. }
  137. // 将总价格转换回浮点数(以元为单位)
  138. this.total = (total / 100).toFixed(2);
  139. console.log('total', this.total);
  140. },
  141. showCart() {
  142. this.$nextTick(() => {
  143. this.$refs.cartPopup.setShow(true)
  144. })
  145. },
  146. btnIc() {
  147. uni.navigateTo({
  148. url: `/pages/diningList/diningList`
  149. })
  150. },
  151. toDetial(e) {
  152. console.log('eeeeee====================', e)
  153. const data = {
  154. spuId: e.spuId,
  155. tobyC: this.buyCount
  156. }
  157. uni.navigateTo({
  158. url: `/pages/goodDetail/goodDetail?data=${encodeURIComponent(JSON.stringify(data))}`
  159. })
  160. },
  161. toBuy() {
  162. console.log('e========carList', this.carList)
  163. uni.navigateTo({
  164. url: `/pages/order/submitOrder/submitOrder`
  165. })
  166. },
  167. onOrder() {
  168. uni.navigateTo({
  169. url: `/pages/order/myOrder/myOrder`
  170. })
  171. },
  172. onMyInfo() {
  173. const info = {
  174. customerPhone: this.cList.customerPhone
  175. }
  176. console.log('======================', info)
  177. uni.setStorageSync("info", info)
  178. uni.navigateTo({
  179. url: `/pages/user/user`
  180. })
  181. },
  182. // 获取餐车列表
  183. async fatchDate() {
  184. const result = await this.$request('post', '/sale/diningCarProduct/queryDiningCarProduct?diningCarId='+this.cList.id)
  185. if (result && result.rows && result.rows.length > 0) {
  186. const queIds = new Set(result.rows.map(item => item.spuId));
  187. const spuIds = Array.from(queIds).join(',');
  188. const res = await this.$request('get', `/item/spu/queryByIds?spuIds=${spuIds}`)
  189. const data = res.data
  190. this.goods = data.filter(item => item.status !== 1)
  191. }else{
  192. this.goods = []
  193. }
  194. },
  195. cartChange(data){
  196. this.buyCount = data.length;
  197. this.carList = data;
  198. this.totalPrice()
  199. },
  200. async carListMeg() {
  201. // const res = await this.$request('get', `/front/shoppingCart/list`, {
  202. // storeId: this.cList.id
  203. // })
  204. // if (res) {
  205. // const carList = res.data
  206. // this.buyCount = carList.length
  207. // }
  208. let cartInfo = uni.getStorageSync('cartInfo');
  209. if(cartInfo){
  210. try{
  211. this.carList = JSON.parse(cartInfo)
  212. this.buyCount = this.carList.length;
  213. this.totalPrice()
  214. }catch(e){}
  215. }
  216. }
  217. }
  218. }
  219. </script>
  220. <style scoped lang="scss">
  221. .goods-category {
  222. width: calc(100% - 100rpx);
  223. border-radius: 14rpx;
  224. overflow: hidden;
  225. .category-box {
  226. height: 70rpx;
  227. width: 100%;
  228. display: flex;
  229. align-items: center;
  230. .category-item {
  231. font-size: 14px;
  232. flex-shrink: 0;
  233. height: 100%;
  234. line-height: 70rpx;
  235. }
  236. .on-category {
  237. color: #FFF;
  238. background-color: #000;
  239. }
  240. }
  241. .classify-icon {
  242. width: 100rpx;
  243. display: flex;
  244. align-items: center;
  245. justify-content: flex-end;
  246. }
  247. }
  248. .goods-item {
  249. width: 48%;
  250. overflow: hidden;
  251. box-sizing: border-box;
  252. border: solid 4px #FFF;
  253. border-radius: 5px;
  254. box-shadow: 0px 3px 10px 0px rgba(213, 221, 232, 0.5);
  255. .img {
  256. width: 100%;
  257. height: 180rpx;
  258. overflow: hidden;
  259. background: #EEE;
  260. }
  261. .title {
  262. width: 100%;
  263. overflow: hidden;
  264. white-space: nowrap;
  265. text-overflow: ellipsis;
  266. padding: 10rpx;
  267. }
  268. }
  269. .cart-bottom {
  270. width: 100%;
  271. position: fixed;
  272. left: 0;
  273. bottom: 0;
  274. height: 130rpx;
  275. box-sizing: border-box;
  276. background-color: #FFF;
  277. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  278. // z-index: 10800;
  279. .cart {
  280. width: calc(100% - 220rpx);
  281. border-radius: 5px;
  282. background-color: #FEEEE4;
  283. display: flex;
  284. align-items: center;
  285. height: 100%;
  286. .cart-total {
  287. padding-left: 40rpx;
  288. font-size: 16px;
  289. font-weight: 700;
  290. }
  291. }
  292. .balance {
  293. width: 200rpx;
  294. height: 100%;
  295. background-color: #FF0000;
  296. font-size: $uni-font-size-lg;
  297. border-radius: 5px;
  298. color: #FFF;
  299. }
  300. }
  301. .spec-box {
  302. position: relative;
  303. z-index: 99999;
  304. }
  305. .classify-popup {
  306. width: 400rpx;
  307. }
  308. .container {
  309. display: flex;
  310. flex-direction: column;
  311. /* 垂直排列子元素 */
  312. align-items: center;
  313. /* 垂直居中子元素 */
  314. justify-content: center;
  315. /* 水平居中子元素 */
  316. }
  317. .icon-container-l {
  318. margin-top: 10px;
  319. margin-left: 15px;
  320. }
  321. .icon-container-r {
  322. margin-left: 20px;
  323. }
  324. </style>