add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <div class="resourceAdd">
  3. <div class="topBox">
  4. <div class="topTitle">资源预约</div>
  5. <div class="choosTimeBox">
  6. <span class="msg">使用时间</span>
  7. <span class="choosIpt" @click="showTime('startTime')">{{ startTime }} </span>
  8. <span class="choosIpt" @click="showTimeList('startTime')">{{ timeListStr }} </span>
  9. <!-- <input placeholder="请选择时间段" class="choosIpt" disabled>-->
  10. </div>
  11. </div>
  12. <ul class="predetermineUl">
  13. <li class="detailLi">
  14. <span class="liName">主题</span>
  15. <span>
  16. <input placeholder="请填写">
  17. <input class="liInfo" placeholder="请填写" v-model="form.subject">
  18. </span>
  19. </li>
  20. <li class="detailLi">
  21. <span class="liName">容纳人数</span>
  22. <span>
  23. <input class="liInfo" placeholder="请填写整数" v-model="form.peopleNumber">
  24. </span>
  25. </li>
  26. <li class="detailLi">
  27. <span class="liName">联系人</span>
  28. <span>
  29. <input class="liInfo" placeholder="请填写" v-model="form.contacts">
  30. </span>
  31. </li>
  32. <li class="detailLi">
  33. <span class="liName">联系电话</span>
  34. <span>
  35. <input class="liInfo" placeholder="请填写" v-model="form.phone">
  36. </span>
  37. </li>
  38. <li class="detailLi2" style="border-bottom: none">
  39. <div class="titleBox">
  40. <span class="liName">备注</span>
  41. </div>
  42. <van-field
  43. :value="form.remarks"
  44. autosize
  45. type="textarea"
  46. placeholder="请输入"
  47. class="myField"
  48. maxlength="2000"
  49. show-word-limit
  50. />
  51. </li>
  52. </ul>
  53. <ul class="predetermineUl">
  54. <li class="detailLi">
  55. <span class="liName">预约单位</span>
  56. <span>
  57. <input class="liInfo" placeholder="" v-model="form.unit">
  58. </span>
  59. </li>
  60. <li class="detailLi">
  61. <span class="liName">预约人</span>
  62. <span>
  63. <input class="liInfo" placeholder="请填写" v-model="form.appointUserName">
  64. </span>
  65. </li>
  66. <li class="detailLi">
  67. <span class="liName">预约时间</span>
  68. <span>
  69. <input class="liInfo" placeholder="请填写" v-model="form.appointTime" disabled>
  70. </span>
  71. </li>
  72. </ul>
  73. <div class="buttonBox">
  74. <button class="btn zcBtn" @click="meetingAppointSubmit('1')">暂存</button>
  75. <button class="btn tjBtn" @click="meetingAppointSubmit('2')">提交</button>
  76. </div>
  77. <van-popup
  78. :show="timeShow"
  79. position="bottom"
  80. custom-style="height: 50%;"
  81. >
  82. <van-datetime-picker
  83. type="date"
  84. :value="currentDate"
  85. :formatter="formatter"
  86. @cancel="timeShow=false"
  87. @confirm="selectTime"
  88. />
  89. </van-popup>
  90. <van-popup
  91. :show="timeListShow"
  92. position="bottom"
  93. custom-style="height: 50%;"
  94. >
  95. <van-picker
  96. show-toolbar
  97. :columns="timeList"
  98. value-key="label"
  99. @confirm="selectTimeList"
  100. @cancel="timeListShow = false"
  101. />
  102. </van-popup>
  103. </div>
  104. </template>
  105. <script>
  106. import {getByCodes, getUserDept, getUserLocalStorageInfo, meetingAppoint, meetingAppointCheck} from "@/js_sdk/http";
  107. import dayjs from "dayjs";
  108. // import Toast from "../../../wxcomponents/weapp/lib/toast/index.vue";
  109. export default {
  110. name: "add",
  111. data() {
  112. return {
  113. dc_key: ['timeSlot'],
  114. getUserLocalStorageInfo: getUserLocalStorageInfo(),
  115. theme: '',
  116. unit: '',
  117. postData: {},
  118. form: {
  119. createdId: getUserLocalStorageInfo().userId,
  120. appointTime: dayjs().format('YYYY-MM-DD HH:mm'),
  121. userType: getUserLocalStorageInfo().userType
  122. },
  123. meetingRoomId: '',
  124. startTime: '请选择使用时间',
  125. timeShow: false,
  126. timePickerType: '',
  127. currentDate: new Date().getTime(),
  128. timeList: [], // 时间段列表
  129. timeListStr: '请选择时间段',
  130. timeListShow: false,
  131. dic_SelectList: [],
  132. }
  133. },
  134. created() {
  135. this.getByCodes()
  136. },
  137. onLoad(options) {
  138. this.meetingRoomId = options.meetingRoomId
  139. },
  140. onShow() {
  141. // 企业端
  142. if (getUserLocalStorageInfo().userType == '1') {
  143. this.form.unit = getUserLocalStorageInfo().username
  144. }
  145. // 管理端
  146. if (getUserLocalStorageInfo().userType == '2') {
  147. const data = {
  148. id: getUserLocalStorageInfo().userId
  149. }
  150. getUserDept(data).then(res => {
  151. this.form.unit = res.msg
  152. })
  153. }
  154. },
  155. methods: {
  156. async getByCodes() {
  157. let data = await getByCodes(JSON.stringify(this.dc_key));
  158. this.dic_SelectList = this.$common.handleDicList(data);
  159. // this.timeList = this.dic_SelectList.timeSlot.map(item =>{
  160. // return item.label;
  161. // });
  162. this.timeList = this.dic_SelectList.timeSlot
  163. },
  164. showTime(e) {
  165. this.timePickerType = e
  166. this.timeShow = true
  167. },
  168. showTimeList(e) {
  169. this.timePickerType = e
  170. this.timeListShow = true
  171. },
  172. // 时间戳转换方法
  173. timestampToDate(timestamp) {
  174. const date = new Date(timestamp); // 如果timestamp是字符串,确保它是整数:parseInt(timestamp)
  175. const year = date.getFullYear();
  176. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  177. const day = date.getDate().toString().padStart(2, '0');
  178. const hours = date.getHours().toString().padStart(2, '0');
  179. const minutes = date.getMinutes().toString().padStart(2, '0');
  180. const seconds = date.getSeconds().toString().padStart(2, '0');
  181. return `${year}-${month}-${day}`;
  182. },
  183. // 时间选择单位
  184. formatter(type, val) {
  185. if (type === 'year') {
  186. return `${val}年`;
  187. } else if (type === 'month') {
  188. return `${val}月`;
  189. } else if (type === 'day') {
  190. return `${val}日`;
  191. } else if (type === 'hour') {
  192. return `${val}时`;
  193. } else if (type === 'minute') {
  194. return `${val}分`;
  195. }
  196. return val;
  197. },
  198. selectTime(e) {
  199. const dateString = this.timestampToDate(e.detail);
  200. this.startTime = dateString
  201. this.timeShow = false
  202. // this.getRoomTime(this.startTime)
  203. },
  204. selectTimeList(e) {
  205. const data = {
  206. id: this.meetingRoomId,
  207. dateStr: this.startTime,
  208. timeSlot: e.detail.value.value
  209. }
  210. meetingAppointCheck(data).then((res) => {
  211. if (res.code == '200') {
  212. this.timeListStr = e.detail.value.label
  213. this.form.timeSlot = e.detail.value.value
  214. this.timeListShow = false
  215. } else {
  216. this.$showToast("时间段已占用或已冻结,请重新选择");
  217. }
  218. }).catch(err => {
  219. this.$showToast(err);
  220. })
  221. },
  222. // // 获取日期可以选择的区间
  223. // getRoomTime(roomTime) {
  224. // const reqData = {
  225. // id: this.roomId,
  226. // useTime: roomTime
  227. // }
  228. // roomTimeSoltUseful(reqData).then((res) => {
  229. // this.timeList = res.data
  230. // console.log('获取日期可以选择的区间_:', res)
  231. // })
  232. // },
  233. // 提交预约
  234. meetingAppointSubmit(e) {
  235. if (this.startTime !== '' && this.startTime !== null && this.startTime !== undefined &&
  236. this.endTime !== '' && this.endTime !== null && this.endTime !== undefined) {
  237. uni.showToast({
  238. title: "请选择使用时间",
  239. });
  240. return false
  241. }
  242. this.form.saveType = e
  243. this.form.useTime = this.startTime
  244. this.form.meetingRoomId = this.meetingRoomId
  245. console.log('提交预约_:', this.form)
  246. meetingAppoint(this.form).then((res) => {
  247. console.log('提交预约_:', res)
  248. if (res.code == '200') {
  249. uni.showToast({
  250. title: '预约成功',
  251. icon: 'success',
  252. mask: true,
  253. duration: 1000
  254. });
  255. uni.navigateBack({})
  256. } else {
  257. uni.showToast({
  258. title: res.msg,
  259. icon: 'success',
  260. mask: true,
  261. duration: 1000
  262. });
  263. }
  264. })
  265. },
  266. }
  267. }
  268. </script>
  269. <style lang="scss">
  270. .resourceAdd {
  271. .topBox {
  272. padding: 24rpx 32rpx;
  273. background: white;
  274. margin: 24rpx 0;
  275. .topTitle {
  276. color: rgba(34, 34, 34, 1);
  277. font-size: 36rpx;
  278. font-weight: 600;
  279. }
  280. .choosTimeBox {
  281. display: flex;
  282. justify-content: space-between;
  283. align-items: center;
  284. .msg {
  285. color: rgba(51, 51, 51, 1);
  286. font-size: 32rpx;
  287. white-space: nowrap;
  288. }
  289. .choosIpt {
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. width: 260rpx;
  294. height: 96rpx;
  295. font-size: 32rpx;
  296. background: rgba(245, 247, 250, 1);
  297. box-sizing: border-box;
  298. }
  299. }
  300. }
  301. .predetermineUl {
  302. margin: 24rpx 0;
  303. background: white;
  304. box-sizing: border-box;
  305. padding: 0 32rpx;
  306. .predetermineLi {
  307. padding: 32rpx 0;
  308. border-bottom: 1px solid rgba(230, 230, 230, 1);
  309. display: flex;
  310. justify-content: space-between;
  311. }
  312. .predetermineLi2 {
  313. padding: 32rpx 0;
  314. border-bottom: 1px solid rgba(230, 230, 230, 1);
  315. display: flex;
  316. flex-direction: column;
  317. }
  318. .van-cell {
  319. background: #F5F7FA !important;
  320. border-radius: 8rpx;
  321. font-size: 28rpx;
  322. margin-top: 16rpx;
  323. }
  324. .liName {
  325. color: rgba(51, 51, 51, 1);
  326. font-size: 32rpx;
  327. }
  328. .liIpt {
  329. color: rgba(102, 102, 102, 1);
  330. font-size: 32rpx;
  331. text-align: right;
  332. }
  333. .detailLi {
  334. display: flex;
  335. justify-content: space-between;
  336. align-items: center;
  337. padding: 32rpx 0;
  338. border-bottom: 2rpx solid #E6E6E6;
  339. .liInfo {
  340. display: inline-block;
  341. text-align: right;
  342. max-width: 488rpx;
  343. width: 488rpx;
  344. color: rgba(102, 102, 102, 1);
  345. font-size: 32rpx;
  346. line-height: 38rpx;
  347. .radio {
  348. margin-left: 64rpx;
  349. }
  350. }
  351. }
  352. .detailLi2 {
  353. display: flex;
  354. flex-direction: column;
  355. padding: 32rpx 0;
  356. border-bottom: 2rpx solid #E6E6E6;
  357. .detailLi2BoxTop {
  358. display: flex;
  359. flex-wrap: wrap;
  360. justify-content: space-between;
  361. margin: 12rpx 0;
  362. .checkItem {
  363. width: 128rpx;
  364. height: 64rpx;
  365. font-size: 28rpx;
  366. color: #666666;
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. background: #F5F7FA;
  371. border-radius: 8rpx;
  372. margin: 12rpx 0;
  373. }
  374. .checked {
  375. background: #0365F9;
  376. color: white;
  377. }
  378. }
  379. }
  380. }
  381. .buttonBox {
  382. display: flex;
  383. justify-content: center;
  384. .btn {
  385. width: 240rpx;
  386. height: 80rpx;
  387. display: flex;
  388. border-radius: 8rpx;
  389. align-items: center;
  390. justify-content: center;
  391. margin: 48rpx 16rpx 150rpx 16rpx;
  392. color: white;
  393. letter-spacing: 2rpx;
  394. text-indent: 2rpx;
  395. }
  396. .zcBtn {
  397. background: #FE8643;
  398. }
  399. .tjBtn {
  400. background: #0365F9;
  401. }
  402. }
  403. }
  404. </style>