teacherFault.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. lifetimes: {
  48. attached: function () {
  49. // 在组件实例被从页面节点树添加时执行
  50. this.changeOrganizeInfo();
  51. },
  52. detached: function () {
  53. // 在组件实例被从页面节点树移除时执行
  54. },
  55. },
  56. /**
  57. * 组件的方法列表
  58. */
  59. methods: {
  60. //选择是故障报修界面还是报修记录界面
  61. bindPageChange: function (event: any) {
  62. console.log("event.detail.value:", event.detail.value)
  63. this.setData({
  64. pageState: event.detail.value
  65. })
  66. },
  67. //选择是否紧急
  68. bindFaultChange: function (event: any) {
  69. this.setData({
  70. faultIndex: event.detail.value
  71. })
  72. },
  73. changeOrganizeInfo: function () {
  74. //设置名字
  75. this.setData({
  76. userName: ConstsData.AppData.myInfoData.name
  77. })
  78. //切换地区
  79. this.setData({
  80. regionOne: [],
  81. regionTwo: [],
  82. regionThree: []
  83. })
  84. ConstsData.AppData.organizeInfo.data.children.forEach((item, index) => {
  85. if (this.data.initFirst) {
  86. if (item.value == ConstsData.AppData.myInfoData.province) {
  87. //如果是当前的
  88. this.setData({
  89. regionOneIndex: index
  90. })
  91. }
  92. }
  93. this.data.regionOne.push(item.title)
  94. })
  95. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item, index) => {
  96. if (this.data.initFirst) {
  97. if (item.value == ConstsData.AppData.myInfoData.city) {
  98. this.setData({
  99. regionTwoIndex: index
  100. })
  101. }
  102. }
  103. this.data.regionTwo.push(item.title)
  104. })
  105. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item, index) => {
  106. if (this.data.initFirst) {
  107. if (item.value == ConstsData.AppData.myInfoData.region) {
  108. this.setData({
  109. regionThreeIndex: index
  110. })
  111. }
  112. }
  113. this.data.regionThree.push(item.title)
  114. })
  115. this.setData({
  116. region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
  117. regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
  118. provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
  119. cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
  120. regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString(),
  121. initFirst: false
  122. })
  123. //切换学校
  124. this.changeSchool();
  125. },
  126. //查询学校
  127. changeSchool: function () {
  128. //查询学校
  129. let params = {
  130. city: this.data.cityValue,
  131. province: this.data.provinceValue,
  132. region: this.data.regionValue,
  133. type: 1,
  134. }
  135. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  136. this.setData({
  137. schoolArray: [],
  138. schoolIndex: 0,
  139. schoolData: res.data.data,
  140. schoolId: res.data.data[0].id
  141. })
  142. let newArray: string[] = [];
  143. res.data.data.forEach((element, index) => {
  144. if (ConstsData.AppData.myInfoData.schoolId == element.id) {
  145. this.setData({
  146. schoolIndex: index,
  147. schoolId: this.data.schoolData[index].id
  148. })
  149. }
  150. newArray.push(element.title)
  151. });
  152. this.data.schoolArray.push(newArray)
  153. this.setData({
  154. schoolArray: this.data.schoolArray
  155. })
  156. //切换班级
  157. this.changeClass()
  158. }).catch(res => {
  159. console.log("查询学校error:", res)
  160. this.setData({
  161. schoolArray: [['暂无学校']],
  162. schoolId: '',
  163. classArray: ['暂无班级'],
  164. classId: ''
  165. })
  166. })
  167. },
  168. //查询班级
  169. changeClass: function () {
  170. let params = {
  171. "city": this.data.cityValue,
  172. "father": this.data.schoolId,//学校ID
  173. "province": this.data.provinceValue,
  174. "region": this.data.regionValue,
  175. "type": 2,
  176. }
  177. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  178. this.setData({
  179. classArray: [],
  180. classIndex: 0
  181. })
  182. this.setData({
  183. classData: res.data.data,
  184. classId: res.data.data[0].id
  185. })
  186. console.log("classData:", this.data.classData)
  187. res.data.data.forEach((element: { id: number; title: string; }, index: number) => {
  188. if (element.id == ConstsData.AppData.myInfoData.classId) {
  189. this.setData({
  190. classIndex: index,
  191. classId: res.data.data[index].id
  192. })
  193. console.log("this.data.classIndex:", this.data.classIndex)
  194. }
  195. this.data.classArray.push(element.title)
  196. });
  197. this.setData({
  198. classArray: this.data.classArray,
  199. })
  200. }).catch(res => {
  201. console.log("查询班级error:", res)
  202. this.setData({
  203. classArray: ['暂无班级'],
  204. classId: ''
  205. })
  206. })
  207. },
  208. bindMultiPickerColumnChange: function (event: any) {
  209. //
  210. switch (Number(event.detail.column)) {
  211. case 0:
  212. //代表第一列
  213. this.setData({
  214. regionOneIndex: event.detail.value,
  215. })
  216. break;
  217. case 1:
  218. //代表第二列
  219. this.setData({
  220. regionTwoIndex: event.detail.value,
  221. })
  222. break;
  223. case 2:
  224. //代表第三列
  225. this.setData({
  226. regionThreeIndex: event.detail.value
  227. })
  228. break;
  229. }
  230. this.changeOrganizeInfo();
  231. },
  232. bindRegionChange: function (event: any) {
  233. this.setData({
  234. regionIndex: event.detail.value
  235. })
  236. },
  237. bindSchoolPicker: function (event: any) {
  238. this.setData({
  239. schoolIndex: event.detail.value,
  240. schoolId: this.data.schoolData[event.detail.value].id
  241. })
  242. this.changeClass();
  243. },
  244. bindClssPicker: function (event: any) {
  245. this.setData({
  246. classIndex: event.detail.value,
  247. classId: this.data.classData[event.detail.value].id
  248. })
  249. },
  250. //获取设备ID的输入
  251. bindDeviceInput(event: any) {
  252. this.setData({
  253. deviceId: event.detail.value
  254. })
  255. },
  256. //获取故障描述输入
  257. bindFaultText: function (event: any) {
  258. this.setData({
  259. describe: event.detail.value
  260. })
  261. },
  262. //提交故障
  263. submitFault: function (event: any) {
  264. if (!this.data.deviceId) {
  265. wx.showToast({
  266. title: '请输入设备ID',
  267. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  268. duration: 1000
  269. })
  270. return;
  271. }
  272. if (!this.data.describe) {
  273. wx.showToast({
  274. title: '请输入故障描述',
  275. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  276. duration: 1000
  277. })
  278. return;
  279. }
  280. let params = {
  281. city: this.data.cityValue,
  282. classId: this.data.classId,
  283. province: this.data.provinceValue,//省份
  284. region: this.data.regionValue,//地区
  285. schoolId: this.data.schoolId,
  286. deviceId: this.data.deviceId,
  287. faultLevel: this.data.faultIndex,
  288. describe: this.data.describe,
  289. userId: httpUtil.httpData.userId
  290. }
  291. console.log("params:", params)
  292. httpUtil.wxPost(httpUtil.interfaces.postDeviceFault, params).then((res: any) => {
  293. console.log("设备报修成功:", res)
  294. if (res.data.success) {
  295. let that = this;
  296. wx.showModal({
  297. title: '',
  298. content: '报修成功',
  299. success: function (res) {
  300. if (res.confirm) {
  301. console.log('点击确认回调')
  302. that.setData({
  303. pageState: 1
  304. })
  305. } else {
  306. console.log('点击取消回调')
  307. }
  308. }
  309. })
  310. } else { }
  311. }).catch((res) => {
  312. console.log("设备报修失败:", res)
  313. })
  314. }
  315. }
  316. })