classify.vue 8.1 KB

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