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.

454 lines
16 KiB

2 years ago
  1. <template>
  2. <div class="companyInfo 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-mb-[20px] tw-font-bold tw-text-base-primary md:t24 md:tw-mb-[30px]">
  9. <two-dots class="tw-mr-[30px]"></two-dots>{{ $t('userProfile.companyInfo')}}
  10. </div>
  11. <div v-if="userCompanyList.length < 1" class="tw-flex tw-flex-col tw-mb-[50px] tw-mt-[80px] md:tw-mb-[30px]">
  12. <img src="~/assets/svg/noCompanyInfo.svg" class="tw-max-w-[160px] tw-mx-auto md:tw-max-w-[210px]" alt="" />
  13. <div class="tw-text-[16px] tw-text-neutrals-800 tw-w-fit tw-mx-auto md:tw-text-[18px]">
  14. {{ $t("No Company info yet ...") }}
  15. </div>
  16. </div>
  17. <div v-else class="tw-mb-[20px] xl:tw-mb-[30px]">
  18. <!-- 手機版 -->
  19. <div v-for="(item, index) in userCompanyList" :key="`mobile-${index}`"
  20. class="tw-flex tw-justify-between tw-w-full tw-bg-white tw-border tw-border-solid tw-py-[15px] tw-px-[15px] tw-rounded-[10px] tw-border-neutrals-200 xl:tw-px-0 tw-mb-[20px] last:tw-mb-0 md:tw-mb-[30px] xl:tw-hidden">
  21. <div>
  22. <div class="tw-pb-[6px] tw-body-4 tw-text-base-primary tw-font-medium">
  23. {{ item.company_tax_no }}
  24. </div>
  25. <div class="tw-pb-[6px] tw-text-[14px] tw-font-medium tw-text-base-primary">
  26. {{ item.company_name }}
  27. </div>
  28. <div class="tw-pb-[6px] tw-body-4 tw-text-base-primary tw-font-medium">
  29. {{
  30. countrySortOptions[item.company_country] +
  31. "." +
  32. item.company_city
  33. }}
  34. </div>
  35. <div class="tw-text-[14px] tw-text-neutrals-700">
  36. {{ item.company_address1 + item.company_address2 }}
  37. </div>
  38. </div>
  39. <div class="tw-flex tw-flex-col md:tw-flex-row tw-my-auto xl:tw-hidden">
  40. <button @click="activeEditCompanyInfoDialog(item)" type="button">
  41. <img src="~/assets/svg/edit.svg" alt=""
  42. class="tw-h-[28px] tw-w-[28px] tw-mb-[20px] md:tw-mb-0 md:tw-mr-[15px]" />
  43. </button>
  44. <button @click="deleteUserCompany(item)" type="button">
  45. <img src="~/assets/svg/delete.svg" alt="" class="tw-h-[28px] tw-w-[28px]" />
  46. </button>
  47. </div>
  48. </div>
  49. <!-- 電腦版 -->
  50. <div class="xl:tw-grid tw-gap-[15px] tw-grid-cols-[148px_116px_86px_110px_220px] tw-hidden tw-mb-[30px]">
  51. <div class="tw-text-neutrals-500 tw-body-4">
  52. {{ $t("userProfile.companyName") }}
  53. </div>
  54. <div class="tw-text-neutrals-500 tw-body-4">
  55. {{ $t("userProfile.taxNumber") }}
  56. </div>
  57. <div class="tw-text-neutrals-500 tw-body-4">
  58. {{ $t("userProfile.companyCountry") }}
  59. </div>
  60. <div class="tw-text-neutrals-500 tw-body-4">{{ $t("userProfile.companyCity") }}</div>
  61. <div class="tw-text-neutrals-500 tw-body-4">
  62. {{ $t("userProfile.companyAddress") }}
  63. </div>
  64. </div>
  65. <div v-for="(item, index) in userCompanyList" :key="index"
  66. class="tw-hidden tw-bg-white tw-mb-[20px] last:tw-mb-0 md:tw-mb-[30px] xl:tw-block">
  67. <div class="tw-flex tw-flex-row">
  68. <div class="xl:tw-grid tw-gap-[15px] tw-grid-cols-[148px_116px_86px_110px_220px] tw-mr-[15px]">
  69. <div>{{ item.company_name }}</div>
  70. <div>{{ item.company_tax_no }}</div>
  71. <div>{{ countrySortOptions[item.company_country] }}</div>
  72. <div>{{ item.company_city }}</div>
  73. <div>{{ item.company_address1 + item.company_address2 }}</div>
  74. </div>
  75. <div>
  76. <button @click="activeEditCompanyInfoDialog(item)" type="button">
  77. <img src="~/assets/svg/edit.svg" alt="" class="tw-h-[28px] tw-w-[28px] tw-mr-[20px]" />
  78. </button>
  79. <button @click="deleteUserCompany(item)" type="button">
  80. <img src="~/assets/svg/delete.svg" alt="" class="tw-h-[28px] tw-w-[28px]" />
  81. </button>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. <button
  87. class="tw-grid tw-grid-cols-[18px_auto] tw-gap-[6px] tw-bg-complementary-1 tw-bg-opacity-10 tw-px-[12px] tw-py-[11px] tw-rounded-[10px] tw-mx-auto tw-mb-[30px] xl:tw-mb-0">
  88. <img src="~/assets/svg/addCompany.svg" alt="" />
  89. <div class="tw-text-[14px] tw-font-medium tw-text-complementary-1" @click="$modal.show('addCompany')">
  90. {{ $t("userProfile.addNewCompany") }}
  91. </div>
  92. </button>
  93. <!-- <v-card
  94. class="mx-7 mb-5 py-3 pe-5 ps-3 border-radius-10"
  95. v-for="(item, index) in userCompanyList"
  96. :key="index"
  97. color="neutrals"
  98. >
  99. <v-spacer class="d-flex">
  100. <v-spacer class="px-3">
  101. <div>{{ item.company_tax_no }}</div>
  102. <div>{{ item.company_name }}</div>
  103. <div class="d-flex align-center">
  104. <span>{{ countrySortOptions[item.company_country] }}</span>
  105. <div class="circle-delimeter mx-1"></div>
  106. <span>{{ item.company_city }}</span>
  107. </div>
  108. <div>
  109. <span v-if="item.company_address1">{{
  110. item.company_address1
  111. }}</span>
  112. <span v-if="item.company_address2 && !item.company_address1">{{
  113. item.company_address2
  114. }}</span>
  115. </div>
  116. </v-spacer>
  117. <div class="d-flex align-center">
  118. <v-btn
  119. @click="activeEditCompanyInfoDialog(item)"
  120. class="d-flex justify-center"
  121. icon
  122. >
  123. <unicon name="pen" height="20px" fill="neutrals-darken5" />
  124. </v-btn>
  125. <v-btn @click="deleteUserCompany(item)" icon>
  126. <unicon
  127. name="trash-alt"
  128. height="20px"
  129. fill="neutrals-darken5"
  130. />
  131. </v-btn>
  132. </div>
  133. </v-spacer>
  134. </v-card>
  135. <v-spacer class="d-flex justify-center mb-15">
  136. <v-btn
  137. @click="$modal.show('addCompany')"
  138. color="primary border-radius-12 text-capitalize"
  139. width="150px"
  140. >
  141. <v-icon>mdi-plus</v-icon>
  142. <span>{{ $t("userProfile.addNewCompany") }}</span>
  143. </v-btn>
  144. </v-spacer>
  145. <v-spacer class="mb-4"></v-spacer> -->
  146. <CompanyEditInfoDialog :companyEditInfoDialogActive="companyEditDialogActive" :userCompany="propUserCompany"
  147. :countryOptions="countryOptions" :user_uuid="user_uuid" @refetch-company="getCompanyList"
  148. @refetch-user="fetchUserData" @close-edit-dialog="
  149. companyEditDialogActive = !companyEditDialogActive
  150. "></CompanyEditInfoDialog>
  151. <CompanyAddNewDialog :companyAddNewDialogActive="companyAddNewDialogActive" :countryOptions="countryOptions"
  152. :addNewCompanyList="userAddNewCompanyList" :user_uuid="user_uuid" @refetch-company="getCompanyList"
  153. @refetch-user="fetchUserData" @close-add-new-dialog="
  154. companyAddNewDialogActive = !companyAddNewDialogActive
  155. "></CompanyAddNewDialog>
  156. <CompanyDeleteDialog :deleteCompanyInfoDialogAcitve="companyDeleteDialogAcitve" :companyData="propUserCompany"
  157. @refetch-company="getCompanyList" @refetch-user="fetchUserData" @closeCompanyDeleteDialog="
  158. companyDeleteDialogAcitve = !companyDeleteDialogAcitve
  159. "></CompanyDeleteDialog>
  160. </div>
  161. </div>
  162. </div>
  163. </template>
  164. <script>
  165. import TwoDots from "@/components/TwoDots";
  166. import CompanyDeleteDialog from "../../components/user/companyDeleteDialog.vue";
  167. import CompanyEditInfoDialog from "../../components/user/companyEditInfoDialog.vue";
  168. import CompanyAddNewDialog from "../../components/user/companyAddNewDialog.vue";
  169. import jwt_decode from "jwt-decode";
  170. import userSidebar from "@/components/user/userSidebar.vue";
  171. export default {
  172. name: "companyInfo",
  173. layout: "profile",
  174. components: {
  175. TwoDots,
  176. CompanyDeleteDialog,
  177. CompanyEditInfoDialog,
  178. CompanyAddNewDialog,
  179. userSidebar,
  180. },
  181. data() {
  182. return {
  183. firstName: "",
  184. lastName: "",
  185. userData: {},
  186. userCompanyId: [],
  187. userCompanyList: [],
  188. userAddNewCompanyList: [],
  189. userSavedExhibitionList: [],
  190. userVisibleSavedExhibitionList: [],
  191. userSavedExhibitionPageLength: 0,
  192. yearOptions: [],
  193. monthOptions: [],
  194. dayOptions: [],
  195. countryOptions: [],
  196. countrySortOptions: [],
  197. yearSelect: "",
  198. monthSelect: "",
  199. daySelect: "",
  200. phoneValid: false,
  201. companyEditDialogActive: false,
  202. companyAddNewDialogActive: false,
  203. companyDeleteDialogAcitve: false,
  204. propUserCompany: {},
  205. countryOptions: [],
  206. user_uuid: "",
  207. emptyImage: require("~/assets/img/companyEmpty.png"),
  208. userCompanyList: [],
  209. userAddNewCompanyList: [],
  210. companyTableColumns: [
  211. {
  212. text: "Company Name",
  213. value: "company_name",
  214. sortable: false,
  215. width: "16%",
  216. },
  217. {
  218. text: "Tax Number",
  219. value: "company_tax_no",
  220. sortable: false,
  221. width: "16%",
  222. },
  223. {
  224. text: "Country",
  225. value: "company_country",
  226. sortable: false,
  227. width: "10%",
  228. },
  229. {
  230. text: "City",
  231. value: "company_city",
  232. sortable: false,
  233. width: "12%",
  234. },
  235. {
  236. text: "Address",
  237. value: "company_address",
  238. sortable: false,
  239. width: "39%",
  240. },
  241. {
  242. text: "",
  243. value: "action",
  244. sortable: false,
  245. width: "7%",
  246. },
  247. ],
  248. };
  249. },
  250. created() {
  251. // this.fetchUserData();
  252. // this.fetchSortCountry();
  253. // this.getCompanyList();
  254. // this.fetchCountry();
  255. if (this.$auth.$storage.getUniversal("jwt")) {
  256. const jsonPayload = jwt_decode(
  257. this.$auth.$storage.getUniversal("jwt").token
  258. );
  259. this.user_uuid = JSON.parse(jsonPayload.ueid);
  260. }
  261. },
  262. mounted() {
  263. this.yearOptions = Array.from(new Array(103), (val, index) =>
  264. (index + 1920).toString()
  265. );
  266. this.monthOptions = Array.from(new Array(13), (val, index) => {
  267. if (index < 10 && index > 0) {
  268. return "0" + index.toString();
  269. }
  270. if (index >= 10) {
  271. return index.toString();
  272. }
  273. });
  274. this.dayOptions = Array.from(new Array(32), (val, index) => {
  275. if (index < 10 && index > 0) {
  276. return "0" + index.toString();
  277. }
  278. if (index >= 10) {
  279. return index.toString();
  280. }
  281. });
  282. this.$nextTick(() => {
  283. window.addEventListener("resize", this.onResize);
  284. });
  285. },
  286. methods: {
  287. fetchSortCountry() {
  288. this.$axios
  289. .get(
  290. `t/exhibitions/locations?lang=${this.$i18n.locale.replace(
  291. "-",
  292. ""
  293. )}&sort=False`
  294. )
  295. .then((res) => {
  296. this.countrySortOptions = res.data.country_name_list;
  297. })
  298. .catch((err) => {
  299. console.log(err);
  300. });
  301. },
  302. patchUserData() {
  303. if (this.width < 1366) {
  304. this.isEditInfoDialogActive = !this.isEditInfoDialogActive;
  305. }
  306. this.userData.prefer_country = JSON.stringify(this.languageSelect);
  307. if (this.$vuetify.breakpoint.name !== "xs") {
  308. this.userData.birth_date =
  309. this.yearSelect + "-" + this.monthSelect + "-" + this.daySelect;
  310. if (this.userData.birth_date.length < 10) {
  311. this.userData.birth_date = null;
  312. }
  313. }
  314. const patchData = JSON.parse(JSON.stringify(this.userData));
  315. delete patchData.LoginLog;
  316. delete patchData.UserCompany;
  317. delete patchData.UserSocialRelation;
  318. delete patchData.UserExhibition;
  319. this.$axios
  320. .put(
  321. `/member/users/${this.$auth.$storage.getUniversal("jwt").user_id
  322. }?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""}`,
  323. patchData
  324. )
  325. .then((res) => {
  326. this.successUpdate = !this.successUpdate;
  327. setTimeout(() => {
  328. this.successUpdate = !this.successUpdate;
  329. }, 1000);
  330. this.fetchUserData();
  331. this.$auth.$storage.setUniversal("userPicture", patchData.picture);
  332. this.$auth.$storage.setUniversal("userLastName", patchData.last_name);
  333. this.$store.dispatch("updatePicture");
  334. })
  335. .catch((err) => {
  336. console.log(err);
  337. });
  338. },
  339. fetchUserData() {
  340. this.$axios
  341. .get(
  342. `/member/users/${this.$auth.$storage.getUniversal("jwt").user_id
  343. }?jwt=${this.$auth.$storage.getUniversal("jwt").token}`
  344. )
  345. .then((res) => {
  346. this.userData = res.data;
  347. this.userCompanyId = res.data.UserCompany;
  348. this.firstName = res.data.first_name;
  349. this.lastName = res.data.last_name;
  350. this.userData.phone
  351. ? (this.phoneValid = true)
  352. : (this.phoneValid = false);
  353. !this.userData.prefer_country &&
  354. typeof this.userData.prefer_country === "object"
  355. ? this.userData.prefer_country
  356. : (this.languageSelect = JSON.parse(this.userData.prefer_country));
  357. if (
  358. !this.userData.birth_date &&
  359. typeof this.userData.birth_date === "object"
  360. ) {
  361. this.yearSelect = "";
  362. this.monthSelect = "";
  363. this.daySelect = "";
  364. } else {
  365. const date = this.userData.birth_date.split("-");
  366. this.yearSelect = date[0];
  367. this.monthSelect = date[1];
  368. this.daySelect = date[2];
  369. }
  370. })
  371. .catch((err) => {
  372. console.log(err);
  373. });
  374. },
  375. logout() {
  376. this.$auth.$storage.removeUniversal("jwt");
  377. this.$auth.$storage.removeUniversal("userPicture");
  378. this.$auth.$storage.removeUniversal("userLastName");
  379. this.$auth.$storage.removeUniversal("userBeforePath");
  380. if (window.innerWidth < 1024) {
  381. this.$router.push(this.localePath("/"));
  382. } else {
  383. this.$router.push(this.localePath("/user"));
  384. }
  385. this.$auth.logout();
  386. },
  387. handleImageUpdate(pictureURL) {
  388. this.userData.picture = pictureURL;
  389. this.patchUserData();
  390. this.closeCropDialog();
  391. },
  392. activeEditCompanyInfoDialog(item) {
  393. // this.companyEditDialogActive = !this.companyEditDialogActive;
  394. this.propUserCompany = { ...item };
  395. this.$modal.show("edit-company-modal");
  396. },
  397. activeAddNewCompanyInfoDialog() {
  398. this.companyAddNewDialogActive = !this.companyAddNewDialogActive;
  399. },
  400. deleteUserCompany(item) {
  401. // this.companyDeleteDialogAcitve = !this.companyDeleteDialogAcitve;
  402. this.$modal.show("delete-company-modal");
  403. this.propUserCompany = { ...item };
  404. },
  405. getCompanyList() {
  406. this.$axios
  407. .post(
  408. `/member/company/list?jwt=${this.$auth.$storage.getUniversal("jwt").token || ""
  409. }`,
  410. this.userCompanyId
  411. )
  412. .then((res) => {
  413. this.userCompanyList = res.data.company_list;
  414. this.userAddNewCompanyList = res.data.add_new_company_list;
  415. })
  416. .catch((err) => {
  417. console.log(err);
  418. });
  419. },
  420. fetchCountry() {
  421. this.$axios
  422. .get("/users/countries")
  423. .then((res) => {
  424. this.countryOptions = res.data.result;
  425. })
  426. .catch((err) => {
  427. console.log(err);
  428. });
  429. },
  430. },
  431. watch: {
  432. userCompanyId: {
  433. handler: function () {
  434. this.getCompanyList();
  435. },
  436. deep: true,
  437. },
  438. },
  439. };
  440. </script>
  441. <style scoped lang="scss">
  442. </style>