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.

609 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
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" :value="genderOptions[0]" :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] tw-gap-[5px]">
  109. <elementCountryCodeSelect :select="{
  110. required: true,
  111. }" :userCodeSelect="codeSelect" :validation="validation.codeSelect" @returnCode = "getReturnCode"></elementCountryCodeSelect>
  112. <vue-phone-number-input v-model="userData.Phone" :validation="validation.PhoneNo" color="#E5e5e5" error-color="#ef5a5a"
  113. valid-color="#e5e5e5"
  114. :error="error" :border-radius="5"
  115. no-flags :no-country-selector="true" no-example @update="getPhoneData" :translations="translateOption">
  116. </vue-phone-number-input>
  117. </div>
  118. </div>
  119. <!-- Birthday -->
  120. <div class="md:tw-col-span-2 xl:tw-col-span-1">
  121. <div class="tw-text-[14px] tw-text-base-primary tw-mb-[10px]">
  122. {{ $t("userProfile.birthday")
  123. }}<span class="tw-text-error-default">*</span>
  124. </div>
  125. <div class="tw-grid tw-grid-cols-3 tw-gap-[20px]">
  126. <div class="element">
  127. <elementSelectWithIndex :select="{
  128. id: 'yearSelect',
  129. required: true,
  130. }" :yearList="yearOptions" :default="yearSelect" :validation="validation.yearSelect"
  131. @change="yearSelect = $event"></elementSelectWithIndex>
  132. </div>
  133. <div class="element">
  134. <elementSelectWithIndex :select="{
  135. id: 'monthSelect',
  136. required: false,
  137. }" :yearList="monthOptions" :default="monthSelect" :validation="validation.monthSelect"
  138. @change="monthSelect = $event"></elementSelectWithIndex>
  139. </div>
  140. <div class="element">
  141. <elementSelectWithIndex :select="{
  142. id: 'daySelect',
  143. required: false,
  144. }" :yearList="dayOptions" :default="daySelect" :validation="validation.daySelect"
  145. @change="daySelect = $event"></elementSelectWithIndex>
  146. </div>
  147. </div>
  148. </div>
  149. <!-- Country -->
  150. <div class="element md:tw-col-span-2 xl:tw-col-span-1">
  151. <elementSelect :select="{
  152. id: 'Country',
  153. label: 'userProfile.countryAndRegion',
  154. required: true,
  155. }" :selectList="countryOptions" :default="userData.CountryID" :validation="validation.CountryID"
  156. @change="userData.CountryID = $event"></elementSelect>
  157. </div>
  158. <!-- language -->
  159. <v-spacer class="tw-items-center md:tw-flex md:tw-justify-start md:tw-mt-[20px] md:tw-flex-nowrap">
  160. <div class="tw-inline-block tw-mb-[20px] md:tw-whitespace-nowrap md:tw-mb-0">
  161. {{ $t("userProfile.preferLanguage") }}
  162. </div>
  163. <v-spacer class="tw-flex md:tw-w-fit md:tw-ml-[30px]">
  164. <v-checkbox v-model="languageSelect.en" class="mt-0" hide-details :label="$t('English')"></v-checkbox>
  165. <v-checkbox v-model="languageSelect.zhtw" class="ms-10 mt-0" hide-details :label="$t('Chinese')">
  166. </v-checkbox>
  167. </v-spacer>
  168. </v-spacer>
  169. </form>
  170. <!-- button -->
  171. <div>
  172. <button
  173. 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]"
  174. @click="patchUserData()">
  175. {{ $t("userProfile.saveButton") }}
  176. </button>
  177. <button
  178. 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">
  179. {{ $t("Cancel") }}
  180. </button>
  181. </div>
  182. </div>
  183. </div>
  184. <CropImageDialog :isCropImageDialogActive="isCropImageDialogActive" :cropImagePreview="cropImagePreview"
  185. @close-crop-dialog="closeCropDialog" @upload-image-success="userPictureUpload"></CropImageDialog>
  186. <loading :isLoading="isPageLoading"></loading>
  187. </div>
  188. </template>
  189. <script>
  190. import elementSelect from "@/components/newComponent/form/ElementSelect.vue";
  191. import elementInput from "@/components/newComponent/form/ElementInput.vue";
  192. import SavedExhibitions from "../../components/user/savedExhibitions.vue";
  193. import SavedExhibitionsDialog from "../../components/user/savedExhibitionsDialog.vue";
  194. import CropImageDialog from "../../components/user/cropImageDialog.vue";
  195. import TwoDots from "@/components/TwoDots";
  196. import userSidebar from "@/components/user/userSidebar.vue";
  197. import elementSelectWithIndex from "@/components/newComponent/form/ElementSelectWithIndex.vue";
  198. import elementCountryCodeSelect from "@/components/newComponent/form/ElementCountryCodeSelect.vue";
  199. import loading from "@/components/newComponent/loading/loading.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. loading,
  216. },
  217. data() {
  218. return {
  219. countryList: [],
  220. genderOptions: ["Mr.", "Ms."],
  221. successUpdate: false,
  222. fileTooBig: false,
  223. firstName: "",
  224. lastName: "",
  225. countryCode: "",
  226. userData: {},
  227. yearOptions: [],
  228. monthOptions: [],
  229. dayOptions: [],
  230. countryOptions: [],
  231. yearSelect: "",
  232. monthSelect: "",
  233. daySelect: "",
  234. languageSelect: {
  235. en: "",
  236. zhtw: "",
  237. },
  238. isCropImageDialogActive: false,
  239. cropImagePreview: "",
  240. translateOption: {
  241. countrySelectorLabel: this.$t("country code"),
  242. phoneNumberLabel: this.$t("phone number"),
  243. },
  244. rules: {
  245. require: (value) => !!value || this.$t("Required."),
  246. email: (v) =>
  247. /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(
  248. v
  249. ) || this.$t("Invalid email"),
  250. checkPassword: (v) =>
  251. (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) &&
  252. v.length >= 8 &&
  253. v.length <= 20) ||
  254. this.$t(
  255. "Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter"
  256. ),
  257. },
  258. phoneValid: false,
  259. validation: {
  260. Title: true,
  261. FirstName: true,
  262. LastName: true,
  263. Email: true,
  264. yearSelect: true,
  265. monthSelect: true,
  266. daySelect: true,
  267. CountryID: true,
  268. codeSelect: true,
  269. PhoneNo: true,
  270. },
  271. errors: null,
  272. userPic: {},
  273. payload:[],
  274. dialCode:"",
  275. test:[],
  276. codeSelect: "",
  277. error: false,
  278. isPageLoading: false,
  279. value: "0",
  280. };
  281. },
  282. created() {
  283. this.isPageLoading = true;
  284. this.fetchCountry();
  285. this.$store.dispatch("updatePicture");
  286. this.fetchUserData();
  287. this.isPageLoading = false;
  288. },
  289. mounted() {
  290. this.yearOptions = Array.from(new Array(103), (val, index) =>
  291. (index + 1920).toString()
  292. );
  293. this.monthOptions = Array.from(new Array(13), (val, index) => {
  294. if (index < 10 && index > 0) {
  295. return "0" + index.toString();
  296. }
  297. if (index >= 10) {
  298. return index.toString();
  299. }
  300. });
  301. this.dayOptions = Array.from(new Array(32), (val, index) => {
  302. if (index < 10 && index > 0) {
  303. return "0" + index.toString();
  304. }
  305. if (index >= 10) {
  306. return index.toString();
  307. }
  308. });
  309. this.$nextTick(() => {
  310. window.addEventListener("resize", this.onResize);
  311. });
  312. },
  313. methods: {
  314. getReturnCode(code){
  315. this.userData.PhoneCode = code;
  316. },
  317. getPhoneData(phoneData) {
  318. this.countryCode = phoneData.countryCode;
  319. //this.userData.PhoneCode = phoneData.countryCallingCode;
  320. this.phoneValid = phoneData.isValid;
  321. },
  322. //Save Member Info
  323. patchUserData() {
  324. this.validators();
  325. if(this.validators()){
  326. if(this.$vuetify.breakpoint.name !== "xs"){
  327. this.userData.BirthDate = this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  328. if(this.userData.BirthDate.length < 10){
  329. this.userData.BirthDate = null;
  330. }
  331. }
  332. if(this.languageSelect.en == true){
  333. this.userData.LanguageID = "en-US";
  334. }else if(this.languageSelect.zhtw == true){
  335. this.userData.LanguageID = "zh-TW";
  336. }else{
  337. this.userData.LanguageID = "null";
  338. }
  339. const patchData = JSON.parse(JSON.stringify(this.userData));
  340. this.$axios
  341. .post(
  342. `/trending/api/Members/Member`, patchData
  343. )
  344. .then((response) => {
  345. //console.log(JSON.stringify(response));
  346. if (response.status == 200) {
  347. this.$notify({
  348. type: "success",
  349. text: "更新成功",
  350. });
  351. }
  352. this.fetchUserData();
  353. this.$auth.$storage.setUniversal("userPicture", patchData.MemberPicture);
  354. this.$store.dispatch("updatePicture");
  355. })
  356. .catch((error) => {
  357. console.log(error);
  358. });
  359. }
  360. },
  361. //Get Member Info
  362. fetchUserData() {
  363. this.$axios
  364. .get(
  365. `/trending/api/Members/Info`
  366. )
  367. .then((response) => {
  368. //console.log(response);
  369. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  370. let data = response.data.DATA.rel
  371. if(data){
  372. this.userData = data;
  373. if(this.userData.CountryID == null){
  374. this.userData.CountryID = "0";
  375. }
  376. if(this.userData.Title == null){
  377. this.userData.Title = "0";
  378. }
  379. if(this.userData.PhoneCode == null){
  380. this.userData.PhoneCode = "0";
  381. }
  382. if(this.userData.BirthDate == null){
  383. this.yearSelect = "0";
  384. this.monthSelect = "0";
  385. this.daySelect = "0";
  386. }
  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. //
  424. getNewPicture(e) {
  425. this.payload = new FormData();
  426. this.payload.append("file", e.target.files[0]);
  427. const path = URL.createObjectURL(e.target.files[0]);
  428. this.cropImagePreview = path ;
  429. this.isCropImageDialogActive = !this.isCropImageDialogActive;
  430. },
  431. userPictureUpload(e) {
  432. //const fileSize = (e.target.files[0].size / 1024 / 1024).toFixed(1);
  433. this.$axios
  434. .post(
  435. `/trending/api/Members/UploadAvatar`, this.payload
  436. )
  437. .then((response) => {
  438. //console.log(JSON.stringify(response))
  439. if(response && response.data){
  440. this.isCropImageDialogActive = !this.isCropImageDialogActive;
  441. this.fetchUserData();
  442. this.$notify({
  443. type: "success",
  444. text: "更新成功",
  445. });
  446. }
  447. })
  448. .catch((error) => {
  449. console.log(error);
  450. });
  451. },
  452. fetchCountry() {
  453. this.$axios
  454. .get(`/trending/api/location/countries?RegionID&Lang=${this.$i18n.localeProperties["langQuery"]}`)
  455. .then((response) => {
  456. //console.log(JSON.stringify(response));
  457. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  458. let data = response.data.DATA.rel
  459. if(data){
  460. this.countryList = data;
  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. if(this.userData.PhoneCode == "999"){
  519. this.validation.codeSelect = false;
  520. }else{
  521. this.validation.codeSelect = true;
  522. }
  523. if (this.userData.Phone == null
  524. ) {
  525. this.validation.PhoneNo = false;
  526. this.error = true;
  527. } else {
  528. this.validation.PhoneNo = true;
  529. this.error = false;
  530. }
  531. this.errors = Object.entries(this.validation).filter(
  532. (e) => e[1] == false
  533. );
  534. if (this.errors.length > 0) {
  535. return false;
  536. } else {
  537. return true;
  538. }
  539. },
  540. },
  541. };
  542. </script>
  543. <style scoped lang="scss" scoped>
  544. select {
  545. background-image: url("~/assets/svg/dropdownarrow.svg");
  546. width: auto;
  547. height: auto;
  548. background-position: right 12px center;
  549. background-repeat: no-repeat;
  550. }
  551. .success-alert {
  552. position: absolute;
  553. left: 13%;
  554. z-index: 10;
  555. top: -3%;
  556. }
  557. .success-alert-dialog {
  558. position: absolute;
  559. left: 13%;
  560. z-index: 10;
  561. top: 3%;
  562. }
  563. :deep() {
  564. .input-tel__input {
  565. height: 44px;
  566. border: 1px solid #e5e5e5;
  567. }
  568. }
  569. </style>