index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. // pages/meeting/subscribe/index.js
  2. import {
  3. insertMeetingRecord,
  4. appointmentDateRecordList,
  5. checkTurnMeeting
  6. } from '../../../utils/api/meeting'
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. type: '',
  13. itemData: {},
  14. appointmentList: [],
  15. form: {
  16. meetingNum: 1,
  17. appointmentDate: null,
  18. aircondition: false,
  19. projection: false,
  20. meetingMonogramStatus: false
  21. },
  22. logoList: [{
  23. name: '需要',
  24. id: true
  25. },
  26. {
  27. name: '不需要',
  28. id: false
  29. },
  30. ],
  31. leftList: [],
  32. rightList: [],
  33. timePeriodList: [],
  34. subscribeYear: null,
  35. startDate: '',
  36. endDate: '',
  37. startTime: '',
  38. endTime: '',
  39. timeDisabled: false,
  40. },
  41. // 获取会议室布局
  42. getSeat() {
  43. let seatNum = this.data.itemData.seatNum
  44. let leftList = []
  45. let rightList = []
  46. for (let i = 0; i < seatNum; i++) {
  47. let data = {
  48. monogram: '',
  49. snack: false,
  50. teaWater: '',
  51. }
  52. if (i % 2 == 0) {
  53. leftList.push(data)
  54. } else {
  55. rightList.push(data)
  56. }
  57. }
  58. this.setData({
  59. leftList,
  60. rightList
  61. })
  62. },
  63. // 茶水
  64. getTeaWater(e) {
  65. let dataset = e.detail.currentTarget.dataset
  66. let name = "leftList[" + dataset.index + "].teaWater"
  67. let name1 = "rightList[" + dataset.index + "].teaWater"
  68. if (dataset.type === 'left') {
  69. this.setData({
  70. [name]: this.data.itemData.meetingBeforeTeaList[e.detail.detail.value]
  71. })
  72. }
  73. if (dataset.type === 'right') {
  74. this.setData({
  75. [name1]: this.data.itemData.meetingBeforeTeaList[e.detail.detail.value]
  76. })
  77. }
  78. },
  79. // 清除茶水
  80. getCleaeTea(e) {
  81. let dataset = e.detail.currentTarget.dataset
  82. let name = "leftList[" + dataset.index + "].teaWater"
  83. let name1 = "rightList[" + dataset.index + "].teaWater"
  84. if (dataset.type === 'left') {
  85. this.setData({
  86. [name]: ''
  87. })
  88. }
  89. if (dataset.type === 'right') {
  90. this.setData({
  91. [name1]: ''
  92. })
  93. }
  94. },
  95. // 点心
  96. getSnack(e) {
  97. let dataset = e.detail.currentTarget.dataset
  98. let name = "leftList[" + dataset.index + "].snack"
  99. let name1 = "rightList[" + dataset.index + "].snack"
  100. if (dataset.type === 'left') {
  101. this.setData({
  102. [name]: !this.data.leftList[dataset.index].snack
  103. })
  104. }
  105. if (dataset.type === 'right') {
  106. this.setData({
  107. [name1]: !this.data.rightList[dataset.index].snack
  108. })
  109. }
  110. },
  111. // 桌签
  112. getMonogram(e) {
  113. let dataset = e.detail
  114. let name = "leftList[" + dataset.index + "].monogram"
  115. let name1 = "rightList[" + dataset.index + "].monogram"
  116. if (dataset.type === 'left') {
  117. this.setData({
  118. [name]: dataset.val
  119. })
  120. }
  121. if (dataset.type === 'right') {
  122. this.setData({
  123. [name1]: dataset.val
  124. })
  125. }
  126. },
  127. getValue(e) {
  128. let type = e.currentTarget.dataset.type
  129. this.setData({
  130. [`form.${type}`]: e.detail
  131. });
  132. if (type == "appointmentDate") {
  133. this.appointmentDateRecordList(e.detail)
  134. }
  135. },
  136. getValue1(e) {
  137. this.setData({
  138. [`form.${e.detail}`]: !this.data.form[e.detail]
  139. })
  140. },
  141. // 会议时间赋值
  142. chooseTime(e) {
  143. let item = e.currentTarget.dataset.item
  144. if (item.type == 1) {
  145. this.setData({
  146. 'form.appointmentStartTime': item.startTime,
  147. 'form.appointmentEndTime': item.endTime,
  148. startTime: item.startTime,
  149. endTime: item.endTime,
  150. })
  151. }
  152. },
  153. // 提交
  154. submit() {
  155. let {
  156. form,
  157. itemData,
  158. leftList,
  159. rightList,
  160. type,
  161. timePeriodList
  162. } = this.data
  163. let that = this
  164. let isType=false
  165. timePeriodList.forEach(item=>{
  166. if(item.type==1){
  167. isType=true
  168. }
  169. })
  170. if(!itemData.meetingTurnRecordId &&!isType){
  171. wx.showToast({
  172. title: '当天会议室已经约满',
  173. icon: 'none'
  174. })
  175. return
  176. }
  177. if (!form.appointmentStartTime || !form.appointmentEndTime) {
  178. wx.showToast({
  179. title: '点击绿色时间段选择会议时间',
  180. icon: 'none'
  181. })
  182. return
  183. }
  184. if (!form.meetingMonogramStatus) {
  185. form.meetingMonogram = null
  186. }
  187. form.meetingRoomId = itemData.meetingRoomId
  188. form.meetingDeskVoList = leftList
  189. form.meetingDeskOtherSideVoList = rightList
  190. if (type == 'transfer-audit') {
  191. form.status = itemData.status
  192. form.refuseReason = itemData.refuseReason
  193. form.meetingTurnRecordId = itemData.meetingTurnRecordId
  194. }
  195. wx.requestSubscribeMessage({
  196. tmplIds: ['mJs6TXjIFuwgPu2JOEIpu3lO9ym9rnai-schUPuLuok'],
  197. success() {
  198. that.check()
  199. }
  200. })
  201. },
  202. async check() {
  203. let {
  204. form,
  205. type
  206. } = this.data
  207. let res
  208. if (type == 'transfer-audit') {
  209. res = await checkTurnMeeting(form)
  210. } else {
  211. res = await insertMeetingRecord(form)
  212. }
  213. if (res.code == 200) {
  214. wx.showToast({
  215. title: '提交成功',
  216. icon: 'none',
  217. duration: 800,
  218. mask: true,
  219. success: function () {
  220. setTimeout(function () {
  221. wx.switchTab({
  222. url: '/pages/home/home',
  223. })
  224. }, 800)
  225. }
  226. })
  227. }
  228. },
  229. // 获取预约日期
  230. getStartDate() {
  231. let {
  232. subscribeYear,
  233. type
  234. } = this.data
  235. this.setData({
  236. startDate: subscribeYear,
  237. 'form.appointmentDate': subscribeYear,
  238. })
  239. if (type != 'transfer-audit') {
  240. this.appointmentDateRecordList(this.data.form.appointmentDate)
  241. }
  242. },
  243. // 获取已预约时间段
  244. appointmentDateRecordList(year) {
  245. let data = {
  246. appointmentDate: year,
  247. meetingRoomId: this.data.itemData.meetingRoomId
  248. }
  249. appointmentDateRecordList(data).then(res => {
  250. this.setData({
  251. appointmentList: res.data
  252. })
  253. this.getTime()
  254. })
  255. },
  256. // 获取时间段
  257. getTime() {
  258. let {
  259. appointmentList,
  260. itemData,
  261. form
  262. } = this.data
  263. if (appointmentList.length == 0) {
  264. let timePeriodList = []
  265. timePeriodList.push({
  266. startTime: itemData.canAppointmentStartTime,
  267. endTime: itemData.canAppointmentEndTime,
  268. type: 1
  269. })
  270. this.setData({
  271. 'form.appointmentStartTime': itemData.canAppointmentStartTime,
  272. 'form.appointmentEndTime': itemData.canAppointmentEndTime,
  273. startTime: itemData.canAppointmentStartTime,
  274. endTime: itemData.canAppointmentEndTime,
  275. timePeriodList
  276. })
  277. } else {
  278. let timePeriodList = []
  279. let ttt = itemData.meetingInterval * 60 * 1000; //获取间隔时间(时间戳)
  280. // 会议总的预约时间(时间戳)
  281. let orderStartTime = Date.parse(form.appointmentDate + ' ' + itemData.canAppointmentStartTime + ':00')
  282. let orderEndTime = Date.parse(form.appointmentDate + ' ' + itemData.canAppointmentEndTime + ':00')
  283. appointmentList.forEach((item, index) => {
  284. let timeStart = Date.parse(form.appointmentDate + ' ' + item.appointmentStartTime + ':00')
  285. let timeEnd = Date.parse(form.appointmentDate + ' ' + appointmentList[(index == 0 ? index : index - 1)].appointmentEndTime + ':00')
  286. let timeEnd1 = Date.parse(form.appointmentDate + ' ' + appointmentList[(index == 0 ? index : index - 1)].appointmentEndTime + ':00')
  287. timePeriodList.push({
  288. startTime: index==0 ? itemData.canAppointmentStartTime : this.convertTime(timeEnd + ttt),
  289. endTime: this.convertTime(timeStart - ttt),
  290. type: 1, //1:可点击;2:禁用
  291. id: index + 'q'
  292. }, {
  293. startTime: item.appointmentStartTime,
  294. endTime: item.appointmentEndTime,
  295. type: 2,
  296. id: index + 'w'
  297. }, )
  298. // 如果已经预约开始时间-间隔时间<会议预约开始时间,去掉前面一项
  299. let index1 = timePeriodList.findIndex(item => {
  300. return item.id == index + 'q'
  301. })
  302. if (index == 0) {
  303. if (timeStart - ttt <= orderStartTime) {
  304. timePeriodList.splice(index1, 1)
  305. }
  306. } else {
  307. if ((timeStart - ttt) <= timeEnd1) {
  308. timePeriodList.splice(index1, 1)
  309. } else if ((timeEnd + ttt) >= (timeStart - ttt)) {
  310. // 如果开始时间>结束时间,去掉前面一项
  311. timePeriodList.splice(index1, 1)
  312. }
  313. }
  314. })
  315. // 获取最后可点击一项
  316. let cc = appointmentList[appointmentList.length - 1].appointmentEndTime
  317. let dd = Date.parse(form.appointmentDate + ' ' + cc + ':00')
  318. if (dd + ttt < orderEndTime) {
  319. timePeriodList.push({
  320. startTime: this.convertTime(dd + ttt),
  321. endTime: itemData.canAppointmentEndTime,
  322. type: 1
  323. })
  324. }
  325. this.setData({
  326. timePeriodList
  327. })
  328. }
  329. },
  330. // 时间补零
  331. convertTime(timestamp) {
  332. let time = new Date(timestamp)
  333. let hours = time.getHours()
  334. let minute = time.getMinutes()
  335. if (hours < 10) {
  336. hours = '0' + hours
  337. }
  338. if (minute < 10) {
  339. minute = '0' + minute
  340. }
  341. return hours + ":" + minute
  342. },
  343. /**
  344. * 生命周期函数--监听页面加载
  345. */
  346. onLoad(options) {
  347. if (options.type) {
  348. this.setData({
  349. type: options.type,
  350. itemData: JSON.parse(options.itemData),
  351. appointmentList: options.appointmentList ? JSON.parse(options.appointmentList) : [],
  352. endDate: options.endDate,
  353. subscribeYear: options.subscribeYear
  354. })
  355. }
  356. // 转让,禁止修改日期时间
  357. if (this.data.type == 'transfer-audit') {
  358. let {
  359. itemData
  360. } = this.data
  361. this.setData({
  362. startTime: itemData.appointmentStartTime,
  363. endTime: itemData.appointmentEndTime,
  364. 'form.appointmentStartTime': itemData.appointmentStartTime,
  365. 'form.appointmentEndTime': itemData.appointmentEndTime,
  366. timeDisabled: true,
  367. })
  368. }
  369. this.getStartDate()
  370. this.getSeat()
  371. },
  372. /**
  373. * 生命周期函数--监听页面初次渲染完成
  374. */
  375. onReady() {
  376. },
  377. /**
  378. * 生命周期函数--监听页面显示
  379. */
  380. onShow() {
  381. },
  382. /**
  383. * 生命周期函数--监听页面隐藏
  384. */
  385. onHide() {
  386. },
  387. /**
  388. * 生命周期函数--监听页面卸载
  389. */
  390. onUnload() {
  391. },
  392. /**
  393. * 页面相关事件处理函数--监听用户下拉动作
  394. */
  395. onPullDownRefresh() {
  396. },
  397. /**
  398. * 页面上拉触底事件的处理函数
  399. */
  400. onReachBottom() {
  401. },
  402. /**
  403. * 用户点击右上角分享
  404. */
  405. onShareAppMessage() {
  406. }
  407. })