classify.vue 9.3 KB

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