register.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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 no_border" v-if="type == 1">
  69. <view class="box_key">
  70. 图片
  71. <span class="span">(上传图片,最多{{ maxImgCount }}张)</span>
  72. </view>
  73. </view>
  74. <view class="filePicker" v-if="type == 1">
  75. <!-- 图片展示区域 -->
  76. <view class="img_box" v-for="(item, index) in imgList" :key="item">
  77. <img class="img" mode="aspectFill" :src="item" @click="handleLookImg(imgList, index)" />
  78. <!-- 关闭图标 -->
  79. <img class="close" src="@/static/images/close.png" @click="handleDelete(index)" />
  80. </view>
  81. <!-- 上传按钮区域 -->
  82. <img v-if="imgList.length < maxImgCount" class="uploading" src="@/static/images/uploading.png" @click="uploadingImg" />
  83. </view>
  84. <!-- 车牌号区域 -->
  85. <view class="body_box">
  86. <view class="box_key">车牌号</view>
  87. <view class="box_value">
  88. <input class="value_input" type="text" placeholder="(选填)驾车请填写车牌号" placeholder-style="color:#CCCCCC;" v-model="visCarNumber" />
  89. </view>
  90. </view>
  91. <!-- 同行人数区域 -->
  92. <view class="body_box">
  93. <view class="box_key">同行人数</view>
  94. <view class="box_value">
  95. <input class="value_input" type="number" placeholder="请输入同行的人数" placeholder-style="color:#CCCCCC;" v-model.number="visPeopleNum" />
  96. <text class="value_text">人</text>
  97. </view>
  98. </view>
  99. <!-- 受访者姓名区域 -->
  100. <view class="body_box" v-if="type == 2">
  101. <view class="box_key">
  102. <text class="key_icon">*</text>
  103. 受访者姓名
  104. </view>
  105. <view class="box_value">
  106. <input :disabled="type == 2" class="value_input" type="text" placeholder="请输入受访者姓名" placeholder-style="color:#CCCCCC;" v-model="passiveName" />
  107. </view>
  108. </view>
  109. <!-- 受访者手机号区域 -->
  110. <view class="body_box" v-if="type == 2">
  111. <view class="box_key">
  112. <text class="key_icon">*</text>
  113. 受访者手机号
  114. </view>
  115. <view class="box_value">
  116. <input :disabled="type == 2" class="value_input" type="text" placeholder="请输入受访者手机号" placeholder-style="color:#CCCCCC;" v-model="passivePhone" />
  117. </view>
  118. </view>
  119. <!-- 选择受访学生区域 -->
  120. <view class="body_box no_border" v-if="type == 1">
  121. <view class="box_key">
  122. <text class="key_icon">*</text>
  123. 选择受访学生(可多选)
  124. </view>
  125. </view>
  126. <!-- 学生列表区域 -->
  127. <view class="student_list" v-if="type == 1">
  128. <!-- 每一个学生区域 -->
  129. <view class="student" v-for="item in list" :key="item.id" @click="handleClick(item)">
  130. <radio class="student_checked" color="#0061FF" :checked="item.isChecked" />
  131. <view class="student_info">{{ item.name }}({{ item.cardNo }})</view>
  132. </view>
  133. </view>
  134. </view>
  135. <!-- 授权区域 -->
  136. <label class="auth" @click="handleAuth">
  137. <radio style="transform: scale(0.5)" color="#0061FF" :checked="authValue" />
  138. <text class="auth_text">同意授权证件号用于访客身份的验证</text>
  139. </label>
  140. <!-- 按钮区域 -->
  141. <view class="btn" :class="{ active: btnFlag }" @click="handleSubmit">访客预约</view>
  142. <!-- 用于图片压缩的canvas画布 -->
  143. <canvas
  144. :style="{
  145. width: cw + 'px',
  146. height: cw + 'px',
  147. position: 'absolute',
  148. zIndex: -1,
  149. left: '-10000rpx',
  150. top: '-10000rpx'
  151. }"
  152. canvas-id="zipCanvas"
  153. ></canvas>
  154. <!--画布结束-->
  155. </view>
  156. </template>
  157. <script setup>
  158. import { ref, computed } from 'vue'
  159. import { onLoad } from '@dcloudio/uni-app'
  160. import { myRequest } from '@/utils/api.js'
  161. import { time_format } from '@/utils/formatTime.js'
  162. import { isVehicleNumber } from '@/utils/plate.js'
  163. import { decryptDes } from '@/utils/des.js'
  164. import getLessLimitSizeImage from '@/utils/imageCompress.js'
  165. import { cos } from '@/utils/cos.js'
  166. // 判断是哪种身份 1为学生家长 2为其他访客
  167. const type = ref('')
  168. // 访客姓名
  169. const visName = ref('')
  170. // 访客手机号
  171. const visPhone = ref('')
  172. // 来访开始时间
  173. const visStartTime = ref('')
  174. // 来访结束时间
  175. const visEndTime = ref('')
  176. // 证件号
  177. const visIdNumber = ref('')
  178. // 访问事由
  179. const visReason = ref('')
  180. // 展示的图片
  181. const imgList = ref([])
  182. // 车牌号
  183. const visCarNumber = ref('')
  184. // 同行人数
  185. const visPeopleNum = ref('')
  186. // 受访学生列表数据
  187. const list = ref([])
  188. // 受访者姓名
  189. const passiveName = ref('')
  190. // 受访者电话
  191. const passivePhone = ref('')
  192. // 是否授权证件号
  193. const authValue = ref(false)
  194. // 图片上传的最大数
  195. const maxImgCount = ref(3)
  196. //画板边长默认是屏幕宽度,正方形画布
  197. const cw = uni.getSystemInfoSync().windowWidth
  198. // 预约按钮是否高亮展示
  199. const btnFlag = computed(() => {
  200. const tem = list.value.some((item) => item.isChecked)
  201. if (
  202. visName.value &&
  203. visPhone.value &&
  204. visStartTime.value &&
  205. visEndTime.value && [type.value === '1' && !visIdNumber.value] &&
  206. visReason.value && [type.value === '1' && !list.value.length] && [type.value === '1' && !tem] && [type.value === '2' && !passiveName.value] && [
  207. type.value === '2' && !passivePhone.value
  208. ] &&
  209. authValue.value
  210. ) {
  211. return true
  212. } else {
  213. return false
  214. }
  215. })
  216. onLoad((options) => {
  217. type.value = options.type
  218. if (type.value === '1') {
  219. visName.value = uni.getStorageSync('userInfo').name
  220. visPhone.value = uni.getStorageSync('userInfo').phone
  221. visIdNumber.value = uni.getStorageSync('userInfo').idCard
  222. getList()
  223. } else {
  224. passiveName.value = uni.getStorageSync('userInfo').name
  225. passivePhone.value = uni.getStorageSync('userInfo').phone
  226. }
  227. })
  228. // 获取家长绑定学生数组
  229. const getList = async () => {
  230. const res = await myRequest({
  231. url: '/wanzai/api/smartUser/queryAffiliateUserById',
  232. data: {
  233. id: uni.getStorageSync('userInfo').id
  234. }
  235. })
  236. // console.log(res)
  237. const result = JSON.parse(decryptDes(res.data))
  238. list.value = result
  239. }
  240. // 访客预约按钮回调
  241. const handleSubmit = () => {
  242. const flag = verifyValue()
  243. if (flag) {
  244. if (type.value === '1') {
  245. parentAppointment()
  246. } else {
  247. otherAppointment()
  248. }
  249. }
  250. }
  251. // 家长预约请求
  252. const parentAppointment = async () => {
  253. let temList = []
  254. list.value.forEach((ele) => {
  255. if (ele.isChecked) {
  256. temList.push(ele)
  257. }
  258. })
  259. const res = await myRequest({
  260. url: '/wanzai/api/smartVisitor/parentsAppointment',
  261. method: 'post',
  262. data: {
  263. userId: uni.getStorageSync('userInfo').id,
  264. visitorTime: visStartTime.value,
  265. visitReason: visReason.value,
  266. carNum: visCarNumber.value,
  267. peerNum: visPeopleNum.value ? visPeopleNum.value : 0,
  268. image: imgList.value.join(','),
  269. students: temList
  270. }
  271. })
  272. // console.log(res)
  273. uni.showToast({
  274. title: res.message,
  275. icon: 'none',
  276. duration: 2000
  277. })
  278. setTimeout(() => {
  279. uni.setStorageSync('Tab-activeIndex', 1)
  280. uni.reLaunch({
  281. url: '/pagesReservation/record/record'
  282. })
  283. }, 2000)
  284. }
  285. // 其他访客预约请求
  286. const otherAppointment = async () => {
  287. const res = await myRequest({
  288. url: '/wanzai/api/smartVisitor/otherAppointment',
  289. method: 'post',
  290. data: {
  291. userId: uni.getStorageSync('userInfo').id,
  292. userName: visName.value,
  293. userPhone: visPhone.value,
  294. userCard: visIdNumber.value,
  295. visitorTime: visStartTime.value,
  296. visitReason: visReason.value,
  297. carNum: visCarNumber.value,
  298. peerNum: visPeopleNum.value ? visPeopleNum.value : 0,
  299. respondentName: passiveName.value,
  300. respondentPhone: passivePhone.value
  301. }
  302. })
  303. // console.log(res)
  304. uni.showToast({
  305. title: res.message,
  306. icon: 'none',
  307. duration: 2000
  308. })
  309. setTimeout(() => {
  310. uni.setStorageSync('Tab-activeIndex', 2)
  311. uni.reLaunch({
  312. url: '/pagesReservation/record/record'
  313. })
  314. }, 2000)
  315. }
  316. // 选择来访开始时间时的回调
  317. const changeStart = (e) => {
  318. // 兼容ios部分系统转换时间格式
  319. const temTime = e.replace(/-/g, '/')
  320. // 转化成时间戳
  321. const timestamp = Date.parse(new Date(temTime))
  322. // 默认访问时间4小时
  323. const addTime = 1000 * 60 * 60 * 4
  324. visEndTime.value = time_format(timestamp + addTime)
  325. }
  326. // 验证表格数据是否符合规范
  327. const verifyValue = () => {
  328. // 姓名验证规则
  329. const regName = /^[\u4e00-\u9fa5]{2,4}$/
  330. // 手机号码验证规则
  331. const regPhone = /^1[3-9]\d{9}$/
  332. // 身份证号码验证规则
  333. const regIdentity = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  334. if (!visName.value) {
  335. uni.showToast({
  336. title: '请输入访客姓名',
  337. icon: 'none'
  338. })
  339. return false
  340. }
  341. if (!regName.test(visName.value)) {
  342. uni.showToast({
  343. title: '姓名格式错误',
  344. icon: 'none'
  345. })
  346. return false
  347. }
  348. if (!visPhone.value) {
  349. uni.showToast({
  350. title: '请输入访客手机号',
  351. icon: 'none'
  352. })
  353. return false
  354. }
  355. if (!regPhone.test(visPhone.value)) {
  356. uni.showToast({
  357. title: '手机号码格式错误',
  358. icon: 'none'
  359. })
  360. return false
  361. }
  362. if (!visStartTime.value) {
  363. uni.showToast({
  364. title: '请选择来访时间',
  365. icon: 'none'
  366. })
  367. return false
  368. }
  369. if (!visEndTime.value) {
  370. uni.showToast({
  371. title: '请选择来访结束时间',
  372. icon: 'none'
  373. })
  374. return false
  375. }
  376. if (type.value != 1 && !visIdNumber.value) {
  377. uni.showToast({
  378. title: '请输入访客证件号',
  379. icon: 'none'
  380. })
  381. return false
  382. }
  383. if (type.value != 1 && !regIdentity.test(visIdNumber.value)) {
  384. uni.showToast({
  385. title: '证件号格式错误',
  386. icon: 'none'
  387. })
  388. return false
  389. }
  390. if (!visReason.value) {
  391. uni.showToast({
  392. title: '请输入访问事由',
  393. icon: 'none'
  394. })
  395. return false
  396. }
  397. if (visCarNumber.value && !isVehicleNumber(visCarNumber.value)) {
  398. uni.showToast({
  399. title: '请输入正确的车牌号',
  400. icon: 'none'
  401. })
  402. return false
  403. }
  404. if (type.value === '1' && !list.value.length) {
  405. uni.showToast({
  406. title: '请绑定学生后再开始预约',
  407. icon: 'none'
  408. })
  409. return false
  410. }
  411. const tem = list.value.some((item) => item.isChecked)
  412. if (type.value === '1' && !tem) {
  413. uni.showToast({
  414. title: '请选择受访学生',
  415. icon: 'none'
  416. })
  417. return false
  418. }
  419. if (type.value === '2' && !passiveName.value) {
  420. uni.showToast({
  421. title: '请输入受访者姓名',
  422. icon: 'none'
  423. })
  424. return false
  425. }
  426. if (type.value === '2' && !regName.test(passiveName.value)) {
  427. uni.showToast({
  428. title: '受访者姓名格式错误',
  429. icon: 'none'
  430. })
  431. return false
  432. }
  433. if (type.value === '2' && !passivePhone.value) {
  434. uni.showToast({
  435. title: '请输入受访者电话',
  436. icon: 'none'
  437. })
  438. return false
  439. }
  440. if (type.value === '2' && !regPhone.test(passivePhone.value)) {
  441. uni.showToast({
  442. title: '受访者手机号格式错误',
  443. icon: 'none'
  444. })
  445. return false
  446. }
  447. if (!authValue.value) {
  448. uni.showToast({
  449. title: '请同意授权证件号',
  450. icon: 'none'
  451. })
  452. return false
  453. }
  454. return true
  455. }
  456. // 点击每一个学生回调
  457. const handleClick = (item) => {
  458. item.isChecked = !item.isChecked
  459. }
  460. // 点击授权radio时的回调
  461. const handleAuth = () => {
  462. authValue.value = !authValue.value
  463. }
  464. // 点击上传图片时的回调
  465. const uploadingImg = () => {
  466. uni.chooseMedia({
  467. count: maxImgCount.value - imgList.value.length,
  468. mediaType: ['image'],
  469. sizeType: ['compressed'],
  470. success: (res) => {
  471. // console.log(res)
  472. res.tempFiles.forEach((ele) => {
  473. //这里的id和页面中写的html代码的canvas的id要一致
  474. let canvasId = 'zipCanvas'
  475. //原图的路径
  476. let imagePath = ele.tempFilePath
  477. //大小限制1024kb
  478. let limitSize = 1024 * 3
  479. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  480. let drawWidth = uni.getSystemInfoSync().windowWidth
  481. // 图片过大压缩
  482. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  483. handleUploadMini(resPath, 1)
  484. })
  485. })
  486. }
  487. })
  488. }
  489. // 上传请求
  490. const handleUploadMini = (ele) => {
  491. // 开始上传
  492. uni.showLoading({
  493. title: '上传中',
  494. mask: true
  495. })
  496. let filePath = ele
  497. let Key = filePath.substr(filePath.lastIndexOf('/') + 1)
  498. cos.postObject(
  499. {
  500. Bucket: 'wanzai-1306339220',
  501. Region: 'ap-shanghai',
  502. Key: Key,
  503. FilePath: filePath,
  504. onProgress: (info) => {
  505. // console.log(info)
  506. }
  507. },
  508. (err, data) => {
  509. if (err) {
  510. console.log('上传失败', err)
  511. } else {
  512. console.log('上传成功', data)
  513. uni.hideLoading()
  514. let imgUrl = 'https://' + data.Location
  515. imgList.value.push(imgUrl)
  516. console.log(imgList.value)
  517. }
  518. }
  519. )
  520. }
  521. // 删除图片回调
  522. const handleDelete = (index) => {
  523. imgList.value.splice(index, 1)
  524. }
  525. // 点击图片回调
  526. const handleLookImg = (urls, current) => {
  527. uni.previewImage({
  528. urls,
  529. current
  530. })
  531. }
  532. </script>
  533. <style lang="scss" scoped>
  534. .container {
  535. display: flex;
  536. flex-direction: column;
  537. min-height: 100vh;
  538. background-color: #f1f6fe;
  539. .body {
  540. margin-top: 20rpx;
  541. padding-left: 20rpx;
  542. background-color: #fff;
  543. .body_box {
  544. display: flex;
  545. justify-content: space-between;
  546. align-items: center;
  547. padding-right: 20rpx;
  548. height: 85rpx;
  549. font-size: 28rpx;
  550. border-bottom: 1rpx solid #e6e6e6;
  551. .box_key {
  552. .key_icon {
  553. color: #d43030;
  554. }
  555. .span {
  556. font-size: 20rpx;
  557. color: #999999;
  558. }
  559. }
  560. .box_value {
  561. display: flex;
  562. justify-content: flex-end;
  563. align-items: center;
  564. width: 50%;
  565. .value_input {
  566. text-align: right;
  567. }
  568. .value_text {
  569. margin-left: 20rpx;
  570. }
  571. .value_time {
  572. text-align: end;
  573. color: #cccccc;
  574. }
  575. .activeTime {
  576. color: #000;
  577. }
  578. }
  579. }
  580. .filePicker {
  581. display: flex;
  582. margin-bottom: 20rpx;
  583. height: 100rpx;
  584. .img_box {
  585. position: relative;
  586. margin-right: 20rpx;
  587. width: 100rpx;
  588. height: 100rpx;
  589. .img {
  590. width: 100rpx;
  591. height: 100rpx;
  592. }
  593. .close {
  594. position: absolute;
  595. top: 0;
  596. right: 0;
  597. width: 40rpx;
  598. height: 40rpx;
  599. background-color: rgba(000, 000, 000, 0.3);
  600. }
  601. }
  602. .uploading {
  603. width: 100rpx;
  604. height: 100rpx;
  605. }
  606. }
  607. .no_border {
  608. border: none;
  609. }
  610. .student_list {
  611. .student {
  612. display: flex;
  613. align-items: center;
  614. margin-bottom: 30rpx;
  615. width: 710rpx;
  616. height: 110rpx;
  617. border-radius: 18rpx;
  618. background-color: #f2f4f9;
  619. .student_checked {
  620. margin-left: 48rpx;
  621. }
  622. .student_info {
  623. margin-left: 53rpx;
  624. font-size: 32rpx;
  625. }
  626. }
  627. }
  628. }
  629. .auth {
  630. display: flex;
  631. align-items: center;
  632. margin: 20rpx 0 40rpx 20rpx;
  633. font-size: 24rpx;
  634. .auth_text {
  635. height: 35rpx;
  636. }
  637. }
  638. .btn {
  639. display: flex;
  640. justify-content: center;
  641. align-items: center;
  642. margin: 0 auto 100rpx;
  643. width: 710rpx;
  644. height: 100rpx;
  645. color: #fff;
  646. font-size: 32rpx;
  647. border-radius: 8rpx;
  648. background-color: #95b8e6;
  649. }
  650. .active {
  651. background-color: #0061ff;
  652. }
  653. }
  654. </style>