teacherFault.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. postFaultListImg: [],
  47. postImg: [],
  48. //报修记录用到的参数
  49. faultList: []
  50. },
  51. lifetimes: {
  52. attached: function () {
  53. // 在组件实例被从页面节点树添加时执行
  54. this.changeOrganizeInfo();
  55. },
  56. detached: function () {
  57. // 在组件实例被从页面节点树移除时执行
  58. },
  59. },
  60. /**
  61. * 组件的方法列表
  62. */
  63. methods: {
  64. //选择是故障报修界面还是报修记录界面
  65. bindPageChange: function (event: any) {
  66. console.log("event.detail.value:", event.detail.value)
  67. if (event.detail.value == 1) {
  68. this.getFaultByUserId();
  69. }
  70. this.setData({
  71. pageState: event.detail.value
  72. })
  73. },
  74. //选择是否紧急
  75. bindFaultChange: function (event: any) {
  76. this.setData({
  77. faultIndex: event.detail.value
  78. })
  79. },
  80. changeOrganizeInfo: function () {
  81. //设置名字
  82. this.setData({
  83. userName: ConstsData.AppData.myInfoData.name
  84. })
  85. //切换地区
  86. this.setData({
  87. regionOne: [],
  88. regionTwo: [],
  89. regionThree: []
  90. })
  91. ConstsData.AppData.organizeInfo.data.children.forEach((item, index) => {
  92. if (this.data.initFirst) {
  93. if (item.value == ConstsData.AppData.myInfoData.province) {
  94. //如果是当前的
  95. this.setData({
  96. regionOneIndex: index
  97. })
  98. }
  99. }
  100. this.data.regionOne.push(item.title)
  101. })
  102. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item, index) => {
  103. if (this.data.initFirst) {
  104. if (item.value == ConstsData.AppData.myInfoData.city) {
  105. this.setData({
  106. regionTwoIndex: index
  107. })
  108. }
  109. }
  110. this.data.regionTwo.push(item.title)
  111. })
  112. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item, index) => {
  113. if (this.data.initFirst) {
  114. if (item.value == ConstsData.AppData.myInfoData.region) {
  115. this.setData({
  116. regionThreeIndex: index
  117. })
  118. }
  119. }
  120. this.data.regionThree.push(item.title)
  121. })
  122. this.setData({
  123. region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
  124. regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
  125. provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
  126. cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
  127. regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString(),
  128. initFirst: false
  129. })
  130. //切换学校
  131. this.changeSchool();
  132. },
  133. //查询学校
  134. changeSchool: function () {
  135. //查询学校
  136. let params = {
  137. city: this.data.cityValue,
  138. province: this.data.provinceValue,
  139. region: this.data.regionValue,
  140. type: 1,
  141. }
  142. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  143. this.setData({
  144. schoolArray: [],
  145. schoolIndex: 0,
  146. schoolData: res.data.data,
  147. schoolId: res.data.data[0].id
  148. })
  149. let newArray: string[] = [];
  150. res.data.data.forEach((element, index) => {
  151. if (ConstsData.AppData.myInfoData.schoolId == element.id) {
  152. this.setData({
  153. schoolIndex: index,
  154. schoolId: this.data.schoolData[index].id
  155. })
  156. }
  157. newArray.push(element.title)
  158. });
  159. this.data.schoolArray.push(newArray)
  160. this.setData({
  161. schoolArray: this.data.schoolArray
  162. })
  163. //切换班级
  164. this.changeClass()
  165. }).catch(res => {
  166. console.log("查询学校error:", res)
  167. this.setData({
  168. schoolArray: [['暂无学校']],
  169. schoolId: '',
  170. classArray: ['暂无班级'],
  171. classId: ''
  172. })
  173. })
  174. },
  175. //查询班级
  176. changeClass: function () {
  177. let params = {
  178. city: this.data.cityValue,
  179. father: this.data.schoolId,//学校ID
  180. province: this.data.provinceValue,
  181. region: this.data.regionValue,
  182. type: 2,
  183. }
  184. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  185. this.setData({
  186. classArray: [],
  187. classIndex: 0
  188. })
  189. this.setData({
  190. classData: res.data.data,
  191. classId: res.data.data[0].id
  192. })
  193. console.log("classData:", this.data.classData)
  194. res.data.data.forEach((element: { id: number; title: string; }, index: number) => {
  195. if (element.id == ConstsData.AppData.myInfoData.classId) {
  196. this.setData({
  197. classIndex: index,
  198. classId: res.data.data[index].id
  199. })
  200. this.getDeviceByRSC()
  201. console.log("this.data.classIndex:", this.data.classIndex)
  202. }
  203. this.data.classArray.push(element.title)
  204. });
  205. this.setData({
  206. classArray: this.data.classArray,
  207. })
  208. }).catch(res => {
  209. console.log("查询班级error:", res)
  210. this.setData({
  211. classArray: ['暂无班级'],
  212. classId: ''
  213. })
  214. })
  215. },
  216. bindMultiPickerColumnChange: function (event: any) {
  217. //
  218. switch (Number(event.detail.column)) {
  219. case 0:
  220. //代表第一列
  221. this.setData({
  222. regionOneIndex: event.detail.value,
  223. })
  224. break;
  225. case 1:
  226. //代表第二列
  227. this.setData({
  228. regionTwoIndex: event.detail.value,
  229. })
  230. break;
  231. case 2:
  232. //代表第三列
  233. this.setData({
  234. regionThreeIndex: event.detail.value
  235. })
  236. break;
  237. }
  238. this.changeOrganizeInfo();
  239. },
  240. bindRegionChange: function (event: any) {
  241. this.setData({
  242. regionIndex: event.detail.value
  243. })
  244. },
  245. bindSchoolPicker: function (event: any) {
  246. this.setData({
  247. schoolIndex: event.detail.value,
  248. schoolId: this.data.schoolData[event.detail.value].id
  249. })
  250. this.changeClass();
  251. },
  252. bindClssPicker: function (event: any) {
  253. this.setData({
  254. classIndex: event.detail.value,
  255. classId: this.data.classData[event.detail.value].id
  256. })
  257. this.getDeviceByRSC()
  258. },
  259. //根据地区,学校,班级获取deviceId
  260. getDeviceByRSC: function () {
  261. let params = {
  262. city: this.data.cityValue,
  263. classId: this.data.classId,
  264. province: this.data.provinceValue,//省份
  265. region: this.data.regionValue,//地区
  266. schoolId: this.data.schoolId,
  267. }
  268. httpUtil.wxGet(httpUtil.interfaces.getDevideIdByRSC, params).then((res: any) => {
  269. console.log("根据省市学校班级获取deviceId成功:", res)
  270. if (res.data.success) {
  271. this.setData({
  272. deviceId: res.data.data.deviceId
  273. })
  274. } else {
  275. this.setData({
  276. deviceId: ''
  277. })
  278. }
  279. }).catch((res) => {
  280. console.log("根据省市学校班级获取deviceId失败:", res)
  281. this.setData({
  282. deviceId: '暂无设备'
  283. })
  284. })
  285. },
  286. //获取设备ID的输入
  287. bindDeviceInput(event: any) {
  288. this.setData({
  289. deviceId: event.detail.value
  290. })
  291. },
  292. //获取故障描述输入
  293. bindFaultText: function (event: any) {
  294. this.setData({
  295. describe: event.detail.value
  296. })
  297. },
  298. //从本机相册获取图片
  299. getFaultImg: function () {
  300. let that = this;
  301. wx.chooseImage({
  302. count: 9, // 默认9
  303. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  304. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  305. success: function (res) {
  306. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  307. that.setData({
  308. postFaultListImg: that.data.postFaultListImg.concat(res.tempFilePaths)
  309. })
  310. res.tempFilePaths.forEach((item, index) => {
  311. httpUtil.wxUploadFile(httpUtil.interfaces.uploadImageList, item, index.toString(), {
  312. 'userId': httpUtil.httpData.userId,
  313. 'deviceId': that.data.deviceId
  314. }).then((res: any) => {
  315. let json = JSON.parse(res.data);
  316. console.log("json:", json.data)
  317. that.setData({
  318. postImg: that.data.postImg.concat(json.data)
  319. })
  320. }).catch((res => {
  321. console.log("上传图片失败:", res)
  322. }))
  323. })
  324. }
  325. })
  326. },
  327. //提交故障
  328. submitFault: function (event: any) {
  329. if (!this.data.deviceId) {
  330. wx.showToast({
  331. title: '请输入设备ID',
  332. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  333. duration: 1000
  334. })
  335. return;
  336. }
  337. if (!this.data.describe) {
  338. wx.showToast({
  339. title: '请输入故障描述',
  340. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  341. duration: 1000
  342. })
  343. return;
  344. }
  345. if (!this.data.deviceId || this.data.deviceId === '暂无设备') {
  346. wx.showToast({
  347. title: '暂无设备',
  348. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  349. duration: 1000
  350. })
  351. return;
  352. }
  353. let img = '';
  354. this.data.postImg.forEach((res, index) => {
  355. if (index < this.data.postImg.length - 1) {
  356. img = img + res + ","
  357. } else {
  358. img = img + res
  359. }
  360. })
  361. console.log("postImg:", img)
  362. let params = {
  363. city: this.data.cityValue,
  364. classId: this.data.classId,
  365. province: this.data.provinceValue,//省份
  366. region: this.data.regionValue,//地区
  367. schoolId: this.data.schoolId,
  368. deviceId: this.data.deviceId,
  369. faultLevel: this.data.faultIndex,
  370. describe: this.data.describe,
  371. userId: httpUtil.httpData.userId,
  372. img: img
  373. }
  374. console.log("params:", params)
  375. httpUtil.wxPost(httpUtil.interfaces.postDeviceFault, params).then((res: any) => {
  376. console.log("设备报修成功:", res)
  377. if (res.data.success) {
  378. let that = this;
  379. wx.showModal({
  380. title: '',
  381. content: '报修成功',
  382. success: function (res) {
  383. if (res.confirm) {
  384. console.log('点击确认回调')
  385. that.getFaultByUserId();
  386. that.setData({
  387. pageState: 1
  388. })
  389. } else {
  390. console.log('点击取消回调')
  391. }
  392. }
  393. })
  394. } else { }
  395. }).catch((res) => {
  396. console.log("设备报修失败:", res)
  397. })
  398. },
  399. getFaultByUserId: function () {
  400. console.log("获取报修记录")
  401. let params = {
  402. pageNo: 1,
  403. pageSize: 10000
  404. }
  405. httpUtil.wxGet(httpUtil.interfaces.getDeviceFault, params).then((res: any) => {
  406. console.log("获取报修记录成功:", res)
  407. this.setData({
  408. faultList: res.data.data.list
  409. })
  410. }).catch((res) => {
  411. console.log("获取报修记录失败:", res)
  412. })
  413. }
  414. }
  415. })