form.vue 6.6 KB

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