search-record.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <template>
  2. <view class="flex-common-css iPhone-bottom box-border-box bgc-f">
  3. <image class="order-bg" src="@/static/img/order-food/ss-bg.png" mode=""></image>
  4. <newNav textName="搜索商品" class="mb-20" titleColor='#333' leftIconColor='#333'></newNav>
  5. <view class="plr-24 box-border-box">
  6. <view class="s-input box-border-box bgc-f align-items-center flex-justify-space b-rad-200 z-3">
  7. <view class="align-items-center flex-1 mr-16">
  8. <image class="wh36 mr-16 flex-shrink0" src="/static/img/order-food/ss-icon.png" mode=""></image>
  9. <input class="input-box fs-32" placeholder-class="fc-9" v-model="search" type="text"
  10. placeholder="请搜索商品" @input="clearInput">
  11. </view>
  12. <view class="align-items-center">
  13. <image v-if="showClearIcon" @click="clearIcon" class="qk-icon mr-24"
  14. src="@/static/img/order-food/qk-icon.png" mode="">
  15. </image>
  16. <view class="input-buttom fs-28 fc-f fw-500 b-rad-200 text-align-center" @click="toList()">搜索</view>
  17. </view>
  18. </view>
  19. </view>
  20. <EnBlank message='暂无商品' :customSrc='true' v-if="goodsList.length <=0 && !historyType">
  21. <template v-slot:blankImg>
  22. <image class="<strong>black-custom-img</strong>" src="@/static/img/common/no-order.png" mode="">
  23. </image>
  24. </template>
  25. </EnBlank>
  26. <view class="scroll-view-css bgc-f seacrh-info box-border-box p-32" v-if="goodsList.length<=0 && historyType">
  27. <view class="flex-justify-space mb-32">
  28. <view class="fs-32 fw-600 fc-3">搜索历史</view>
  29. <view class="align-items-center" v-if="list.length > 0">
  30. <view @click="isOpen=!isOpen" class="">{{!isOpen?'收起':'展开'}}</view>
  31. <view @click="isOpen=!isOpen" :class="!isOpen?'down':'up'">
  32. <uni-icons type="right" size="14" color="#999"></uni-icons>
  33. </view>
  34. <view class="view-x"></view>
  35. <uni-icons @click="delList()" type="trash" size="18" color="#999"></uni-icons>
  36. </view>
  37. </view>
  38. <view id='' :class="isOpen?'hide-h':''" class="flex-wrap-wrap mb-50 search-history" v-if="list.length > 0">
  39. <view class="fs-28 list-item text-overflow-ellipsis-one" @click="toList(item)" v-for="(item,i) in list"
  40. :key="i">{{item}}</view>
  41. </view>
  42. </view>
  43. <scroll-view scroll-y="true" class="scroll-view-css bgc-F5F4F9 p-32 box-border-box" v-else
  44. @scrolltolower="scrolltolower">
  45. <!-- <view class="scroll-view-css bgc-F5F4F9 p-32 box-border-box" v-else> -->
  46. <view class="menu-list flex-justify-space bgc-f p-24 box-border-box b-rad-20 mb-16"
  47. v-for="(info,k) in goodsList" :key="k" :id="'goods_id'+ info.goods_id">
  48. <image class="flex-shrink0 goods_img mr-20" :src="info.goods_image" mode="scaleToFill"></image>
  49. <view class="menu-list-right flex-direction flex-justify-space">
  50. <view class="mb-8">
  51. <view class="mb-4 goods-name text-overflow-ellipsis fs-32 fw-600">
  52. {{info.goods_name}}
  53. </view>
  54. <!-- <view class="text-overflow-ellipsis-one fw-400 fc-9 fs-24 mb-2 goods-name"
  55. v-if="info.spec_type == 1">
  56. {{info.goods_desc?info.goods_desc:''}}
  57. </view> -->
  58. </view>
  59. <view class="flex-justify-space align-items-flex-end">
  60. <view class="">
  61. <span class="fs-24 fw-400 fc-3">¥</span>
  62. <span class="fs-36 fw-b fc-3">{{info.seckill_money>0?info.seckill_money:info.price}}</span>
  63. <span class="fs-24 fc-9">/份起</span>
  64. </view>
  65. <view class="display-flex align-items-center" v-if="info.spec_type == 1">
  66. <image v-show="info.num > 0" class="wh-44" @click="addred(1,info)"
  67. src="@/static/img/order-food/reduce-img.png" mode=""></image>
  68. <view v-show="info.num > 0" class="right-only-right-2 text-align-center fs-28 fw-400">
  69. {{info.num}}
  70. </view>
  71. <image class="wh-44" src="@/static/img/order-food/add-img.png" @click="addred(2,info)"
  72. mode=""></image>
  73. </view>
  74. <view v-else class="right-only-right text-align-center b-rad-200" @click="addred(3,info)">
  75. <view class="fw-500 fs-28 fc-f">
  76. 选规格
  77. </view>
  78. <view class="selectedNum" v-if="info.num>0">
  79. {{info.num}}
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. <!-- </view> -->
  86. </scroll-view>
  87. <view v-if="goodsList.length>0" class="shop-buttom-money p-24 box-border-box bgc-F5F4F9" @click="openBuyCrad()">
  88. <view
  89. class="shop-buttom-money-1 bgc-f flex-justify-space align-items-center pl-24 box-border-box pr-8 b-rad-200">
  90. <view class="align-items-center">
  91. <image class="gwc-img mr-36" src="@/static/img/order-food/gwc-img.png" mode="scaleToFill"></image>
  92. <view class="shop-buttom-num bgc-FE6B2C fs-24 fc-f text-align-center">{{cartData.total_num || 0}}
  93. </view>
  94. <view class="align-items-baseline">
  95. <view class="fw-600 fs-28 fc-3 mr-4">¥</view>
  96. <view class="fw-600 fs-48 fc-3">{{cartData.total_goods_money || 0}}</view>
  97. </view>
  98. </view>
  99. <view class="shop-buttom-money-2 text-align-center fc-f fs-32 fw-600 b-rad-200"
  100. :class="cartData.total_num>0?'':'opacity-4'" @click.stop="toConfirmOrder()">去结算
  101. </view>
  102. </view>
  103. </view>
  104. <uni-popup ref="popupBuy" type="bottom" background-color="transparent" borderRadius='20px 20rpx 0 0'>
  105. <view class="buy-card flex-index-css">
  106. <view class="buy-card-top box-border-box plr-32 flex-justify-space align-items-center b-rad-20-20-0-0">
  107. <view class="">
  108. <span class="fs-32 fc-3 mr-12">已选商品</span>
  109. </view>
  110. <view class="fs-28 fw-400 fc-9 align-items-center" @click.stop="setShopIngDel">
  111. <view class="">
  112. <uni-icons type="trash" size="18" color="#999"></uni-icons>
  113. </view>
  114. <view class="fs-28 fw-400 fc-9">清空</view>
  115. </view>
  116. </view>
  117. <view class="scroll-view-css bgc-ECECEC box-border-box car-scroll-box">
  118. <view class="buy-card-item bgc-f b-rad-20 display-flex p-20 box-border-box"
  119. v-for="(goods,i) in cartData.goods_list" :key="i">
  120. <image class="goods_img" :src="goods.goods_image" mode="scaleToFill"></image>
  121. <view class="flex-1 flex-direction flex-justify-space">
  122. <view class="">
  123. <view class="w-514 text-overflow-ellipsis-one fs-34 fw-600 mb-8">
  124. {{goods.goods_name}}
  125. </view>
  126. <view class="fc-6" v-show="goods.goods_attr">
  127. {{goods.goods_attr}}
  128. </view>
  129. </view>
  130. <view class="flex-justify-space">
  131. <view class="">
  132. <span class="fs-24 fc-FB3D03 fw-400">¥</span>
  133. <span class="fs-40 fc-FB3D03 fw-b">{{goods.price}}</span>
  134. </view>
  135. <view class="display-flex align-items-center">
  136. <image class="wh-44" @click.stop="setShoppingSave(goods,2)"
  137. src="@/static/img/order-food/reduce-img.png" mode="">
  138. </image>
  139. <view class="right-only-right-2 text-align-center fs-28 fw-400">
  140. {{goods.goods_number}}
  141. </view>
  142. <image class="wh-44" src="/static/img/order-food/add-img.png"
  143. @click.stop="setShoppingSave(goods,1)" mode=""></image>
  144. </view>
  145. </view>
  146. </view>
  147. </view>
  148. <en-blank navBackgroundColor='#ECECEC' v-if="cartData.goods_list.length<=0"
  149. message="快去选购商品吧!~"></en-blank>
  150. </view>
  151. <view class="pop-shop-buttom-money box-border-box" @click="openBuyCrad()">
  152. <view
  153. class="shop-buttom-money-1 bgc-f flex-justify-space align-items-center pl-24 box-border-box pr-8 b-rad-200">
  154. <view class="align-items-center">
  155. <image class="gwc-img mr-36" src="@/static/img/order-food/gwc-img.png" mode="scaleToFill">
  156. </image>
  157. <view class="shop-buttom-num bgc-FE6B2C fs-24 fc-f text-align-center">{{cartData.total_num}}
  158. </view>
  159. <view class="align-items-baseline">
  160. <view class="fw-600 fs-28 fc-3 mr-4">¥</view>
  161. <view class="fw-600 fs-48 fc-3">{{cartData.total_goods_money}}</view>
  162. </view>
  163. </view>
  164. <view class="shop-buttom-money-2 text-align-center fc-f fs-32 fw-600 b-rad-200"
  165. :class="cartData.total_num>0?'':'opacity-4'" @click.stop="toConfirmOrder()">去结算
  166. </view>
  167. </view>
  168. </view>
  169. </view>
  170. </uni-popup>
  171. </view>
  172. </template>
  173. <script>
  174. import cartStore from '@/utils/cartStore.js';
  175. import tools from "@/service/tools";
  176. import EnBlank from "@/components/en-utils/en-blank/en-blank";
  177. import {
  178. getSearch,
  179. getSearchList,
  180. delSearch
  181. } from '@/api/goods.js';
  182. export default {
  183. components: {
  184. EnBlank
  185. },
  186. data() {
  187. return {
  188. search: '',
  189. isOpen: false,
  190. showClearIcon: false,
  191. list: [],
  192. goodsList: [],
  193. historyType: true,
  194. total: '',
  195. page: 1,
  196. cartData: { // 添加购物车数据
  197. total_price: 0,
  198. total_num: 0,
  199. pack_price: 0,
  200. total_goods_money: 0,
  201. goods_list: []
  202. }
  203. }
  204. },
  205. onLoad() {
  206. cartStore.setShopId();
  207. this.getList()
  208. },
  209. onShow() {
  210. this.getCartData();
  211. },
  212. mounted() {},
  213. methods: {
  214. toConfirmOrder() {
  215. uni.navigateTo({
  216. url: '/pages-takeout/goods-order'
  217. })
  218. },
  219. scrolltolower() {
  220. if (this.goodsList.length < this.total) {
  221. this.page += 1;
  222. this.getSearch(this.search);
  223. }
  224. },
  225. openBuyCrad() {
  226. this.$refs.popupBuy.open()
  227. },
  228. getCartData() {
  229. // 获取购物车数据
  230. const shopCart = cartStore.getShopCart(this.shop_id);
  231. if (shopCart) {
  232. this.cartData = {
  233. ...this.cartData,
  234. total_price: shopCart.total_price || 0,
  235. total_num: shopCart.total_num || 0,
  236. goods_list: shopCart.goods_list || [],
  237. pack_price: shopCart.pack_price || 0,
  238. total_goods_money: shopCart.total_goods_money || 0
  239. };
  240. // 更新商品列表中的数量显示
  241. this.updateGoodsNumFromCart();
  242. }
  243. },
  244. // 更新商品列表中的数量显示
  245. updateGoodsNumFromCart() {
  246. if (!this.goodsList.length) return;
  247. const shopCart = cartStore.getShopCart(this.shop_id);
  248. if (!shopCart) return;
  249. // 创建商品数量映射
  250. const goodsQuantityMap = {};
  251. shopCart.goods_list.forEach(item => {
  252. if (!goodsQuantityMap[item.goods_id]) {
  253. goodsQuantityMap[item.goods_id] = 0;
  254. }
  255. goodsQuantityMap[item.goods_id] += item.goods_number;
  256. });
  257. // 更新商品列表数量
  258. this.goodsList.forEach(goods => {
  259. goods.num = goodsQuantityMap[goods.goods_id] || 0;
  260. });
  261. },
  262. toList(name) {
  263. let search = '';
  264. if (name) {
  265. search = name;
  266. this.search = name
  267. } else {
  268. search = this.search;
  269. }
  270. if (search) {
  271. this.historyType = false
  272. this.page = 1
  273. this.goodsList = []
  274. this.getSearch(search)
  275. } else {
  276. tools.error('请输入搜索内容')
  277. }
  278. },
  279. getSearch(search) {
  280. // 搜索商品列表
  281. getSearch({
  282. search: search,
  283. page: this.page
  284. }).then((res) => {
  285. if (res.code * 1 === 1) {
  286. const newGoods = res.data.items || [];
  287. // 为每个商品添加购物车数量
  288. newGoods.forEach(goods => {
  289. goods.num = 0; // 初始化为0
  290. goods.pack_price = parseFloat(goods.pack_price || 0);
  291. });
  292. this.total = res.data.total
  293. this.goodsList = [...this.goodsList, ...res.data.items]
  294. // 更新购物车数量显示
  295. this.updateGoodsNumFromCart();
  296. }
  297. })
  298. },
  299. addred(type, item) {
  300. if (type === 1) {
  301. // 减
  302. if (item.num <= 0) return;
  303. item.num--;
  304. if (item.num <= 0) {
  305. // 从购物车移除
  306. cartStore.removeFromCart(item.goods_id, item.goods_spec || []);
  307. } else {
  308. // 更新数量
  309. cartStore.updateQuantity(item.goods_id, item.goods_spec || [], item.num);
  310. }
  311. } else if (type === 2) {
  312. // 加
  313. item.num++;
  314. // 判断是否已存在购物车
  315. const currentQty = cartStore.getGoodsQuantity(item.goods_id, item.goods_spec || []);
  316. if (currentQty <= 0) {
  317. // 新商品,添加到购物车
  318. cartStore.addToCart(item, item.goods_spec || [], 1);
  319. } else {
  320. // 已存在,更新数量
  321. cartStore.updateQuantity(item.goods_id, item.goods_spec || [], item.num);
  322. }
  323. } else if (type === 3) {
  324. // 选规格
  325. uni.navigateTo({
  326. url: `/pages-takeout/new-specs-info?goods_id=${item.goods_id}&category_id=${item.category_id}`
  327. })
  328. }
  329. // 更新购物车数据
  330. this.getCartData();
  331. },
  332. setShoppingSave(item, type) {
  333. if (type === 1) {
  334. // 加
  335. item.goods_number = item.goods_number + 1
  336. } else {
  337. // 减
  338. item.goods_number = item.goods_number - 1
  339. }
  340. if (item.goods_number <= 0) {
  341. // 数量为0,移除商品
  342. cartStore.removeFromCart(item.goods_id, item.goods_spec || []);
  343. } else {
  344. // 更新商品数量
  345. cartStore.updateQuantity(
  346. item.goods_id,
  347. item.goods_spec || [],
  348. item.goods_number
  349. );
  350. }
  351. // 更新页面数据
  352. this.getShopIngList();
  353. },
  354. getShopIngList() {
  355. // 获取购物车列表
  356. const shopCart = cartStore.getShopCart(this.shop_id);
  357. if (shopCart) {
  358. this.cartData = {
  359. ...this.cartData,
  360. total_price: shopCart.total_price,
  361. total_num: shopCart.total_num,
  362. goods_list: shopCart.goods_list
  363. };
  364. // 同步更新商品列表中的数量
  365. this.updateGoodsNumFromCart();
  366. }
  367. },
  368. clearIcon() {
  369. this.search = '';
  370. this.showClearIcon = false;
  371. },
  372. clearInput(event) {
  373. this.search = event.detail.value;
  374. if (event.detail.value.length > 0) {
  375. this.showClearIcon = true;
  376. } else {
  377. this.showClearIcon = false;
  378. }
  379. },
  380. getList() {
  381. // 获取搜索历史内容
  382. getSearchList().then((res) => {
  383. if (res.code === 1) {
  384. this.list = res.data.my_search;
  385. }
  386. })
  387. },
  388. delList() {
  389. delSearch().then((res) => {
  390. if (res.code === 1) {
  391. tools.success('删除成功');
  392. this.list = [];
  393. }
  394. })
  395. },
  396. },
  397. }
  398. </script>
  399. <style scoped lang="scss">
  400. .buy-card-item {
  401. width: 100%;
  402. margin-bottom: 32rpx;
  403. }
  404. .right-only-right-2 {
  405. min-width: 50rpx;
  406. }
  407. .pop-shop-buttom-money {
  408. width: 100%;
  409. // height: 140rpx;
  410. background: #ECECEC;
  411. padding-left: 24rpx;
  412. padding-right: 24rpx;
  413. padding-bottom: calc(env(safe-area-inset-bottom) + 12rpx);
  414. padding-top: 22rpx;
  415. position: fixed;
  416. left: 0;
  417. bottom: 0;
  418. z-index: 5;
  419. }
  420. .goods_img {
  421. width: 152rpx;
  422. height: 152rpx;
  423. border-radius: 12rpx;
  424. margin-right: 20rpx;
  425. }
  426. .car-scroll-box {
  427. padding: 12rpx 24rpx calc(env(safe-area-inset-bottom) + 48rpx);
  428. }
  429. .buy-card {
  430. height: 60vh;
  431. border-radius: 24rpx 24rpx 0rpx 0rpx;
  432. }
  433. .buy-card-top {
  434. width: 100%;
  435. height: 92rpx;
  436. background: #FCF5DB;
  437. border-radius: 24rpx 24rpx 0rpx 0rpx;
  438. }
  439. .shop-buttom-money-1 {
  440. width: 100%;
  441. height: 96rpx;
  442. position: relative;
  443. }
  444. .qk-icon {
  445. width: 32rpx;
  446. height: 32rpx;
  447. }
  448. .shop-buttom-money {
  449. width: 100%;
  450. // height: 140rpx;
  451. }
  452. .shop-buttom-money-1 {
  453. width: 100%;
  454. height: 96rpx;
  455. position: relative;
  456. }
  457. .shop-buttom-money-2 {
  458. width: 200rpx;
  459. height: 80rpx;
  460. line-height: 80rpx;
  461. background: linear-gradient(270deg, #FF3333 0%, #FE6122 100%);
  462. }
  463. .gwc-img {
  464. width: 88rpx;
  465. height: 88rpx;
  466. }
  467. .shop-buttom-num {
  468. width: 32rpx;
  469. height: 32rpx;
  470. line-height: 32rpx;
  471. border-radius: 50%;
  472. position: absolute;
  473. top: 0rpx;
  474. left: 85rpx;
  475. border: 1rpx solid #FFFFFF;
  476. }
  477. .z-3 {
  478. position: relative;
  479. z-index: 3;
  480. }
  481. .order-bg {
  482. width: 100%;
  483. height: 17vh;
  484. position: fixed;
  485. left: 0;
  486. top: 0;
  487. }
  488. .hide-h {
  489. height: 232rpx !important;
  490. overflow: hidden !important;
  491. }
  492. .down {
  493. transform: rotate(-90deg);
  494. transition: all 0.5s;
  495. }
  496. .up {
  497. transform: rotate(90deg);
  498. transition: all 0.5s;
  499. }
  500. .view-x {
  501. width: 2rpx;
  502. height: 20rpx;
  503. background-color: #eee;
  504. margin: 0 24rpx;
  505. }
  506. .find-item {
  507. width: 48%;
  508. text-align: left;
  509. }
  510. .list-item {
  511. max-height: 688rpx;
  512. min-width: 10rpx;
  513. height: 56rpx;
  514. line-height: 56rpx;
  515. background: #F7F8FC;
  516. border-radius: 200rpx;
  517. margin: 0 8rpx 32rpx 0;
  518. box-sizing: border-box;
  519. padding: 0 24rpx;
  520. }
  521. .seacrh-bg {
  522. position: absolute;
  523. top: 0;
  524. left: 0;
  525. width: 100%;
  526. height: 376rpx;
  527. filter: blur(80rpx);
  528. background-image: linear-gradient(to right, #C9F7FC, #F9F6E0, #F6F5F3);
  529. z-index: -1;
  530. }
  531. .wh36 {
  532. width: 36rpx;
  533. height: 36rpx;
  534. }
  535. .input-box {
  536. width: 100%;
  537. }
  538. .input-buttom {
  539. width: 120rpx;
  540. height: 60rpx;
  541. background: linear-gradient(270deg, #FF3333 0%, #FE6122 100%);
  542. line-height: 60rpx;
  543. }
  544. .s-input {
  545. width: 100%;
  546. height: 72rpx;
  547. padding: 6rpx 6rpx 6rpx 24rpx;
  548. }
  549. .seacrh-info {
  550. margin-top: 20rpx;
  551. border-radius: 24rpx 24rpx 0rpx 0rpx;
  552. }
  553. .seacrh-record-index {
  554. position: relative;
  555. }
  556. .wh-44 {
  557. width: 44rpx;
  558. height: 44rpx;
  559. }
  560. .menu-list {
  561. width: 100%;
  562. .goods_img {
  563. width: 168rpx;
  564. height: 168rpx;
  565. border-radius: 12rpx;
  566. }
  567. }
  568. .menu-list-right {
  569. flex: 1;
  570. }
  571. .right-only-right-red {
  572. width: 44rpx;
  573. height: 44rpx;
  574. line-height: 40rpx;
  575. border-radius: 12rpx;
  576. border: 1rpx solid #41ABF5;
  577. color: #41ABF5;
  578. }
  579. .right-only-right-add {
  580. width: 44rpx;
  581. height: 44rpx;
  582. line-height: 40rpx;
  583. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  584. border-radius: 12rpx;
  585. }
  586. .right-only-right {
  587. width: 116rpx;
  588. height: 44rpx;
  589. background: linear-gradient(270deg, #FF3333 0%, #FE6122 100%);
  590. line-height: 44rpx;
  591. position: relative;
  592. }
  593. .selectedNum {
  594. position: absolute;
  595. right: -10rpx;
  596. top: -22rpx;
  597. font-size: 24rpx;
  598. color: #fff;
  599. width: 32rpx;
  600. height: 32rpx;
  601. line-height: 32rpx;
  602. background: #FE6B2C;
  603. border-radius: 50%;
  604. border: 1rpx solid #FFFFFF;
  605. }
  606. </style>