subscribe.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <view class="container">
  3. <view class="body" v-if="form.name">
  4. <view class="box">
  5. <view class="box_key">学生姓名:</view>
  6. <view class="box_value">
  7. <input class="input" type="text" placeholder="请输入学生姓名" placeholder-style="color:#CCCCCC;font-size:28rpx" v-model="form.name" />
  8. </view>
  9. </view>
  10. <view class="box">
  11. <view class="box_key">手机号:</view>
  12. <view class="box_value">
  13. <input class="input" type="text" placeholder="请输入手机号" placeholder-style="color:#CCCCCC;font-size:28rpx" v-model="form.phone" />
  14. </view>
  15. </view>
  16. <!-- <view class="box">
  17. <view class="box_key">陪同人数:</view>
  18. <view class="box_value">
  19. <input class="input" type="text" placeholder="请输入陪同人数" placeholder-style="color:#CCCCCC;font-size:28rpx" v-model="form.peerNum" />
  20. </view>
  21. </view> -->
  22. <view class="box">
  23. <view class="box_key">校区:</view>
  24. <view class="box_value">
  25. <picker @change="bindPickerChange" :value="currtIndex" :range="schoolList" range-key="school">
  26. <view class="select" :class="{ active: currtIndex != null }">
  27. {{ currtIndex != null ? schoolList[currtIndex].school : '请选择校区' }}
  28. <uni-icons type="down" size="20" color="#ccc"></uni-icons>
  29. </view>
  30. </picker>
  31. </view>
  32. </view>
  33. <view class="box">
  34. <view class="box_key">车牌号:</view>
  35. <view class="box_value" @click="showKeyboard">
  36. <view class="select" :class="{ active: form.carNumber }">
  37. {{ form.carNumber ? form.carNumber : '请选择车牌号' }}
  38. <uni-icons type="down" size="20" color="#ccc"></uni-icons>
  39. </view>
  40. <xm-keyboard-v2 ref="xmKeyboard" disable="I,O" @confirm="confirm"></xm-keyboard-v2>
  41. </view>
  42. </view>
  43. <view class="box">
  44. <view class="box_key">到访开始时间:</view>
  45. <view class="box_value">
  46. <uni-datetime-picker type="datetime" :start="Date.now()" v-model="form.startTime" @change="changeTime">
  47. <view class="select" :class="{ active: form.startTime }">
  48. {{ form.startTime ? form.startTime : '请选择到访开始时间' }}
  49. <uni-icons type="down" size="20" color="#ccc"></uni-icons>
  50. </view>
  51. </uni-datetime-picker>
  52. </view>
  53. </view>
  54. <view class="box">
  55. <view class="box_key">到访结束时间:</view>
  56. <view class="box_value">
  57. <uni-datetime-picker
  58. type="datetime"
  59. :start="form.startTime"
  60. :end="form.startTime.substring(0, 10) + ' 23:59:59'"
  61. v-model="form.endTime"
  62. :disabled="!form.startTime"
  63. >
  64. <view class="select" :class="{ active: form.endTime }">
  65. {{ form.endTime ? form.endTime : '请选择到访结束时间' }}
  66. <uni-icons type="down" size="20" color="#ccc"></uni-icons>
  67. </view>
  68. </uni-datetime-picker>
  69. </view>
  70. </view>
  71. <view class="box">
  72. <view class="box_key">访问事由:</view>
  73. <view class="box_value">
  74. <input class="input" type="text" placeholder="请输入访问事由" placeholder-style="color:#CCCCCC;font-size:28rpx" v-model="form.visitorReason" disabled />
  75. </view>
  76. </view>
  77. <!-- 提交按钮区域 -->
  78. <view class="btn" @click="handleSubmit">提交</view>
  79. </view>
  80. </view>
  81. </template>
  82. <script setup>
  83. import { onLoad } from '@dcloudio/uni-app'
  84. import { ref } from 'vue'
  85. import { getSchoolListDataReq, addVisitorRecordReq, getVisitorRecordReq } from '@/api/index.js'
  86. const form = ref({
  87. phone: '', // 手机号
  88. name: '', // 学生姓名
  89. cardId: '', // 证件号
  90. peerNum: 0, // 同行人数不能为空
  91. visitorReason: '学校报到', // 访问事由
  92. schoolId: '', // 校区id
  93. school: '', // 校区名称不能为空 只能为墨轩湖校区或黄家湖校区
  94. startTime: '', // 到访开始时间
  95. endTime: '', // 到访结束时间
  96. carNumber: '' // 车牌号
  97. })
  98. // 校区索引
  99. const currtIndex = ref(null)
  100. // 校区数组
  101. const schoolList = ref([])
  102. // 车牌弹窗DOM
  103. const xmKeyboard = ref()
  104. onLoad(() => {
  105. getVisitorRecord()
  106. })
  107. const getVisitorRecord = async () => {
  108. const res = await getVisitorRecordReq()
  109. // console.log(res)
  110. if (res.code == 200) {
  111. if (res.data) {
  112. uni.reLaunch({
  113. url: '/pages/mySubscribe/mySubscribe'
  114. })
  115. } else {
  116. let info = uni.getStorageSync('studentInfo')
  117. form.value.name = info.name
  118. form.value.phone = info.phone
  119. // form.value.cardId = info.cardId
  120. if (info.avs.length) {
  121. form.value.peerNum = info.avs.length
  122. }
  123. // 获取校区数据
  124. getSchoolListData()
  125. }
  126. }
  127. }
  128. // 获取校区数据
  129. const getSchoolListData = async () => {
  130. const res = await getSchoolListDataReq()
  131. // console.log(res)
  132. if (res.code == 200) {
  133. schoolList.value = res.data
  134. let info = uni.getStorageSync('studentInfo')
  135. if (info.schoolId) {
  136. schoolList.value.forEach((ele, index) => {
  137. if (ele.id == info.schoolId) {
  138. currtIndex.value = index
  139. }
  140. })
  141. form.value.school = info.school
  142. form.value.schoolId = info.schoolId
  143. }
  144. }
  145. }
  146. // 选择校区回调
  147. const bindPickerChange = (e) => {
  148. // console.log(e)
  149. currtIndex.value = e.detail.value
  150. form.value.school = schoolList.value[currtIndex.value].school
  151. form.value.schoolId = schoolList.value[currtIndex.value].id
  152. }
  153. // 打开选择车牌弹窗
  154. const showKeyboard = () => {
  155. xmKeyboard.value.toShow()
  156. }
  157. // 选择车牌弹窗完成按钮
  158. const confirm = (e) => {
  159. // console.log(e)
  160. form.value.carNumber = e
  161. }
  162. const changeTime = () => {
  163. form.value.endTime = ''
  164. }
  165. // 提交按钮回调
  166. const handleSubmit = () => {
  167. if (!form.value.name) {
  168. uni.showToast({
  169. title: '请输入学生姓名',
  170. icon: 'none'
  171. })
  172. return
  173. }
  174. if (!form.value.phone) {
  175. uni.showToast({
  176. title: '请输入手机号',
  177. icon: 'none'
  178. })
  179. return
  180. }
  181. let reg = /^1[3-9]\d{9}$/
  182. if (!reg.test(form.value.phone)) {
  183. uni.showToast({
  184. title: '手机号格式错误',
  185. icon: 'none'
  186. })
  187. return
  188. }
  189. // if (!form.value.peerNum) {
  190. // uni.showToast({
  191. // title: '请输入同行人数',
  192. // icon: 'none'
  193. // })
  194. // return
  195. // }
  196. if (currtIndex.value == null) {
  197. uni.showToast({
  198. title: '请选择校区',
  199. icon: 'none'
  200. })
  201. return
  202. }
  203. if (!form.value.carNumber) {
  204. uni.showToast({
  205. title: '请输入车牌号',
  206. icon: 'none'
  207. })
  208. return
  209. }
  210. if (!form.value.startTime) {
  211. uni.showToast({
  212. title: '请选择到访开始时间',
  213. icon: 'none'
  214. })
  215. return
  216. }
  217. if (!form.value.endTime) {
  218. uni.showToast({
  219. title: '请选择到访结束时间',
  220. icon: 'none'
  221. })
  222. return
  223. }
  224. if (!form.value.visitorReason) {
  225. uni.showToast({
  226. title: '请输入访问事由',
  227. icon: 'none'
  228. })
  229. return
  230. }
  231. submit()
  232. }
  233. // 提交请求
  234. const submit = () => {
  235. // console.log(form.value)
  236. uni.showModal({
  237. title: '提示',
  238. content: '车牌预约之后将不能修改,确定提交么?',
  239. success: async (res) => {
  240. if (res.confirm) {
  241. const res = await addVisitorRecordReq(form.value)
  242. // console.log(res)
  243. if (res.code == 200) {
  244. uni.showToast({
  245. title: '提交成功',
  246. icon: 'success'
  247. })
  248. setTimeout(() => {
  249. uni.reLaunch({
  250. url: '/pages/mySubscribe/mySubscribe'
  251. })
  252. }, 1500)
  253. }
  254. }
  255. }
  256. })
  257. }
  258. </script>
  259. <style lang="scss" scoped>
  260. .container {
  261. box-sizing: border-box;
  262. padding-top: 12rpx;
  263. min-height: 100vh;
  264. background-color: #f5f9ff;
  265. .body {
  266. box-sizing: border-box;
  267. padding: 30rpx 15rpx;
  268. background-color: #fff;
  269. .box {
  270. display: flex;
  271. align-items: center;
  272. margin-bottom: 20rpx;
  273. .box_key {
  274. width: 216rpx;
  275. font-size: 28rpx;
  276. text-align: end;
  277. }
  278. .box_value {
  279. padding: 0 20rpx;
  280. width: 507rpx;
  281. height: 74rpx;
  282. border-radius: 4rpx;
  283. border: 2rpx solid #cccccc;
  284. .input {
  285. height: 100%;
  286. }
  287. .select {
  288. display: flex;
  289. align-items: center;
  290. justify-content: space-between;
  291. height: 74rpx;
  292. font-size: 28rpx;
  293. color: #ccc;
  294. }
  295. .active {
  296. color: #000;
  297. }
  298. }
  299. }
  300. .btn {
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. margin: 100rpx auto 50rpx;
  305. height: 100rpx;
  306. font-size: 32rpx;
  307. color: #fff;
  308. border-radius: 8rpx;
  309. background-color: #0061ff;
  310. }
  311. }
  312. }
  313. </style>