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.

259 lines
8.1 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
  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. </div>
  42. </template>
  43. <script>
  44. import TwoDots from "@/components/TwoDots";
  45. import AddContactModal from "@/components/newComponent/modal/UserAddContactModal.vue";
  46. import ContactInfoContent from "@/components/user/contactInfoContent.vue";
  47. import Swal from "sweetalert2";
  48. import userSidebar from "@/components/user/userSidebar.vue";
  49. export default {
  50. name: "contactInfo",
  51. layout: "profile",
  52. components: {
  53. TwoDots,
  54. AddContactModal,
  55. ContactInfoContent,
  56. userSidebar,
  57. },
  58. data() {
  59. return {
  60. firstName: "",
  61. lastName: "",
  62. userData: {},
  63. userCompanyId: [],
  64. userCompanyList: [],
  65. userAddNewCompanyList: [],
  66. userSavedExhibitionList: [],
  67. userVisibleSavedExhibitionList: [],
  68. yearOptions: [],
  69. monthOptions: [],
  70. dayOptions: [],
  71. yearSelect: "",
  72. monthSelect: "",
  73. daySelect: "",
  74. languageSelect: {
  75. en: "",
  76. zhtw: "",
  77. },
  78. phoneValid: false,
  79. contactImg: require("../../assets/img/noContact.png"),
  80. plusImg: require("~/assets/svg/addCompany.svg"),
  81. userContact: [],
  82. };
  83. },
  84. created() {
  85. this.fetchUserData();
  86. this.fetchContactInfo();
  87. },
  88. mounted() {
  89. this.yearOptions = Array.from(new Array(103), (val, index) =>
  90. (index + 1920).toString()
  91. );
  92. this.monthOptions = Array.from(new Array(13), (val, index) => {
  93. if (index < 10 && index > 0) {
  94. return "0" + index.toString();
  95. }
  96. if (index >= 10) {
  97. return index.toString();
  98. }
  99. });
  100. this.dayOptions = Array.from(new Array(32), (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.$nextTick(() => {
  109. window.addEventListener("resize", this.onResize);
  110. });
  111. },
  112. methods: {
  113. patchUserData() {
  114. if (this.width < 1366) {
  115. this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
  116. }
  117. this.userData.prefer_country = JSON.stringify(this.languageSelect);
  118. if (this.$vuetify.breakpoint.name !== "xs") {
  119. this.userData.birth_date =
  120. this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  121. if (this.userData.birth_date.length < 10) {
  122. this.userData.birth_date = null;
  123. }
  124. }
  125. const patchData = JSON.parse(JSON.stringify(this.userData));
  126. delete patchData.LoginLog;
  127. delete patchData.UserCompany;
  128. delete patchData.UserSocialRelation;
  129. delete patchData.UserExhibition;
  130. this.$axios
  131. .put(
  132. `/member/users/${this.$route.params.id}?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  133. }`,
  134. patchData
  135. )
  136. .then((res) => {
  137. this.successUpdate = !this.successUpdate;
  138. setTimeout(() => {
  139. this.successUpdate = !this.successUpdate;
  140. }, 1000);
  141. this.fetchUserData();
  142. this.$auth.$storage.setUniversal("userPicture", patchData.picture);
  143. this.$auth.$storage.setUniversal("userLastName", patchData.last_name);
  144. this.$store.dispatch("updatePicture");
  145. })
  146. .catch((err) => {
  147. console.log(err);
  148. });
  149. },
  150. fetchUserData() {
  151. this.$axios
  152. .get(
  153. `/trending/api/Members/Info`
  154. )
  155. .then((response) => {
  156. //console.log(JSON.stringify(response));
  157. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  158. let data = response.data.DATA.rel
  159. if(data){
  160. this.userData = data;
  161. this.firstName = this.userData.FirstName;
  162. this.lastName = this.userData.LastName;
  163. this.userData.Phone ? (this.phoneValid = true): (this.phoneValid = false);
  164. this.userData.phone
  165. ? (this.phoneValid = true)
  166. : (this.phoneValid = false);
  167. if(this.userData.ArgumentID == "en-US"){
  168. this.languageSelect.en = true;
  169. }else if(this.userData.ArgumentID == "zh-TW"){
  170. this.languageSelect.zhtw = true;
  171. }else{
  172. this.languageSelect.en = "";
  173. this.languageSelect.zhtw = "";
  174. }
  175. if (
  176. this.userData.BirthDate && typeof this.userData.BirthDate === "object"
  177. ){
  178. this.yearSelect = "";
  179. this.monthSelect = "";
  180. this.daySelect = "";
  181. }else{
  182. const space = this.userData.BirthDate.split("T");
  183. const date = space[0].split("-");
  184. this.yearSelect = date[0];
  185. this.monthSelect = date[1];
  186. this.daySelect = date[2];
  187. }
  188. }
  189. }
  190. })
  191. .catch((error) => {
  192. console.log(error);
  193. });
  194. },
  195. handleImageUpdate(pictureURL) {
  196. this.userData.picture = pictureURL;
  197. //this.patchUserData();
  198. this.closeCropDialog();
  199. },
  200. showCode(object) {
  201. this.userData.country_code = object.dialCode;
  202. },
  203. logout() {
  204. this.$auth.$storage.removeUniversal("jwt");
  205. this.$auth.$storage.removeUniversal("userPicture");
  206. this.$auth.$storage.removeUniversal("userLastName");
  207. this.$auth.$storage.removeUniversal("userBeforePath");
  208. if (window.innerWidth < 1024) {
  209. this.$router.push(this.localePath("/"));
  210. } else {
  211. this.$router.push(this.localePath("/user"));
  212. }
  213. this.$auth.logout();
  214. },
  215. fetchContactInfo() {
  216. this.$axios
  217. .get(
  218. `/trending/api/Members/Contacts`
  219. )
  220. .then((response) => {
  221. //console.log(JSON.stringify(response));
  222. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  223. let data = response.data.DATA.rel
  224. if(data){
  225. this.userContact = data;
  226. }
  227. }
  228. })
  229. .catch((error) => {
  230. console.log(error);
  231. });
  232. },
  233. successUpdate() {
  234. this.$notify({
  235. type: "success",
  236. text: "更新成功",
  237. });
  238. this.fetchContactInfo();
  239. },
  240. },
  241. };
  242. </script>
  243. <style scoped lang="scss">
  244. </style>