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.

255 lines
7.6 KiB

2 years ago
  1. <template>
  2. <modal name="add-modal" width="100%" :clickToClose="false">
  3. <div class="tw-p-[40px]">
  4. <div
  5. class="modal-header tw-flex tw-justify-center tw-items-center tw-mb-[40px] md:tw-mb-[40px] xl:tw-justify-between">
  6. <div class="tw-text-[20px] tw-font-bold tw-leading-[26px]">
  7. {{ $t("Add Company Info") }}
  8. </div>
  9. <button class="close tw-transition tw-btn-md" @click="$modal.hide('add-modal')"></button>
  10. </div>
  11. <div class="modal-content tw-grid tw-grid-cols-1 tw-gap-y-[10px] md:tw-grid-cols-2 md:tw-gap-x-[60px]">
  12. <div class="element">
  13. <elementInput :input="{
  14. id: 'CompanyName',
  15. label: 'Company Name',
  16. required: true,
  17. type: 'text',
  18. }" :default="formData.company_name" :validation="validation.company_name"
  19. @change="formData.company_name = $event"></elementInput>
  20. </div>
  21. <div class="element">
  22. <elementInput :input="{
  23. id: 'TaxNumber',
  24. label: 'Tax Number',
  25. required: true,
  26. type: 'tel',
  27. }" :default="formData.company_tax_no" :validation="validation.company_tax_no"
  28. @change="formData.company_tax_no = $event"></elementInput>
  29. </div>
  30. <div class="element md:tw-col-span-2">
  31. <elementAddress :input="{
  32. id: 'StreetAddress',
  33. label: 'Street address',
  34. required: true,
  35. type: 'street',
  36. }" :default1="formData.company_address1" :default2="formData.company_address2"
  37. :validation1="validation.company_address1" :validation2="validation.company_address2"
  38. @change1="formData.company_address1 = $event" @change2="formData.company_address2 = $event">
  39. </elementAddress>
  40. </div>
  41. <div class="element">
  42. <elementInput :input="{
  43. id: 'City',
  44. label: 'City',
  45. required: true,
  46. type: 'text',
  47. }" :default="formData.company_city" :validation="validation.company_city"
  48. @change="formData.company_city = $event"></elementInput>
  49. </div>
  50. <div class="element">
  51. <elementInput :input="{
  52. id: 'State',
  53. label: 'State/Province',
  54. required: false,
  55. type: 'text',
  56. }" :default="formData.company_state" :validation="validation.company_state"
  57. @change="formData.company_state = $event"></elementInput>
  58. </div>
  59. <div class="element">
  60. <elementSelect :select="{
  61. id: 'Country',
  62. label: 'Country',
  63. required: true,
  64. }" :selectList="selectList" :default="formData.company_country" :validation="validation.company_country"
  65. @change="formData.company_country = $event"></elementSelect>
  66. </div>
  67. <div class="element">
  68. <elementInput :input="{
  69. id: 'ZIP',
  70. label: 'ZIP/Postal code',
  71. required: true,
  72. type: 'zip',
  73. }" :default="formData.company_zipcode" :validation="validation.company_zipcode"
  74. @change="formData.company_zipcode = $event"></elementInput>
  75. </div>
  76. </div>
  77. <div class="modal-footer tw-flex tw-justify-end tw-items-center tw-mt-[60px]">
  78. <button class="tw-transition tw-btn-md tw-text-primary-1 tw-px-[30px] tw-py-[9.5px] tw-mr-[10px] tw-rounded-2xl"
  79. @click="reset">
  80. {{ $t("Clear") }}
  81. </button>
  82. <button
  83. class="tw-transition tw-btn-md tw-bg-primary-1 tw-px-[30px] tw-py-[9.5px] tw-rounded-2xl hover:tw-bg-primary-2"
  84. @click="save">
  85. {{ $t("Save") }}
  86. </button>
  87. </div>
  88. </div>
  89. </modal>
  90. </template>
  91. <script>
  92. import elementInput from "@/components/newComponent/form/ElementInput";
  93. import elementSelect from "@/components/newComponent/form/ElementSelect";
  94. import elementAddress from "@/components/newComponent/form/ElementAddress";
  95. import is from "is_js";
  96. export default {
  97. name: "AddCompanyModal",
  98. components: {
  99. elementInput,
  100. elementSelect,
  101. elementAddress,
  102. is,
  103. },
  104. props: {
  105. selectList: {
  106. type: Array,
  107. },
  108. },
  109. data() {
  110. return {
  111. formData: {
  112. company_state: "",
  113. company_zipcode: "",
  114. company_tax_no: "",
  115. company_address1: "",
  116. company_city: "",
  117. company_country: 0,
  118. company_name: "",
  119. company_address2: "",
  120. },
  121. validation: {
  122. company_state: true,
  123. company_zipcode: true,
  124. company_tax_no: true,
  125. company_address1: true,
  126. company_city: true,
  127. company_country: true,
  128. company_name: true,
  129. company_address2: true,
  130. },
  131. errors: null,
  132. };
  133. },
  134. mounted() {},
  135. methods: {
  136. reset() {
  137. this.formData = {
  138. company_state: "",
  139. company_zipcode: "",
  140. company_tax_no: "",
  141. company_address1: "",
  142. company_city: "",
  143. company_country: 0,
  144. company_name: "",
  145. company_address2: "",
  146. company_country_name: "",
  147. };
  148. },
  149. save() {
  150. this.validators();
  151. if (this.validators()) {
  152. const patchData = JSON.parse(JSON.stringify(this.formData));
  153. this.$axios
  154. .post(
  155. `/member/company?jwt=${
  156. this.$auth.$storage.getUniversal("jwt").token
  157. }`,
  158. patchData
  159. )
  160. .then((result) => {
  161. if (result.status == 200) {
  162. this.$emit("update", true);
  163. this.reset();
  164. this.$modal.hide("add-modal");
  165. }
  166. })
  167. .catch((err) => {
  168. console.log(err);
  169. });
  170. }
  171. },
  172. validators() {
  173. if (is.empty(this.formData.company_name)) {
  174. this.validation.company_name = false;
  175. } else {
  176. this.validation.company_name = true;
  177. }
  178. if (is.empty(this.formData.company_tax_no)) {
  179. this.validation.company_tax_no = false;
  180. } else {
  181. this.validation.company_tax_no = true;
  182. }
  183. if (is.empty(this.formData.company_address1)) {
  184. this.validation.company_address1 = false;
  185. } else {
  186. this.validation.company_address1 = true;
  187. }
  188. if (is.empty(this.formData.company_city)) {
  189. this.validation.company_city = false;
  190. } else {
  191. this.validation.company_city = true;
  192. }
  193. if (this.formData.company_country == 0) {
  194. this.validation.company_country = false;
  195. } else {
  196. this.validation.company_country = true;
  197. }
  198. if (is.empty(this.formData.company_zipcode)) {
  199. this.validation.company_zipcode = false;
  200. } else {
  201. this.validation.company_zipcode = true;
  202. }
  203. this.errors = Object.entries(this.validation).filter(
  204. (e) => e[1] == false
  205. );
  206. if (this.errors.length > 0) {
  207. return false;
  208. } else {
  209. return true;
  210. }
  211. },
  212. },
  213. };
  214. </script>
  215. <style lang="scss" scoped>
  216. .close {
  217. position: absolute;
  218. right: 25px;
  219. top: 25px;
  220. background-image: url("~/assets/svg/close.svg");
  221. background-position: center;
  222. background-repeat: no-repeat;
  223. background-size: cover;
  224. width: 14px;
  225. height: 14px;
  226. @media screen and (min-width: 1366px) {
  227. position: relative;
  228. right: initial;
  229. top: initial;
  230. }
  231. }
  232. :deep() {
  233. .v--modal-box {
  234. height: 100vh !important;
  235. @media screen and (min-width: 768px) {
  236. height: max-content !important;
  237. width: max-content;
  238. }
  239. }
  240. .v--modal {
  241. height: 100vh !important;
  242. @media screen and (min-width: 768px) {
  243. height: max-content !important;
  244. width: max-content;
  245. }
  246. }
  247. }
  248. </style>