classify.vue 9.3 KB

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