Panel.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div class="panel-container">
  3. <el-button class="panel-button" @click="showPanel = !showPanel" type="primary" circle>
  4. <i :class="showPanel ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
  5. </el-button>
  6. <el-card class="panel" :class="{ 'panel-open': showPanel }">
  7. <div slot="header" class="header-title">
  8. <p>Get in touch with a TrustyPay expert</p>
  9. <p>We're eager to help you succeed with <br>our range of solutions.</p>
  10. </div>
  11. <el-form :model="form" :rules="rules" ref="contactForm" label-width="120px" label-position="top">
  12. <el-form-item label="Name" prop="name">
  13. <el-input v-model="form.name" prop="name" ></el-input>
  14. </el-form-item>
  15. <el-form-item label="Business Name" prop="businessName">
  16. <el-input v-model="form.businessName"></el-input>
  17. </el-form-item>
  18. <el-form-item label="Mobile(10 digits)" prop="mobile">
  19. <el-input v-model="form.mobile"></el-input>
  20. </el-form-item>
  21. <el-form-item label="Email" prop="email">
  22. <el-input v-model="form.email"></el-input>
  23. </el-form-item>
  24. <el-form-item label="Language Preference" prop="language">
  25. <el-select v-model="form.language" placeholder="Select Language">
  26. <el-option label="English" value="English"></el-option>
  27. <el-option label="中文" value="中文"></el-option>
  28. <el-option label="한국" value="한국"></el-option>
  29. <el-option label="हिंदी" value="हिंदी"></el-option>
  30. <el-option label="Ελληνικά" value="Ελληνικά"></el-option>
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="Your message" prop="message">
  34. <el-input type="text" v-model="form.message"></el-input>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button type="primary" @click="submitForm('contactForm')" class="sbuBtn" :loading="isLoading">Submit</el-button>
  38. </el-form-item>
  39. </el-form>
  40. </el-card>
  41. </div>
  42. </template>
  43. <script>
  44. import { elIsEmail, elIsValidatePhone } from "@/utils/el-validate";
  45. import { send as emailSend } from "@emailjs/browser";
  46. import { emailConfig } from "@/utils/config"
  47. import { SEND_COUNT_KEY, isSameDay } from "@/utils";
  48. import { Store } from "@/utils/store";
  49. export default {
  50. data() {
  51. return {
  52. showPanel: true,
  53. isLoading:false,
  54. form: {
  55. name: '',
  56. businessName: '',
  57. mobile: '',
  58. email: '',
  59. language: '',
  60. message: '',
  61. },
  62. rules: {
  63. name: [
  64. {
  65. required: true,
  66. message: 'Please enter your name',
  67. trigger: 'blur'
  68. }],
  69. businessName: [
  70. {
  71. required: true,
  72. message: 'Please enter your business name',
  73. trigger: 'blur'
  74. }],
  75. mobile: [
  76. {
  77. required: true,
  78. trigger: ["blur"],
  79. validator: elIsValidatePhone
  80. }],
  81. email: [
  82. {
  83. required: true,
  84. trigger: ["blur"],
  85. validator: elIsEmail
  86. },
  87. ],
  88. },
  89. }
  90. },
  91. methods: {
  92. submitForm(formName) {
  93. const store = new Store();
  94. const localStorageData = store.get(SEND_COUNT_KEY, {
  95. time: Date.now(),
  96. count: 0,
  97. });
  98. // 判断是否同一天
  99. if (isSameDay(localStorageData.time, new Date().getTime())) {
  100. // 同一天 超过3次 则不允许提交
  101. if (localStorageData.count >= 3) {
  102. this.$alert(
  103. "You have reached the maximum number of submissions!",
  104. "",
  105. {
  106. callback: (action) => {},
  107. }
  108. );
  109. return;
  110. }
  111. }
  112. this.$refs[formName].validate(async (valid) => {
  113. if (valid) {
  114. try {
  115. this.isLoading = true;
  116. const data = await emailSend(
  117. emailConfig.SERVICE_ID,
  118. emailConfig.TEMPLATE_ID,
  119. {
  120. name: this.form.name,
  121. businessName: this.form.businessName,
  122. mobile: this.form.mobile,
  123. email: this.form.email,
  124. languagePreference: this.form.language,
  125. message: this.form.message,
  126. }
  127. );
  128. this.isLoading = false;
  129. if (data.status === 200) {
  130. this.$alert( "Thank you for contacting us. We’ll get in touch with you in the next 24 hours", '',
  131. {
  132. callback: action => {
  133. this.$refs[formName].resetFields();
  134. }
  135. });
  136. // 发送成功后,保存发送次数
  137. store.save(SEND_COUNT_KEY, {
  138. time: Date.now(),
  139. count:
  140. localStorageData.count + 1 >= 4
  141. ? 1
  142. : localStorageData.count + 1,
  143. });1213
  144. } else {
  145. window.alert("Form submitted failed!");
  146. }
  147. } catch (error) {
  148. console.log("Error submitting form!", error);
  149. }
  150. } else {
  151. this.isLoading=false;
  152. console.log("Error submitting form!");
  153. return false;
  154. }
  155. });
  156. }
  157. }
  158. }
  159. </script>
  160. <style scoped>
  161. .el-card{
  162. background: #9bc943;
  163. }
  164. .panel-container {
  165. position: fixed;
  166. bottom: 60px;
  167. right: 20px;
  168. z-index: 1000;
  169. }
  170. .panel-button {
  171. position: absolute;
  172. bottom: 0;
  173. right: 0;
  174. z-index: 999;
  175. }
  176. .panel {
  177. width: auto;
  178. max-height: 0;
  179. overflow: hidden;
  180. transition: max-height 0.3s ease;
  181. }
  182. .panel-open {
  183. max-height: 7090px;
  184. }
  185. .header-title{
  186. p{
  187. margin: 0;
  188. font-size: 16px;
  189. text-align: center;
  190. }
  191. }
  192. /* 去掉显示的底部 */
  193. .el-card{
  194. border: none;
  195. }
  196. /* 设置按钮的大小 */
  197. .el-button.is-circle{
  198. width: 70px;
  199. height: 70px;
  200. margin-bottom: -25px;
  201. }
  202. .el-form-item {
  203. margin-bottom: 0;
  204. }
  205. /deep/.el-form--label-top .el-form-item__label{
  206. padding-bottom: 0px;
  207. }
  208. .el-form-item__label{
  209. line-height: normal;
  210. }
  211. .el-select{
  212. display: initial;
  213. }
  214. .sbuBtn{
  215. margin: 15px 120px;
  216. }
  217. </style>