index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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: 0,
  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: null,
  49. snack: false,
  50. teaWater: null,
  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. getSnack(e) {
  81. let dataset = e.detail.currentTarget.dataset
  82. let name = "leftList[" + dataset.index + "].snack"
  83. let name1 = "rightList[" + dataset.index + "].snack"
  84. if (dataset.type === 'left') {
  85. this.setData({
  86. [name]: !this.data.leftList[dataset.index].snack
  87. })
  88. }
  89. if (dataset.type === 'right') {
  90. this.setData({
  91. [name1]: !this.data.rightList[dataset.index].snack
  92. })
  93. }
  94. },
  95. // 桌签
  96. getMonogram(e) {
  97. let dataset = e.detail
  98. let name = "leftList[" + dataset.index + "].monogram"
  99. let name1 = "rightList[" + dataset.index + "].monogram"
  100. if (dataset.type === 'left') {
  101. this.setData({
  102. [name]: dataset.val
  103. })
  104. }
  105. if (dataset.type === 'right') {
  106. this.setData({
  107. [name1]: dataset.val
  108. })
  109. }
  110. },
  111. getValue(e) {
  112. let type = e.currentTarget.dataset.type
  113. this.setData({
  114. [`form.${type}`]: e.detail
  115. });
  116. if (type == "appointmentDate") {
  117. this.appointmentDateRecordList(e.detail)
  118. }
  119. // if (type == "meetingNum") {
  120. // this.getSeat()
  121. // }
  122. },
  123. getValue1(e) {
  124. this.setData({
  125. [`form.${e.detail}`]: !this.data.form[e.detail]
  126. })
  127. },
  128. // 会议时间赋值
  129. chooseTime(e) {
  130. let item = e.currentTarget.dataset.item
  131. if (item.type == 1) {
  132. this.setData({
  133. 'form.appointmentStartTime': item.startTime,
  134. 'form.appointmentEndTime': item.endTime,
  135. startTime: item.startTime,
  136. endTime: item.endTime,
  137. })
  138. }
  139. },
  140. // 提交
  141. submit() {
  142. let {
  143. form,
  144. itemData,
  145. leftList,
  146. rightList,
  147. type
  148. } = this.data
  149. if (!form.appointmentStartTime || !form.appointmentEndTime) {
  150. wx.showToast({
  151. title: '请填写完整',
  152. icon: 'none'
  153. })
  154. return
  155. }
  156. if (!form.meetingMonogramStatus) {
  157. form.meetingMonogram = null
  158. }
  159. form.meetingRoomId = itemData.meetingRoomId
  160. form.meetingDeskVoList = leftList
  161. form.meetingDeskOtherSideVoList = rightList
  162. if (type == 'transfer-audit') {
  163. form.status = itemData.status
  164. form.refuseReason = itemData.refuseReason
  165. form.meetingTurnRecordId = itemData.meetingTurnRecordId
  166. }
  167. wx.requestSubscribeMessage({
  168. tmplIds: ['mJs6TXjIFuwgPu2JOEIpu3lO9ym9rnai-schUPuLuok'],
  169. success(res) {
  170. if (type == 'transfer-audit') {
  171. checkTurnMeeting(form).then(res => {
  172. wx.showToast({
  173. title: '提交成功',
  174. icon: 'none',
  175. duration: 800,
  176. mask: true,
  177. success: function () {
  178. setTimeout(function () {
  179. wx.switchTab({
  180. url: '/pages/home/home',
  181. })
  182. }, 800)
  183. }
  184. })
  185. })
  186. } else {
  187. insertMeetingRecord(form).then(res => {
  188. wx.showToast({
  189. title: '提交成功',
  190. icon: 'none',
  191. duration: 800,
  192. mask: true,
  193. success: function () {
  194. setTimeout(function () {
  195. wx.switchTab({
  196. url: '/pages/home/home',
  197. })
  198. }, 800)
  199. }
  200. })
  201. })
  202. }
  203. }
  204. })
  205. },
  206. // 获取预约日期
  207. getStartDate() {
  208. let {
  209. subscribeYear,
  210. type
  211. } = this.data
  212. this.setData({
  213. startDate: subscribeYear,
  214. 'form.appointmentDate': subscribeYear,
  215. })
  216. if (type != 'transfer-audit') {
  217. this.appointmentDateRecordList(this.data.form.appointmentDate)
  218. }
  219. },
  220. // 获取已预约时间段
  221. appointmentDateRecordList(year) {
  222. let data = {
  223. appointmentDate: year,
  224. meetingRoomId: this.data.itemData.meetingRoomId
  225. }
  226. appointmentDateRecordList(data).then(res => {
  227. this.setData({
  228. appointmentList: res.data
  229. })
  230. this.getTime()
  231. })
  232. },
  233. // 获取时间段
  234. getTime() {
  235. let {
  236. appointmentList,
  237. itemData,
  238. form
  239. } = this.data
  240. if (appointmentList.length == 0) {
  241. let timePeriodList = []
  242. timePeriodList.push({
  243. startTime: itemData.canAppointmentStartTime,
  244. endTime: itemData.canAppointmentEndTime,
  245. type: 1
  246. })
  247. this.setData({
  248. 'form.appointmentStartTime': itemData.canAppointmentStartTime,
  249. 'form.appointmentEndTime': itemData.canAppointmentEndTime,
  250. startTime: itemData.canAppointmentStartTime,
  251. endTime: itemData.canAppointmentEndTime,
  252. timePeriodList
  253. })
  254. } else {
  255. let timePeriodList = []
  256. let ttt = itemData.meetingInterval * 60 * 1000; //获取间隔时间(时间戳)
  257. // 会议总的预约时间(时间戳)
  258. let orderStartTime = Date.parse(form.appointmentDate + ' ' + itemData.canAppointmentStartTime + ':00')
  259. let orderEndTime = Date.parse(form.appointmentDate + ' ' + itemData.canAppointmentEndTime + ':00')
  260. appointmentList.forEach((item, index) => {
  261. let timeStart = Date.parse(form.appointmentDate + ' ' + item.appointmentStartTime + ':00')
  262. let timeEnd = Date.parse(form.appointmentDate + ' ' + appointmentList[(index == 0 ? index : index - 1)].appointmentEndTime + ':00')
  263. let timeEnd1 = Date.parse(form.appointmentDate + ' ' + appointmentList[(index == 0 ? index : index - 1)].appointmentEndTime + ':00')
  264. timePeriodList.push({
  265. startTime: appointmentList.length == 0 ? itemData.canAppointmentStartTime : this.convertTime(timeEnd + ttt),
  266. endTime: this.convertTime(timeStart - ttt),
  267. type: 1, //1:可点击;2:禁用
  268. id: index + 'q'
  269. }, {
  270. startTime: item.appointmentStartTime,
  271. endTime: item.appointmentEndTime,
  272. type: 2,
  273. id: index + 'w'
  274. }, )
  275. // 如果已经预约开始时间-间隔时间<会议预约开始时间,去掉前面一项
  276. let index1 = timePeriodList.findIndex(item => {
  277. return item.id == index + 'q'
  278. })
  279. if (index == 0) {
  280. if (timeStart - ttt <= orderStartTime) {
  281. timePeriodList.splice(index1, 1)
  282. }
  283. } else {
  284. if ((timeStart - ttt) <= timeEnd1) {
  285. timePeriodList.splice(index1, 1)
  286. } else if ((timeEnd + ttt) >= (timeStart - ttt)) {
  287. // 如果开始时间>结束时间,去掉前面一项
  288. timePeriodList.splice(index1, 1)
  289. }
  290. }
  291. })
  292. // 获取最后可点击一项
  293. let cc = appointmentList[appointmentList.length - 1].appointmentEndTime
  294. let dd = Date.parse(form.appointmentDate + ' ' + cc + ':00')
  295. if (dd + ttt < orderEndTime) {
  296. timePeriodList.push({
  297. startTime: this.convertTime(dd + ttt),
  298. endTime: itemData.canAppointmentEndTime,
  299. type: 1
  300. })
  301. }
  302. this.setData({
  303. timePeriodList
  304. })
  305. }
  306. },
  307. // 时间补零
  308. convertTime(timestamp) {
  309. let time = new Date(timestamp)
  310. let hours = time.getHours()
  311. let minute = time.getMinutes()
  312. if (hours < 10) {
  313. hours = '0' + hours
  314. }
  315. if (minute < 10) {
  316. minute = '0' + minute
  317. }
  318. return hours + ":" + minute
  319. },
  320. /**
  321. * 生命周期函数--监听页面加载
  322. */
  323. onLoad(options) {
  324. if (options.type) {
  325. this.setData({
  326. type: options.type,
  327. itemData: JSON.parse(options.itemData),
  328. appointmentList: options.appointmentList ? JSON.parse(options.appointmentList) : [],
  329. endDate: options.endDate,
  330. subscribeYear: options.subscribeYear
  331. })
  332. }
  333. // 转让,禁止修改日期时间
  334. if (this.data.type == 'transfer-audit') {
  335. let {
  336. itemData
  337. } = this.data
  338. this.setData({
  339. startTime: itemData.appointmentStartTime,
  340. endTime: itemData.appointmentEndTime,
  341. 'form.appointmentStartTime': itemData.appointmentStartTime,
  342. 'form.appointmentEndTime': itemData.appointmentEndTime,
  343. timeDisabled: true,
  344. })
  345. }
  346. this.getStartDate()
  347. this.getSeat()
  348. },
  349. /**
  350. * 生命周期函数--监听页面初次渲染完成
  351. */
  352. onReady() {
  353. },
  354. /**
  355. * 生命周期函数--监听页面显示
  356. */
  357. onShow() {
  358. },
  359. /**
  360. * 生命周期函数--监听页面隐藏
  361. */
  362. onHide() {
  363. },
  364. /**
  365. * 生命周期函数--监听页面卸载
  366. */
  367. onUnload() {
  368. },
  369. /**
  370. * 页面相关事件处理函数--监听用户下拉动作
  371. */
  372. onPullDownRefresh() {
  373. },
  374. /**
  375. * 页面上拉触底事件的处理函数
  376. */
  377. onReachBottom() {
  378. },
  379. /**
  380. * 用户点击右上角分享
  381. */
  382. onShareAppMessage() {
  383. }
  384. })