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.

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