register.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <div class="register-page">
  3. <custom-header :name="'注册' + pageName" bgColor="#E6F2FF"></custom-header>
  4. <div class="content">
  5. <Form @submit="onSubmit" required="auto" label-width="74px" ref="formRef">
  6. <div class="card">
  7. <div class="card-title">
  8. <img src="@/assets/img/mine/label-icon.png" alt="" />
  9. <span>基本信息</span>
  10. </div>
  11. <div class="form">
  12. <field
  13. v-model="formData.name"
  14. label="姓名"
  15. :rules="[{ required: true, message: '请输入姓名' }]"
  16. placeholder="请输入姓名"
  17. />
  18. <field
  19. v-model="formData.tel"
  20. type="tel"
  21. name="tel"
  22. label="联系电话"
  23. :rules="[{ required: true, validator: validatorTel, message: '请输入电话号码' }]"
  24. placeholder="请输入电话号码"
  25. />
  26. <field
  27. v-show="pageType === 'NZ'"
  28. v-model="formData.subjectName"
  29. label="主体名称"
  30. placeholder="请输入主体名称"
  31. />
  32. <template v-if="pageType === 'EXPERT'">
  33. <field
  34. label-width="130px"
  35. readonly
  36. v-model="number"
  37. label="服务过的果园数量"
  38. placeholder="点击选择服务数量"
  39. >
  40. <template #input>
  41. <el-dropdown trigger="click">
  42. <div class="el-dropdown-link-text">
  43. {{ number }}
  44. <el-icon class="el-icon--right">
  45. <CaretBottom />
  46. </el-icon>
  47. </div>
  48. <template #dropdown>
  49. <el-dropdown-menu class="v-dropdown-menu">
  50. <el-dropdown-item
  51. v-for="(item, index) in numberList"
  52. :key="index"
  53. :class="{ active: numberActive === index }"
  54. @click="handleNumberDropdown(item, index)"
  55. >{{ item }}</el-dropdown-item
  56. >
  57. </el-dropdown-menu>
  58. </template>
  59. </el-dropdown>
  60. </template>
  61. </field>
  62. <field
  63. label-width="130px"
  64. readonly
  65. v-model="year"
  66. label="从事种植指导年数"
  67. placeholder="点击选择指导年数"
  68. >
  69. <template #input>
  70. <el-dropdown trigger="click">
  71. <div class="el-dropdown-link-text">
  72. {{ year }}
  73. <el-icon class="el-icon--right">
  74. <CaretBottom />
  75. </el-icon>
  76. </div>
  77. <template #dropdown>
  78. <el-dropdown-menu class="v-dropdown-menu">
  79. <el-dropdown-item
  80. v-for="(item, index) in yearList"
  81. :key="index"
  82. :class="{ active: yearActive === index }"
  83. @click="handleYearDropdown(item, index)"
  84. >{{ item }}</el-dropdown-item
  85. >
  86. </el-dropdown-menu>
  87. </template>
  88. </el-dropdown>
  89. </template>
  90. </field>
  91. </template>
  92. <div class="flex" v-else>
  93. <field v-model="formData.address" label="服务区域" readonly placeholder="默认位置" />
  94. <el-dropdown trigger="click">
  95. <div class="el-dropdown-link">
  96. {{ dropdownName }}
  97. <el-icon class="el-icon--right">
  98. <CaretBottom />
  99. </el-icon>
  100. </div>
  101. <template #dropdown>
  102. <el-dropdown-menu class="v-dropdown-menu">
  103. <el-dropdown-item
  104. v-for="(item, index) in dropdownList"
  105. :key="index"
  106. :class="{ active: active === index }"
  107. @click="handleDropdown(item, index)"
  108. >{{ item }}</el-dropdown-item
  109. >
  110. </el-dropdown-menu>
  111. </template>
  112. </el-dropdown>
  113. </div>
  114. <upload v-show="pageType === 'NZ'" exampleImg :maxCount="1" class="upload-wrap" @handleUpload="handleUploadSuccess">
  115. <div class="upload-btn">
  116. 点击上传营业执照
  117. </div>
  118. </upload>
  119. </div>
  120. </div>
  121. <div class="card" v-if="pageType == 'EXPERT'">
  122. <div class="card-title">
  123. <img src="@/assets/img/mine/label-icon.png" alt="" />
  124. <span>个人简介</span>
  125. </div>
  126. <div class="form">
  127. <el-input v-model="input" :rows="5" type="textarea" placeholder="描述:" />
  128. </div>
  129. </div>
  130. <template v-else>
  131. <ServiceInfo
  132. v-model:crops="crops"
  133. v-model:serviceTypes="serviceTypes"
  134. v-model:machines="machines"
  135. v-model:isEdit="isEdit"
  136. />
  137. </template>
  138. <Button class="button" round block type="primary" native-type="submit"> 提交 </Button>
  139. </Form>
  140. </div>
  141. </div>
  142. </template>
  143. <script setup>
  144. import customHeader from "@/components/customHeader.vue";
  145. import { Field, Form, Button } from "vant";
  146. import { onActivated, ref } from "vue";
  147. import { useRoute, useRouter } from "vue-router";
  148. import { ElMessage } from "element-plus";
  149. import upload from "@/components/upload";
  150. import ServiceInfo from "@/components/pageComponents/ServiceInfo.vue";
  151. const route = useRoute();
  152. const router = useRouter();
  153. const formRef = ref(null);
  154. const formData = ref({
  155. name: "",
  156. tel: "",
  157. subjectName: "",
  158. point: "",
  159. serviceCropsJson: [],
  160. agriculturalEquipmentJson: [],
  161. licenseImg: [],
  162. });
  163. const validatorTel = (val) => {
  164. const phoneRegex = /^1[3-9]\d{9}$/;
  165. if (!phoneRegex.test(val)) return "请输入正确的电话号码";
  166. };
  167. const onSubmit = () => {
  168. formData.value.point = "POINT(113.1093017627431 22.574540836684672)";
  169. if (pageType.value === "NZ" && !formData.value.licenseImg) {
  170. ElMessage.warning("请上传营业执照");
  171. return;
  172. }
  173. VE_API.mine.register(formData.value).then(res =>{
  174. if(res.code===0){
  175. ElMessage.success('注册成功,待审核')
  176. router.push('/mine')
  177. }else{
  178. ElMessage.success('注册失败')
  179. }
  180. })
  181. };
  182. const resetForm = () => {
  183. formRef.value.resetValidation();
  184. };
  185. const number = ref("请选择");
  186. const numberList = ["请选择", "10", "20", "30", "40"];
  187. const numberActive = ref(0);
  188. const handleNumberDropdown = (item, index) => {
  189. number.value = item;
  190. numberActive.value = index;
  191. };
  192. const year = ref("请选择");
  193. const yearList = ["请选择", "10", "20", "30", "40"];
  194. const yearActive = ref(0);
  195. const handleYearDropdown = (item, index) => {
  196. year.value = item;
  197. yearActive.value = index;
  198. };
  199. const dropdownList = ["周边20公里", "飞防类", "技术类", "劳力类", "机械类"];
  200. const active = ref(0);
  201. const dropdownName = ref("周边20公里");
  202. const handleDropdown = (item, index) => {
  203. dropdownName.value = item;
  204. active.value = index;
  205. };
  206. const input = ref("");
  207. const pageName = ref("");
  208. const pageType = ref("");
  209. const identityTyepe = {
  210. EXPERT: "专家",
  211. NZ: "农资",
  212. };
  213. // NF: "农服",
  214. // 服务信息数据,转换为 ServiceInfo 组件需要的格式
  215. const isEdit = ref(true); // 默认编辑状态
  216. const crops = ref([
  217. { name: "荔枝", isSelf: 0 },
  218. { name: "龙眼", isSelf: 1 }
  219. ]);
  220. const serviceTypes = ref([
  221. { name: "播种", isSelf: 1 },
  222. { name: "收获", isSelf: 0 }
  223. ]);
  224. const machines = ref([
  225. { name: "收割机", isSelf: 1 },
  226. { name: "灌溉机", isSelf: 0 }
  227. ]);
  228. const handleUploadSuccess = (data) => {
  229. formData.value.licenseImg = data.imgArr[0];
  230. };
  231. onActivated(() => {
  232. pageName.value = identityTyepe[route.query.identity];
  233. pageType.value = route.query.identity;
  234. formData.value = {};
  235. resetForm();
  236. });
  237. </script>
  238. <style lang="scss" scoped>
  239. .register-page {
  240. width: 100%;
  241. height: 100vh;
  242. background-color: #f5f7fb;
  243. ::v-deep{
  244. .main-content {
  245. margin: 12px 0;
  246. }
  247. }
  248. .content {
  249. height: calc(100% - 40px);
  250. padding: 12px;
  251. overflow: auto;
  252. box-sizing: border-box;
  253. background: linear-gradient(180deg, #e6f2ff 0%, #8fc5fe 100%);
  254. .card {
  255. background: #fff;
  256. border-radius: 12px;
  257. padding: 15px 12px;
  258. box-sizing: border-box;
  259. .card-title {
  260. display: flex;
  261. align-items: center;
  262. margin-bottom: 10px;
  263. font-size: 18px;
  264. img {
  265. width: 14px;
  266. height: 8px;
  267. margin-right: 6px;
  268. }
  269. }
  270. .form {
  271. .van-cell {
  272. background: #f5f5f5;
  273. border-radius: 8px;
  274. ::v-deep {
  275. .van-field__label {
  276. color: #666666;
  277. border-right: 1px solid #dddddd;
  278. }
  279. }
  280. }
  281. .van-cell + .van-cell {
  282. margin-top: 12px;
  283. }
  284. .btn {
  285. width: 92%;
  286. color: #2199f8;
  287. font-size: 16px;
  288. border-radius: 8px;
  289. text-align: center;
  290. padding: 12px;
  291. margin-top: 12px;
  292. border: 1px solid #2199f8;
  293. }
  294. .el-dropdown-link-text {
  295. color: #2199f8;
  296. display: flex;
  297. align-items: center;
  298. }
  299. .flex {
  300. display: flex;
  301. align-items: center;
  302. margin-top: 12px;
  303. .el-dropdown-link {
  304. display: flex;
  305. align-items: center;
  306. justify-content: center;
  307. color: #2199f8;
  308. width: 100px;
  309. font-size: 12px;
  310. padding: 14px 0;
  311. border-radius: 8px;
  312. border: 1px solid rgba(33, 153, 248, 0.2);
  313. background: #fff;
  314. margin-left: 5px;
  315. }
  316. }
  317. .el-icon--right {
  318. margin-left: 4px;
  319. }
  320. .upload-btn {
  321. color: #2199f8;
  322. font-size: 16px;
  323. padding: 12px 0;
  324. text-align: center;
  325. width: 170px;
  326. border-radius: 8px;
  327. border: 1px solid #2199f8;
  328. background: #fff;
  329. }
  330. .upload-wrap{
  331. margin-top: 12px;
  332. }
  333. }
  334. }
  335. .card + .card {
  336. margin-top: 12px;
  337. }
  338. .card-footer {
  339. display: flex;
  340. align-items: center;
  341. justify-content: space-between;
  342. font-size: 16px;
  343. .tips {
  344. position: relative;
  345. &::before {
  346. content: "*";
  347. position: absolute;
  348. top: 0;
  349. right: -1px;
  350. color: #ff0000;
  351. font-weight: bold;
  352. }
  353. }
  354. .btn {
  355. color: #fff;
  356. background: #2199f8;
  357. border-radius: 8px;
  358. padding: 5px 37px;
  359. text-align: center;
  360. font-size: 14px;
  361. }
  362. }
  363. .button {
  364. border-radius: 8px;
  365. font-size: 18px;
  366. padding: 10px;
  367. text-align: center;
  368. background: #2199f8;
  369. color: #fff;
  370. margin-top: 12px;
  371. border: none;
  372. }
  373. }
  374. }
  375. </style>
  376. <style lang="scss">
  377. .v-dropdown-menu {
  378. .active {
  379. color: #2199f8;
  380. }
  381. }
  382. .image-preview {
  383. position: fixed;
  384. top: 0;
  385. left: 0;
  386. right: 0;
  387. bottom: 0;
  388. background: rgba(0, 0, 0, 0.8);
  389. display: flex;
  390. align-items: center;
  391. justify-content: center;
  392. z-index: 1000;
  393. }
  394. .image-preview img {
  395. max-width: 90%;
  396. max-height: 90%;
  397. object-fit: contain;
  398. }
  399. </style>