classify.vue 8.4 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 @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. uni.$on('register_refresh', () => {
  97. this.fatchDate()
  98. this.carListMeg()
  99. this.total = 0
  100. })
  101. },
  102. methods: {
  103. // 加购
  104. goCart(e) {
  105. // console.log('================', e)
  106. this.cardMsg = e
  107. this.$nextTick(() => {
  108. this.$refs.specPopup.open();
  109. });
  110. },
  111. handleSelectedChanged(selectedItems) {
  112. //console.log('选中的数据:', selectedItems)
  113. this.carList = selectedItems
  114. this.carListMeg()
  115. this.totalPrice()
  116. },
  117. //计算selected为true的
  118. totalPrice() {
  119. let total = 0;
  120. for (let i = 0; i < this.carList.length; i++) {
  121. // 检查商品是否有 selected 属性
  122. if (this.carList[i].hasOwnProperty('selected')) {
  123. // 如果 selected 属性存在,只有当它为 true 时才计算
  124. if (this.carList[i].selected) {
  125. let priceInCents = Math.round(this.carList[i].price * 100);
  126. let quant = this.carList[i].quantity;
  127. total += priceInCents * quant;
  128. }
  129. } else {
  130. // 如果 selected 属性不存在,直接计算所有商品
  131. let priceInCents = Math.round(this.carList[i].price * 100);
  132. let quant = this.carList[i].quantity;
  133. total += priceInCents * quant;
  134. }
  135. }
  136. // 将总价格转换回浮点数(以元为单位)
  137. this.total = (total / 100).toFixed(2);
  138. },
  139. showCart() {
  140. this.$nextTick(() => {
  141. this.$refs.cartPopup.setShow(true)
  142. })
  143. },
  144. btnIc() {
  145. uni.navigateTo({
  146. url: `/pages/diningList/diningList`
  147. })
  148. },
  149. toDetial(e) {
  150. // console.log('eeeeee====================', e)
  151. const data = {
  152. spuId: e.spuId,
  153. tobyC: this.buyCount
  154. }
  155. uni.navigateTo({
  156. url: `/pages/goodDetail/goodDetail?data=${encodeURIComponent(JSON.stringify(data))}`
  157. })
  158. },
  159. toBuy() {
  160. // console.log('e========carList', this.carList)
  161. const carlist = {
  162. carlist: this.carList,
  163. total: this.total
  164. }
  165. if (carlist.carlist.length <= 0) {
  166. // this.$refs.uNotify.show({'请选择'})
  167. uni.showToast({
  168. title: '请选择',
  169. icon: 'error',
  170. duration: 2000
  171. });
  172. } else {
  173. uni.navigateTo({
  174. url: `/pages/order/submitOrder/submitOrder?data=${encodeURIComponent(JSON.stringify(carlist))}`
  175. })
  176. this.$nextTick(() => {
  177. this.$refs.cartPopup.setShow(false)
  178. })
  179. }
  180. },
  181. onOrder() {
  182. uni.navigateTo({
  183. url: `/pages/order/myOrder/myOrder`
  184. })
  185. },
  186. onMyInfo() {
  187. const info = {
  188. customerPhone: this.cList.customerPhone
  189. }
  190. uni.setStorageSync("info", info)
  191. uni.navigateTo({
  192. url: `/pages/user/user`
  193. })
  194. },
  195. // 获取餐车列表
  196. async fatchDate() {
  197. var queryParmas = {
  198. id: this.cList.id
  199. }
  200. // console.log('idididididid', queryParmas)
  201. const result = await this.$request('post', '/sale/diningCarProduct/queryDiningCarProduct', queryParmas,
  202. true)
  203. if (result) {
  204. const queIds = new Set(result.rows.map(item => item.spuId));
  205. const spuIds = Array.from(queIds).join(',');
  206. const res = await this.$request('get', `/item/spu/queryByIds?spuIds=${spuIds}`)
  207. const data = res.data
  208. this.goods = data.filter(item => item.status !== 1)
  209. }
  210. },
  211. async carListMeg() {
  212. const res = await this.$request('get', `/front/shoppingCart/list`, {
  213. storeId: this.cList.id
  214. })
  215. if (res) {
  216. const carList = res.data
  217. this.buyCount = carList.length
  218. }
  219. }
  220. }
  221. }
  222. </script>
  223. <style scoped lang="scss">
  224. .goods-category {
  225. width: calc(100% - 100rpx);
  226. border-radius: 14rpx;
  227. overflow: hidden;
  228. .category-box {
  229. height: 70rpx;
  230. width: 100%;
  231. display: flex;
  232. align-items: center;
  233. .category-item {
  234. font-size: 14px;
  235. flex-shrink: 0;
  236. height: 100%;
  237. line-height: 70rpx;
  238. }
  239. .on-category {
  240. color: #FFF;
  241. background-color: #000;
  242. }
  243. }
  244. .classify-icon {
  245. width: 100rpx;
  246. display: flex;
  247. align-items: center;
  248. justify-content: flex-end;
  249. }
  250. }
  251. .goods-item {
  252. width: 48%;
  253. overflow: hidden;
  254. box-sizing: border-box;
  255. border: solid 4px #FFF;
  256. border-radius: 5px;
  257. box-shadow: 0px 3px 10px 0px rgba(213, 221, 232, 0.5);
  258. .img {
  259. width: 100%;
  260. height: 180rpx;
  261. overflow: hidden;
  262. background: #EEE;
  263. }
  264. .title {
  265. width: 100%;
  266. overflow: hidden;
  267. white-space: nowrap;
  268. text-overflow: ellipsis;
  269. padding: 10rpx;
  270. }
  271. }
  272. .cart-bottom {
  273. width: 100%;
  274. position: fixed;
  275. left: 0;
  276. bottom: 0;
  277. height: 130rpx;
  278. box-sizing: border-box;
  279. background-color: #FFF;
  280. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  281. z-index: 10800;
  282. .cart {
  283. width: calc(100% - 220rpx);
  284. border-radius: 5px;
  285. background-color: #FEEEE4;
  286. display: flex;
  287. align-items: center;
  288. height: 100%;
  289. .cart-total {
  290. padding-left: 40rpx;
  291. font-size: 16px;
  292. font-weight: 700;
  293. }
  294. }
  295. .balance {
  296. width: 200rpx;
  297. height: 100%;
  298. background-color: #FF0000;
  299. font-size: $uni-font-size-lg;
  300. border-radius: 5px;
  301. color: #FFF;
  302. }
  303. }
  304. .spec-box {
  305. position: relative;
  306. z-index: 99999;
  307. }
  308. .classify-popup {
  309. width: 400rpx;
  310. }
  311. .container {
  312. display: flex;
  313. flex-direction: column;
  314. /* 垂直排列子元素 */
  315. align-items: center;
  316. /* 垂直居中子元素 */
  317. justify-content: center;
  318. /* 水平居中子元素 */
  319. }
  320. .icon-container-l {
  321. margin-top: 10px;
  322. margin-left: 15px;
  323. }
  324. .icon-container-r {
  325. margin-left: 20px;
  326. }
  327. </style>