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.

268 lines
8.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="contactInfo 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 :userData="userData" :firstName="firstName" :lastName="lastName" class="tw-hidden xl:tw-block">
  5. </userSidebar>
  6. <!-- <div class="xl:tw-hidden"></div> -->
  7. <div class="tw-bg-white xl:tw-p-[30px] xl:tw-rounded-[20px] xl:tw-min-w-[900px] xl:tw-max-w-[900px]">
  8. <div class="tw-text-[20px] tw-font-bold tw-text-base-primary md:t24 xl:tw-mb-[30px]">
  9. <two-dots class="tw-mr-[30px]"></two-dots>{{ $t('Contact Info')}}
  10. </div>
  11. <div v-if="userContact.length < 1"
  12. class="tw-flex tw-justify-center tw-mt-[80px] tw-mb-[50px] md:tw-mb-[30px] md:tw-mt-[90px]">
  13. <div>
  14. <img :src="contactImg" alt="" class="tw-h-[142px] tw-w-[160px]" />
  15. <div class="tw-text-center tw-t16">
  16. {{ $t("No Contact yet ...") }}
  17. </div>
  18. </div>
  19. </div>
  20. <div v-else class="tw-w-full xl:tw-mb-[40px]">
  21. <ContactInfoContent :contacts="userContact" @refetch-contact-info="successUpdate"></ContactInfoContent>
  22. </div>
  23. <div :class="
  24. userContact.length < 1
  25. ? 'tw-flex tw-justify-center tw-mt-[50px] tw-mb-[36px] md:tw-mt-[60px] md:tw-mb-0'
  26. : 'tw-flex tw-justify-center tw-mt-[20px] tw-mb-[30px] md:tw-mt-[30px] md:tw-mb-0 xl:tw-mt-0'
  27. ">
  28. <button @click="$modal.show('add-contact-modal')" type="button"
  29. class="tw-bg-complementary-1 tw-bg-opacity-10 tw-px-6 tw-rounded-2xl tw-h-[40px] tw-w-[169px]">
  30. <div class="tw-flex tw-items-center">
  31. <img :src="plusImg" alt="" class="tw-h-[18px] tw-w-[18px] tw-mr-2" />
  32. <span class="tw-t16 tw-text-complementary-1">{{
  33. $t("Add Contact")
  34. }}</span>
  35. </div>
  36. </button>
  37. </div>
  38. <AddContactModal @update="successUpdate"></AddContactModal>
  39. </div>
  40. </div>
  41. <loading :isLoading="isPageLoading"></loading>
  42. </div>
  43. </template>
  44. <script>
  45. import TwoDots from "@/components/TwoDots";
  46. import AddContactModal from "@/components/newComponent/modal/UserAddContactModal.vue";
  47. import ContactInfoContent from "@/components/user/contactInfoContent.vue";
  48. import Swal from "sweetalert2";
  49. import userSidebar from "@/components/user/userSidebar.vue";
  50. import loading from "@/components/newComponent/loading/loading.vue";
  51. export default {
  52. name: "contactInfo",
  53. layout: "profile",
  54. components: {
  55. TwoDots,
  56. AddContactModal,
  57. ContactInfoContent,
  58. userSidebar,
  59. loading
  60. },
  61. data() {
  62. return {
  63. firstName: "",
  64. lastName: "",
  65. userData: {},
  66. userCompanyId: [],
  67. userCompanyList: [],
  68. userAddNewCompanyList: [],
  69. userSavedExhibitionList: [],
  70. userVisibleSavedExhibitionList: [],
  71. yearOptions: [],
  72. monthOptions: [],
  73. dayOptions: [],
  74. yearSelect: "",
  75. monthSelect: "",
  76. daySelect: "",
  77. languageSelect: {
  78. en: "",
  79. zhtw: "",
  80. },
  81. phoneValid: false,
  82. contactImg: require("../../assets/img/noContact.png"),
  83. plusImg: require("~/assets/svg/addCompany.svg"),
  84. userContact: [],
  85. isPageLoading: false
  86. };
  87. },
  88. created() {
  89. this.isPageLoading = true;
  90. this.fetchUserData();
  91. this.fetchContactInfo();
  92. this.$nextTick(()=>{
  93. this.isPageLoading = false;
  94. });
  95. },
  96. mounted() {
  97. this.yearOptions = Array.from(new Array(103), (val, index) =>
  98. (index + 1920).toString()
  99. );
  100. this.monthOptions = Array.from(new Array(13), (val, index) => {
  101. if (index < 10 && index > 0) {
  102. return "0" + index.toString();
  103. }
  104. if (index >= 10) {
  105. return index.toString();
  106. }
  107. });
  108. this.dayOptions = Array.from(new Array(32), (val, index) => {
  109. if (index < 10 && index > 0) {
  110. return "0" + index.toString();
  111. }
  112. if (index >= 10) {
  113. return index.toString();
  114. }
  115. });
  116. this.$nextTick(() => {
  117. window.addEventListener("resize", this.onResize);
  118. });
  119. },
  120. methods: {
  121. patchUserData() {
  122. if (this.width < 1366) {
  123. this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
  124. }
  125. this.userData.prefer_country = JSON.stringify(this.languageSelect);
  126. if (this.$vuetify.breakpoint.name !== "xs") {
  127. this.userData.birth_date =
  128. this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  129. if (this.userData.birth_date.length < 10) {
  130. this.userData.birth_date = null;
  131. }
  132. }
  133. const patchData = JSON.parse(JSON.stringify(this.userData));
  134. delete patchData.LoginLog;
  135. delete patchData.UserCompany;
  136. delete patchData.UserSocialRelation;
  137. delete patchData.UserExhibition;
  138. this.$axios
  139. .put(
  140. `/member/users/${this.$route.params.id}?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  141. }`,
  142. patchData
  143. )
  144. .then((res) => {
  145. this.successUpdate = !this.successUpdate;
  146. setTimeout(() => {
  147. this.successUpdate = !this.successUpdate;
  148. }, 1000);
  149. this.fetchUserData();
  150. this.$auth.$storage.setUniversal("userPicture", patchData.picture);
  151. this.$auth.$storage.setUniversal("userLastName", patchData.last_name);
  152. this.$store.dispatch("updatePicture");
  153. })
  154. .catch((err) => {
  155. console.log(err);
  156. });
  157. },
  158. fetchUserData() {
  159. this.$axios
  160. .get(
  161. `/trending/api/Members/Info`
  162. )
  163. .then((response) => {
  164. //console.log(JSON.stringify(response));
  165. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  166. let data = response.data.DATA.rel
  167. if(data){
  168. this.userData = data;
  169. this.firstName = this.userData.FirstName;
  170. this.lastName = this.userData.LastName;
  171. this.userData.Phone ? (this.phoneValid = true): (this.phoneValid = false);
  172. this.userData.phone
  173. ? (this.phoneValid = true)
  174. : (this.phoneValid = false);
  175. if(this.userData.ArgumentID == "en-US"){
  176. this.languageSelect.en = true;
  177. }else if(this.userData.ArgumentID == "zh-TW"){
  178. this.languageSelect.zhtw = true;
  179. }else{
  180. this.languageSelect.en = "";
  181. this.languageSelect.zhtw = "";
  182. }
  183. if (
  184. this.userData.BirthDate && typeof this.userData.BirthDate === "object"
  185. ){
  186. this.yearSelect = "";
  187. this.monthSelect = "";
  188. this.daySelect = "";
  189. }else{
  190. const space = this.userData.BirthDate.split("T");
  191. const date = space[0].split("-");
  192. this.yearSelect = date[0];
  193. this.monthSelect = date[1];
  194. this.daySelect = date[2];
  195. }
  196. }
  197. }
  198. })
  199. .catch((error) => {
  200. console.log(error);
  201. });
  202. },
  203. handleImageUpdate(pictureURL) {
  204. this.userData.picture = pictureURL;
  205. //this.patchUserData();
  206. this.closeCropDialog();
  207. },
  208. showCode(object) {
  209. this.userData.country_code = object.dialCode;
  210. },
  211. logout() {
  212. this.$auth.$storage.removeUniversal("jwt");
  213. this.$auth.$storage.removeUniversal("userPicture");
  214. this.$auth.$storage.removeUniversal("userLastName");
  215. this.$auth.$storage.removeUniversal("userBeforePath");
  216. if (window.innerWidth < 1024) {
  217. this.$router.push(this.localePath("/"));
  218. } else {
  219. this.$router.push(this.localePath("/user"));
  220. }
  221. this.$auth.logout();
  222. },
  223. fetchContactInfo() {
  224. this.$axios
  225. .get(
  226. `/trending/api/Members/Contacts`
  227. )
  228. .then((response) => {
  229. //console.log(JSON.stringify(response));
  230. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  231. let data = response.data.DATA.rel
  232. if(data){
  233. this.userContact = data;
  234. }
  235. }
  236. })
  237. .catch((error) => {
  238. console.log(error);
  239. });
  240. },
  241. successUpdate() {
  242. this.$notify({
  243. type: "success",
  244. text: "更新成功",
  245. });
  246. this.fetchContactInfo();
  247. },
  248. },
  249. };
  250. </script>
  251. <style scoped lang="scss">
  252. </style>