collect.vue 11 KB

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