form.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <!-- @format -->
  2. <script lang="ts" setup>
  3. import type { FormInstance, FormRules } from 'element-plus'
  4. import { consultingServiceApi, getDictListApi } from '~/api/model/common'
  5. const ruleFormRef = ref<FormInstance>()
  6. const formInfo = ref<any>({
  7. name: '',
  8. mail: '',
  9. subjects: '',
  10. mobile: '',
  11. message: '',
  12. country: undefined,
  13. })
  14. const countryList = ref()
  15. const rules = ref<FormRules>({
  16. name: [
  17. {
  18. required: false,
  19. message: 'FirstName must be filled in',
  20. trigger: 'blur',
  21. },
  22. ],
  23. mail: [
  24. {
  25. required: false,
  26. message: 'email must be filled in',
  27. trigger: 'blur',
  28. },
  29. ],
  30. subjects: [
  31. {
  32. required: false,
  33. message: 'subjects must be filled in',
  34. trigger: 'blur',
  35. },
  36. ],
  37. mobile: [
  38. {
  39. required: false,
  40. message: 'mobile must be filled in',
  41. trigger: 'blur',
  42. },
  43. ],
  44. message: [
  45. {
  46. required: false,
  47. message: 'message must be filled in',
  48. trigger: 'blur',
  49. },
  50. ],
  51. country: [
  52. {
  53. required: false,
  54. message: 'country must be selected',
  55. trigger: 'change',
  56. },
  57. ],
  58. })
  59. async function submitInfo(formEl: FormInstance | undefined) {
  60. if (!formEl)
  61. return
  62. await formEl.validate(async (valid) => {
  63. if (valid) {
  64. await consultingServiceApi(formInfo.value)
  65. ElMessage.success('You have been submitted successfully!')
  66. formEl.resetFields()
  67. }
  68. else {
  69. console.log('error submit!')
  70. }
  71. })
  72. }
  73. async function getCountryList() {
  74. const list = await getDictListApi('A070')
  75. countryList.value = list
  76. }
  77. getCountryList()
  78. </script>
  79. <template>
  80. <div class="py-80px bg-#F9FAFB">
  81. <div class="w-1200-auto">
  82. <h2 class="text-36px text-center fw-800 ls-2 text-#333 custom-title-font">
  83. Submit Your Product <span class="custom-title-bg !pb-0">Needs</span>
  84. </h2>
  85. <div class="text-22px lh-40px text-#999 text-center mt-30px">
  86. 7th Floor, Tianbo International Building, 55 Jiangdong
  87. </div>
  88. <div class="text-22px lh-40px text-#999 text-center mb-60px">
  89. Middle Road, Yiwu, Zhejiang, China
  90. </div>
  91. <div class="form w-550px m-auto">
  92. <el-form
  93. ref="ruleFormRef"
  94. class="custom-form-item"
  95. :rules="rules"
  96. :model="formInfo"
  97. >
  98. <el-form-item label="Name" prop="name">
  99. <el-input
  100. v-model="formInfo.name"
  101. placeholder="Please enter your name"
  102. class="h-40px item-input !b-rd-10px"
  103. />
  104. </el-form-item>
  105. <el-form-item label="Email" prop="mail">
  106. <el-input
  107. v-model="formInfo.mail"
  108. placeholder="Please enter your email"
  109. class="h-40px item-input !b-rd-10px"
  110. />
  111. </el-form-item>
  112. <el-form-item label="Subjects" prop="subjects">
  113. <el-input
  114. v-model="formInfo.subjects"
  115. placeholder="Please enter your subjects"
  116. class="h-40px item-input !b-rd-10px"
  117. />
  118. </el-form-item>
  119. <el-form-item label="Country" prop="country" class="custom-form-item">
  120. <el-select
  121. v-model="formInfo.country"
  122. placeholder="Please enter your country"
  123. >
  124. <el-option
  125. v-for="(item, index) in countryList"
  126. :key="index"
  127. :value="item.value"
  128. :label="`${item.label}`"
  129. >
  130. {{ item.label }}
  131. </el-option>
  132. </el-select>
  133. </el-form-item>
  134. <el-form-item label="Phone number" prop="mobile">
  135. <el-input
  136. v-model="formInfo.mobile"
  137. placeholder="Please enter your Phone number"
  138. class="h-40px item-input !b-rd-10px"
  139. />
  140. </el-form-item>
  141. <el-form-item label="Message" prop="message" class="!mb-60px">
  142. <el-input
  143. v-model="formInfo.message"
  144. type="textarea"
  145. :rows="4"
  146. placeholder="Please enter information"
  147. class="!b-rd-10px"
  148. />
  149. </el-form-item>
  150. <el-form-item>
  151. <el-button
  152. class="!w-full !h-50px !text-16px !fw-500 !b-rd-300px !bg-#9B6CFF !text-#fff"
  153. @click="submitInfo(ruleFormRef)"
  154. >
  155. Submit
  156. </el-button>
  157. </el-form-item>
  158. </el-form>
  159. </div>
  160. </div>
  161. </div>
  162. </template>
  163. <style lang="less" scoped>
  164. :deep(.custom-form-item) {
  165. .el-form-item__label {
  166. margin-bottom: 10px;
  167. font-size: 16px !important;
  168. font-weight: bold;
  169. color: #333 !important;
  170. }
  171. .el-form-item {
  172. display: block !important;
  173. margin-bottom: 34px;
  174. &:last-child {
  175. margin-bottom: 0px !important;
  176. }
  177. .el-form-item__content {
  178. .el-textarea {
  179. .el-textarea__inner {
  180. height: 100px !important;
  181. }
  182. }
  183. .el-select {
  184. .el-select__wrapper {
  185. box-shadow: none !important;
  186. height: 40px !important;
  187. border-radius: 10px !important;
  188. }
  189. }
  190. .item-input {
  191. .el-input__wrapper {
  192. box-shadow: none !important;
  193. border-radius: 10px !important;
  194. }
  195. }
  196. .el-textarea {
  197. .el-textarea__inner {
  198. box-shadow: none !important;
  199. border-radius: 10px !important;
  200. }
  201. }
  202. }
  203. }
  204. }
  205. </style>