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.

280 lines
8.3 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
  1. <template>
  2. <modal name="addCompany" :clickToClose="false">
  3. <div class="tw-text-base-primary">
  4. <div class="modal-header tw-w-full tw-mb-[20px] md:tw-mb-[50px]">
  5. <div class="tw-text-[18px] tw-font-bold md:tw-text-[20px]">
  6. {{ $t("userProfile.addCompanyInfo") }}
  7. </div>
  8. <button class="close tw-transition tw-btn-md" @click="$modal.hide('addCompany')"></button>
  9. </div>
  10. <div
  11. class="modal-content tw-grid tw-grid-cols-1 tw-gap-y-[20px] tw-mb-[30px] md:tw-grid-cols-[260px_260px] md:tw-gap-x-[64px] md:tw-mb-[60px]">
  12. <div class="element">
  13. <elementInput :input="{
  14. id: 'CompanyName',
  15. label: 'userProfile.companyName',
  16. required: true,
  17. type: 'text',
  18. }" :default="userCompany.CompanyName" :validation="validation.CompanyName"
  19. @change="userCompany.CompanyName = $event"></elementInput>
  20. </div>
  21. <div class="element">
  22. <elementInput :input="{
  23. id: 'TaxNumber',
  24. label: 'userProfile.taxNumber',
  25. required: true,
  26. type: 'tel',
  27. }" :default="userCompany.TaxNumber" :validation="validation.TaxNumber"
  28. @change="userCompany.TaxNumber = $event"></elementInput>
  29. </div>
  30. <div class="element md:tw-col-span-2">
  31. <elementAddress :input="{
  32. id: 'StreetAddress',
  33. label: 'userProfile.companyAddress',
  34. required: true,
  35. type: 'street',
  36. }" :default1="userCompany.Street1" :default2="userCompany.Street2"
  37. :validation1="validation.Street1" :validation2="validation.Street2"
  38. @change1="userCompany.Street1 = $event" @change2="userCompany.Street2 = $event">
  39. </elementAddress>
  40. </div>
  41. <div class="element">
  42. <elementInput :input="{
  43. id: 'City',
  44. label: 'userProfile.companyCity',
  45. required: true,
  46. type: 'text',
  47. }" :default="userCompany.CityName" :validation="validation.CityName"
  48. @change="userCompany.CityName = $event"></elementInput>
  49. </div>
  50. <div class="element">
  51. <elementInput :input="{
  52. id: 'State',
  53. label: 'userProfile.stateAndProvince',
  54. required: false,
  55. type: 'text',
  56. }" :default="userCompany.StateName" :validation="validation.StateName"
  57. @change="userCompany.StateName = $event"></elementInput>
  58. </div>
  59. <div class="element">
  60. <elementSelect :select="{
  61. id: 'Country',
  62. label: 'userProfile.companyCountry',
  63. required: true,
  64. }" :selectList="countryOptions" :default="userCompany.CountryID"
  65. :validation="validation.CountryID" @change="userCompany.CountryID = $event"></elementSelect>
  66. </div>
  67. <div class="element">
  68. <elementInput :input="{
  69. id: 'ZIP',
  70. label: 'userProfile.zipAndPostalCode',
  71. required: true,
  72. type: 'zip',
  73. }" :default="userCompany.ZipCode" :validation="validation.ZipCode"
  74. @change="userCompany.ZipCode = $event"></elementInput>
  75. </div>
  76. </div>
  77. <div class="md:tw-flex md:tw-flex-row-reverse">
  78. <button
  79. class="tw-transition tw-btn-md tw-bg-primary-1 tw-text-white tw-w-full tw-py-[13px] tw-rounded-[16px] tw-mb-[10px] md:hover:tw-bg-primary-2 md:tw-w-fit md:tw-px-[24px] md:tw-mb-0"
  80. @click="save()">
  81. {{ $t("userProfile.save") }}
  82. </button>
  83. <button
  84. class="tw-transition tw-btn-md tw-bg-white tw-text-primary-1 tw-w-full tw-py-[13px] tw-rounded-[16px] md:tw-w-fit md:tw-px-[24px] md:tw-mr-[10px]"
  85. @click="reset()">
  86. {{ $t('userProfile.cancel')}}
  87. </button>
  88. </div>
  89. </div>
  90. </modal>
  91. </template>
  92. <script>
  93. import elementInput from "@/components/newComponent/form/ElementInput.vue";
  94. import elementAddress from "@/components/newComponent/form/ElementAddress.vue";
  95. import elementSelect from "@/components/newComponent/form/ElementSelect.vue";
  96. import is from "is_js";
  97. export default {
  98. name: "addCompany",
  99. props: {
  100. countryOptions: {
  101. type: Array,
  102. },
  103. selectList: {
  104. type: Array,
  105. },
  106. },
  107. data() {
  108. return {
  109. userCompany: {
  110. CompanyName: "",
  111. TaxNumber: "",
  112. Street1: "",
  113. Street2: "",
  114. CityName: "",
  115. StateName: "",
  116. CountryID: "",
  117. ZipCode: "",
  118. },
  119. validation: {
  120. CompanyName: true,
  121. TaxNumber: true,
  122. Street1: true,
  123. Street2: true,
  124. CityName: true,
  125. StateName: true,
  126. CountryID: true,
  127. ZipCode: true,
  128. },
  129. // valid: false,
  130. errors: null,
  131. };
  132. },
  133. components: {
  134. elementInput,
  135. elementAddress,
  136. elementSelect,
  137. is,
  138. },
  139. methods: {
  140. reset() {
  141. this.userCompany = {
  142. CompanyName: "",
  143. TaxNumber: "",
  144. Street1: "",
  145. Street2: "",
  146. CityName: "",
  147. StateName: "",
  148. CountryID: "",
  149. ZipCode: "",
  150. };
  151. this.$modal.hide("addCompany");
  152. },
  153. patchUserData() {
  154. this.$axios
  155. .post(`/trending/api/Members/Company`, this.userCompany)
  156. .then((response) => {
  157. //console.log(JSON.stringify(response));
  158. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  159. let data = response.data.DATA.rel
  160. if(data){
  161. this.$emit("refetch-user");
  162. this.$modal.hide("addCompany");
  163. }
  164. }
  165. })
  166. .catch((error) => {
  167. console.log(error);
  168. });
  169. },
  170. validators() {
  171. if (is.empty(this.userCompany.CompanyName)) {
  172. this.validation.CompanyName = false;
  173. } else {
  174. this.validation.CompanyName = true;
  175. }
  176. if (is.empty(this.userCompany.TaxNumber)) {
  177. this.validation.TaxNumber = false;
  178. } else {
  179. this.validation.TaxNumber = true;
  180. }
  181. if (is.empty(this.userCompany.Street1)) {
  182. this.validation.Street1 = false;
  183. } else {
  184. this.validation.Street1 = true;
  185. }
  186. if (is.empty(this.userCompany.CityName)) {
  187. this.validation.CityName = false;
  188. } else {
  189. this.validation.CityName = true;
  190. }
  191. if (this.userCompany.CountryID == "") {
  192. this.validation.CountryID = false;
  193. } else {
  194. this.validation.CountryID = true;
  195. }
  196. if (is.empty(this.userCompany.ZipCode)) {
  197. this.validation.ZipCode = false;
  198. } else {
  199. this.validation.ZipCode = true;
  200. }
  201. this.errors = Object.entries(this.validation).filter(
  202. (e) => e[1] == false
  203. );
  204. if (this.errors.length > 0) {
  205. return false;
  206. } else {
  207. return true;
  208. }
  209. },
  210. save() {
  211. this.validators();
  212. if (this.validators()) {
  213. const patchData = this.userCompany;
  214. this.$axios
  215. .post(`/trending/api/Members/Company`, patchData)
  216. .then((response) => {
  217. //console.log(JSON.stringify(response));
  218. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  219. let data = response.data.DATA.rel
  220. if(data){
  221. this.$emit("refetch-user");
  222. this.reset();
  223. this.$modal.hide("addCompany");
  224. }
  225. }
  226. })
  227. .catch((error) => {
  228. console.log(error);
  229. });
  230. }
  231. },
  232. },
  233. };
  234. </script>
  235. <style scoped lang="scss">
  236. .close {
  237. position: absolute;
  238. right: 30px;
  239. top: 30px;
  240. background-image: url("~/assets/svg/close.svg");
  241. background-position: center;
  242. background-repeat: no-repeat;
  243. background-size: cover;
  244. width: 14px;
  245. height: 14px;
  246. @media screen and (min-width: 768px) {
  247. right: 40px;
  248. top: 40px;
  249. }
  250. }
  251. .v--modal-overlay::v-deep {
  252. .v--modal {
  253. padding: 30px;
  254. width: 100% !important;
  255. height: 100vh !important;
  256. @media screen and (min-width: 768px) {
  257. padding: 40px;
  258. width: max-content;
  259. height: max-content !important;
  260. border-radius: 30px;
  261. }
  262. }
  263. .v--modal-box {
  264. height: 100vh !important;
  265. overflow: auto;
  266. @media screen and (min-width: 768px) {
  267. padding: 40px;
  268. width: max-content;
  269. height: max-content !important;
  270. }
  271. }
  272. }
  273. </style>