teacherFault.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. // component/teacher/teacherFault/teacherFault.ts
  2. import { ConstsData } from "../../../utils/const"
  3. import { httpUtil } from "../../../utils/restful";
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. //判断当前页面显示哪个view
  15. pageState: 0,
  16. pageStateText: ['故障报修', '报修记录'],
  17. //故障报修界面所用数据
  18. fault: ['普通', '待查', '紧急'],
  19. faultIndex: 0,
  20. regionOne: Array<String>(),
  21. regionTwo: Array<String>(),
  22. regionThree: Array<String>(),
  23. regionOneIndex: 0,
  24. regionTwoIndex: 0,
  25. regionThreeIndex: 0,
  26. region: [
  27. Array<String>(),
  28. Array<String>(),
  29. Array<String>()
  30. ],
  31. regionIndex: [0, 0, 0],
  32. schoolArray: [['暂无学校']],
  33. schoolIndex: 0,
  34. classArray: ['暂无班级'],
  35. classIndex: 0,
  36. provinceValue: '',//省份value
  37. regionValue: '',//地区value
  38. cityValue: '',
  39. schoolData: [{ 'id': '' }],
  40. schoolId: '',
  41. classData: [{ 'id': '' }],
  42. classId: '',
  43. initFirst: true,
  44. deviceId: '',
  45. describe: "",
  46. //报修记录用到的参数
  47. faultList: []
  48. },
  49. lifetimes: {
  50. attached: function () {
  51. // 在组件实例被从页面节点树添加时执行
  52. this.changeOrganizeInfo();
  53. },
  54. detached: function () {
  55. // 在组件实例被从页面节点树移除时执行
  56. },
  57. },
  58. /**
  59. * 组件的方法列表
  60. */
  61. methods: {
  62. //选择是故障报修界面还是报修记录界面
  63. bindPageChange: function (event: any) {
  64. console.log("event.detail.value:", event.detail.value)
  65. if (event.detail.value == 1) {
  66. this.getFaultByUserId();
  67. }
  68. this.setData({
  69. pageState: event.detail.value
  70. })
  71. },
  72. //选择是否紧急
  73. bindFaultChange: function (event: any) {
  74. this.setData({
  75. faultIndex: event.detail.value
  76. })
  77. },
  78. changeOrganizeInfo: function () {
  79. //设置名字
  80. this.setData({
  81. userName: ConstsData.AppData.myInfoData.name
  82. })
  83. //切换地区
  84. this.setData({
  85. regionOne: [],
  86. regionTwo: [],
  87. regionThree: []
  88. })
  89. ConstsData.AppData.organizeInfo.data.children.forEach((item, index) => {
  90. if (this.data.initFirst) {
  91. if (item.value == ConstsData.AppData.myInfoData.province) {
  92. //如果是当前的
  93. this.setData({
  94. regionOneIndex: index
  95. })
  96. }
  97. }
  98. this.data.regionOne.push(item.title)
  99. })
  100. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item, index) => {
  101. if (this.data.initFirst) {
  102. if (item.value == ConstsData.AppData.myInfoData.city) {
  103. this.setData({
  104. regionTwoIndex: index
  105. })
  106. }
  107. }
  108. this.data.regionTwo.push(item.title)
  109. })
  110. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item, index) => {
  111. if (this.data.initFirst) {
  112. if (item.value == ConstsData.AppData.myInfoData.region) {
  113. this.setData({
  114. regionThreeIndex: index
  115. })
  116. }
  117. }
  118. this.data.regionThree.push(item.title)
  119. })
  120. this.setData({
  121. region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
  122. regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
  123. provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
  124. cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
  125. regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString(),
  126. initFirst: false
  127. })
  128. //切换学校
  129. this.changeSchool();
  130. },
  131. //查询学校
  132. changeSchool: function () {
  133. //查询学校
  134. let params = {
  135. city: this.data.cityValue,
  136. province: this.data.provinceValue,
  137. region: this.data.regionValue,
  138. type: 1,
  139. }
  140. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  141. this.setData({
  142. schoolArray: [],
  143. schoolIndex: 0,
  144. schoolData: res.data.data,
  145. schoolId: res.data.data[0].id
  146. })
  147. let newArray: string[] = [];
  148. res.data.data.forEach((element, index) => {
  149. if (ConstsData.AppData.myInfoData.schoolId == element.id) {
  150. this.setData({
  151. schoolIndex: index,
  152. schoolId: this.data.schoolData[index].id
  153. })
  154. }
  155. newArray.push(element.title)
  156. });
  157. this.data.schoolArray.push(newArray)
  158. this.setData({
  159. schoolArray: this.data.schoolArray
  160. })
  161. //切换班级
  162. this.changeClass()
  163. }).catch(res => {
  164. console.log("查询学校error:", res)
  165. this.setData({
  166. schoolArray: [['暂无学校']],
  167. schoolId: '',
  168. classArray: ['暂无班级'],
  169. classId: ''
  170. })
  171. })
  172. },
  173. //查询班级
  174. changeClass: function () {
  175. let params = {
  176. city: this.data.cityValue,
  177. father: this.data.schoolId,//学校ID
  178. province: this.data.provinceValue,
  179. region: this.data.regionValue,
  180. type: 2,
  181. }
  182. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  183. this.setData({
  184. classArray: [],
  185. classIndex: 0
  186. })
  187. this.setData({
  188. classData: res.data.data,
  189. classId: res.data.data[0].id
  190. })
  191. console.log("classData:", this.data.classData)
  192. res.data.data.forEach((element: { id: number; title: string; }, index: number) => {
  193. if (element.id == ConstsData.AppData.myInfoData.classId) {
  194. this.setData({
  195. classIndex: index,
  196. classId: res.data.data[index].id
  197. })
  198. console.log("this.data.classIndex:", this.data.classIndex)
  199. }
  200. this.data.classArray.push(element.title)
  201. });
  202. this.setData({
  203. classArray: this.data.classArray,
  204. })
  205. }).catch(res => {
  206. console.log("查询班级error:", res)
  207. this.setData({
  208. classArray: ['暂无班级'],
  209. classId: ''
  210. })
  211. })
  212. },
  213. bindMultiPickerColumnChange: function (event: any) {
  214. //
  215. switch (Number(event.detail.column)) {
  216. case 0:
  217. //代表第一列
  218. this.setData({
  219. regionOneIndex: event.detail.value,
  220. })
  221. break;
  222. case 1:
  223. //代表第二列
  224. this.setData({
  225. regionTwoIndex: event.detail.value,
  226. })
  227. break;
  228. case 2:
  229. //代表第三列
  230. this.setData({
  231. regionThreeIndex: event.detail.value
  232. })
  233. break;
  234. }
  235. this.changeOrganizeInfo();
  236. },
  237. bindRegionChange: function (event: any) {
  238. this.setData({
  239. regionIndex: event.detail.value
  240. })
  241. },
  242. bindSchoolPicker: function (event: any) {
  243. this.setData({
  244. schoolIndex: event.detail.value,
  245. schoolId: this.data.schoolData[event.detail.value].id
  246. })
  247. this.changeClass();
  248. },
  249. bindClssPicker: function (event: any) {
  250. this.setData({
  251. classIndex: event.detail.value,
  252. classId: this.data.classData[event.detail.value].id
  253. })
  254. this.getDeviceByRSC()
  255. },
  256. //根据地区,学校,班级获取deviceId
  257. getDeviceByRSC: function () {
  258. let params = {
  259. city: this.data.cityValue,
  260. classId: this.data.classId,
  261. province: this.data.provinceValue,//省份
  262. region: this.data.regionValue,//地区
  263. schoolId: this.data.schoolId,
  264. }
  265. httpUtil.wxGet(httpUtil.interfaces.getDevideIdByRSC, params).then((res: any) => {
  266. console.log("根据省市学校班级获取deviceId成功:", res)
  267. if (res.data.success) {
  268. this.setData({
  269. deviceId: res.data.data.deviceId
  270. })
  271. } else {
  272. this.setData({
  273. deviceId: ''
  274. })
  275. }
  276. }).catch((res) => {
  277. console.log("根据省市学校班级获取deviceId失败:", res)
  278. this.setData({
  279. deviceId: '暂无设备'
  280. })
  281. })
  282. },
  283. //获取设备ID的输入
  284. bindDeviceInput(event: any) {
  285. this.setData({
  286. deviceId: event.detail.value
  287. })
  288. },
  289. //获取故障描述输入
  290. bindFaultText: function (event: any) {
  291. this.setData({
  292. describe: event.detail.value
  293. })
  294. },
  295. //提交故障
  296. submitFault: function (event: any) {
  297. if (!this.data.deviceId) {
  298. wx.showToast({
  299. title: '请输入设备ID',
  300. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  301. duration: 1000
  302. })
  303. return;
  304. }
  305. if (!this.data.describe) {
  306. wx.showToast({
  307. title: '请输入故障描述',
  308. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  309. duration: 1000
  310. })
  311. return;
  312. }
  313. if (!this.data.deviceId || this.data.deviceId === '暂无设备') {
  314. wx.showToast({
  315. title: '暂无设备',
  316. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  317. duration: 1000
  318. })
  319. return;
  320. }
  321. let params = {
  322. city: this.data.cityValue,
  323. classId: this.data.classId,
  324. province: this.data.provinceValue,//省份
  325. region: this.data.regionValue,//地区
  326. schoolId: this.data.schoolId,
  327. deviceId: this.data.deviceId,
  328. faultLevel: this.data.faultIndex,
  329. describe: this.data.describe,
  330. userId: httpUtil.httpData.userId
  331. }
  332. console.log("params:", params)
  333. httpUtil.wxPost(httpUtil.interfaces.postDeviceFault, params).then((res: any) => {
  334. console.log("设备报修成功:", res)
  335. if (res.data.success) {
  336. let that = this;
  337. wx.showModal({
  338. title: '',
  339. content: '报修成功',
  340. success: function (res) {
  341. if (res.confirm) {
  342. console.log('点击确认回调')
  343. that.getFaultByUserId();
  344. that.setData({
  345. pageState: 1
  346. })
  347. } else {
  348. console.log('点击取消回调')
  349. }
  350. }
  351. })
  352. } else { }
  353. }).catch((res) => {
  354. console.log("设备报修失败:", res)
  355. })
  356. },
  357. getFaultByUserId: function () {
  358. console.log("获取报修记录")
  359. let params = {
  360. pageNo: 1,
  361. pageSize: 10000
  362. }
  363. httpUtil.wxGet(httpUtil.interfaces.getDeviceFault, params).then((res: any) => {
  364. console.log("获取报修记录成功:", res)
  365. this.setData({
  366. faultList: res.data.data.list
  367. })
  368. }).catch((res) => {
  369. console.log("获取报修记录失败:", res)
  370. })
  371. }
  372. }
  373. })