register.vue 17 KB

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