form.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 { console.log('error submit!') }
  69. })
  70. }
  71. async function getCountryList() {
  72. const list = await getDictListApi('A070')
  73. countryList.value = list
  74. }
  75. getCountryList()
  76. </script>
  77. <template>
  78. <div class="py-80px bg-#F9FAFB">
  79. <div class="w-1200-auto">
  80. <h2 class="text-36px text-center fw-800 ls-2 text-#333 custom-title-font">
  81. Submit Your Product <span class="custom-title-bg !pb-0">Needs</span>
  82. </h2>
  83. <div class="text-22px lh-40px text-#999 text-center mt-30px">
  84. 7th Floor, Tianbo International Building, 55 Jiangdong
  85. </div>
  86. <div class="text-22px lh-40px text-#999 text-center mb-60px">
  87. Middle Road, Yiwu, Zhejiang, China
  88. </div>
  89. <div class="form w-550px m-auto">
  90. <el-form
  91. ref="ruleFormRef"
  92. class="custom-form-item"
  93. :rules="rules"
  94. :model="formInfo"
  95. >
  96. <el-form-item label="Name" prop="name">
  97. <el-input
  98. v-model="formInfo.name"
  99. placeholder="Please enter your name"
  100. class="h-40px item-input !b-rd-10px"
  101. />
  102. </el-form-item>
  103. <el-form-item label="Email" prop="mail">
  104. <el-input
  105. v-model="formInfo.mail"
  106. placeholder="Please enter your email"
  107. class="h-40px item-input !b-rd-10px"
  108. />
  109. </el-form-item>
  110. <el-form-item label="Subjects" prop="subjects">
  111. <el-input
  112. v-model="formInfo.subjects"
  113. placeholder="Please enter your subjects"
  114. class="h-40px item-input !b-rd-10px"
  115. />
  116. </el-form-item>
  117. <el-form-item label="Country" prop="country" class="custom-form-item">
  118. <el-select v-model="formInfo.country" placeholder="Please enter your country">
  119. <el-option
  120. v-for="(item, index) in countryList"
  121. :key="index"
  122. :value="item.value"
  123. :label="`${item.label}`"
  124. >
  125. {{ item.label }}
  126. </el-option>
  127. </el-select>
  128. </el-form-item>
  129. <el-form-item label="Phone number" prop="mobile">
  130. <el-input
  131. v-model="formInfo.mobile"
  132. placeholder="Please enter your Phone number"
  133. class="h-40px item-input !b-rd-10px"
  134. />
  135. </el-form-item>
  136. <el-form-item label="Message" prop="message" class="!mb-60px">
  137. <el-input
  138. v-model="formInfo.message"
  139. type="textarea"
  140. :rows="4"
  141. placeholder="Please enter information"
  142. class="!b-rd-10px"
  143. />
  144. </el-form-item>
  145. <el-form-item>
  146. <el-button
  147. class="!w-full !h-50px !text-16px !fw-500 !b-rd-300px !bg-#9B6CFF !text-#fff"
  148. @click="submitInfo(ruleFormRef)"
  149. >
  150. Submit
  151. </el-button>
  152. </el-form-item>
  153. </el-form>
  154. </div>
  155. </div>
  156. </div>
  157. </template>
  158. <style lang="less" scoped>
  159. :deep(.custom-form-item) {
  160. .el-form-item__label {
  161. margin-bottom: 10px;
  162. font-size: 16px !important;
  163. font-weight: bold;
  164. color: #333 !important;
  165. }
  166. .el-form-item{
  167. display: block !important;
  168. margin-bottom: 34px;
  169. &:last-child {
  170. margin-bottom: 0px!important;
  171. }
  172. .el-form-item__content {
  173. .el-textarea {
  174. .el-textarea__inner {
  175. height: 100px !important;
  176. }
  177. }
  178. .el-select{
  179. .el-select__wrapper{
  180. box-shadow: none !important;
  181. height: 40px !important;
  182. border-radius: 10px !important;
  183. }
  184. }
  185. .item-input{
  186. .el-input__wrapper{
  187. box-shadow: none !important;
  188. border-radius: 10px !important;
  189. }
  190. }
  191. .el-textarea{
  192. .el-textarea__inner{
  193. box-shadow: none !important;
  194. border-radius: 10px !important;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. </style>