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.

240 lines
7.7 KiB

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. if (this.$auth.loggedIn) {
  87. //this.fetchContactInfo();
  88. }
  89. },
  90. mounted() {
  91. this.yearOptions = Array.from(new Array(103), (val, index) =>
  92. (index + 1920).toString()
  93. );
  94. this.monthOptions = Array.from(new Array(13), (val, index) => {
  95. if (index < 10 && index > 0) {
  96. return "0" + index.toString();
  97. }
  98. if (index >= 10) {
  99. return index.toString();
  100. }
  101. });
  102. this.dayOptions = Array.from(new Array(32), (val, index) => {
  103. if (index < 10 && index > 0) {
  104. return "0" + index.toString();
  105. }
  106. if (index >= 10) {
  107. return index.toString();
  108. }
  109. });
  110. this.$nextTick(() => {
  111. window.addEventListener("resize", this.onResize);
  112. });
  113. },
  114. methods: {
  115. patchUserData() {
  116. if (this.width < 1366) {
  117. this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
  118. }
  119. this.userData.prefer_country = JSON.stringify(this.languageSelect);
  120. if (this.$vuetify.breakpoint.name !== "xs") {
  121. this.userData.birth_date =
  122. this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  123. if (this.userData.birth_date.length < 10) {
  124. this.userData.birth_date = null;
  125. }
  126. }
  127. const patchData = JSON.parse(JSON.stringify(this.userData));
  128. delete patchData.LoginLog;
  129. delete patchData.UserCompany;
  130. delete patchData.UserSocialRelation;
  131. delete patchData.UserExhibition;
  132. this.$axios
  133. .put(
  134. `/member/users/${this.$route.params.id}?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  135. }`,
  136. patchData
  137. )
  138. .then((res) => {
  139. this.successUpdate = !this.successUpdate;
  140. setTimeout(() => {
  141. this.successUpdate = !this.successUpdate;
  142. }, 1000);
  143. this.fetchUserData();
  144. this.$auth.$storage.setUniversal("userPicture", patchData.picture);
  145. this.$auth.$storage.setUniversal("userLastName", patchData.last_name);
  146. this.$store.dispatch("updatePicture");
  147. })
  148. .catch((err) => {
  149. console.log(err);
  150. });
  151. },
  152. fetchUserData() {
  153. this.$axios
  154. .get(
  155. `/member/users/${this.$auth.$storage.getUniversal("jwt").user_id
  156. }?jwt=${this.$auth.$storage.getUniversal("jwt").token}`
  157. )
  158. .then((res) => {
  159. this.userData = res.data;
  160. this.userCompanyId = res.data.UserCompany;
  161. this.firstName = res.data.first_name;
  162. this.lastName = res.data.last_name;
  163. this.userData.phone
  164. ? (this.phoneValid = true)
  165. : (this.phoneValid = false);
  166. !this.userData.prefer_country &&
  167. typeof this.userData.prefer_country === "object"
  168. ? this.userData.prefer_country
  169. : (this.languageSelect = JSON.parse(this.userData.prefer_country));
  170. if (
  171. !this.userData.birth_date &&
  172. typeof this.userData.birth_date === "object"
  173. ) {
  174. this.yearSelect = "";
  175. this.monthSelect = "";
  176. this.daySelect = "";
  177. } else {
  178. const date = this.userData.birth_date.split("-");
  179. this.yearSelect = date[0];
  180. this.monthSelect = date[1];
  181. this.daySelect = date[2];
  182. }
  183. })
  184. .catch((err) => {
  185. console.log(err);
  186. });
  187. },
  188. handleImageUpdate(pictureURL) {
  189. this.userData.picture = pictureURL;
  190. this.patchUserData();
  191. this.closeCropDialog();
  192. },
  193. showCode(object) {
  194. this.userData.country_code = object.dialCode;
  195. },
  196. logout() {
  197. this.$auth.$storage.removeUniversal("jwt");
  198. this.$auth.$storage.removeUniversal("userPicture");
  199. this.$auth.$storage.removeUniversal("userLastName");
  200. this.$auth.$storage.removeUniversal("userBeforePath");
  201. if (window.innerWidth < 1024) {
  202. console.log(window.innerWidth);
  203. this.$router.push(this.localePath("/"));
  204. } else {
  205. this.$router.push(this.localePath("/user"));
  206. }
  207. this.$auth.logout();
  208. },
  209. fetchContactInfo() {
  210. this.$axios
  211. .get(
  212. `/member/contacts?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  213. }`
  214. )
  215. .then((result) => {
  216. this.userContact = result.data.contacts;
  217. })
  218. .catch((err) => {
  219. console.log(err);
  220. });
  221. },
  222. successUpdate() {
  223. this.$notify({
  224. type: "success",
  225. text: "更新成功",
  226. });
  227. this.fetchContactInfo();
  228. },
  229. },
  230. };
  231. </script>
  232. <style scoped lang="scss">
  233. </style>