register.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <template>
  2. <view class="container">
  3. <view class="body">
  4. <!-- 访客姓名区域 -->
  5. <view class="body_box">
  6. <view class="box_key">
  7. <text class="key_icon">*</text>
  8. 访客姓名
  9. </view>
  10. <view class="box_value">
  11. <input :disabled="type == 1" class="value_input" type="text" placeholder="请输入访客姓名" placeholder-style="color:#CCCCCC;" v-model="visName" />
  12. </view>
  13. </view>
  14. <!-- 访客手机号区域 -->
  15. <view class="body_box">
  16. <view class="box_key">
  17. <text class="key_icon">*</text>
  18. 访客手机号
  19. </view>
  20. <view class="box_value">
  21. <input :disabled="type == 1" class="value_input" type="text" placeholder="请输入访客手机号" placeholder-style="color:#CCCCCC;" v-model="visPhone" />
  22. </view>
  23. </view>
  24. <!-- 来访时间区域 -->
  25. <view class="body_box">
  26. <view class="box_key">
  27. <text class="key_icon">*</text>
  28. 来访时间
  29. </view>
  30. <view class="box_value">
  31. <uni-datetime-picker v-model="visStartTime" @change="changeStart">
  32. <view class="value_time" :class="{ activeTime: visStartTime }">{{ visStartTime || '请选择来访时间 >' }}</view>
  33. </uni-datetime-picker>
  34. </view>
  35. </view>
  36. <view class="body_box">
  37. <view class="box_key">
  38. <text class="key_icon">*</text>
  39. 来访结束时间
  40. </view>
  41. <view class="box_value">
  42. <!-- <uni-datetime-picker v-model="visEndTime" :start="visStartTime"> -->
  43. <view class="value_time" :class="{ activeTime: visEndTime }">{{ visEndTime || '来访时间为4小时' }}</view>
  44. <!-- </uni-datetime-picker> -->
  45. </view>
  46. </view>
  47. <!-- 证件号区域 -->
  48. <view class="body_box" v-if="type != 1">
  49. <view class="box_key">
  50. <text class="key_icon">*</text>
  51. 证件号
  52. </view>
  53. <view class="box_value">
  54. <input :disabled="type == 1" class="value_input" type="text" placeholder="请输入访客证件号" placeholder-style="color:#CCCCCC;" v-model="visIdNumber" />
  55. </view>
  56. </view>
  57. <!-- 访问事由区域 -->
  58. <view class="body_box">
  59. <view class="box_key">
  60. <text class="key_icon">*</text>
  61. 访问事由
  62. </view>
  63. <view class="box_value">
  64. <input class="value_input" type="text" placeholder="请输入访问事由" placeholder-style="color:#CCCCCC;" v-model="visReason" maxlength="100" />
  65. </view>
  66. </view>
  67. <!-- 车牌号区域 -->
  68. <view class="body_box">
  69. <view class="box_key">车牌号</view>
  70. <view class="box_value">
  71. <input class="value_input" type="text" placeholder="(选填)驾车请填写车牌号" placeholder-style="color:#CCCCCC;" v-model="visCarNumber" />
  72. </view>
  73. </view>
  74. <!-- 同行人数区域 -->
  75. <view class="body_box">
  76. <view class="box_key">同行人数</view>
  77. <view class="box_value">
  78. <input class="value_input" type="number" placeholder="请输入同行的人数" placeholder-style="color:#CCCCCC;" v-model.number="visPeopleNum" />
  79. <text class="value_text">人</text>
  80. </view>
  81. </view>
  82. <!-- 受访者姓名区域 -->
  83. <view class="body_box" v-if="type == 2">
  84. <view class="box_key">
  85. <text class="key_icon">*</text>
  86. 受访者姓名
  87. </view>
  88. <view class="box_value">
  89. <input :disabled="type == 2" class="value_input" type="text" placeholder="请输入受访者姓名" placeholder-style="color:#CCCCCC;" v-model="passiveName" />
  90. </view>
  91. </view>
  92. <!-- 受访者手机号区域 -->
  93. <view class="body_box" v-if="type == 2">
  94. <view class="box_key">
  95. <text class="key_icon">*</text>
  96. 受访者手机号
  97. </view>
  98. <view class="box_value">
  99. <input :disabled="type == 2" class="value_input" type="text" placeholder="请输入受访者手机号" placeholder-style="color:#CCCCCC;" v-model="passivePhone" />
  100. </view>
  101. </view>
  102. <!-- 选择受访学生区域 -->
  103. <view class="body_box no_border" v-if="type == 1">
  104. <view class="box_key">
  105. <text class="key_icon">*</text>
  106. 选择受访学生(可多选)
  107. </view>
  108. </view>
  109. <!-- 学生列表区域 -->
  110. <view class="student_list" v-if="type == 1">
  111. <!-- 每一个学生区域 -->
  112. <view class="student" v-for="item in list" :key="item.id" @click="handleClick(item)">
  113. <radio class="student_checked" color="#0061FF" :checked="item.isChecked" />
  114. <view class="student_info">{{ item.name }}({{ item.cardNo }})</view>
  115. </view>
  116. </view>
  117. </view>
  118. <!-- 授权区域 -->
  119. <label class="auth" @click="handleAuth">
  120. <radio style="transform: scale(0.5)" color="#0061FF" :checked="authValue" />
  121. <text class="auth_text">同意授权证件号用于访客身份的验证</text>
  122. </label>
  123. <!-- 按钮区域 -->
  124. <view class="btn" :class="{ active: btnFlag }" @click="handleSubmit">访客预约</view>
  125. </view>
  126. </template>
  127. <script setup>
  128. import { ref, computed } from 'vue'
  129. import { onLoad } from '@dcloudio/uni-app'
  130. import { myRequest } from '@/utils/api.js'
  131. import { time_format } from '@/utils/formatTime.js'
  132. import { isVehicleNumber } from '@/utils/plate.js'
  133. import { decryptDes } from '@/utils/des.js'
  134. // 判断是哪种身份 1为学生家长 2为其他访客
  135. const type = ref('')
  136. // 访客姓名
  137. const visName = ref('')
  138. // 访客手机号
  139. const visPhone = ref('')
  140. // 来访开始时间
  141. const visStartTime = ref('')
  142. // 来访结束时间
  143. const visEndTime = ref('')
  144. // 证件号
  145. const visIdNumber = ref('')
  146. // 访问事由
  147. const visReason = ref('')
  148. // 车牌号
  149. const visCarNumber = ref('')
  150. // 同行人数
  151. const visPeopleNum = ref('')
  152. // 受访学生列表数据
  153. const list = ref([])
  154. // 受访者姓名
  155. const passiveName = ref('')
  156. // 受访者电话
  157. const passivePhone = ref('')
  158. // 是否授权证件号
  159. const authValue = ref(false)
  160. // 预约按钮是否高亮展示
  161. const btnFlag = computed(() => {
  162. const tem = list.value.some((item) => item.isChecked)
  163. if (
  164. visName.value &&
  165. visPhone.value &&
  166. visStartTime.value &&
  167. visEndTime.value && [type.value === '1' && !visIdNumber.value] &&
  168. visReason.value && [type.value === '1' && !list.value.length] && [type.value === '1' && !tem] && [type.value === '2' && !passiveName.value] && [
  169. type.value === '2' && !passivePhone.value
  170. ] &&
  171. authValue.value
  172. ) {
  173. return true
  174. } else {
  175. return false
  176. }
  177. })
  178. onLoad((options) => {
  179. type.value = options.type
  180. if (type.value === '1') {
  181. visName.value = uni.getStorageSync('userInfo').name
  182. visPhone.value = uni.getStorageSync('userInfo').phone
  183. visIdNumber.value = uni.getStorageSync('userInfo').idCard
  184. getList()
  185. } else {
  186. passiveName.value = uni.getStorageSync('userInfo').name
  187. passivePhone.value = uni.getStorageSync('userInfo').phone
  188. }
  189. })
  190. // 获取家长绑定学生数组
  191. const getList = async () => {
  192. const res = await myRequest({
  193. url: '/wanzai/api/smartUser/queryAffiliateUserById',
  194. data: {
  195. id: uni.getStorageSync('userInfo').id
  196. }
  197. })
  198. // console.log(res)
  199. const result = JSON.parse(decryptDes(res.data))
  200. list.value = result
  201. }
  202. // 访客预约按钮回调
  203. const handleSubmit = () => {
  204. const flag = verifyValue()
  205. if (flag) {
  206. if (type.value === '1') {
  207. parentAppointment()
  208. } else {
  209. otherAppointment()
  210. }
  211. }
  212. }
  213. // 家长预约请求
  214. const parentAppointment = async () => {
  215. let temList = []
  216. list.value.forEach((ele) => {
  217. if (ele.isChecked) {
  218. temList.push(ele)
  219. }
  220. })
  221. const res = await myRequest({
  222. url: '/wanzai/api/smartVisitor/parentsAppointment',
  223. method: 'post',
  224. data: {
  225. userId: uni.getStorageSync('userInfo').id,
  226. visitorTime: visStartTime.value,
  227. visitReason: visReason.value,
  228. carNum: visCarNumber.value,
  229. peerNum: visPeopleNum.value ? visPeopleNum.value : 0,
  230. students: temList
  231. }
  232. })
  233. // console.log(res)
  234. uni.showToast({
  235. title: res.message,
  236. icon: 'none',
  237. duration: 2000
  238. })
  239. setTimeout(() => {
  240. uni.setStorageSync('Tab-activeIndex', 1)
  241. uni.reLaunch({
  242. url: '/pagesReservation/record/record'
  243. })
  244. }, 2000)
  245. }
  246. // 其他访客预约请求
  247. const otherAppointment = async () => {
  248. const res = await myRequest({
  249. url: '/wanzai/api/smartVisitor/otherAppointment',
  250. method: 'post',
  251. data: {
  252. userId: uni.getStorageSync('userInfo').id,
  253. userName: visName.value,
  254. userPhone: visPhone.value,
  255. userCard: visIdNumber.value,
  256. visitorTime: visStartTime.value,
  257. visitReason: visReason.value,
  258. carNum: visCarNumber.value,
  259. peerNum: visPeopleNum.value ? visPeopleNum.value : 0,
  260. respondentName: passiveName.value,
  261. respondentPhone: passivePhone.value
  262. }
  263. })
  264. // console.log(res)
  265. uni.showToast({
  266. title: res.message,
  267. icon: 'none',
  268. duration: 2000
  269. })
  270. setTimeout(() => {
  271. uni.setStorageSync('Tab-activeIndex', 2)
  272. uni.reLaunch({
  273. url: '/pagesReservation/record/record'
  274. })
  275. }, 2000)
  276. }
  277. // 选择来访开始时间时的回调
  278. const changeStart = (e) => {
  279. // 兼容ios部分系统转换时间格式
  280. const temTime = e.replace(/-/g, '/')
  281. // 转化成时间戳
  282. const timestamp = Date.parse(new Date(temTime))
  283. // 默认访问时间4小时
  284. const addTime = 1000 * 60 * 60 * 4
  285. visEndTime.value = time_format(timestamp + addTime)
  286. }
  287. // 验证表格数据是否符合规范
  288. const verifyValue = () => {
  289. // 姓名验证规则
  290. const regName = /^[\u4e00-\u9fa5]{2,4}$/
  291. // 手机号码验证规则
  292. const regPhone = /^1[3-9]\d{9}$/
  293. // 身份证号码验证规则
  294. const regIdentity = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  295. if (!visName.value) {
  296. uni.showToast({
  297. title: '请输入访客姓名',
  298. icon: 'none'
  299. })
  300. return false
  301. }
  302. if (!regName.test(visName.value)) {
  303. uni.showToast({
  304. title: '姓名格式错误',
  305. icon: 'none'
  306. })
  307. return false
  308. }
  309. if (!visPhone.value) {
  310. uni.showToast({
  311. title: '请输入访客手机号',
  312. icon: 'none'
  313. })
  314. return false
  315. }
  316. if (!regPhone.test(visPhone.value)) {
  317. uni.showToast({
  318. title: '手机号码格式错误',
  319. icon: 'none'
  320. })
  321. return false
  322. }
  323. if (!visStartTime.value) {
  324. uni.showToast({
  325. title: '请选择来访时间',
  326. icon: 'none'
  327. })
  328. return false
  329. }
  330. if (!visEndTime.value) {
  331. uni.showToast({
  332. title: '请选择来访结束时间',
  333. icon: 'none'
  334. })
  335. return false
  336. }
  337. if (type.value != 1 && !visIdNumber.value) {
  338. uni.showToast({
  339. title: '请输入访客证件号',
  340. icon: 'none'
  341. })
  342. return false
  343. }
  344. if (type.value != 1 && !regIdentity.test(visIdNumber.value)) {
  345. uni.showToast({
  346. title: '证件号格式错误',
  347. icon: 'none'
  348. })
  349. return false
  350. }
  351. if (!visReason.value) {
  352. uni.showToast({
  353. title: '请输入访问事由',
  354. icon: 'none'
  355. })
  356. return false
  357. }
  358. if (visCarNumber.value && !isVehicleNumber(visCarNumber.value)) {
  359. uni.showToast({
  360. title: '请输入正确的车牌号',
  361. icon: 'none'
  362. })
  363. return false
  364. }
  365. if (type.value === '1' && !list.value.length) {
  366. uni.showToast({
  367. title: '请绑定学生后再开始预约',
  368. icon: 'none'
  369. })
  370. return false
  371. }
  372. const tem = list.value.some((item) => item.isChecked)
  373. if (type.value === '1' && !tem) {
  374. uni.showToast({
  375. title: '请选择受访学生',
  376. icon: 'none'
  377. })
  378. return false
  379. }
  380. if (type.value === '2' && !passiveName.value) {
  381. uni.showToast({
  382. title: '请输入受访者姓名',
  383. icon: 'none'
  384. })
  385. return false
  386. }
  387. if (type.value === '2' && !regName.test(passiveName.value)) {
  388. uni.showToast({
  389. title: '受访者姓名格式错误',
  390. icon: 'none'
  391. })
  392. return false
  393. }
  394. if (type.value === '2' && !passivePhone.value) {
  395. uni.showToast({
  396. title: '请输入受访者电话',
  397. icon: 'none'
  398. })
  399. return false
  400. }
  401. if (type.value === '2' && !regPhone.test(passivePhone.value)) {
  402. uni.showToast({
  403. title: '受访者手机号格式错误',
  404. icon: 'none'
  405. })
  406. return false
  407. }
  408. if (!authValue.value) {
  409. uni.showToast({
  410. title: '请同意授权证件号',
  411. icon: 'none'
  412. })
  413. return false
  414. }
  415. return true
  416. }
  417. // 点击每一个学生回调
  418. const handleClick = (item) => {
  419. item.isChecked = !item.isChecked
  420. }
  421. // 点击授权radio时的回调
  422. const handleAuth = () => {
  423. authValue.value = !authValue.value
  424. }
  425. </script>
  426. <style lang="scss" scoped>
  427. .container {
  428. display: flex;
  429. flex-direction: column;
  430. min-height: 100vh;
  431. background-color: #f1f6fe;
  432. .body {
  433. margin-top: 20rpx;
  434. padding-left: 20rpx;
  435. background-color: #fff;
  436. .body_box {
  437. display: flex;
  438. justify-content: space-between;
  439. align-items: center;
  440. padding-right: 20rpx;
  441. height: 85rpx;
  442. font-size: 28rpx;
  443. border-bottom: 1rpx solid #e6e6e6;
  444. .box_key {
  445. .key_icon {
  446. color: #d43030;
  447. }
  448. }
  449. .box_value {
  450. display: flex;
  451. justify-content: flex-end;
  452. align-items: center;
  453. width: 50%;
  454. .value_input {
  455. text-align: right;
  456. }
  457. .value_text {
  458. margin-left: 20rpx;
  459. }
  460. .value_time {
  461. text-align: end;
  462. color: #cccccc;
  463. }
  464. .activeTime {
  465. color: #000;
  466. }
  467. }
  468. }
  469. .no_border {
  470. border: none;
  471. }
  472. .student_list {
  473. .student {
  474. display: flex;
  475. align-items: center;
  476. margin-bottom: 30rpx;
  477. width: 710rpx;
  478. height: 110rpx;
  479. border-radius: 18rpx;
  480. background-color: #f2f4f9;
  481. .student_checked {
  482. margin-left: 48rpx;
  483. }
  484. .student_info {
  485. margin-left: 53rpx;
  486. font-size: 32rpx;
  487. }
  488. }
  489. }
  490. }
  491. .auth {
  492. display: flex;
  493. align-items: center;
  494. margin: 20rpx 0 40rpx 20rpx;
  495. font-size: 24rpx;
  496. .auth_text {
  497. height: 35rpx;
  498. }
  499. }
  500. .btn {
  501. display: flex;
  502. justify-content: center;
  503. align-items: center;
  504. margin: 0 auto 100rpx;
  505. width: 710rpx;
  506. height: 100rpx;
  507. color: #fff;
  508. font-size: 32rpx;
  509. border-radius: 8rpx;
  510. background-color: #95b8e6;
  511. }
  512. .active {
  513. background-color: #0061ff;
  514. }
  515. }
  516. </style>