123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- // component/teacher/teacherFault/teacherFault.ts
- import { ConstsData } from "../../../utils/const"
- import { httpUtil } from "../../../utils/restful";
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- //判断当前页面显示哪个view
- pageState: 0,
- pageStateText: ['故障报修', '报修记录'],
- //故障报修界面所用数据
- fault: ['普通', '待查', '紧急'],
- faultIndex: 0,
- regionOne: Array<String>(),
- regionTwo: Array<String>(),
- regionThree: Array<String>(),
- regionOneIndex: 0,
- regionTwoIndex: 0,
- regionThreeIndex: 0,
- region: [
- Array<String>(),
- Array<String>(),
- Array<String>()
- ],
- regionIndex: [0, 0, 0],
- schoolArray: [['暂无学校']],
- schoolIndex: 0,
- classArray: ['暂无班级'],
- classIndex: 0,
- provinceValue: '',//省份value
- regionValue: '',//地区value
- cityValue: '',
- schoolData: [{ 'id': '' }],
- schoolId: '',
- classData: [{ 'id': '' }],
- classId: '',
- initFirst: true,
- deviceId: '',
- describe: "",
- postFaultListImg: [],
- postImg: [],
- //报修记录用到的参数
- faultList: []
- },
- lifetimes: {
- attached: function () {
- // 在组件实例被从页面节点树添加时执行
- this.changeOrganizeInfo();
- },
- detached: function () {
- // 在组件实例被从页面节点树移除时执行
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- //选择是故障报修界面还是报修记录界面
- bindPageChange: function (event: any) {
- console.log("event.detail.value:", event.detail.value)
- if (event.detail.value == 1) {
- this.getFaultByUserId();
- }
- this.setData({
- pageState: event.detail.value
- })
- },
- //选择是否紧急
- bindFaultChange: function (event: any) {
- this.setData({
- faultIndex: event.detail.value
- })
- },
- changeOrganizeInfo: function () {
- //设置名字
- this.setData({
- userName: ConstsData.AppData.myInfoData.name
- })
- //切换地区
- this.setData({
- regionOne: [],
- regionTwo: [],
- regionThree: []
- })
- ConstsData.AppData.organizeInfo.data.children.forEach((item, index) => {
- if (this.data.initFirst) {
- if (item.value == ConstsData.AppData.myInfoData.province) {
- //如果是当前的
- this.setData({
- regionOneIndex: index
- })
- }
- }
- this.data.regionOne.push(item.title)
- })
- ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item, index) => {
- if (this.data.initFirst) {
- if (item.value == ConstsData.AppData.myInfoData.city) {
- this.setData({
- regionTwoIndex: index
- })
- }
- }
- this.data.regionTwo.push(item.title)
- })
- ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item, index) => {
- if (this.data.initFirst) {
- if (item.value == ConstsData.AppData.myInfoData.region) {
- this.setData({
- regionThreeIndex: index
- })
- }
- }
- this.data.regionThree.push(item.title)
- })
- this.setData({
- region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
- regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
- provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
- cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
- regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString(),
- initFirst: false
- })
- //切换学校
- this.changeSchool();
- },
- //查询学校
- changeSchool: function () {
- //查询学校
- let params = {
- city: this.data.cityValue,
- province: this.data.provinceValue,
- region: this.data.regionValue,
- type: 1,
- }
- httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
- this.setData({
- schoolArray: [],
- schoolIndex: 0,
- schoolData: res.data.data,
- schoolId: res.data.data[0].id
- })
- let newArray: string[] = [];
- res.data.data.forEach((element, index) => {
- if (ConstsData.AppData.myInfoData.schoolId == element.id) {
- this.setData({
- schoolIndex: index,
- schoolId: this.data.schoolData[index].id
- })
- }
- newArray.push(element.title)
- });
- this.data.schoolArray.push(newArray)
- this.setData({
- schoolArray: this.data.schoolArray
- })
- //切换班级
- this.changeClass()
- }).catch(res => {
- console.log("查询学校error:", res)
- this.setData({
- schoolArray: [['暂无学校']],
- schoolId: '',
- classArray: ['暂无班级'],
- classId: ''
- })
- })
- },
- //查询班级
- changeClass: function () {
- let params = {
- city: this.data.cityValue,
- father: this.data.schoolId,//学校ID
- province: this.data.provinceValue,
- region: this.data.regionValue,
- type: 2,
- }
- httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
- this.setData({
- classArray: [],
- classIndex: 0
- })
- this.setData({
- classData: res.data.data,
- classId: res.data.data[0].id
- })
- console.log("classData:", this.data.classData)
- res.data.data.forEach((element: { id: number; title: string; }, index: number) => {
- if (element.id == ConstsData.AppData.myInfoData.classId) {
- this.setData({
- classIndex: index,
- classId: res.data.data[index].id
- })
- this.getDeviceByRSC()
- console.log("this.data.classIndex:", this.data.classIndex)
- }
- this.data.classArray.push(element.title)
- });
- this.setData({
- classArray: this.data.classArray,
- })
- }).catch(res => {
- console.log("查询班级error:", res)
- this.setData({
- classArray: ['暂无班级'],
- classId: ''
- })
- })
- },
- bindMultiPickerColumnChange: function (event: any) {
- //
- switch (Number(event.detail.column)) {
- case 0:
- //代表第一列
- this.setData({
- regionOneIndex: event.detail.value,
- })
- break;
- case 1:
- //代表第二列
- this.setData({
- regionTwoIndex: event.detail.value,
- })
- break;
- case 2:
- //代表第三列
- this.setData({
- regionThreeIndex: event.detail.value
- })
- break;
- }
- this.changeOrganizeInfo();
- },
- bindRegionChange: function (event: any) {
- this.setData({
- regionIndex: event.detail.value
- })
- },
- bindSchoolPicker: function (event: any) {
- this.setData({
- schoolIndex: event.detail.value,
- schoolId: this.data.schoolData[event.detail.value].id
- })
- this.changeClass();
- },
- bindClssPicker: function (event: any) {
- this.setData({
- classIndex: event.detail.value,
- classId: this.data.classData[event.detail.value].id
- })
- this.getDeviceByRSC()
- },
- //根据地区,学校,班级获取deviceId
- getDeviceByRSC: function () {
- let params = {
- city: this.data.cityValue,
- classId: this.data.classId,
- province: this.data.provinceValue,//省份
- region: this.data.regionValue,//地区
- schoolId: this.data.schoolId,
- }
- httpUtil.wxGet(httpUtil.interfaces.getDevideIdByRSC, params).then((res: any) => {
- console.log("根据省市学校班级获取deviceId成功:", res)
- if (res.data.success) {
- this.setData({
- deviceId: res.data.data.deviceId
- })
- } else {
- this.setData({
- deviceId: ''
- })
- }
- }).catch((res) => {
- console.log("根据省市学校班级获取deviceId失败:", res)
- this.setData({
- deviceId: '暂无设备'
- })
- })
- },
- //获取设备ID的输入
- bindDeviceInput(event: any) {
- this.setData({
- deviceId: event.detail.value
- })
- },
- //获取故障描述输入
- bindFaultText: function (event: any) {
- this.setData({
- describe: event.detail.value
- })
- },
- //从本机相册获取图片
- getFaultImg: function () {
- let that = this;
- wx.chooseImage({
- count: 9, // 默认9
- sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
- success: function (res) {
- // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
- that.setData({
- postFaultListImg: that.data.postFaultListImg.concat(res.tempFilePaths)
- })
- res.tempFilePaths.forEach((item, index) => {
- httpUtil.wxUploadFile(httpUtil.interfaces.uploadImageList, item, index.toString(), {
- 'userId': httpUtil.httpData.userId,
- 'deviceId': that.data.deviceId
- }).then((res: any) => {
- let json = JSON.parse(res.data);
- console.log("json:", json.data)
- that.setData({
- postImg: that.data.postImg.concat(json.data)
- })
- }).catch((res => {
- console.log("上传图片失败:", res)
- }))
- })
- }
- })
- },
- //提交故障
- submitFault: function (event: any) {
- if (!this.data.deviceId) {
- wx.showToast({
- title: '请输入设备ID',
- icon: 'none', //如果要纯文本,不要icon,将值设为'none'
- duration: 1000
- })
- return;
- }
- if (!this.data.describe) {
- wx.showToast({
- title: '请输入故障描述',
- icon: 'none', //如果要纯文本,不要icon,将值设为'none'
- duration: 1000
- })
- return;
- }
- if (!this.data.deviceId || this.data.deviceId === '暂无设备') {
- wx.showToast({
- title: '暂无设备',
- icon: 'none', //如果要纯文本,不要icon,将值设为'none'
- duration: 1000
- })
- return;
- }
- let img = '';
- this.data.postImg.forEach((res, index) => {
- if (index < this.data.postImg.length - 1) {
- img = img + res + ","
- } else {
- img = img + res
- }
- })
- console.log("postImg:", img)
- let params = {
- city: this.data.cityValue,
- classId: this.data.classId,
- province: this.data.provinceValue,//省份
- region: this.data.regionValue,//地区
- schoolId: this.data.schoolId,
- deviceId: this.data.deviceId,
- faultLevel: this.data.faultIndex,
- describe: this.data.describe,
- userId: httpUtil.httpData.userId,
- img: img
- }
- console.log("params:", params)
- httpUtil.wxPost(httpUtil.interfaces.postDeviceFault, params).then((res: any) => {
- console.log("设备报修成功:", res)
- if (res.data.success) {
- let that = this;
- wx.showModal({
- title: '',
- content: '报修成功',
- success: function (res) {
- if (res.confirm) {
- console.log('点击确认回调')
- that.getFaultByUserId();
- that.setData({
- pageState: 1
- })
- } else {
- console.log('点击取消回调')
- }
- }
- })
- } else { }
- }).catch((res) => {
- console.log("设备报修失败:", res)
- })
- },
- getFaultByUserId: function () {
- console.log("获取报修记录")
- let params = {
- pageNo: 1,
- pageSize: 10000
- }
- httpUtil.wxGet(httpUtil.interfaces.getDeviceFault, params).then((res: any) => {
- console.log("获取报修记录成功:", res)
- this.setData({
- faultList: res.data.data.list
- })
- }).catch((res) => {
- console.log("获取报修记录失败:", res)
- })
- }
- }
- })
|