search-record.vue 17 KB

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