officialLogin.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="p-[30rpx] bg-[#f5f5f5]">
  3. <!-- 页面标题 -->
  4. <view class="text-[36rpx] font-bold text-[#333] text-center mb-[20rpx]">
  5. 发包方信息
  6. </view>
  7. <!-- 提示信息 -->
  8. <view class="text-[28rpx] text-[#666] text-center mb-[30rpx]">
  9. 通过上传身份证可识别姓名和身份证号码,错误请自行修改
  10. </view>
  11. <!-- 身份证上传区域 -->
  12. <view class="mb-[30rpx]">
  13. <view
  14. class="w-full h-[300rpx] bg-[#f0f7ff] rounded-[12rpx] flex flex-col items-center justify-center relative overflow-hidden">
  15. <image src="/static/avatar.png" class="w-[120rpx] h-[120rpx] rounded-full mb-[20rpx]"
  16. mode="aspectFill" />
  17. <view class="w-full p-[20rpx] text-center">
  18. <view class="text-[24rpx] text-[#666] mb-[6rpx]">姓名:<text
  19. class="text-[#333]">{{ userInfo.name || '未填写' }}</text></view>
  20. <view class="text-[24rpx] text-[#666]">公民身份证号码:<text
  21. class="text-[#333]">{{ userInfo.idCard || '未填写' }}</text></view>
  22. </view>
  23. </view>
  24. <button
  25. class="w-full h-[80rpx] bg-[#e6f7ff] text-[#007aff] text-[28rpx] rounded-[12rpx] mt-[20rpx] leading-[80rpx] text-center"
  26. @click="uploadIdCard">
  27. 上传身份证人像面
  28. </button>
  29. </view>
  30. <!-- 表单区域 -->
  31. <view class="mb-[30rpx]">
  32. <!-- 所在地区 -->
  33. <view class="mb-[20rpx] bg-white rounded-[12rpx] p-[20rpx]">
  34. <view class="text-[28rpx] text-[#333] font-bold mb-[10rpx]">所在地区:</view>
  35. <picker @change="onRegionChange" :value="selectedRegionIndex" :range="regionList" mode="selector"
  36. class="h-[80rpx] border-solid border-1 border-black rounded-[12rpx] px-[20rpx] flex items-center justify-between text-[28rpx] text-[#333]">
  37. <view :class="selectedRegion ? 'text-[#333]' : 'text-[#999]'">
  38. {{ selectedRegion || '请选择您的所在地区' }}
  39. </view>
  40. </picker>
  41. </view>
  42. <!-- 姓名 -->
  43. <view class="mb-[20rpx] bg-white rounded-[12rpx] p-[20rpx]">
  44. <view class="text-[28rpx] text-[#333] font-bold mb-[10rpx]">姓名:</view>
  45. <input v-model="userInfo.name" type="text" placeholder="请填写确权承包方姓名"
  46. class="h-[80rpx] border-solid border-1 border-black rounded-[12rpx] px-[20rpx] text-[28rpx] text-[#333]" />
  47. </view>
  48. <!-- 身份证号码 -->
  49. <view class="mb-[20rpx] bg-white rounded-[12rpx] p-[20rpx]">
  50. <view class="text-[28rpx] text-[#333] font-bold mb-[10rpx]">身份证号码:</view>
  51. <input v-model="userInfo.idCard" type="text" placeholder="请填写确权承包方身份证号码"
  52. class="h-[80rpx] border-solid border-1 border-black rounded-[12rpx] px-[20rpx] text-[28rpx] text-[#333]" />
  53. </view>
  54. </view>
  55. <!-- 确认按钮 -->
  56. <view class="mt-[20rpx]">
  57. <button
  58. class="w-full h-[80rpx] bg-[#007aff] text-white text-[28rpx] rounded-[12rpx] leading-[80rpx] text-center"
  59. @click="confirmInfo">
  60. 确认
  61. </button>
  62. </view>
  63. </view>
  64. </template>
  65. <script setup lang="ts">
  66. import { ref, reactive } from 'vue'
  67. import { employerLogin } from '@/api/cgbList.js';
  68. // 用户信息
  69. const userInfo = reactive({
  70. name: '杨万全',
  71. gender: '',
  72. birth: '',
  73. idCard: '432427196210271716'
  74. })
  75. // 地区列表
  76. const regionList = ref([
  77. '湖南省常德市石门县'
  78. ])
  79. // 当前选中的地区索引
  80. const selectedRegionIndex = ref(0)
  81. // 当前选中的地区名称
  82. const selectedRegion = ref(regionList.value[0])
  83. // 指示器样式
  84. const indicatorStyle = ref('height: 80rpx; line-height: 80rpx;')
  85. // 上传身份证
  86. const uploadIdCard = () => {
  87. uni.chooseImage({
  88. count: 1,
  89. sizeType: ['compressed'],
  90. sourceType: ['album', 'camera'],
  91. success: (res) => {
  92. console.log('选择图片结果:', res)
  93. const tempFilePaths = res.tempFilePaths
  94. // 模拟身份证识别结果
  95. userInfo.name = '张三'
  96. userInfo.gender = '男'
  97. userInfo.birth = '1980年1月1日'
  98. userInfo.idCard = '430102198001011234'
  99. // 上传图片(示例)
  100. uni.uploadFile({
  101. url: 'https://example.com/upload', // 替换为实际上传地址
  102. filePath: tempFilePaths[0],
  103. name: 'file',
  104. formData: {
  105. 'user': 'test'
  106. },
  107. success: (uploadRes) => {
  108. console.log('图片上传成功:', uploadRes.data)
  109. },
  110. fail: (err) => {
  111. console.error('图片上传失败:', err)
  112. uni.showToast({
  113. title: '图片上传失败',
  114. icon: 'none'
  115. })
  116. }
  117. })
  118. },
  119. fail: (err) => {
  120. console.error('选择图片失败:', err)
  121. uni.showToast({
  122. title: '选择图片失败',
  123. icon: 'none'
  124. })
  125. }
  126. })
  127. }
  128. // 地区选择变化
  129. const onRegionChange = (e : any) => {
  130. selectedRegionIndex.value = e.detail.value
  131. selectedRegion.value = regionList.value[e.detail.value]
  132. }
  133. /**
  134. * 页面跳转封装(统一处理跳转逻辑)
  135. * @param pagePath 目标页面路径
  136. */
  137. const navigateToPage = (pagePath : string) => {
  138. uni.hideLoading() // 确保关闭加载态
  139. uni.navigateTo({
  140. url: pagePath,
  141. fail: (err) => {
  142. console.error('页面跳转失败:', err)
  143. uni.showToast({
  144. title: '页面跳转失败',
  145. icon: 'none'
  146. })
  147. }
  148. })
  149. }
  150. /**
  151. * 查询农户信息并处理结果
  152. * @param name 姓名
  153. * @param idCard 身份证号
  154. */
  155. async function getTotal(name : string, idCard : string) {
  156. // 加载中提示
  157. uni.showLoading({
  158. title: '查询中...'
  159. })
  160. try {
  161. // 调用查询接口
  162. const res = await employerLogin({
  163. fbffzrxm: name,
  164. fzrzjhm: idCard,
  165. });
  166. console.log('农户信息查询结果:', res.data)
  167. // 1. 判断返回数据是否为空数组
  168. if (Array.isArray(res.data) && res.data.length === 0) {
  169. uni.hideLoading() // 关闭加载态
  170. uni.showToast({
  171. title: '库中不存在此人员信息',
  172. icon: 'none',
  173. duration: 2000
  174. })
  175. return // 终止后续逻辑
  176. }
  177. uni.hideLoading() // 关闭加载态
  178. uni.navigateTo({
  179. url: `/pages/official/index?groupInfo=${encodeURIComponent(JSON.stringify(res.data))}`
  180. })
  181. } catch (err) {
  182. console.error('农户信息查询失败:', err)
  183. uni.hideLoading() // 异常时关闭加载态
  184. uni.showToast({
  185. title: '查询失败,请检查网络',
  186. icon: 'none'
  187. })
  188. }
  189. }
  190. // 确认信息提交
  191. const confirmInfo = () => {
  192. // 姓名校验
  193. if (!userInfo.name) {
  194. uni.showToast({
  195. title: '请输入姓名',
  196. icon: 'none'
  197. })
  198. return
  199. }
  200. // 身份证校验
  201. if (!userInfo.idCard) {
  202. uni.showToast({
  203. title: '请输入身份证号码',
  204. icon: 'none'
  205. })
  206. return
  207. }
  208. // 身份证格式简单校验(可选)
  209. const idCardReg = /^\d{17}[\dXx]$/
  210. if (!idCardReg.test(userInfo.idCard)) {
  211. uni.showToast({
  212. title: '请输入有效的18位身份证号码',
  213. icon: 'none'
  214. })
  215. return
  216. }
  217. // 调用查询方法
  218. getTotal(userInfo.name, userInfo.idCard)
  219. }
  220. </script>