favorites.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <Navbar fixed border>
  5. <template #center>
  6. <view class="nav_search">
  7. <Search
  8. v-model="searchValue"
  9. @confirm="searchConfirm"
  10. :placeholder="t('商品的链接或名称')"
  11. >
  12. <template #prefix>
  13. <i class="icon-font icon-search"></i>
  14. </template>
  15. </Search>
  16. </view>
  17. </template>
  18. <template #right>
  19. <navMenu :options="{ icon: 'icon-home', text: '主页' }" />
  20. </template>
  21. </Navbar>
  22. <view class="content">
  23. <view id="tabs" :style="{ top: tabTop + 'px' }">
  24. <!-- <view class="cont_tab">
  25. <Tab :active="tabActive" :tabList="tabList" @confirm="tabConfirm" keyName="text" />
  26. </view> -->
  27. <y-select
  28. v-model:current="cateId"
  29. :label="selectLabel"
  30. :options="selectList"
  31. key-name="text"
  32. @select="selectItem"
  33. ref="selectRef"
  34. >
  35. <template #optionItem="{ item }">
  36. <view class="select_item">
  37. <image
  38. :src="`../../static/shop/icon_${item.channel}.png`"
  39. class="img"
  40. v-if="typeof item.channel == 'number'"
  41. ></image>
  42. <view class="_item_text">
  43. <trans :_t="item.text" />
  44. </view>
  45. </view>
  46. </template>
  47. </y-select>
  48. </view>
  49. <view class="cont" :style="{ 'padding-top': tabHeight + 'px' }">
  50. <List
  51. url="/shop/collect/list"
  52. pagesize="10"
  53. :topHeight="tabHeight"
  54. :class="tabActive == 0 ? 'list0' : 'list1'"
  55. :defaultParams="{ keywords: searchValue, ...params }"
  56. ref="listRef"
  57. >
  58. <template #item="{ item }">
  59. <template v-if="tabActive == 0">
  60. <good_list :item="item" @delete="deleteItem" />
  61. </template>
  62. <template v-else>
  63. <shop_list :item="item" @delete="deleteItem" />
  64. </template>
  65. </template>
  66. </List>
  67. </view>
  68. </view>
  69. </view>
  70. </Theme>
  71. </template>
  72. <script setup>
  73. import Navbar from "@/components/navbar";
  74. import navMenu from "@/components/nav_menu";
  75. import Search from "@/components/input";
  76. import Tab from "@/components/tabs";
  77. import List from "@/components/list";
  78. import { ref, onMounted, nextTick, computed } from "vue";
  79. import { t } from "@/locale";
  80. import ySelect from "@/components/select";
  81. import good_list from "./components/good_list";
  82. import shop_list from "./components/shop_list";
  83. import { query, systemInfo } from "@/utils";
  84. import { onReachBottom, onLoad } from "@dcloudio/uni-app";
  85. const searchValue = ref("");
  86. const tabActive = ref(0);
  87. const listRef = ref(null);
  88. const tabList = [
  89. { text: "产品", type: "good" },
  90. { text: "店铺", type: "shop" },
  91. ];
  92. const cateId = ref(0);
  93. const tabTop = ref(44);
  94. const selectRef = ref(null);
  95. const tabHeight = ref(0);
  96. const change = ref(null);
  97. const selectList = [
  98. {
  99. text: "默认",
  100. channel: "",
  101. },
  102. {
  103. text: "1688",
  104. channel: 0,
  105. },
  106. {
  107. text: "淘宝",
  108. channel: 1,
  109. },
  110. {
  111. text: "JD",
  112. channel: 3,
  113. },
  114. ];
  115. const selectLabel = computed(() => selectList[cateId.value].text);
  116. const params = computed(() => {
  117. return {
  118. type: tabList[tabActive.value].type,
  119. channel: selectList[cateId.value].channel,
  120. change: change.value,
  121. };
  122. });
  123. const searchConfirm = () => {
  124. nextTick(() => {
  125. listRef.value && listRef.value.handleRefresh();
  126. });
  127. };
  128. const selectItem = () => {
  129. nextTick(() => {
  130. listRef.value && listRef.value.handleRefresh();
  131. });
  132. };
  133. const deleteItem = (res) => {
  134. nextTick(() => {
  135. listRef.value && listRef.value.handleRefresh(true);
  136. });
  137. };
  138. const tabConfirm = (item, index) => {
  139. selectRef.value && selectRef.value.close();
  140. if (!item) return;
  141. if (tabActive.value == index) return;
  142. tabActive.value = index;
  143. nextTick(() => {
  144. listRef.value && listRef.value.handleRefresh();
  145. });
  146. };
  147. onMounted(async () => {
  148. const res = await query("#tabs", this);
  149. tabTop.value = res.top + systemInfo().statusBarHeight;
  150. tabHeight.value = res.height;
  151. });
  152. onLoad((options) => {
  153. change.value = options.change;
  154. nextTick(() => {
  155. listRef.value && listRef.value.getData();
  156. });
  157. });
  158. onReachBottom(() => {
  159. nextTick(() => {
  160. listRef.value && listRef.value.scrolltolower();
  161. });
  162. });
  163. </script>
  164. <style lang="less" scoped>
  165. @import url("@/style.less");
  166. .wrap {
  167. height: 100vh;
  168. background-color: var(--bg);
  169. .flex();
  170. flex-direction: column;
  171. /deep/ .u-navbar__content {
  172. justify-content: unset;
  173. .u-navbar__content__left,
  174. .u-navbar__content__right {
  175. position: unset;
  176. }
  177. }
  178. .nav_search {
  179. flex: 1;
  180. .icon-search {
  181. color: #a8abb2;
  182. .size(16px);
  183. }
  184. }
  185. .content {
  186. // flex-grow: 1;
  187. // height: calc(100vh - 44px);
  188. flex-direction: column;
  189. .flex();
  190. #tabs {
  191. position: fixed;
  192. top: 44px;
  193. left: 0;
  194. right: 0;
  195. z-index: 1;
  196. }
  197. .cont_tab {
  198. background-color: var(--light);
  199. padding: 0 24rpx;
  200. }
  201. /deep/ .u-select {
  202. padding: 0 32rpx;
  203. background-color: var(--bg);
  204. .select_item {
  205. color: #606266;
  206. cursor: pointer;
  207. .ver();
  208. font-size: 28rpx;
  209. line-height: 44rpx;
  210. padding: 10rpx 32rpx;
  211. white-space: nowrap;
  212. .img {
  213. width: calc(32rpx);
  214. height: calc(32rpx);
  215. display: block;
  216. }
  217. ._item_text {
  218. .ver();
  219. font-size: 28rpx;
  220. font-weight: 500;
  221. line-height: 60rpx;
  222. color: #62708c;
  223. margin: 0 8rpx;
  224. font-weight: 700;
  225. }
  226. }
  227. }
  228. .cont {
  229. flex-grow: 1;
  230. overflow: hidden scroll;
  231. padding: 0 32rpx;
  232. background-color: var(--bg);
  233. }
  234. .cont_footer {
  235. line-height: 120rpx;
  236. background-color: var(--light);
  237. box-shadow: 0 -4px 6px #0000000d;
  238. padding: 0 24rpx;
  239. .flex_position(space-between);
  240. .total_btn {
  241. .size(24rpx);
  242. height: 38px;
  243. margin-left: 16rpx;
  244. min-width: 180rpx;
  245. background-color: var(--black);
  246. color: var(--light);
  247. border-radius: 16rpx;
  248. padding: 16rpx 30rpx;
  249. text-align: center;
  250. .flex_center();
  251. margin-left: 24rpx;
  252. }
  253. }
  254. }
  255. .list0 {
  256. /deep/ .uni-scroll-view-content {
  257. margin-top: 16rpx;
  258. > uni-view {
  259. .flex();
  260. flex-wrap: wrap;
  261. gap: 8rpx 16rpx;
  262. .u-list-item {
  263. width: calc((100% - 16rpx) / 2);
  264. }
  265. }
  266. }
  267. }
  268. }
  269. </style>