565 lines
20 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
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
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
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="editPersonalInfo 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="tw-bg-white xl:tw-p-[30px] xl:tw-rounded-[20px] xl:tw-min-w-[900px] xl:tw-max-w-[900px]">
  7. <div class="tw-text-[20px] tw-font-bold tw-text-base-primary tw-mb-[20px] md:t24 md:tw-mb-[30px]">
  8. <two-dots class="tw-mr-[30px]"></two-dots>{{ $t("userProfile.editPersonalInfo") }}
  9. </div>
  10. <!-- alert -->
  11. <div v-if="successUpdate" class="tw-flex tw-w-full tw-right-auto tw-left-auto">
  12. <div type="success"
  13. class="tw-absolute tw-top-0 tw-right-0 tw-left-0 tw-mx-auto tw-flex tw-flex-row tw-w-fit tw-items-center tw-bg-success-background tw-rounded-[12px] tw-px-[12px] tw-py-[10px]">
  14. <img src="~/assets/svg/alert_success.svg" class="tw-w-[16px] tw-mr-[10px] md:tw-w-[20px]" alt="" />
  15. <div class="tw-hidden md:tw-block tw-text-success-default tw-font-bold tw-text-[16px] md:tw-mr-[16px]">
  16. Awesome!
  17. </div>
  18. <div class="tw-text-[12px] tw-text-success-default tw-mr-[9px] md:tw-text-[16px] md:tw-mr-[16px]">
  19. Successfully updated.
  20. </div>
  21. <img src="~/assets/svg/alert_close.svg" @click="successUpdate = !successUpdate" />
  22. </div>
  23. </div>
  24. <div v-if="fileTooBig" class="tw-flex tw-w-full tw-right-auto tw-left-auto">
  25. <div type="error"
  26. class="tw-absolute tw-top-0 tw-right-0 tw-left-0 tw-mx-auto tw-flex tw-flex-row tw-w-fit tw-items-center tw-bg-error-background tw-rounded-[16px] tw-px-[12px] tw-py-[10px] tw-text-[12px]">
  27. <img src="~/assets/svg/alert_notice.svg" class="tw-w-[16px] tw-mr-[10px] md:tw-w-[20px]" alt="" />
  28. <div class="tw-hidden md:tw-block tw-text-error-default tw-mr-[25px] tw-text-[16px]">
  29. Oops!
  30. </div>
  31. <div class="tw-text-error-default tw-mr-[8px] md:tw-text-[16px] md:tw-mr-[16px]">
  32. Please upload an image under 2MB.
  33. </div>
  34. <img src="~/assets/svg/alert_close_red.svg" @click="fileTooBig = !fileTooBig" alt="" />
  35. </div>
  36. </div>
  37. <!-- user picture -->
  38. <div class="tw-flex tw-items-center tw-mb-[30px]">
  39. <div>
  40. <img v-if="userData.MemberPicture" :src="userData.MemberPicture"
  41. class="tw-border tw-border-solid tw-border-neutral-300 tw-h-[64px] tw-w-[64px] tw-rounded-[50px] tw-mr-[15px] md:tw-h-[90px] md:tw-w-[90px] md:tw-mr-[30px]"
  42. alt="" />
  43. <div v-else
  44. class="tw-flex tw-justify-center tw-items-center tw-bg-primary-1 tw-text-white tw-text-[32px] tw-h-[64px] tw-w-[64px] tw-rounded-[50px] tw-mr-[15px] md:tw-h-[90px] md:tw-w-[90px] md:tw-mr-[30px]">
  45. {{ lastName.split("")[0] || "" }}
  46. </div>
  47. </div>
  48. <div>
  49. <button
  50. class="tw-border tw-border-solid tw-border-primary-1 tw-text-[14px] tw-text-primary-1 tw-px-[16px] tw-py-[9px] tw-rounded-[12px] md:tw-text-[16px]"
  51. @click="handleUploadEvent">
  52. {{ $t("userProfile.uploadPicture") }}
  53. </button>
  54. <input type="file" class="d-none" ref="uploader" @change="getNewPicture($event)" />
  55. <!-- <input type="file" class="d-none" ref="uploader" @change="userPictureUpload" /> -->
  56. </div>
  57. </div>
  58. <!-- form -->
  59. <form
  60. class="tw-grid tw-grid-cols-1 tw-gap-y-[20px] tw-mb-[58px] md:tw-grid-cols-2 md:tw-gap-x-[60px] md:tw-mb-[50px]">
  61. <!-- tilte -->
  62. <div class="element md:tw-col-span-2 md:tw-max-w-[394px]">
  63. <div class="tw-text-[14px] tw-text-base-primary tw-mb-[10px]">
  64. {{ $t("userProfile.Title") }}
  65. </div>
  66. <elementSelectWithIndex :select="{
  67. id: 'Title',
  68. label: 'Title',
  69. required: false,
  70. }" :yearList="genderOptions" :default="userData.Title" :validation="validation.Title"
  71. @change="userData.Title = $event"></elementSelectWithIndex>
  72. </div>
  73. <!-- firstName -->
  74. <div class="element">
  75. <elementInput :input="{
  76. id: 'FirstName',
  77. label: 'First Name',
  78. required: true,
  79. type: 'text',
  80. }" :default="userData.FirstName" :validation="validation.FirstName"
  81. @change="userData.FirstName = $event"></elementInput>
  82. </div>
  83. <!-- lastName -->
  84. <div class="element">
  85. <elementInput :input="{
  86. id: 'LastName',
  87. label: 'Last Name',
  88. required: true,
  89. type: 'text',
  90. }" :default="userData.LastName" :validation="validation.LastName" @change="userData.LastName = $event">
  91. </elementInput>
  92. </div>
  93. <!-- email -->
  94. <div class="element">
  95. <elementInput :input="{
  96. id: 'Email',
  97. label: 'userProfile.personalMail',
  98. required: true,
  99. type: 'email',
  100. }" :default="userData.Email" :validation="validation.Email" @change="userData.Email = $event">
  101. </elementInput>
  102. </div>
  103. <!-- Phone -->
  104. <div>
  105. <div class="tw-text-[14px] tw-text-base-primary tw-mb-[10px]">
  106. {{ $t("userProfile.phone") }}
  107. </div>
  108. <div>
  109. <vue-country-code class="d-none" v-model="countryCode" enabldCountryCode :enabledFlags="false"
  110. @onSelect="showCode"></vue-country-code>
  111. <vue-phone-number-input v-model="userData.Phone" color="#EF5A5A" valid-color="#EE9546" :border-radius="5"
  112. no-flags no-example @update="getPhoneData" :translations="translateOption">
  113. </vue-phone-number-input>
  114. </div>
  115. </div>
  116. <!-- Birthday -->
  117. <div class="md:tw-col-span-2 xl:tw-col-span-1">
  118. <div class="tw-text-[14px] tw-text-base-primary tw-mb-[10px]">
  119. {{ $t("userProfile.birthday")
  120. }}<span class="tw-text-error-default">*</span>
  121. </div>
  122. <div class="tw-grid tw-grid-cols-3 tw-gap-[20px]">
  123. <div class="element">
  124. <elementSelectWithIndex :select="{
  125. id: 'yearSelect',
  126. required: true,
  127. }" :yearList="yearOptions" :default="yearSelect" :validation="validation.yearSelect"
  128. @change="yearSelect = $event"></elementSelectWithIndex>
  129. </div>
  130. <div class="element">
  131. <elementSelectWithIndex :select="{
  132. id: 'monthSelect',
  133. required: false,
  134. }" :yearList="monthOptions" :default="monthSelect" :validation="validation.monthSelect"
  135. @change="monthSelect = $event"></elementSelectWithIndex>
  136. </div>
  137. <div class="element">
  138. <elementSelectWithIndex :select="{
  139. id: 'daySelect',
  140. required: false,
  141. }" :yearList="dayOptions" :default="daySelect" :validation="validation.daySelect"
  142. @change="daySelect = $event"></elementSelectWithIndex>
  143. </div>
  144. </div>
  145. </div>
  146. <!-- Country -->
  147. <div class="element md:tw-col-span-2 xl:tw-col-span-1">
  148. <elementSelect :select="{
  149. id: 'Country',
  150. label: 'userProfile.countryAndRegion',
  151. required: true,
  152. }" :selectList="countryOptions" :default="userData.CountryID" :validation="validation.CountryID"
  153. @change="userData.CountryID = $event"></elementSelect>
  154. </div>
  155. <!-- language -->
  156. <v-spacer class="tw-items-center md:tw-flex md:tw-justify-start md:tw-mt-[20px] md:tw-flex-nowrap">
  157. <div class="tw-inline-block tw-mb-[20px] md:tw-whitespace-nowrap md:tw-mb-0">
  158. {{ $t("userProfile.preferLanguage") }}
  159. </div>
  160. <v-spacer class="tw-flex md:tw-w-fit md:tw-ml-[30px]">
  161. <v-checkbox v-model="languageSelect.en" class="mt-0" hide-details :label="$t('English')"></v-checkbox>
  162. <v-checkbox v-model="languageSelect.zhtw" class="ms-10 mt-0" hide-details :label="$t('Chinese')">
  163. </v-checkbox>
  164. </v-spacer>
  165. </v-spacer>
  166. </form>
  167. <!-- button -->
  168. <div>
  169. <button
  170. class="tw-text-[18px] tw-bg-primary-1 tw-text-white tw-py-[12px] tw-w-full tw-rounded-[16px] tw-mb-[10px] md:tw-w-fit md:tw-px-[16px] md:tw-mr-[20px]"
  171. @click="patchUserData()">
  172. {{ $t("userProfile.saveButton") }}
  173. </button>
  174. <button
  175. class="tw-text-[18px] tw-bg-white tw-text-primary-1 tw-py-[12px] tw-w-full tw-rounded-[16px] md:tw-w-fit md:tw-px-[16px] xl:tw-hidden">
  176. {{ $t("Cancel") }}
  177. </button>
  178. </div>
  179. </div>
  180. </div>
  181. <CropImageDialog :isCropImageDialogActive="isCropImageDialogActive" :cropImagePreview="cropImagePreview"
  182. @close-crop-dialog="closeCropDialog" @upload-image-success="userPictureUpload"></CropImageDialog>
  183. </div>
  184. </template>
  185. <script>
  186. import elementSelect from "@/components/newComponent/form/ElementSelect.vue";
  187. import elementInput from "@/components/newComponent/form/ElementInput.vue";
  188. import SavedExhibitions from "../../components/user/savedExhibitions.vue";
  189. import SavedExhibitionsDialog from "../../components/user/savedExhibitionsDialog.vue";
  190. import CropImageDialog from "../../components/user/cropImageDialog.vue";
  191. import TwoDots from "@/components/TwoDots";
  192. import userSidebar from "@/components/user/userSidebar.vue";
  193. import elementSelectWithIndex from "@/components/newComponent/form/ElementSelectWithIndex.vue";
  194. import is from "is_js";
  195. export default {
  196. name: "editPersonalInfo",
  197. layout: "profile",
  198. components: {
  199. elementSelect,
  200. elementInput,
  201. SavedExhibitions,
  202. SavedExhibitionsDialog,
  203. CropImageDialog,
  204. TwoDots,
  205. userSidebar,
  206. elementSelectWithIndex,
  207. is,
  208. },
  209. data() {
  210. return {
  211. countryList: [],
  212. genderOptions: ["Mr.", "Ms."],
  213. successUpdate: false,
  214. fileTooBig: false,
  215. firstName: "",
  216. lastName: "",
  217. countryCode: "",
  218. userData: {},
  219. userCompanyId: [],
  220. propUserCompany: {},
  221. yearOptions: [],
  222. monthOptions: [],
  223. dayOptions: [],
  224. countryOptions: [],
  225. countrySortOptions: [],
  226. yearSelect: "",
  227. monthSelect: "",
  228. daySelect: "",
  229. languageSelect: {
  230. en: "",
  231. zhtw: "",
  232. },
  233. isCropImageDialogActive: false,
  234. cropImagePreview: "",
  235. dateMenu: false,
  236. translateOption: {
  237. countrySelectorLabel: this.$t("country code"),
  238. phoneNumberLabel: this.$t("phone number"),
  239. },
  240. rules: {
  241. require: (value) => !!value || this.$t("Required."),
  242. email: (v) =>
  243. /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(
  244. v
  245. ) || this.$t("Invalid email"),
  246. checkPassword: (v) =>
  247. (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) &&
  248. v.length >= 8 &&
  249. v.length <= 20) ||
  250. this.$t(
  251. "Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter"
  252. ),
  253. },
  254. personalInfoValid: false,
  255. phoneValid: false,
  256. isNavActive: true,
  257. // width: 0,
  258. validation: {
  259. Title: true,
  260. FirstName: true,
  261. LastName: true,
  262. Email: true,
  263. yearSelect: true,
  264. monthSelect: true,
  265. daySelect: true,
  266. CountryID: true,
  267. },
  268. errors: null,
  269. userPic: {},
  270. payload:[],
  271. dialCode:"",
  272. test:[],
  273. };
  274. },
  275. created() {
  276. this.fetchCountry();
  277. this.$store.dispatch("updatePicture");
  278. this.fetchUserData();
  279. },
  280. mounted() {
  281. this.yearOptions = Array.from(new Array(103), (val, index) =>
  282. (index + 1920).toString()
  283. );
  284. this.monthOptions = Array.from(new Array(13), (val, index) => {
  285. if (index < 10 && index > 0) {
  286. return "0" + index.toString();
  287. }
  288. if (index >= 10) {
  289. return index.toString();
  290. }
  291. });
  292. this.dayOptions = Array.from(new Array(32), (val, index) => {
  293. if (index < 10 && index > 0) {
  294. return "0" + index.toString();
  295. }
  296. if (index >= 10) {
  297. return index.toString();
  298. }
  299. });
  300. this.$nextTick(() => {
  301. window.addEventListener("resize", this.onResize);
  302. });
  303. },
  304. methods: {
  305. getPhoneData(phoneData) {
  306. this.countryCode = phoneData.countryCode;
  307. this.userData.PhoneCode = phoneData.countryCallingCode;
  308. this.phoneValid = phoneData.isValid;
  309. },
  310. showCode(object) {
  311. //this.userData.PhoneCode = object.dialCode;
  312. },
  313. patchUserData() {
  314. // if (this.width < 1366) {
  315. // this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
  316. // }
  317. this.validators();
  318. // if (this.validators()) {
  319. // this.userData.prefer_country = JSON.stringify(this.languageSelect);
  320. // if (this.$vuetify.breakpoint.name !== "xs") {
  321. // this.userData.birth_date =
  322. // this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  323. // if (this.userData.birth_date.length < 10) {
  324. // this.userData.birth_date = null;
  325. // }
  326. // }
  327. if(this.$vuetify.breakpoint.name !== "xs"){
  328. this.userData.BirthDate = this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  329. if(this.userData.BirthDate.length < 10){
  330. this.userData.BirthDate = null;
  331. }
  332. }
  333. if(this.languageSelect.en == true){
  334. this.userData.LanguageID = "en-US";
  335. }else if(this.languageSelect.zhtw == true){
  336. this.userData.LanguageID = "zh-TW";
  337. }else{
  338. this.userData.LanguageID = "null";
  339. }
  340. const patchData = JSON.parse(JSON.stringify(this.userData));
  341. // delete patchData.LoginLog;
  342. //delete patchData.UserCompany;
  343. // delete patchData.UserSocialRelation;
  344. // delete patchData.UserExhibition;
  345. this.$axios
  346. .post(
  347. `/trending/api/Members/Member`, patchData
  348. )
  349. .then((response) => {
  350. //console.log(JSON.stringify(response));
  351. if (response.status == 200) {
  352. this.$notify({
  353. type: "success",
  354. text: "更新成功",
  355. });
  356. }
  357. this.fetchUserData();
  358. this.$auth.$storage.setUniversal("userPicture", patchData.MemberPicture);
  359. // this.$auth.$storage.setUniversal(
  360. // "userLastName",
  361. // patchData.LastName
  362. // );
  363. this.$store.dispatch("updatePicture");
  364. })
  365. .catch((error) => {
  366. console.log(error);
  367. });
  368. },
  369. fetchUserData() {
  370. this.$axios
  371. .get(
  372. `/trending/api/Members/Info`
  373. )
  374. .then((response) => {
  375. //console.log(JSON.stringify(response));
  376. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  377. let data = response.data.DATA.rel
  378. if(data){
  379. this.userData = data;
  380. this.firstName = this.userData.FirstName;
  381. this.lastName = this.userData.LastName;
  382. this.userData.Phone ? (this.phoneValid = true): (this.phoneValid = false);
  383. //this.countryCode = this.userData.PhoneCode;
  384. if(this.userData.LanguageID == "en-US"){
  385. this.languageSelect.en = true;
  386. }else if(this.userData.LanguageID == "zh-TW"){
  387. this.languageSelect.zhtw = true;
  388. }else{
  389. this.languageSelect.en = "";
  390. this.languageSelect.zhtw = "";
  391. }
  392. if (
  393. this.userData.BirthDate && typeof this.userData.BirthDate === "object"
  394. ){
  395. this.yearSelect = "";
  396. this.monthSelect = "";
  397. this.daySelect = "";
  398. }else{
  399. const space = this.userData.BirthDate.split("T");
  400. const date = space[0].split("-");
  401. this.yearSelect = date[0];
  402. this.monthSelect = date[1];
  403. this.daySelect = date[2];
  404. }
  405. }
  406. }
  407. })
  408. .catch((error) => {
  409. console.log(error);
  410. });
  411. },
  412. handleUploadEvent() {
  413. window.addEventListener("focus", () => { }, { once: true });
  414. this.$refs.uploader.click();
  415. },
  416. getNewPicture(e) {
  417. this.payload = new FormData();
  418. this.payload.append("file", e.target.files[0]);
  419. const path = URL.createObjectURL(e.target.files[0]);
  420. this.cropImagePreview = path ;
  421. this.isCropImageDialogActive = !this.isCropImageDialogActive;
  422. },
  423. userPictureUpload(e) {
  424. //const fileSize = (e.target.files[0].size / 1024 / 1024).toFixed(1);
  425. this.$axios
  426. .post(
  427. `/trending/api/Members/UploadAvatar`, this.payload
  428. )
  429. .then((response) => {
  430. //console.log(JSON.stringify(response))
  431. if(response && response.data){
  432. this.isCropImageDialogActive = !this.isCropImageDialogActive;
  433. this.patchUserData();
  434. }
  435. })
  436. .catch((error) => {
  437. console.log(error);
  438. });
  439. },
  440. fetchCountry() {
  441. this.$axios
  442. .get(`/trending/api/location/countries?RegionID&Lang=${this.$i18n.localeProperties["langQuery"]}`)
  443. .then((response) => {
  444. //console.log(JSON.stringify(response));
  445. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  446. let data = response.data.DATA.rel
  447. if(data){
  448. this.countryList = data;
  449. //console.log(this.countryList);
  450. this.countryOptions = this.countryList.map((item) => {
  451. return {
  452. id: item.CountryID,
  453. name: item.CountryName,
  454. };
  455. });
  456. }
  457. }
  458. })
  459. .catch((error) => {
  460. console.log(error);
  461. });
  462. },
  463. closeCropDialog() {
  464. this.isCropImageDialogActive = !this.isCropImageDialogActive;
  465. },
  466. handleImageUpdate() {
  467. this.fetchUserData();
  468. //this.patchUserData();
  469. this.closeCropDialog();
  470. },
  471. validators() {
  472. if (is.empty(this.userData.FirstName)) {
  473. this.validation.FirstName = false;
  474. } else {
  475. this.validation.FirstName = true;
  476. }
  477. if (is.empty(this.userData.LastName)) {
  478. this.validation.LastName = false;
  479. } else {
  480. this.validation.LastName = true;
  481. }
  482. if (is.empty(this.userData.Email) || is.not.email(this.userData.Email)) {
  483. this.validation.Email = false;
  484. } else {
  485. this.validation.Email = true;
  486. }
  487. if (is.empty(this.yearSelect)) {
  488. this.validation.yearSelect = false;
  489. } else {
  490. this.validation.yearSelect = true;
  491. }
  492. if (is.empty(this.monthSelect)) {
  493. this.validation.monthSelect = false;
  494. } else {
  495. this.validation.monthSelect = true;
  496. }
  497. if (is.empty(this.daySelect)) {
  498. this.validation.daySelect = false;
  499. } else {
  500. this.validation.daySelect = true;
  501. }
  502. if (is.null(this.userData.CountryID) || this.userData.CountryID == 0) {
  503. this.validation.CountryID = false;
  504. } else {
  505. this.validation.CountryID = true;
  506. }
  507. this.errors = Object.entries(this.validation).filter(
  508. (e) => e[1] == false
  509. );
  510. if (this.errors.length > 0) {
  511. return false;
  512. } else {
  513. return true;
  514. }
  515. },
  516. },
  517. };
  518. </script>
  519. <style scoped lang="scss" scoped>
  520. .success-alert {
  521. position: absolute;
  522. left: 13%;
  523. z-index: 10;
  524. top: -3%;
  525. }
  526. .success-alert-dialog {
  527. position: absolute;
  528. left: 13%;
  529. z-index: 10;
  530. top: 3%;
  531. }
  532. </style>