teacherFault.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. console.log("this.data.classIndex:", this.data.classIndex)
  201. }
  202. this.data.classArray.push(element.title)
  203. });
  204. this.setData({
  205. classArray: this.data.classArray,
  206. })
  207. }).catch(res => {
  208. console.log("查询班级error:", res)
  209. this.setData({
  210. classArray: ['暂无班级'],
  211. classId: ''
  212. })
  213. })
  214. },
  215. bindMultiPickerColumnChange: function (event: any) {
  216. //
  217. switch (Number(event.detail.column)) {
  218. case 0:
  219. //代表第一列
  220. this.setData({
  221. regionOneIndex: event.detail.value,
  222. })
  223. break;
  224. case 1:
  225. //代表第二列
  226. this.setData({
  227. regionTwoIndex: event.detail.value,
  228. })
  229. break;
  230. case 2:
  231. //代表第三列
  232. this.setData({
  233. regionThreeIndex: event.detail.value
  234. })
  235. break;
  236. }
  237. this.changeOrganizeInfo();
  238. },
  239. bindRegionChange: function (event: any) {
  240. this.setData({
  241. regionIndex: event.detail.value
  242. })
  243. },
  244. bindSchoolPicker: function (event: any) {
  245. this.setData({
  246. schoolIndex: event.detail.value,
  247. schoolId: this.data.schoolData[event.detail.value].id
  248. })
  249. this.changeClass();
  250. },
  251. bindClssPicker: function (event: any) {
  252. this.setData({
  253. classIndex: event.detail.value,
  254. classId: this.data.classData[event.detail.value].id
  255. })
  256. this.getDeviceByRSC()
  257. },
  258. //根据地区,学校,班级获取deviceId
  259. getDeviceByRSC: function () {
  260. let params = {
  261. city: this.data.cityValue,
  262. classId: this.data.classId,
  263. province: this.data.provinceValue,//省份
  264. region: this.data.regionValue,//地区
  265. schoolId: this.data.schoolId,
  266. }
  267. httpUtil.wxGet(httpUtil.interfaces.getDevideIdByRSC, params).then((res: any) => {
  268. console.log("根据省市学校班级获取deviceId成功:", res)
  269. if (res.data.success) {
  270. this.setData({
  271. deviceId: res.data.data.deviceId
  272. })
  273. } else {
  274. this.setData({
  275. deviceId: ''
  276. })
  277. }
  278. }).catch((res) => {
  279. console.log("根据省市学校班级获取deviceId失败:", res)
  280. this.setData({
  281. deviceId: '暂无设备'
  282. })
  283. })
  284. },
  285. //获取设备ID的输入
  286. bindDeviceInput(event: any) {
  287. this.setData({
  288. deviceId: event.detail.value
  289. })
  290. },
  291. //获取故障描述输入
  292. bindFaultText: function (event: any) {
  293. this.setData({
  294. describe: event.detail.value
  295. })
  296. },
  297. //从本机相册获取图片
  298. getFaultImg: function () {
  299. let that = this;
  300. wx.chooseImage({
  301. count: 9, // 默认9
  302. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  303. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  304. success: function (res) {
  305. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  306. that.setData({
  307. postFaultListImg: that.data.postFaultListImg.concat(res.tempFilePaths)
  308. })
  309. res.tempFilePaths.forEach((item, index) => {
  310. httpUtil.wxUploadFile(httpUtil.interfaces.uploadImageList, item, index.toString(), {
  311. 'userId': httpUtil.httpData.userId,
  312. 'deviceId': that.data.deviceId
  313. }).then((res: any) => {
  314. //拿不到data
  315. console.log("上传图片成功:", res)
  316. console.log("上传图片成功:", res.data)
  317. that.setData({
  318. postImg: that.data.postImg.concat(res.data)
  319. })
  320. console.log(" that.data.postImg:", that.data.postImg)
  321. }).catch((res => {
  322. console.log("上传图片失败:", res)
  323. }))
  324. })
  325. }
  326. })
  327. },
  328. //提交故障
  329. submitFault: function (event: any) {
  330. if (!this.data.deviceId) {
  331. wx.showToast({
  332. title: '请输入设备ID',
  333. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  334. duration: 1000
  335. })
  336. return;
  337. }
  338. if (!this.data.describe) {
  339. wx.showToast({
  340. title: '请输入故障描述',
  341. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  342. duration: 1000
  343. })
  344. return;
  345. }
  346. if (!this.data.deviceId || this.data.deviceId === '暂无设备') {
  347. wx.showToast({
  348. title: '暂无设备',
  349. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  350. duration: 1000
  351. })
  352. return;
  353. }
  354. let img = '';
  355. this.data.postImg.forEach((res, index) => {
  356. if (index < this.data.postImg.length) {
  357. img = img + res + ","
  358. } else {
  359. img = img + res
  360. }
  361. })
  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. }
  373. console.log("params:", params)
  374. httpUtil.wxPost(httpUtil.interfaces.postDeviceFault, params).then((res: any) => {
  375. console.log("设备报修成功:", res)
  376. if (res.data.success) {
  377. let that = this;
  378. wx.showModal({
  379. title: '',
  380. content: '报修成功',
  381. success: function (res) {
  382. if (res.confirm) {
  383. console.log('点击确认回调')
  384. that.getFaultByUserId();
  385. that.setData({
  386. pageState: 1
  387. })
  388. } else {
  389. console.log('点击取消回调')
  390. }
  391. }
  392. })
  393. } else { }
  394. }).catch((res) => {
  395. console.log("设备报修失败:", res)
  396. })
  397. },
  398. getFaultByUserId: function () {
  399. console.log("获取报修记录")
  400. let params = {
  401. pageNo: 1,
  402. pageSize: 10000
  403. }
  404. httpUtil.wxGet(httpUtil.interfaces.getDeviceFault, params).then((res: any) => {
  405. console.log("获取报修记录成功:", res)
  406. this.setData({
  407. faultList: res.data.data.list
  408. })
  409. }).catch((res) => {
  410. console.log("获取报修记录失败:", res)
  411. })
  412. }
  413. }
  414. })