You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

374 lines
12 KiB

2 years ago
  1. <template>
  2. <div class="saveExhibition xl:tw-max-w-[1246px] xl:tw-mx-auto">
  3. <div class="xl:tw-flex xl:tw-justify-between xl:tw-items-start">
  4. <userSidebar
  5. :userData="userData"
  6. :firstName="firstName"
  7. :lastName="lastName"
  8. class="tw-hidden xl:tw-block"
  9. >
  10. </userSidebar>
  11. <!-- <div class="xl:tw-hidden"></div> -->
  12. <div
  13. class="tw-bg-white xl:tw-p-[30px] xl:tw-rounded-[20px] xl:tw-min-w-[900px] xl:tw-max-w-[900px]"
  14. >
  15. <div
  16. class="tw-text-[20px] tw-font-bold tw-text-base-primary tw-mb-[20px] md:t24 md:tw-mb-[30px]"
  17. >
  18. <two-dots class="tw-mr-[30px]"></two-dots
  19. >{{ $t("userProfile.savedExhibitions") }}
  20. </div>
  21. <div class="tw-text-[14px] tw-text-base-primary tw-mb-[10px]">
  22. {{ $t("userProfile.savedExhibitionsFilter") }}
  23. </div>
  24. <div>
  25. <select
  26. v-model="countrySelect"
  27. class="tw-text-neutrals-500 tw-w-[196px] tw-border tw-border-solid tw-border-neutrals-200 tw-rounded-[10px] tw-px-[15px] tw-py-[9px] tw-head-body tw-outline-none focus:tw-border-primary-1 md:tw-text-[16px]"
  28. >
  29. <option
  30. v-for="(item, index) in countryOptions"
  31. :key="index"
  32. :value="item.id"
  33. >
  34. {{ item.name }}
  35. </option>
  36. </select>
  37. <!-- <select
  38. class="tw-text-neutrals-500 tw-border tw-border-solid tw-border-neutrals-200 tw-rounded-[10px] tw-px-[15px] tw-py-[9px] tw-head-body tw-outline-none focus:tw-border-primary-1 md:tw-text-[16px]"
  39. >
  40. <option v-for="(item, index) in statusOptions" :key="index">
  41. {{ item.status }}
  42. </option>
  43. </select> -->
  44. </div>
  45. <div
  46. v-if="userVisibleSavedExhibitionList.length == 0"
  47. class="tw-mt-[80px] md:tw-mt-[90px]"
  48. >
  49. <img
  50. class="tw-flex tw-mx-auto tw-w-[160px]"
  51. src="~/assets/img/savedExhibitionEmpty.png"
  52. alt=""
  53. />
  54. <div
  55. class="tw-text-[16px] tw-text-neutrals-800 tw-w-fit tw-mx-auto tw-mb-[50px] md:tw-mb-[60px]"
  56. >
  57. {{ $t("userProfile.noSavedExhibitions") }}
  58. </div>
  59. <nuxt-link
  60. :to="localePath('/')"
  61. class="tw-flex tw-text-[16px] tw-w-fit tw-bg-primary-1 tw-text-white tw-px-[16px] tw-py-[9px] tw-rounded-[12px] tw-mx-auto tw-mb-[37px] md:tw-mb-0"
  62. >
  63. {{ $t("Explore with ShowEasy") }}
  64. </nuxt-link>
  65. </div>
  66. <div v-else class="tw-mt-[20px] md:tw-mt-[30px]">
  67. <ExhibitionListCard
  68. v-for="(exhibition, index) in countryFilterList.slice(
  69. (this.page - 1) * 6,
  70. this.page * 6
  71. )"
  72. :key="index"
  73. class="tw-mb-[20px]"
  74. :item="exhibition"
  75. @toggle-favorite="removeExhibitionRelation($event)"
  76. >
  77. </ExhibitionListCard>
  78. <v-pagination
  79. v-model="page"
  80. class="tw-mt-[28px]"
  81. :length="userSavedExhibitionPageLength"
  82. ></v-pagination>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </template>
  88. <script>
  89. import TwoDots from "@/components/TwoDots";
  90. import ExhibitionListCard from "~/components/exhibition/ExhibitionListCard.vue";
  91. import userSidebar from "@/components/user/userSidebar.vue";
  92. import elementSelect from "@/components/newComponent/form/ElementSelect.vue";
  93. export default {
  94. name: "saveExhibition",
  95. layout: "profile",
  96. components: {
  97. TwoDots,
  98. ExhibitionListCard,
  99. userSidebar,
  100. elementSelect,
  101. },
  102. data() {
  103. return {
  104. firstName: "",
  105. lastName: "",
  106. userData: {},
  107. userCompanyId: [],
  108. userCompanyList: [],
  109. userAddNewCompanyList: [],
  110. userSavedExhibitionList: [],
  111. userVisibleSavedExhibitionList: [],
  112. userSavedExhibitionPageLength: 0,
  113. savedExhibitionPerPage: 6,
  114. yearOptions: [],
  115. monthOptions: [],
  116. dayOptions: [],
  117. yearSelect: "",
  118. monthSelect: "",
  119. daySelect: "",
  120. languageSelect: {
  121. en: "",
  122. zhtw: "",
  123. },
  124. phoneValid: false,
  125. countryOptions: [],
  126. countrySelect: 999,
  127. statusOptions: [],
  128. statusSelect: 100,
  129. page: 1,
  130. filterList: [],
  131. countryFilterList: [],
  132. };
  133. },
  134. async created() {
  135. // await this.fetchUserData();
  136. // await this.fetchSavedExhibition();
  137. // await this.$axios
  138. // .get(`users/countries?lang=${this.$i18n.locale.replace("-", "")}`)
  139. // .then((result) => {
  140. // const initial = {
  141. // name: this.$t("userProfile.allCountries"),
  142. // id: 999,
  143. // };
  144. // this.countryOptions = result.data.result;
  145. // this.countryOptions.splice(0, 0, initial);
  146. // })
  147. // .catch((err) => {
  148. // console.log(err);
  149. // });
  150. // await this.$axios
  151. // .get(`exhibitions/filters?lang=${this.$i18n.locale.replace("-", "")}`)
  152. // .then((result) => {
  153. // this.statusOptions = result.data.filters.statuses;
  154. // })
  155. // .catch((err) => {
  156. // console.log(err);
  157. // });
  158. this.countryFilterList = this.userVisibleSavedExhibitionList;
  159. },
  160. mounted() {
  161. this.yearOptions = Array.from(new Array(103), (val, index) =>
  162. (index + 1920).toString()
  163. );
  164. this.monthOptions = Array.from(new Array(13), (val, index) => {
  165. if (index < 10 && index > 0) {
  166. return "0" + index.toString();
  167. }
  168. if (index >= 10) {
  169. return index.toString();
  170. }
  171. });
  172. this.dayOptions = Array.from(new Array(32), (val, index) => {
  173. if (index < 10 && index > 0) {
  174. return "0" + index.toString();
  175. }
  176. if (index >= 10) {
  177. return index.toString();
  178. }
  179. });
  180. this.$nextTick(() => {
  181. window.addEventListener("resize", this.onResize);
  182. });
  183. },
  184. watch: {
  185. countrySelect: {
  186. handler: function () {
  187. if (this.countrySelect) {
  188. this.filterSavedExhibition(this.countrySelect);
  189. // this.fetchSavedExhibition();
  190. }
  191. },
  192. },
  193. },
  194. computed: {},
  195. methods: {
  196. patchUserData() {
  197. if (this.width < 1366) {
  198. this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
  199. }
  200. this.userData.prefer_country = JSON.stringify(this.languageSelect);
  201. if (this.$vuetify.breakpoint.name !== "xs") {
  202. this.userData.birth_date =
  203. this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  204. if (this.userData.birth_date.length < 10) {
  205. this.userData.birth_date = null;
  206. }
  207. }
  208. const patchData = JSON.parse(JSON.stringify(this.userData));
  209. delete patchData.LoginLog;
  210. delete patchData.UserCompany;
  211. delete patchData.UserSocialRelation;
  212. delete patchData.UserExhibition;
  213. this.$axios
  214. .put(
  215. `/member/users/${this.$route.params.id}?jwt=${
  216. this.$auth.$storage.getUniversal("jwt").token || ""
  217. }`,
  218. patchData
  219. )
  220. .then((res) => {
  221. this.successUpdate = !this.successUpdate;
  222. setTimeout(() => {
  223. this.successUpdate = !this.successUpdate;
  224. }, 1000);
  225. this.fetchUserData();
  226. this.$auth.$storage.setUniversal("userPicture", patchData.picture);
  227. this.$auth.$storage.setUniversal("userLastName", patchData.last_name);
  228. this.$store.dispatch("updatePicture");
  229. })
  230. .catch((err) => {
  231. console.log(err);
  232. });
  233. },
  234. async fetchUserData() {
  235. await this.$axios
  236. .get(
  237. `/member/users/${
  238. this.$auth.$storage.getUniversal("jwt").user_id
  239. }?jwt=${this.$auth.$storage.getUniversal("jwt").token}`
  240. )
  241. .then((res) => {
  242. this.userData = res.data;
  243. console.log(this.userData.UserExhibition);
  244. this.userCompanyId = res.data.UserCompany;
  245. this.firstName = res.data.first_name;
  246. this.lastName = res.data.last_name;
  247. this.userData.phone
  248. ? (this.phoneValid = true)
  249. : (this.phoneValid = false);
  250. !this.userData.prefer_country &&
  251. typeof this.userData.prefer_country === "object"
  252. ? this.userData.prefer_country
  253. : (this.languageSelect = JSON.parse(this.userData.prefer_country));
  254. if (
  255. !this.userData.birth_date &&
  256. typeof this.userData.birth_date === "object"
  257. ) {
  258. this.yearSelect = "";
  259. this.monthSelect = "";
  260. this.daySelect = "";
  261. } else {
  262. const date = this.userData.birth_date.split("-");
  263. this.yearSelect = date[0];
  264. this.monthSelect = date[1];
  265. this.daySelect = date[2];
  266. }
  267. })
  268. .catch((err) => {
  269. console.log(err);
  270. });
  271. },
  272. handleImageUpdate(pictureURL) {
  273. this.userData.picture = pictureURL;
  274. this.patchUserData();
  275. this.closeCropDialog();
  276. },
  277. logout() {
  278. this.$auth.$storage.removeUniversal("jwt");
  279. this.$auth.$storage.removeUniversal("userPicture");
  280. this.$auth.$storage.removeUniversal("userLastName");
  281. this.$auth.$storage.removeUniversal("userBeforePath");
  282. if (window.innerWidth < 1024) {
  283. this.$router.push(this.localePath("/"));
  284. } else {
  285. this.$router.push(this.localePath("/user"));
  286. }
  287. this.$auth.logout();
  288. },
  289. async fetchSavedExhibition() {
  290. // if (this.width < 1366) {
  291. // this.isSavedExhibitionsDialogActive =
  292. // !this.isSavedExhibitionsDialogActive;
  293. // } else {
  294. // this.tabs = "savedExhibitions";
  295. // }
  296. const exhibitionList = [];
  297. for (let i = 0; i < this.userData.UserExhibition.length; i++) {
  298. exhibitionList.push(this.userData.UserExhibition[i].exhibition_id);
  299. }
  300. if (exhibitionList.length > 0) {
  301. await this.$axios
  302. .get(
  303. `/member/exhibitions?lang=${this.$i18n.locale.replace(
  304. "-",
  305. ""
  306. )}&exhibition_id=${[...exhibitionList]}`
  307. )
  308. .then((result) => {
  309. this.userSavedExhibitionList = result.data;
  310. console.log(this.userSavedExhibitionList);
  311. this.userSavedExhibitionPageLength = Math.ceil(
  312. this.userSavedExhibitionList.length / this.savedExhibitionPerPage
  313. );
  314. this.userSavedExhibitionList = this.userSavedExhibitionList;
  315. for (let i = 0; i < this.userSavedExhibitionList.length; i++) {
  316. this.userSavedExhibitionList[i].saved = true;
  317. }
  318. this.userVisibleSavedExhibitionList = JSON.parse(
  319. JSON.stringify(this.userSavedExhibitionList)
  320. );
  321. })
  322. .catch((err) => {
  323. console.log(err);
  324. });
  325. }
  326. },
  327. filterSavedExhibition(countryId) {
  328. this.page = 1;
  329. if (countryId == "999") {
  330. this.countryFilterList = JSON.parse(
  331. JSON.stringify(this.userSavedExhibitionList)
  332. );
  333. } else {
  334. this.countryFilterList = this.userVisibleSavedExhibitionList.filter(
  335. (item) => {
  336. return item.country.id == countryId;
  337. }
  338. );
  339. }
  340. this.userSavedExhibitionPageLength = Math.ceil(
  341. this.countryFilterList.length / this.savedExhibitionPerPage
  342. );
  343. },
  344. async removeExhibitionRelation() {
  345. this.page = 1;
  346. await this.fetchUserData();
  347. await this.fetchSavedExhibition();
  348. this.countryFilterList = this.userVisibleSavedExhibitionList;
  349. if (this.countrySelect.toString() !== "999") {
  350. this.countrySelect = 999;
  351. }
  352. },
  353. },
  354. };
  355. </script>
  356. <style scoped lang="scss">
  357. select {
  358. background-image: url("~/assets/svg/dropdownarrow.svg");
  359. width: auto;
  360. height: auto;
  361. background-position: right 12px center;
  362. background-repeat: no-repeat;
  363. }
  364. </style>