classList.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // pages/Components/classList/classList.js
  2. const app = getApp()
  3. const util = require("../../../utils/util")
  4. const urlDef = require("../../../utils/urls")
  5. Component({
  6. lifetimes: {
  7. attached: function () {
  8. wx.getSystemInfo({
  9. success: (result) => {
  10. this.setData({
  11. height: result.windowHeight
  12. })
  13. },
  14. })
  15. }
  16. },
  17. pageLifetimes: {
  18. show: function () {
  19. let action = this.properties.action
  20. this.setData({ action: action })
  21. if ('1' == this.data.action) {
  22. this.setData({ actionName: '补' })
  23. } else if ('2' == this.data.action) {
  24. this.setData({ actionName: '加' })
  25. } else {
  26. this.setData({ actionName: '调' })
  27. }
  28. }
  29. },
  30. /**
  31. * 组件的属性列表
  32. */
  33. properties: {
  34. showLeaveNum: { //是否显示请假余额
  35. type: Boolean,
  36. value: false
  37. },
  38. showTime: { //是否显示上课时间
  39. type: Boolean,
  40. value: true
  41. },
  42. showFlag: { //是否显示上课状态
  43. type: Boolean,
  44. value: true
  45. },
  46. showBtn: { //是否显示功能按钮
  47. type: Boolean,
  48. value: false,
  49. },
  50. showRadio: { //是否显示单选按钮
  51. type: Boolean,
  52. value: false,
  53. },
  54. showLevel: {
  55. type: Boolean,
  56. value: false,
  57. },
  58. date: {
  59. type: String
  60. },
  61. list: {
  62. type: Array,
  63. value: []
  64. },
  65. action: {
  66. type: String
  67. },
  68. source: {
  69. type: Object
  70. }
  71. },
  72. /**
  73. * 组件的初始数据
  74. */
  75. data: {
  76. animation: null,
  77. height: 0,
  78. overflow: 'auto',
  79. source: null,
  80. target: null,
  81. key: null,
  82. action: null,
  83. actionName: null
  84. },
  85. /**
  86. * 组件的方法列表
  87. */
  88. methods: {
  89. toPages: function (e) {
  90. let urls = urlDef.urls
  91. let stu = wx.getStorageSync('student')
  92. let item = e.currentTarget.dataset.item;
  93. this.properties.list.map(h => {
  94. if (item == null) {
  95. if (h.items && h.items.length > 0) {
  96. item = h.items.filter(o => o.id == e.currentTarget.dataset.id)[0]
  97. }
  98. }
  99. })
  100. let action = e.currentTarget.dataset.action
  101. if (action == '1' || action == '3' || action == '4') {
  102. item.curDate = item.beginTime.substring(0, 10)
  103. wx.navigateTo({
  104. url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: item, action: (action ? action : 0), dayScope: 14 }),
  105. })
  106. } else if (action == '2') {
  107. util.apiPost(urls.get_last_classes + '&q.studentId=' + stu.studentId + '&q.classesId=' + item.classesId).then(rs => {
  108. if (rs == null) {
  109. wx.showToast({
  110. title: '未查询到排课数据',
  111. icon: 'none'
  112. })
  113. return;
  114. }
  115. rs.curDate = rs.beginTime.substring(0, 10)
  116. rs.classromeId = null; // 加课不用传 教室id
  117. wx.navigateTo({
  118. url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: rs, action: (action ? action : 0), dayScope: 14 }),
  119. })
  120. })
  121. }
  122. },
  123. showChoose: function () {
  124. // 判断是否选择了
  125. let key = this.data.key
  126. if (key == null || key == undefined) {
  127. wx.showToast({
  128. title: '请选择目标课程',
  129. icon: 'none'
  130. })
  131. return;
  132. }
  133. let ks = key.split('#')
  134. let action = this.data.action
  135. this.properties.list.map(o => {
  136. if (o.date == ks[0]) {
  137. o.items.map(i => {
  138. if (i.attendTeacherId == ks[1] && i.bt == ks[2]) {
  139. let source = this.properties.source
  140. if (source.curDate) {
  141. source.date = source.curDate.substring(0, 10)
  142. source.week = this.getWeek(source.date)
  143. }
  144. if (source.beginTime) {
  145. source.bt = source.beginTime.substring(11, 16)
  146. }
  147. if (source.endTime) {
  148. source.et = source.endTime.substring(11, 16)
  149. }
  150. if (i.newDate) {
  151. i.date = i.newDate.substring(0, 10)
  152. i.week = this.getWeek(i.date)
  153. }
  154. this.setData({ target: i, source: source, action: action })
  155. }
  156. })
  157. }
  158. })
  159. this.animation = wx.createAnimation({
  160. timingFunction: 'linear',
  161. })
  162. const bottom = 0
  163. this.animation.translateY(bottom).step()
  164. this.setData({
  165. overflow: 'hidden',
  166. animation: this.animation.export(),
  167. bottom
  168. })
  169. },
  170. hideChoose: function () {
  171. this.animation = wx.createAnimation({
  172. timingFunction: 'linear',
  173. })
  174. const bottom = 2000
  175. this.animation.translateY(bottom).step()
  176. this.setData({
  177. overflow: 'auto',
  178. animation: this.animation.export(),
  179. })
  180. setTimeout(() => {
  181. this.setData({
  182. bottom
  183. })
  184. }, 400);
  185. },
  186. getLeaveNumList: function () {
  187. wx.navigateTo({
  188. url: '/pages/leaveRecord/leaveRecord',
  189. })
  190. },
  191. radioChange: function (e) {
  192. this.setData({ key: e.detail.value })
  193. },
  194. getWeek: function (d) {
  195. return '星期' + '天一二三四五六'.charAt(new Date(d).getDay());
  196. },
  197. doSave: function () {
  198. let that = this
  199. wx.showModal({
  200. title: '确认信息',
  201. content: '确定要执行' + this.data.actionName + '课申请?',
  202. showCancel: true,
  203. cancelText: "否",
  204. confirmText: "是",
  205. success: function (res) {
  206. if (res.cancel) {
  207. that.hideChoose()
  208. } else {
  209. that.doRealSave()
  210. }
  211. }
  212. })
  213. },
  214. doRealSave: function () {
  215. wx.showLoading({
  216. title: '正在保存数据...',
  217. mask: true
  218. })
  219. const urls = urlDef.urls;
  220. let stu = wx.getStorageSync('student')
  221. let data = {}
  222. data.orgId = stu.orgId;
  223. data.operator = stu.studentId
  224. data.studentId = stu.studentId;
  225. data.studentName = stu.name
  226. if ('1' === this.data.action) {
  227. data.leaveId = this.data.source.leaveId;
  228. data.attenceStudentId = this.data.source.attenceStudentId;
  229. } else {
  230. data.attenceStudentId = this.data.source.studentId;
  231. }
  232. data.oldAttenceTeacherId = this.data.source.attenceTeacherId;
  233. data.oldKindId = this.data.source.kindId;
  234. data.attendTeacherId = this.data.target.attendTeacherId;
  235. data.beginTime = this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.beginTime + ':00';
  236. data.endTime = this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.endTime + ':00';
  237. data.classesId = this.data.target.classesId;
  238. data.courseName = this.data.target.courseName;
  239. data.classesName = this.data.target.classesName;
  240. data.name = this.data.target.classesName;
  241. data.kindId = this.data.target.kindId;
  242. data.teacherId = this.data.target.teacherId;
  243. data.classRoomId = this.data.target.classroomId;
  244. let saveURL = urls.classes_switch_save;
  245. if ('1' === this.data.action) {
  246. saveURL = urls.student_makeup;
  247. }
  248. if ('2' === this.data.action) {
  249. data.classesId = this.data.source.classesId; // 原课程的classesId, 不然找不到当前学生的最后一节课
  250. let gridList = [];
  251. gridList.push(
  252. {
  253. personNum: this.data.target.personNum,
  254. attendTeacherId: this.data.target.attendTeacherId,
  255. teacherName: this.data.target.teacherName,
  256. endDate: this.data.target.endDate,
  257. classroomId: this.data.target.classroomId,
  258. beginDate: this.data.target.beginDate,
  259. classesId: this.data.target.classesId,
  260. courseName: this.data.target.courseName,
  261. teacherId: this.data.target.teacherId,
  262. classesName: this.data.target.classesName,
  263. beginTime: this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.beginTime + ':00',
  264. courseId: this.data.target.courseId,
  265. kindId: this.data.target.kindId,
  266. classRoomId: this.data.target.classroomId,
  267. endTime: this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.endTime + ':00'
  268. }
  269. );
  270. data.gridList = gridList;
  271. saveURL = urls.add_classes;
  272. }
  273. util.apiPost(saveURL, data, 'application/json').then((rs) => {
  274. wx.hideLoading({})
  275. this.hideChoose()
  276. if (rs.message) {
  277. wx.showToast({
  278. title: this.data.actionName + '课失败,' + rs.message,
  279. icon: 'none'
  280. })
  281. return;
  282. }
  283. wx.showToast({
  284. title: '您已' + this.data.actionName + '课成功!'
  285. })
  286. setTimeout(() => {
  287. wx.navigateBack({
  288. delta: 1, // 返回上一级页面。
  289. success: function () {
  290. console.log('成功!')
  291. }
  292. })
  293. }, 1000)
  294. })
  295. }
  296. }
  297. })