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.

239 lines
6.8 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
  1. <template>
  2. <modal name="edit-contact-modal" width="100%" :clickToClose="false">
  3. <div class="tw-p-[30px] md:tw-p-0 tw-h-full tw-overflow-auto">
  4. <div
  5. class="modal-header tw-flex tw-justify-start tw-items-center tw-mb-[20px] md:tw-mb-[50px] xl:tw-justify-between">
  6. <div class="tw-text-[18px] tw-font-bold tw-leading-[26px] md:tw-text-[20px]">
  7. {{ $t("userProfile.editContactInfo") }}
  8. </div>
  9. <button class="close tw-transition tw-btn-md" @click="$modal.hide('edit-contact-modal')"></button>
  10. </div>
  11. {{ formData }}
  12. <div
  13. class="modal-content tw-grid tw-grid-cols-1 tw-gap-y-[20px] tw-mb-[30px] md:tw-grid-cols-2 md:tw-gap-x-[64px] md:tw-mb-[60px]">
  14. <div class="element">
  15. <elementInput :input="{
  16. id: 'FirstName',
  17. label: 'userProfile.firstName',
  18. required: true,
  19. type: 'text',
  20. }" :default="formData.FirstName" :validation="validation.FirstName" @change="formData.FirstName = $event">
  21. </elementInput>
  22. </div>
  23. <div class="element">
  24. <elementInput :input="{
  25. id: 'LastName',
  26. label: 'userProfile.lastName',
  27. required: true,
  28. type: 'text',
  29. }" :default="formData.LastName" :validation="validation.LastName" @change="formData.LastName = $event">
  30. </elementInput>
  31. </div>
  32. <div class="element">
  33. <elementInput :input="{
  34. id: 'Email',
  35. label: 'Email',
  36. required: true,
  37. type: 'email',
  38. }" :default="formData.Email" :validation="validation.Email" @change="formData.Email = $event">
  39. </elementInput>
  40. </div>
  41. <div class="element">
  42. <label class="tw-block tw-mb-[10px]"><span>{{ $t("Phone") }}<span class="required">*</span></span></label>
  43. <vue-country-code
  44. class="d-none"
  45. enabledCountryCode
  46. :enabledFlags="false"
  47. @onSelect="showCode"
  48. v-model="formData.PhoneCountryCode"
  49. ></vue-country-code>
  50. <vue-phone-number-input
  51. color="#e5e5e5"
  52. :border-radius="5"
  53. error-color="#ef5a5a"
  54. valid-color="#e5e5e5"
  55. :error="error"
  56. required
  57. no-flags
  58. no-example
  59. :validation="validation.PhoneNo"
  60. v-model="formData.PhoneNo"
  61. ></vue-phone-number-input>
  62. </div>
  63. </div>
  64. <div class="modal-footer md:tw-flex md:tw-justify-start md:tw-items-center md:tw-flex-row-reverse">
  65. <button
  66. class="tw-transition tw-text-[18px] tw-btn-md tw-bg-primary-1 tw-w-full tw-mb-[10px] md:tw-mb-0 md:tw-w-fit md:tw-px-[30px] tw-py-[9.5px] tw-rounded-2xl hover:tw-bg-primary-2"
  67. @click="save">
  68. {{ $t("userProfile.save") }}
  69. </button>
  70. <button
  71. class="tw-transition tw-text-[18px] tw-btn-md tw-text-primary-1 tw-w-full md:tw-w-fit md:tw-px-[30px] tw-py-[9.5px] tw-mr-[10px] tw-rounded-2xl"
  72. @click="reset">
  73. {{ $t("Clear") }}
  74. </button>
  75. </div>
  76. </div>
  77. </modal>
  78. </template>
  79. <script>
  80. import elementInput from "@/components/newComponent/form/ElementInput";
  81. import Swal from "sweetalert2";
  82. import is from "is_js";
  83. export default {
  84. name: "EditContactModal",
  85. components: {
  86. elementInput,
  87. },
  88. props: {
  89. contact: {
  90. type: Object,
  91. },
  92. },
  93. data() {
  94. return {
  95. formData: {},
  96. isValid: false,
  97. countryCode: "",
  98. phoneValid: false,
  99. validation: {
  100. FirstName: true,
  101. LastName: true,
  102. Email: true,
  103. PhoneNo: true,
  104. },
  105. errors: null,
  106. error: false,
  107. };
  108. },
  109. mounted() { },
  110. watch: {
  111. contact: {
  112. handler: function () {
  113. this.formData = JSON.parse(JSON.stringify(this.contact));
  114. },
  115. },
  116. },
  117. methods: {
  118. reset() {
  119. this.formData = {
  120. FirstName: "",
  121. LastName: "",
  122. Email: "",
  123. PhoneNo: "",
  124. };
  125. // (this.isValid = false),
  126. // (this.PhoneCountryCode = ""),
  127. // (this.phoneValid = false);
  128. },
  129. getPhoneData(phoneData) {
  130. this.formData.PhoneCountryCode = phoneData.countryCode;
  131. },
  132. showCode(object) {
  133. this.formData.PhoneCountryCode = object.dialCode;
  134. },
  135. validators() {
  136. if (is.empty(this.formData.FirstName)) {
  137. this.validation.FirstName = false;
  138. } else {
  139. this.validation.FirstName = true;
  140. }
  141. if (is.empty(this.formData.LastName)) {
  142. this.validation.LastName = false;
  143. } else {
  144. this.validation.LastName = true;
  145. }
  146. if (is.empty(this.formData.Email) || is.not.email(this.formData.Email)) {
  147. this.validation.Email = false;
  148. } else {
  149. this.validation.Email = true;
  150. }
  151. if (is.empty(this.formData.PhoneNo)
  152. ) {
  153. this.validation.PhoneNo = false;
  154. this.error = true;
  155. } else {
  156. this.validation.PhoneNo = true;
  157. this.error = false;
  158. }
  159. this.errors = Object.entries(this.validation).filter(
  160. (e) => e[1] == false
  161. );
  162. if (this.errors.length > 0) {
  163. return false;
  164. } else {
  165. return true;
  166. }
  167. },
  168. save() {
  169. this.validators();
  170. if (this.validators()) {
  171. const patchData = JSON.parse(JSON.stringify(this.formData));
  172. this.$axios
  173. .post(
  174. `/trending/api/Members/Contact`, patchData
  175. )
  176. .then((response) => {
  177. console.log(JSON.stringify(response));
  178. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  179. let data = response.data.DATA.rel
  180. if(data){
  181. console.log("儲存成功");
  182. this.$emit("update", true);
  183. this.$modal.hide("edit-contact-modal");
  184. }
  185. }
  186. })
  187. .catch((error) => {
  188. console.log(error);
  189. });
  190. }
  191. },
  192. },
  193. };
  194. </script>
  195. <style lang="scss" scoped>
  196. .close {
  197. position: absolute;
  198. right: 30px;
  199. top: 32px;
  200. background-image: url("~/assets/svg/close.svg");
  201. background-position: center;
  202. background-repeat: no-repeat;
  203. background-size: cover;
  204. width: 14px;
  205. height: 14px;
  206. @media screen and (min-width: 768px) {
  207. right: 40px;
  208. top: 40px;
  209. }
  210. }
  211. .v--modal-overlay::v-deep {
  212. .v--modal {
  213. width: 100% !important;
  214. height: 100vh !important;
  215. @media screen and (min-width: 768px) {
  216. padding: 40px;
  217. width: max-content;
  218. height: max-content !important;
  219. border-radius: 30px;
  220. }
  221. }
  222. .v--modal-box {
  223. height: 100vh !important;
  224. overflow: auto;
  225. @media screen and (min-width: 768px) {
  226. padding: 40px;
  227. width: max-content;
  228. height: max-content !important;
  229. }
  230. }
  231. }
  232. </style>