collect.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <div class="sld_collect_wrapper">
  3. <MemberTitle
  4. :memberTitle="collectIndex == 1 ? L['收藏的商品'] : L['店铺收藏']"
  5. style="padding-left: 20px"
  6. ></MemberTitle>
  7. <div class="wrapper_main myorder sld_collect">
  8. <div class="sld_follow_m">
  9. <!-- 选择横幅 -->
  10. <div class="sld_h3_wrap clearfix">
  11. <div class="sld_grade_nav fl">
  12. <a
  13. :class="1 === collectIndex ? 'on' : ''"
  14. @click="switchCollect(1)"
  15. >
  16. {{ L["收藏的商品"] }}</a
  17. >
  18. <a
  19. :class="2 === collectIndex ? 'on' : ''"
  20. @click="switchCollect(2)"
  21. >
  22. {{ L["店铺收藏"] }}
  23. </a>
  24. </div>
  25. <div
  26. class="sld_option fr"
  27. v-show="1 === collectIndex && collectGoodsData.list.length"
  28. >
  29. <div
  30. class="sld_option_list fl"
  31. v-show="optAct"
  32. @click="selectAll(true)"
  33. >
  34. <img :src="collectGoodsChoose" alt="" />
  35. <span ref="chooseWord">{{ L["全选"] }}</span>
  36. </div>
  37. <div
  38. class="sld_option_list fl"
  39. v-show="optAct"
  40. @click="selectAll(false)"
  41. >
  42. <span>{{ L["取消全选"] }}</span>
  43. </div>
  44. <div
  45. class="sld_option_list fl"
  46. v-show="optAct"
  47. @click="cancelCollect"
  48. >
  49. <img src="/member/delete.png" alt="" />
  50. <span>{{ L["取消收藏"] }}</span>
  51. </div>
  52. <button class="sld_option_btn fr" @click="optAct = !optAct">
  53. {{ L["管理"] }}
  54. </button>
  55. </div>
  56. </div>
  57. <div>
  58. <!-- 收藏的商品 -->
  59. <div class="fav_goods_list" v-show="1 === collectIndex">
  60. <ul class="clearfix">
  61. <li
  62. class="sld_follow_goods"
  63. v-for="(item, index) in collectGoodsData.list"
  64. :key="index"
  65. >
  66. <div class="cg_img">
  67. <nuxt-link
  68. :to="'/goods/detail/'+ calcProductName(item.goodsName) +'_'+ item.productId"
  69. target="_blank"
  70. >
  71. <coverImage :src="item.productImage" class="lazy" />
  72. </nuxt-link>
  73. </div>
  74. <p class="cg_price clearfix">
  75. <span class="fl"
  76. ><strong>{{item.goodsMoney}}</strong></span
  77. >
  78. </p>
  79. <p class="cg_name">
  80. <em v-if="isOwnStore">{{ L["自营"] }}</em>
  81. {{ item.goodsName }} {{ item.goodsBrief }}
  82. </p>
  83. <div class="cg_btns">
  84. <nuxt-link
  85. :to="'/store/'+ calcProductName(item.storeName) +'_'+ item.storeId"
  86. class="govendor"
  87. target="_blank"
  88. >{{ L["进入店铺"] }}</nuxt-link
  89. >
  90. </div>
  91. <div class="check_wrap" v-show="optAct">
  92. <input
  93. type="checkbox"
  94. name="option"
  95. :id="`GoodsCheck${index}`"
  96. class="item_check"
  97. :value="item.productId"
  98. v-model="chosedItem"
  99. />
  100. <label :for="`GoodsCheck${index}`" class="border">
  101. <div class="checklogo"></div>
  102. </label>
  103. </div>
  104. </li>
  105. <SldCommonEmpty
  106. v-show="!collectGoodsData.list.length"
  107. totalWidth="1003"
  108. :tip="L['暂无收藏商品']"
  109. />
  110. </ul>
  111. <!-- 分页 -->
  112. <div class="flex_row_end_center sld_pagination">
  113. <el-pagination
  114. @current-change="handleCurrentChange"
  115. v-model:currentPage="pageData.current"
  116. :page-size="pageData.pageSize"
  117. layout="prev, pager, next, jumper"
  118. :total="pageData.total"
  119. :hide-on-single-page="true"
  120. >
  121. </el-pagination>
  122. </div>
  123. </div>
  124. <!-- 收藏的店铺 -->
  125. <div class="fav_store_list" v-show="2 === collectIndex">
  126. <!-- 普通关注的店铺 -->
  127. <!-- <div v-else>-->
  128. <div v-for="(item1, index1) in commonFollowStore" :key="index1">
  129. <CollectStoreItem
  130. :item="item1"
  131. :ItemIndex="index1"
  132. @collectStoreUpdate="collectStoreUpdate"
  133. collectStoreIndex="2"
  134. >
  135. </CollectStoreItem>
  136. </div>
  137. <SldCommonEmpty
  138. v-show="!collectLength.commonLength"
  139. totalWidth="1003"
  140. :tip="L['暂无收藏店铺']"
  141. />
  142. <!-- 分页 -->
  143. <div class="flex_row_end_center sld_pagination">
  144. <el-pagination
  145. @current-change="handleStoreCurrentChange"
  146. v-model:currentPage="pageDataStore.current"
  147. :page-size="pageDataStore.pageSize"
  148. layout="prev, pager, next, jumper"
  149. :total="pageDataStore.total"
  150. :hide-on-single-page="true"
  151. >
  152. </el-pagination>
  153. </div>
  154. <!-- </div>-->
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. </template>
  161. <script setup>
  162. import { ElPagination,ElMessage,ElMessageBox } from "element-plus";
  163. import {
  164. reactive,
  165. getCurrentInstance,
  166. onMounted,
  167. ref,
  168. watchEffect,
  169. watch,
  170. } from "vue";
  171. // import { lang_zn } from "@/assets/language/zh";
  172. import { getCurLanguage } from '@/composables/common.js';
  173. // const L = lang_zn;
  174. const L = getCurLanguage();
  175. definePageMeta({
  176. layout: "member",
  177. middleware: ["auth"],
  178. });
  179. const route = useRoute();
  180. const collectIndex = ref(1); //收藏的商品和店铺的切换标志
  181. const collectStoreIndex = ref(1); //切换收藏店铺 普通关注和特别关注 的标志值
  182. const collectGoodsData = reactive({
  183. list: [],
  184. }); //收藏的商品
  185. const specialFollowStore = ref([]); //特殊收藏的店铺
  186. const commonFollowStore = ref([]); //普通收藏的店铺
  187. const { proxy } = getCurrentInstance();
  188. const optAct = ref(false); //显示操作
  189. const chosedItem = ref([]); //取消收藏选择的商品集合
  190. const collectGoodsChoose = ref("/member/chooseAll.png");
  191. const cartListData = reactive({ data: [] }); //获取vux的store中的购物车数据
  192. const collectLength = reactive({
  193. commonLength: 0,
  194. specialLength: 0,
  195. });
  196. const pageData = reactive({
  197. current: 1,
  198. pageSize: 10,
  199. total: null,
  200. });
  201. const pageDataStore = reactive({
  202. current: 1,
  203. pageSize: 5,
  204. total: null,
  205. });
  206. const params = reactive({
  207. current: pageData.current,
  208. });
  209. const paramsStore = reactive({
  210. current: pageDataStore.current,
  211. pageSize: pageDataStore.pageSize,
  212. });
  213. //获取数据,初始化
  214. const getInitData = (params) => {
  215. get("v3/member/front/followProduct/list", params).then((res) => {
  216. //获取收藏商品信息
  217. if (res.state == 200) {
  218. collectGoodsData.list = res.data.list;
  219. pageData.current = res.data.pagination.current;
  220. pageData.pageSize = res.data.pagination.pageSize;
  221. pageData.total = res.data.pagination.total;
  222. }
  223. });
  224. };
  225. const getStoreData = (paramsStore) => {
  226. get("v3/member/front/followStore/list",paramsStore).then((res) => {
  227. //获取收藏店铺信息
  228. if (res.state == 200) {
  229. // specialFollowStore.value = res.data.storeList.filter(
  230. // (item) => item.isTop == 1
  231. // );
  232. commonFollowStore.value = res.data.storeList.filter(
  233. // (item) => item.isTop == 0
  234. (item) => item
  235. );
  236. collectLength.specialLength = specialFollowStore.value.length;
  237. collectLength.commonLength = commonFollowStore.value.length;
  238. pageDataStore.current = res.data.pagination.current;
  239. pageDataStore.pageSize = res.data.pagination.pageSize;
  240. pageDataStore.total = res.data.pagination.total;
  241. }
  242. });
  243. };
  244. //切换收藏商品和店铺
  245. const switchCollect = (index) => {
  246. collectIndex.value = index;
  247. };
  248. const handlePrevClickChange = (e) => {
  249. proxy.$refs.chooseWord.style.color = "";
  250. params.current = e;
  251. getInitData(params);
  252. };
  253. const handleNextClickChange = (e) => {
  254. proxy.$refs.chooseWord.style.color = "";
  255. params.current = e;
  256. getInitData(params);
  257. };
  258. const handleCurrentChange = (e) => {
  259. proxy.$refs.chooseWord.style.color = "";
  260. params.current = e;
  261. getInitData(params);
  262. };
  263. // 关注店铺分页
  264. const handleStorePrevClickChange = (e) => {
  265. paramsStore.current = e;
  266. getStoreData(paramsStore);
  267. };
  268. const handleStoreNextClickChange = (e) => {
  269. paramsStore.current = e;
  270. getStoreData(paramsStore);
  271. };
  272. const handleStoreCurrentChange = (e) => {
  273. paramsStore.current = e;
  274. getStoreData(paramsStore);
  275. };
  276. //切换收藏店铺的特别关注和普通关注
  277. const switchStoreType = (index) => {
  278. collectStoreIndex.value = index;
  279. };
  280. //取消商品收藏的post操作
  281. const cancelCollect = () => {
  282. if (chosedItem.value.length > 0) {
  283. ElMessageBox.confirm("确定取消收藏吗?", "提示", {
  284. confirmButtonText: "确定",
  285. cancelButtonText: "取消",
  286. type: "warning",
  287. })
  288. .then(() => {
  289. cancelConfirm();
  290. })
  291. .catch(() => {});
  292. } else {
  293. ElMessage.warning({
  294. message: "请选择商品",
  295. offset: 95,
  296. center: true,
  297. });
  298. }
  299. };
  300. //取消收藏的确认事件
  301. const cancelConfirm = () => {
  302. let params = {
  303. isCollect: false,
  304. productIds: chosedItem.value.join(","),
  305. };
  306. post("v3/member/front/followProduct/edit", params).then((res) => {
  307. if (res.state == 200) {
  308. chosedItem.value = [];
  309. getInitData();
  310. ElMessage(res.msg);
  311. }
  312. });
  313. };
  314. const collectStoreUpdate = () => {
  315. getStoreData(paramsStore);
  316. };
  317. //全选或反选操作
  318. const selectAll = (checks) => {
  319. if (checks) {
  320. let listArr = [];
  321. collectGoodsData.list.forEach((item) => {
  322. listArr.push(item.productId);
  323. });
  324. chosedItem.value = listArr;
  325. proxy.$refs.chooseWord.style.color = "#e1251b";
  326. collectGoodsChoose.value = ref("/member/chooseAll_red.png");
  327. } else {
  328. chosedItem.value = [];
  329. proxy.$refs.chooseWord.style.color = "";
  330. collectGoodsChoose.value = ref("/member/chooseAll.png");
  331. }
  332. };
  333. watch(chosedItem, () => {
  334. if (chosedItem.value.length == collectGoodsData.list.length) {
  335. proxy.$refs.chooseWord.style.color = "#e1251b";
  336. collectGoodsChoose.value = ref("/member/chooseAll_red.png");
  337. } else {
  338. proxy.$refs.chooseWord.style.color = "";
  339. collectGoodsChoose.value = ref("/member/chooseAll.png");
  340. }
  341. });
  342. watchEffect(() => {
  343. if (route.query.type == "store") {
  344. collectIndex.value = 2;
  345. } else {
  346. collectIndex.value = 1;
  347. }
  348. });
  349. onMounted(() => {
  350. getInitData(params);
  351. getStoreData(paramsStore);
  352. if (route.query.type == "store") {
  353. collectIndex.value = 2;
  354. } else {
  355. collectIndex.value = 1;
  356. }
  357. });
  358. </script>
  359. <style lang="scss" scoped>
  360. @use "@/assets/style/base.scss" as *;
  361. @use "@/assets/style/member/collect.scss" as *;
  362. .sld_pagination {
  363. margin-top: 20px;
  364. }
  365. </style>