subscribe.vue 8.2 KB

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