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.

581 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
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" />
  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. picName: "",
  272. picSize: "",
  273. picType: "",
  274. picPath:"",
  275. mozFullPath:"",
  276. },
  277. dialCode:"",
  278. };
  279. },
  280. created() {
  281. this.fetchCountry();
  282. this.$store.dispatch("updatePicture");
  283. this.fetchUserData();
  284. },
  285. mounted() {
  286. this.yearOptions = Array.from(new Array(103), (val, index) =>
  287. (index + 1920).toString()
  288. );
  289. this.monthOptions = Array.from(new Array(13), (val, index) => {
  290. if (index < 10 && index > 0) {
  291. return "0" + index.toString();
  292. }
  293. if (index >= 10) {
  294. return index.toString();
  295. }
  296. });
  297. this.dayOptions = Array.from(new Array(32), (val, index) => {
  298. if (index < 10 && index > 0) {
  299. return "0" + index.toString();
  300. }
  301. if (index >= 10) {
  302. return index.toString();
  303. }
  304. });
  305. this.$nextTick(() => {
  306. window.addEventListener("resize", this.onResize);
  307. });
  308. },
  309. methods: {
  310. getPhoneData(phoneData) {
  311. this.countryCode = phoneData.countryCode;
  312. this.userData.PhoneCode = phoneData.countryCallingCode;
  313. this.phoneValid = phoneData.isValid;
  314. },
  315. showCode(object) {
  316. //this.userData.PhoneCode = object.dialCode;
  317. },
  318. patchUserData() {
  319. // if (this.width < 1366) {
  320. // this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
  321. // }
  322. this.validators();
  323. // if (this.validators()) {
  324. // this.userData.prefer_country = JSON.stringify(this.languageSelect);
  325. // if (this.$vuetify.breakpoint.name !== "xs") {
  326. // this.userData.birth_date =
  327. // this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  328. // if (this.userData.birth_date.length < 10) {
  329. // this.userData.birth_date = null;
  330. // }
  331. // }
  332. if(this.$vuetify.breakpoint.name !== "xs"){
  333. this.userData.BirthDate = this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  334. if(this.userData.BirthDate.length < 10){
  335. this.userData.BirthDate = null;
  336. }
  337. }
  338. if(this.languageSelect.en == true){
  339. this.userData.LanguageID = "en-US";
  340. }else if(this.languageSelect.zhtw == true){
  341. this.userData.LanguageID = "zh-TW";
  342. }else{
  343. this.userData.LanguageID = "null";
  344. }
  345. const patchData = JSON.parse(JSON.stringify(this.userData));
  346. // delete patchData.LoginLog;
  347. //delete patchData.UserCompany;
  348. // delete patchData.UserSocialRelation;
  349. // delete patchData.UserExhibition;
  350. this.$axios
  351. .post(
  352. `/trending/api/Members/Member`, patchData
  353. )
  354. .then((response) => {
  355. //console.log(JSON.stringify(response));
  356. if (response.status == 200) {
  357. this.$notify({
  358. type: "success",
  359. text: "更新成功",
  360. });
  361. }
  362. this.fetchUserData();
  363. this.$auth.$storage.setUniversal("userPicture", patchData.MemberPicture);
  364. // this.$auth.$storage.setUniversal(
  365. // "userLastName",
  366. // patchData.LastName
  367. // );
  368. this.$store.dispatch("updatePicture");
  369. })
  370. .catch((error) => {
  371. console.log(error);
  372. });
  373. },
  374. fetchUserData() {
  375. this.$axios
  376. .get(
  377. `/trending/api/Members/Info`
  378. )
  379. .then((response) => {
  380. //console.log(JSON.stringify(response));
  381. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  382. let data = response.data.DATA.rel
  383. if(data){
  384. this.userData = data;
  385. this.firstName = this.userData.FirstName;
  386. this.lastName = this.userData.LastName;
  387. this.userData.Phone ? (this.phoneValid = true): (this.phoneValid = false);
  388. //this.countryCode = this.userData.PhoneCode;
  389. if(this.userData.LanguageID == "en-US"){
  390. this.languageSelect.en = true;
  391. }else if(this.userData.LanguageID == "zh-TW"){
  392. this.languageSelect.zhtw = true;
  393. }else{
  394. this.languageSelect.en = "";
  395. this.languageSelect.zhtw = "";
  396. }
  397. if (
  398. this.userData.BirthDate && typeof this.userData.BirthDate === "object"
  399. ){
  400. this.yearSelect = "";
  401. this.monthSelect = "";
  402. this.daySelect = "";
  403. }else{
  404. const space = this.userData.BirthDate.split("T");
  405. const date = space[0].split("-");
  406. this.yearSelect = date[0];
  407. this.monthSelect = date[1];
  408. this.daySelect = date[2];
  409. }
  410. }
  411. }
  412. })
  413. .catch((error) => {
  414. console.log(error);
  415. });
  416. },
  417. handleUploadEvent() {
  418. window.addEventListener("focus", () => { }, { once: true });
  419. this.$refs.uploader.click();
  420. },
  421. getNewPicture(e) {
  422. const path = URL.createObjectURL(e.target.files[0]);
  423. this.cropImagePreview = path ;
  424. console.log("image:" + this.cropImagePreview);
  425. this.isCropImageDialogActive = !this.isCropImageDialogActive;
  426. },
  427. userPictureUpload(e) {
  428. const fileSize = (e.target.files[0].size / 1024 / 1024).toFixed(1);
  429. if (fileSize >= 2) {
  430. this.fileTooBig = !this.fileTooBig;
  431. } else {
  432. this.$axios
  433. .post(
  434. `/trending/api/Members/UploadAvatar`
  435. )
  436. .then((response) => {
  437. //console.log(JSON.stringify(response));
  438. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  439. let data = response.data.DATA.rel
  440. if(data){
  441. this.cropImagePreview = data;
  442. }
  443. }
  444. })
  445. .catch((error) => {
  446. console.log(error);
  447. });
  448. this.isCropImageDialogActive = !this.isCropImageDialogActive;
  449. }
  450. },
  451. fetchCountry() {
  452. this.$axios
  453. .get(`/trending/api/location/countries?RegionID&Lang=${this.$i18n.localeProperties["langQuery"]}`)
  454. .then((response) => {
  455. //console.log(JSON.stringify(response));
  456. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  457. let data = response.data.DATA.rel
  458. if(data){
  459. this.countryList = data;
  460. //console.log(this.countryList);
  461. this.countryOptions = this.countryList.map((item) => {
  462. return {
  463. id: item.CountryID,
  464. name: item.CountryName,
  465. };
  466. });
  467. }
  468. }
  469. })
  470. .catch((error) => {
  471. console.log(error);
  472. });
  473. },
  474. closeCropDialog() {
  475. this.isCropImageDialogActive = !this.isCropImageDialogActive;
  476. },
  477. handleImageUpdate() {
  478. this.fetchUserData();
  479. //this.patchUserData();
  480. this.closeCropDialog();
  481. },
  482. validators() {
  483. if (is.empty(this.userData.FirstName)) {
  484. this.validation.FirstName = false;
  485. } else {
  486. this.validation.FirstName = true;
  487. }
  488. if (is.empty(this.userData.LastName)) {
  489. this.validation.LastName = false;
  490. } else {
  491. this.validation.LastName = true;
  492. }
  493. if (is.empty(this.userData.Email) || is.not.email(this.userData.Email)) {
  494. this.validation.Email = false;
  495. } else {
  496. this.validation.Email = true;
  497. }
  498. if (is.empty(this.yearSelect)) {
  499. this.validation.yearSelect = false;
  500. } else {
  501. this.validation.yearSelect = true;
  502. }
  503. if (is.empty(this.monthSelect)) {
  504. this.validation.monthSelect = false;
  505. } else {
  506. this.validation.monthSelect = true;
  507. }
  508. if (is.empty(this.daySelect)) {
  509. this.validation.daySelect = false;
  510. } else {
  511. this.validation.daySelect = true;
  512. }
  513. if (is.null(this.userData.CountryID) || this.userData.CountryID == 0) {
  514. this.validation.CountryID = false;
  515. } else {
  516. this.validation.CountryID = true;
  517. }
  518. this.errors = Object.entries(this.validation).filter(
  519. (e) => e[1] == false
  520. );
  521. if (this.errors.length > 0) {
  522. return false;
  523. } else {
  524. return true;
  525. }
  526. },
  527. },
  528. };
  529. </script>
  530. <style scoped lang="scss" scoped>
  531. .success-alert {
  532. position: absolute;
  533. left: 13%;
  534. z-index: 10;
  535. top: -3%;
  536. }
  537. .success-alert-dialog {
  538. position: absolute;
  539. left: 13%;
  540. z-index: 10;
  541. top: 3%;
  542. }
  543. </style>