register.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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 ref="uploadRef" 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. ref="serviceInfoRef"
  137. />
  138. </template>
  139. <Button class="button" round block type="primary" native-type="submit"> 提交 </Button>
  140. </Form>
  141. </div>
  142. </div>
  143. </template>
  144. <script setup>
  145. import customHeader from "@/components/customHeader.vue";
  146. import { Field, Form, Button } from "vant";
  147. import { onActivated, onDeactivated, ref } from "vue";
  148. import { useRoute, useRouter } from "vue-router";
  149. import { ElMessage } from "element-plus";
  150. import upload from "@/components/upload";
  151. import ServiceInfo from "@/components/pageComponents/ServiceInfo.vue";
  152. const route = useRoute();
  153. const router = useRouter();
  154. const uploadRef = ref(null);
  155. const serviceInfoRef = ref(null);
  156. const formRef = ref(null);
  157. const formData = ref({
  158. name: "",
  159. tel: "",
  160. subjectName: "",
  161. point: "",
  162. serviceCropsJson: [],
  163. agriculturalEquipmentJson: [],
  164. licenseImg: [],
  165. });
  166. const validatorTel = (val) => {
  167. const phoneRegex = /^1[3-9]\d{9}$/;
  168. if (!phoneRegex.test(val)) return "请输入正确的电话号码";
  169. };
  170. const onSubmit = () => {
  171. formData.value.point = "POINT(113.1093017627431 22.574540836684672)";
  172. if (pageType.value === "NZ" && !formData.value.licenseImg) {
  173. ElMessage.warning("请上传营业执照");
  174. return;
  175. }
  176. const {serviceCropsJson, serviceTypeJson, agriculturalEquipmentJson} = serviceInfoRef.value.getServiceInfo();
  177. const params = {
  178. ...formData.value,
  179. serviceCropsJson,
  180. serviceTypeJson,
  181. agriculturalEquipmentJson,
  182. }
  183. VE_API.mine.register(params).then(res =>{
  184. if(res.code===0){
  185. ElMessage.success('注册成功,待审核')
  186. router.push('/mine')
  187. }else{
  188. ElMessage.success('注册失败')
  189. }
  190. })
  191. };
  192. const resetForm = () => {
  193. formRef.value.resetValidation();
  194. };
  195. const number = ref("请选择");
  196. const numberList = ["请选择", "10", "20", "30", "40"];
  197. const numberActive = ref(0);
  198. const handleNumberDropdown = (item, index) => {
  199. number.value = item;
  200. numberActive.value = index;
  201. };
  202. const year = ref("请选择");
  203. const yearList = ["请选择", "10", "20", "30", "40"];
  204. const yearActive = ref(0);
  205. const handleYearDropdown = (item, index) => {
  206. year.value = item;
  207. yearActive.value = index;
  208. };
  209. const dropdownList = ["周边20公里", "周边10公里", "周边5公里"];
  210. const active = ref(0);
  211. const dropdownName = ref("周边20公里");
  212. const handleDropdown = (item, index) => {
  213. dropdownName.value = item;
  214. active.value = index;
  215. };
  216. const input = ref("");
  217. const pageName = ref("");
  218. const pageType = ref("");
  219. const identityTyepe = {
  220. EXPERT: "专家",
  221. NZ: "农资",
  222. };
  223. // NF: "农服",
  224. // 服务信息数据,转换为 ServiceInfo 组件需要的格式
  225. const isEdit = ref(true); // 默认编辑状态
  226. const crops = ref([
  227. { name: "荔枝", isSelf: 0 },
  228. { name: "水稻", isSelf: 0 },
  229. { name: "菠萝", isSelf: 0 },
  230. { name: "柚子", isSelf: 0 },
  231. { name: "蔬菜", isSelf: 0 },
  232. { name: "小麦", isSelf: 0 },
  233. ]);
  234. const serviceTypes = ref([
  235. { name: "嫁接", isSelf: 0 },
  236. { name: "施肥打药", isSelf: 0 },
  237. { name: "修剪", isSelf: 0 },
  238. ]);
  239. const machines = ref([
  240. { name: "植保机", isSelf: 0 },
  241. { name: "喷药车", isSelf: 0 },
  242. { name: "收割机", isSelf: 0 }
  243. ]);
  244. const handleUploadSuccess = (data) => {
  245. formData.value.licenseImg = data.imgArr[0];
  246. };
  247. onActivated(() => {
  248. pageName.value = identityTyepe[route.query.identity];
  249. pageType.value = route.query.identity;
  250. formData.value = {};
  251. resetForm();
  252. });
  253. onDeactivated(() => {
  254. // 重置 ServiceInfo 组件的选中状态
  255. crops.value.forEach(item => {
  256. item.selected = false;
  257. });
  258. serviceTypes.value.forEach(item => {
  259. item.selected = false;
  260. });
  261. machines.value.forEach(item => {
  262. item.selected = false;
  263. });
  264. uploadRef.value && uploadRef.value.uploadReset();
  265. });
  266. </script>
  267. <style lang="scss" scoped>
  268. .register-page {
  269. width: 100%;
  270. height: 100vh;
  271. background-color: #f5f7fb;
  272. ::v-deep{
  273. .main-content {
  274. margin: 12px 0;
  275. }
  276. }
  277. .content {
  278. height: calc(100% - 40px);
  279. padding: 12px;
  280. overflow: auto;
  281. box-sizing: border-box;
  282. background: linear-gradient(180deg, #e6f2ff 0%, #8fc5fe 100%);
  283. .card {
  284. background: #fff;
  285. border-radius: 12px;
  286. padding: 15px 12px;
  287. box-sizing: border-box;
  288. .card-title {
  289. display: flex;
  290. align-items: center;
  291. margin-bottom: 10px;
  292. font-size: 18px;
  293. img {
  294. width: 14px;
  295. height: 8px;
  296. margin-right: 6px;
  297. }
  298. }
  299. .form {
  300. .van-cell {
  301. background: #f5f5f5;
  302. border-radius: 8px;
  303. ::v-deep {
  304. .van-field__label {
  305. color: #666666;
  306. border-right: 1px solid #dddddd;
  307. }
  308. }
  309. }
  310. .van-cell + .van-cell {
  311. margin-top: 12px;
  312. }
  313. .btn {
  314. width: 92%;
  315. color: #2199f8;
  316. font-size: 16px;
  317. border-radius: 8px;
  318. text-align: center;
  319. padding: 12px;
  320. margin-top: 12px;
  321. border: 1px solid #2199f8;
  322. }
  323. .el-dropdown-link-text {
  324. color: #2199f8;
  325. display: flex;
  326. align-items: center;
  327. }
  328. .flex {
  329. display: flex;
  330. align-items: center;
  331. margin-top: 12px;
  332. .el-dropdown-link {
  333. display: flex;
  334. align-items: center;
  335. justify-content: center;
  336. color: #2199f8;
  337. width: 100px;
  338. font-size: 12px;
  339. padding: 14px 0;
  340. border-radius: 8px;
  341. border: 1px solid rgba(33, 153, 248, 0.2);
  342. background: #fff;
  343. margin-left: 5px;
  344. }
  345. }
  346. .el-icon--right {
  347. margin-left: 4px;
  348. }
  349. .upload-btn {
  350. color: #2199f8;
  351. font-size: 16px;
  352. padding: 12px 0;
  353. text-align: center;
  354. width: 170px;
  355. border-radius: 8px;
  356. border: 1px solid #2199f8;
  357. background: #fff;
  358. }
  359. .upload-wrap{
  360. margin-top: 12px;
  361. }
  362. }
  363. }
  364. .card + .card {
  365. margin-top: 12px;
  366. }
  367. .card-footer {
  368. display: flex;
  369. align-items: center;
  370. justify-content: space-between;
  371. font-size: 16px;
  372. .tips {
  373. position: relative;
  374. &::before {
  375. content: "*";
  376. position: absolute;
  377. top: 0;
  378. right: -1px;
  379. color: #ff0000;
  380. font-weight: bold;
  381. }
  382. }
  383. .btn {
  384. color: #fff;
  385. background: #2199f8;
  386. border-radius: 8px;
  387. padding: 5px 37px;
  388. text-align: center;
  389. font-size: 14px;
  390. }
  391. }
  392. .button {
  393. border-radius: 8px;
  394. font-size: 18px;
  395. padding: 10px;
  396. text-align: center;
  397. background: #2199f8;
  398. color: #fff;
  399. margin-top: 12px;
  400. border: none;
  401. }
  402. }
  403. }
  404. </style>
  405. <style lang="scss">
  406. .v-dropdown-menu {
  407. .active {
  408. color: #2199f8;
  409. }
  410. }
  411. .image-preview {
  412. position: fixed;
  413. top: 0;
  414. left: 0;
  415. right: 0;
  416. bottom: 0;
  417. background: rgba(0, 0, 0, 0.8);
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. z-index: 1000;
  422. }
  423. .image-preview img {
  424. max-width: 90%;
  425. max-height: 90%;
  426. object-fit: contain;
  427. }
  428. </style>