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.

266 lines
8.0 KiB

2 years ago
  1. <template>
  2. <div class="myBooking 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-transparent xl: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-flex tw-flex-col md:tw-flex-row md:tw-justify-between md:tw-items-center tw-mb-[20px] md:tw-mb-[34px]"
  17. >
  18. <div
  19. class="tw-text-[20px] tw-font-bold tw-text-base-primary tw-mb-[20px] md:t24 md:tw-mb-0"
  20. >
  21. <two-dots class="tw-mr-[30px]"></two-dots>{{ $t("My Bookings") }}
  22. </div>
  23. <div class="element tw-w-full md:tw-w-[320px]">
  24. <userSearchBar
  25. :input="{
  26. id: 'searchQuery',
  27. placeHolder: $t('Enter exhibitions, booking number ...'),
  28. type: 'text',
  29. }"
  30. :default="searchQuery"
  31. @change="searchQuery = $event"
  32. ></userSearchBar>
  33. </div>
  34. </div>
  35. <bookingListContent
  36. :searchQuery="searchQuery"
  37. :width="width"
  38. ></bookingListContent>
  39. <section class="step sercion-6 tw-w-full md:tw-px-0 xl:tw-col-span-2">
  40. <h2 class="title-icon-left t16 md:t20 xl:t18 xl:tw-font-bold">
  41. {{ $t("You might like ...") }}
  42. </h2>
  43. <userYouMightLike
  44. :list="youMightLikeList"
  45. :countrycode="countrycode"
  46. :regionName="regionName"
  47. >
  48. </userYouMightLike>
  49. </section>
  50. </div>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import TwoDots from "@/components/TwoDots";
  56. import userSearchBar from "@/components/user/userSearchBar.vue";
  57. import bookingListContent from "@/components/user/bookingListContent.vue";
  58. import userYouMightLike from "@/components/user/userYouMightLike.vue";
  59. import userSidebar from "@/components/user/userSidebar.vue";
  60. export default {
  61. name: "myBooking",
  62. layout: "profile_gray",
  63. components: {
  64. TwoDots,
  65. userSearchBar,
  66. bookingListContent,
  67. userYouMightLike,
  68. userSidebar,
  69. },
  70. data() {
  71. return {
  72. firstName: "",
  73. lastName: "",
  74. userData: {},
  75. userCompanyId: [],
  76. userCompanyList: [],
  77. userAddNewCompanyList: [],
  78. userSavedExhibitionList: [],
  79. userVisibleSavedExhibitionList: [],
  80. yearOptions: [],
  81. monthOptions: [],
  82. dayOptions: [],
  83. yearSelect: "",
  84. monthSelect: "",
  85. daySelect: "",
  86. languageSelect: {
  87. en: "",
  88. zhtw: "",
  89. },
  90. phoneValid: false,
  91. width: 0,
  92. searchQuery: "",
  93. youMightLikeList: [],
  94. countrycode: [],
  95. regionName: [],
  96. };
  97. },
  98. created() {
  99. // this.fetchUserData();
  100. // this.getLocationName();
  101. // this.getYouMightLikeData();
  102. if (process.browser) {
  103. window.addEventListener("resize", this.handleResize);
  104. }
  105. this.handleResize();
  106. },
  107. mounted() {
  108. this.yearOptions = Array.from(new Array(103), (val, index) =>
  109. (index + 1920).toString()
  110. );
  111. this.monthOptions = Array.from(new Array(13), (val, index) => {
  112. if (index < 10 && index > 0) {
  113. return "0" + index.toString();
  114. }
  115. if (index >= 10) {
  116. return index.toString();
  117. }
  118. });
  119. this.dayOptions = Array.from(new Array(32), (val, index) => {
  120. if (index < 10 && index > 0) {
  121. return "0" + index.toString();
  122. }
  123. if (index >= 10) {
  124. return index.toString();
  125. }
  126. });
  127. this.$nextTick(() => {
  128. window.addEventListener("resize", this.onResize);
  129. });
  130. },
  131. destroyed() {
  132. if (process.browser) {
  133. window.removeEventListener("resize", this.handleResize);
  134. }
  135. },
  136. methods: {
  137. patchUserData() {
  138. if (this.width < 1366) {
  139. this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
  140. }
  141. this.userData.prefer_country = JSON.stringify(this.languageSelect);
  142. if (this.width < 768) {
  143. this.userData.birth_date =
  144. this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  145. if (this.userData.birth_date.length < 10) {
  146. this.userData.birth_date = null;
  147. }
  148. }
  149. const patchData = JSON.parse(JSON.stringify(this.userData));
  150. delete patchData.LoginLog;
  151. delete patchData.UserCompany;
  152. delete patchData.UserSocialRelation;
  153. delete patchData.UserExhibition;
  154. this.$axios
  155. .put(
  156. `/member/users/${this.$route.params.id}?jwt=${
  157. this.$auth.$storage.getUniversal("jwt").token || ""
  158. }`,
  159. patchData
  160. )
  161. .then((res) => {
  162. this.successUpdate = !this.successUpdate;
  163. setTimeout(() => {
  164. this.successUpdate = !this.successUpdate;
  165. }, 1000);
  166. this.fetchUserData();
  167. this.$auth.$storage.setUniversal("userPicture", patchData.picture);
  168. this.$auth.$storage.setUniversal("userLastName", patchData.last_name);
  169. this.$store.dispatch("updatePicture");
  170. })
  171. .catch((err) => {
  172. console.log(err);
  173. });
  174. },
  175. fetchUserData() {
  176. this.$axios
  177. .get(
  178. `/member/users/${
  179. this.$auth.$storage.getUniversal("jwt").user_id
  180. }?jwt=${this.$auth.$storage.getUniversal("jwt").token}`
  181. )
  182. .then((res) => {
  183. this.userData = res.data;
  184. this.userCompanyId = res.data.UserCompany;
  185. this.firstName = res.data.first_name;
  186. this.lastName = res.data.last_name;
  187. this.userData.phone
  188. ? (this.phoneValid = true)
  189. : (this.phoneValid = false);
  190. !this.userData.prefer_country &&
  191. typeof this.userData.prefer_country === "object"
  192. ? this.userData.prefer_country
  193. : (this.languageSelect = JSON.parse(this.userData.prefer_country));
  194. if (
  195. !this.userData.birth_date &&
  196. typeof this.userData.birth_date === "object"
  197. ) {
  198. this.yearSelect = "";
  199. this.monthSelect = "";
  200. this.daySelect = "";
  201. } else {
  202. const date = this.userData.birth_date.split("-");
  203. this.yearSelect = date[0];
  204. this.monthSelect = date[1];
  205. this.daySelect = date[2];
  206. }
  207. })
  208. .catch((err) => {
  209. console.log(err);
  210. });
  211. },
  212. handleImageUpdate(pictureURL) {
  213. this.userData.picture = pictureURL;
  214. this.patchUserData();
  215. this.closeCropDialog();
  216. },
  217. showCode(object) {
  218. this.userData.country_code = object.dialCode;
  219. },
  220. logout() {
  221. this.$auth.$storage.removeUniversal("jwt");
  222. this.$auth.$storage.removeUniversal("userPicture");
  223. this.$auth.$storage.removeUniversal("userLastName");
  224. this.$auth.$storage.removeUniversal("userBeforePath");
  225. if (width < 1024) {
  226. this.$router.push(this.localePath("/"));
  227. } else {
  228. this.$router.push(this.localePath("/user"));
  229. }
  230. this.$auth.logout();
  231. },
  232. async getLocationName() {
  233. this.$axios
  234. .get(
  235. `/t/exhibitions/locations?lang=${this.$i18n.localeProperties["langQuery"]}&sort=False`
  236. )
  237. .then((response) => {
  238. this.regionName = response.data.region_ori;
  239. this.countrycode = response.data.country_ori;
  240. })
  241. .catch((error) => console.log(error));
  242. },
  243. async getYouMightLikeData() {
  244. this.$axios
  245. .get(
  246. `https://dev-api-console.showeasy.com/user-services/advertisements?region=0&country=0&city=0&expo=0&counts=3&lang_code=${this.$i18n.localeProperties["langQuery"]}`
  247. )
  248. .then((res) => {
  249. this.youMightLikeList = res.data;
  250. })
  251. .catch((error) => console.log(error));
  252. },
  253. handleResize() {
  254. if (process.browser) {
  255. this.width = window.innerWidth;
  256. }
  257. },
  258. },
  259. };
  260. </script>
  261. <style scoped lang="scss"></style>