studentBook.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. import Api from "../../model/api";
  2. //TODO 待优化 FIXME DEFAULT IGNORE
  3. const app = getApp();
  4. Page({
  5. data: {
  6. partNull: false,
  7. nullDataText: '学员手册未配置',
  8. nullDataArr: ['封皮未配置', '目录前页未配置', '学院简介未配置', '日程安排未配置', '座位图未配置', '学员名单未配置', '培训项目组成员名单未配置', '临时党支部委员会委员未配置', '授课教师简介未配置', '中共中央组织部关于在干部教育培训中进一步加强学院管理的规定未配置', '学员须知未配置', '学院位置区域图未配置'],
  9. list: [],
  10. nullArr: [],
  11. active: 0,
  12. STUDENT_JOBS: {
  13. "2": "书记",
  14. "3": "组织",
  15. "4": "宣传"
  16. },
  17. up: true,
  18. down: true,
  19. teamId: ''
  20. },
  21. async onLoad(options) {
  22. let teamId = options.teamId;
  23. let index = parseInt(options.index);
  24. this.data.teamId = teamId;
  25. let res = await Api.getBook({
  26. teamId: this.data.teamId
  27. });
  28. if (res.rows.length != 0) {
  29. this.setData({
  30. list: res.rows,
  31. partNull: false,
  32. })
  33. console.log(res.rows)
  34. res.rows.map(item => {
  35. this.data.nullArr.push(false)
  36. })
  37. this.setData({
  38. nullArr: this.data.nullArr
  39. })
  40. console.log(this.data.nullArr)
  41. if (res.rows[0].manualUrl) {
  42. this.getDataByIndex(res.rows[0].manualUrl);
  43. } else {
  44. let index = 'nullArr[0]'
  45. this.setData({
  46. [index]: true,
  47. partNull: true,
  48. nullDataText: this.data.nullDataArr[0]
  49. })
  50. console.log(this.data.nullArr)
  51. }
  52. } else {
  53. this.setData({
  54. partNull: true,
  55. up: false,
  56. down: false,
  57. })
  58. }
  59. this.data.active = index - 1;
  60. this.next();
  61. },
  62. async getDataByIndex(index) {
  63. console.log(index)
  64. console.log(this.data.active)
  65. let res = await Api.getStudentBookByIndex(index);
  66. if (this.data.active == 0 || this.data.active == 11) {
  67. res.data.configContent = res.data.configContent.replace(/width\s*:\s*[0-9]+px/g, 'width:100%');
  68. res.data.configContent = res.data.configContent.replace(/<([\/]?)(center)((:?\s*)(:?[^>]*)(:?\s*))>/g, '<$1div$3>');
  69. res.data.configContent = res.data.configContent.replace(/\<img/gi, '<img class="rich-img" ');
  70. }
  71. if (this.data.active == 1 || this.data.active == 2 || this.data.active == 10) {
  72. res.data.configContent = res.data.configContent.replace(/\<p/gi, '<P class="rich-p" ');
  73. }
  74. this.data.list[this.data.active].manualContent = res.data.configContent;
  75. this.setData({
  76. list: this.data.list
  77. })
  78. },
  79. pre(e) {
  80. this.setData({
  81. active: this.data.active - 1
  82. })
  83. if (this.data.nullArr[this.data.active]) {
  84. this.setData({
  85. partNull: true,
  86. nullDataText: this.data.nullDataArr[this.data.active]
  87. })
  88. } else {
  89. this.setData({
  90. partNull: false
  91. })
  92. }
  93. },
  94. async next(e) {
  95. this.setData({
  96. active: this.data.active + 1
  97. })
  98. if (this.data.active == 1) {
  99. if (this.data.list[1].manualUrl) {
  100. this.getDataByIndex(this.data.list[1].manualUrl)
  101. this.setData({
  102. partNull: false
  103. })
  104. } else {
  105. let index = 'nullArr[1]';
  106. this.setData({
  107. [index]: true,
  108. partNull: true,
  109. nullDataText: this.data.nullDataArr[1]
  110. })
  111. }
  112. }
  113. if (this.data.active == 2) {
  114. if (this.data.list[2].manualUrl) {
  115. this.getDataByIndex(this.data.list[2].manualUrl)
  116. this.setData({
  117. partNull: false
  118. })
  119. } else {
  120. let index = 'nullArr[2]';
  121. this.setData({
  122. [index]: true,
  123. partNull: true,
  124. nullDataText: this.data.nullDataArr[2]
  125. })
  126. }
  127. }
  128. if (this.data.active == 3) {
  129. let res = await Api.studentBookSchedule({
  130. teamId: this.data.teamId
  131. });
  132. if (res.rows) {
  133. this.data.list[this.data.active].manualContent = res.rows;
  134. this.setData({
  135. partNull: false,
  136. list: this.data.list
  137. })
  138. } else {
  139. let index = 'nullArr[3]';
  140. this.setData({
  141. [index]: true,
  142. partNull: true,
  143. nullDataText: this.data.nullDataArr[3]
  144. })
  145. }
  146. }
  147. if (this.data.active == 4) {
  148. if (this.data.list[4].manualUrl) {
  149. let res = await Api.studentBookSeat(this.data.list[4].manualUrl);
  150. console.log(res, '我是座位图')
  151. this.data.list[this.data.active].manualContent = res.data;
  152. this.setData({
  153. partNull: false,
  154. list: this.data.list
  155. })
  156. } else {
  157. let index = 'nullArr[4]';
  158. this.setData({
  159. [index]: true,
  160. partNull: true,
  161. nullDataText: this.data.nullDataArr[4]
  162. })
  163. }
  164. }
  165. if (this.data.active == 5) {
  166. let res = await Api.studentBookLists({
  167. teamId: this.data.teamId
  168. });
  169. console.log(res, '我是学员名单')
  170. if (res.data) {
  171. let newArr = res.data.filter(item => item.groupName !== '未分组');
  172. newArr.shift();
  173. this.data.list[this.data.active].manualContent = newArr;
  174. this.setData({
  175. partNull: false,
  176. list: this.data.list
  177. })
  178. } else {
  179. let index = 'nullArr[5]';
  180. this.setData({
  181. [index]: true,
  182. partNull: true,
  183. nullDataText: this.data.nullDataArr[5]
  184. })
  185. }
  186. }
  187. if (this.data.active == 6 || this.data.active == 7) {
  188. let res = await Api.studentBookGroups(this.data.teamId);
  189. console.log(res, '我是项目组+党支部委员成员名单')
  190. let jobs = []
  191. res.data.teamStuJobList.map(item => {
  192. let key2 = this.data.STUDENT_JOBS[Object.keys(item)]
  193. let value2 = Object.values(item)
  194. if (key2 == '书记') {
  195. jobs.push({
  196. name: '书记',
  197. value: value2[0]
  198. })
  199. }
  200. if (key2 == '组织') {
  201. jobs.push({
  202. name: '组织',
  203. value: value2[0]
  204. })
  205. }
  206. if (key2 == '宣传') {
  207. jobs.push({
  208. name: '宣传',
  209. value: value2[0]
  210. })
  211. }
  212. })
  213. let data = [];
  214. if (this.data.active == 6) {
  215. if (res.data.itemLeadesName || res.data.subLedaersName || res.data.itemAssistantsName || res.data.teamDirectorList || res.data.teamStuJobList) {
  216. data.push(res.data.itemLeadesName, res.data.subLedaersName, res.data.itemAssistantsName, res.data.teamDirectorList, res.data.teamStuJobList)
  217. } else {
  218. let index = 'nullArr[6]';
  219. this.setData({
  220. [index]: true,
  221. partNull: true,
  222. nullDataText: this.data.nullDataArr[6]
  223. })
  224. }
  225. } else {
  226. if (res.data.teamStuJobList.length > 0) {
  227. data.push(res.data.itemLeadesName, res.data.subLedaersName, res.data.itemAssistantsName, res.data.teamDirectorList, jobs)
  228. } else {
  229. let index = 'nullArr[7]';
  230. this.setData({
  231. [index]: true,
  232. partNull: true,
  233. nullDataText: this.data.nullDataArr[7]
  234. })
  235. }
  236. }
  237. this.data.list[this.data.active].manualContent = data;
  238. this.setData({
  239. list: this.data.list
  240. })
  241. }
  242. if (this.data.active == 8) {
  243. console.log(this.data.list, 'xxxxxxxxxxx')
  244. if (this.data.list[8].manualUrl) {
  245. let res = await Api.studentBookTeacher(this.data.list[8].manualContent);
  246. this.data.list[this.data.active].manualContent = res.data;
  247. this.setData({
  248. list: this.data.list,
  249. partNull: false,
  250. })
  251. } else {
  252. let index = 'nullArr[8]';
  253. this.setData({
  254. [index]: true,
  255. partNull: true,
  256. nullDataText: this.data.nullDataArr[8]
  257. })
  258. }
  259. }
  260. if (this.data.active == 9) {
  261. if (this.data.list[9].manualUrl) {
  262. this.getDataByIndex(this.data.list[9].manualUrl)
  263. this.setData({
  264. partNull: false,
  265. })
  266. } else {
  267. let index = 'nullArr[9]';
  268. this.setData({
  269. [index]: true,
  270. partNull: true,
  271. nullDataText: this.data.nullDataArr[9]
  272. })
  273. }
  274. }
  275. if (this.data.active == 10) {
  276. if (this.data.list[10].manualUrl) {
  277. this.getDataByIndex(this.data.list[10].manualUrl)
  278. this.setData({
  279. partNull: false,
  280. })
  281. } else {
  282. let index = 'nullArr[10]';
  283. this.setData({
  284. [index]: true,
  285. partNull: true,
  286. nullDataText: this.data.nullDataArr[10]
  287. })
  288. }
  289. }
  290. if (this.data.active == 11) {
  291. if (this.data.list[11].manualUrl) {
  292. this.getDataByIndex(this.data.list[11].manualUrl)
  293. this.setData({
  294. partNull: false,
  295. })
  296. } else {
  297. let index = 'nullArr[10]';
  298. this.setData({
  299. [index]: true,
  300. partNull: true,
  301. nullDataText: this.data.nullDataArr[11]
  302. })
  303. }
  304. }
  305. },
  306. });