Browse Source

1.登录过直接进入选择的相应界面
2.保存userid到本地
3.报修故障提交接口
4.报修列表接口

FailedToRead 2 years atrás
parent
commit
7dfe8849a8

+ 31 - 7
miniprogram/component/faultItem/faultItem.ts

@@ -1,13 +1,34 @@
 // component/faultItem/faultItem.ts
+import { TimeUtil } from '../../utils/TimeUtil'
 Component({
     /**
      * 组件的属性列表
      */
     properties: {
-        //0=已完成 1=维修中 2=待维修
+        //0=待维修 1=维修中 2=已完成
         faultStatus: {
             type: Number,
             value: 0
+        },
+        faultRepairNo: {
+            type: String,
+            value: ''
+        },
+        faultReportTime: {
+            type: String,
+            value: ''
+        },
+        faultProvinceCity: {
+            type: String,
+            value: ''
+        },
+        faultSchoolName: {
+            type: String,
+            value: ''
+        },
+        faultClassName: {
+            type: String,
+            value: ''
         }
     },
 
@@ -16,29 +37,32 @@ Component({
      */
     data: {
         status: 0,
-        statusText: ""
+        statusText: "",
+        faultTime: '',
     },
     lifetimes: {
         attached: function () {
             // 在组件实例被从页面节点树添加时执行
+
             let text = "";
             switch (Number(this.properties.faultStatus)) {
                 case 0:
-                    text = "已完成";
-
+                    text = "待维修";
                     break;
                 case 1:
                     text = "维修中";
                     break;
                 case 2:
-                    text = "待维修";
+                    text = "已完成";
                     break;
             }
             this.setData({
                 status: this.properties.faultStatus,
-                statusText: text
+                statusText: text,
+                faultTime: TimeUtil.dateFormat(parseInt(this.properties.faultReportTime), "yyyy-MM-dd HH:mm")
             })
-
+            console.log("status:", this.data.status)
+            console.log("propertiesstatus:", this.properties.faultStatus)
         },
         detached: function () {
             // 在组件实例被从页面节点树移除时执行

+ 7 - 4
miniprogram/component/faultItem/faultItem.wxml

@@ -1,23 +1,26 @@
 <!--component/faultItem/faultItem.wxml-->
 
 <view class="item_bg">
-    <view class="{{faultStatus==2?'fault_status_wait':''}} {{status==0?'fault_status_over':''}}  {{status==1?'fault_status_repair':''}}">
+    <view class="{{status==0?'fault_status_wait':''}} {{status==1?'fault_status_over':''}}  {{status==1?'fault_status_repair':''}}">
         <text class="fault_status_text">{{statusText}}</text>
     </view>
 
     <view class="fault_info_layout">
         <view class="fault_info_layout_item_bg">
             <image src="../../image/fault/fault_time.png" class="fault_info_layout_item_icon"></image>
-            <text class="fault_info_layout_item_text">提交时间:2021-12-20 18:02</text>
+            <text class="fault_info_layout_item_text">提交时间:</text>
+            <text class="fault_info_layout_item_text" style="flex: 1;">{{faultTime}}</text>
         </view>
         <view class="fault_info_layout_item_bg">
             <image src=" ../../image/fault/fault_number.png" class="fault_info_layout_item_icon">
             </image>
-            <text class=" fault_info_layout_item_text">报修单号:16832226565</text>
+            <text class=" fault_info_layout_item_text">报修单号:</text>
+            <text class="fault_info_layout_item_text" style="flex: 1;">{{faultRepairNo}}</text>
         </view>
         <view class="fault_info_layout_item_bg">
             <image src="../../image/fault/fault_address.png" class="fault_info_layout_item_icon"></image>
-            <text class="fault_info_layout_item_text">详细地址:北京市-海淀区 第二小学 三年级2班</text>
+            <text class="fault_info_layout_item_text">详细地址:</text>
+            <text class="fault_info_layout_item_text" style="flex: 1;">{{faultProvinceCity}} {{faultSchoolName}} {{faultClassName}}</text>
         </view>
     </view>
 

+ 1 - 1
miniprogram/component/faultItem/faultItem.wxss

@@ -67,7 +67,7 @@
     flex-direction: row;
     display: flex;
     justify-content: start;
-    align-items: center;
+    align-items: flex-start;
     margin-left: 17rpx;
 }
 

+ 67 - 7
miniprogram/component/teacher/teacherFault/teacherFault.ts

@@ -44,7 +44,9 @@ Component({
         classId: '',
         initFirst: true,
         deviceId: '',
-        describe: ""
+        describe: "",
+        //报修记录用到的参数
+        faultList: []
 
     },
 
@@ -70,6 +72,9 @@ Component({
         //选择是故障报修界面还是报修记录界面
         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
             })
@@ -204,11 +209,11 @@ Component({
         //查询班级
         changeClass: function () {
             let params = {
-                "city": this.data.cityValue,
-                "father": this.data.schoolId,//学校ID
-                "province": this.data.provinceValue,
-                "region": this.data.regionValue,
-                "type": 2,
+                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({
@@ -293,9 +298,40 @@ Component({
                 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({
@@ -328,9 +364,16 @@ Component({
                 })
                 return;
             }
+            if (!this.data.deviceId || this.data.deviceId === '暂无设备') {
+                wx.showToast({
+                    title: '暂无设备',
+                    icon: 'none',    //如果要纯文本,不要icon,将值设为'none'
+                    duration: 1000
+                })
+                return;
+            }
 
             let params = {
-
                 city: this.data.cityValue,
                 classId: this.data.classId,
                 province: this.data.provinceValue,//省份
@@ -353,6 +396,7 @@ Component({
                         success: function (res) {
                             if (res.confirm) {
                                 console.log('点击确认回调')
+                                that.getFaultByUserId();
                                 that.setData({
                                     pageState: 1
                                 })
@@ -370,6 +414,22 @@ Component({
 
 
 
+        },
+
+        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)
+            })
         }
 
     }

+ 4 - 4
miniprogram/component/teacher/teacherFault/teacherFault.wxml

@@ -70,13 +70,13 @@
             <!--选择班级end-->
             <view class="item_input_bg" style="margin-top: 1rpx;box-shadow: 0px 1px 0px 0px #EEEEEE;">
                 <text class="item_input_title">设备ID:</text>
-                <input class="item_input_content" placeholder="请输入设备ID" bindinput="bindDeviceInput" />
+                <input class="item_input_content" placeholder="请输入设备ID" bindinput="bindDeviceInput" value="{{deviceId}}" />
             </view>
         </view>
         <view class="fault_info_layout">
             <textarea bindinput="bindFaultText" class="fault_info_textarea" placeholder="故障描述:请描述故障情况请描述故障情况,\n请描述故障情况请描述故障情况" value="{{describe}}"></textarea>
             <scroll-view scroll-x class="fault_info_scroll">
-                <view wx:for="{{6}}" wx:key="index" style="display:inline-block;">
+                <view wx:for="{{1}}" wx:key="index" style="display:inline-block;">
                     <image class="fault_info_scroll_item"></image>
                 </view>
             </scroll-view>
@@ -93,8 +93,8 @@
 
     <!-- 报修记录-->
     <scroll-view wx:if="{{pageState==1}}" scroll-y="true" class="scrollview">
-        <view wx:for="{{30}}" class="scroll_item_bg" wx:key="index">
-            <fauleItem faultStatus="{{index%3}}"></fauleItem>
+        <view wx:for="{{faultList}}" class="scroll_item_bg" wx:key="key" wx:for-index="idx" wx:for-item="item">
+            <fauleItem faultStatus="{{item.processType}}" faultRepairNo="{{item.repairNo}}" faultProvinceCity="{{item.provinceCity}}" faultSchoolName="{{item.schoolName}}" faultClassName="{{item.className}}" faultReportTime="{{item.reportTime}}"></fauleItem>
         </view>
     </scroll-view>
     <!-- 报修记录-->

+ 52 - 5
miniprogram/pages/index/index.ts

@@ -2,6 +2,7 @@
 import { httpUtil } from "../../utils/restful";
 import { loginType } from '../../utils/loginType';
 import { ConstsData } from "../../utils/const"
+import { storage } from "../../utils/storageUtil"
 
 Page({
 
@@ -9,50 +10,96 @@ Page({
      * 页面的初始数据
      */
     data: {
-
+        init: false
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad() {
+
+
+
         httpUtil.wxGet(httpUtil.interfaces.getOrganizeAll, null).then((res: any) => {
             ConstsData.AppData.organizeInfo = res.data
-
+            storage.getStorage(storage.storageKey.userId).then((res: any) => {
+                httpUtil.httpData.userId = res.data
+                httpUtil.wxGet(httpUtil.interfaces.getUserById, null).then(((myinfo: any) => {
+                    console.log("获取个人信息成功:", myinfo)
+                    ConstsData.AppData.myInfoData = myinfo.data.data
+                    this.setData({
+                        init: true
+                    })
+                })).catch((myinfo) => {
+                    console.log("获取个人信息失败:", myinfo)
+                    this.setData({
+                        init: true
+                    })
+                })
+            }).catch((res) => {
+                console.log("获取保存的UID失败了=", res)
+                this.setData({
+                    init: true
+                })
+            })
         }).catch((res) => {
             console.log(res)
+            this.setData({
+                init: true
+            })
         })
+
     },
     clickItem: function (event: any) {
+        if (!this.data.init) {
+            wx.showToast({
+                title: '初始化信息中',
+                icon: 'none'
+            })
+            return;
+        }
         console.log(event.target.id)
         let type = null;
+        let toUrl = '';
         switch (Number(event.target.id)) {
             case 0:
                 console.log("click teacher")
                 type = loginType.Teacher
+                toUrl = "../teacher/index/index"
                 break;
             case 1:
                 console.log("click installer")
                 type = loginType.Installer
+                toUrl = "../installer/index/index"
                 break;
             case 2:
                 console.log("click repairman")
                 type = loginType.Repairman
+                toUrl = "../repairman/index/index"
                 break;
             case 3:
                 console.log("click it")
                 type = loginType.IT
+                toUrl = "../itadministrator/index/index"
                 break;
         }
-        this.toLoginPage(type)
+
+        if (ConstsData.AppData.myInfoData.id == 0) {
+            //代表没有获取到用户,去登录界面
+            toUrl = '../login/login?loginType=' + type;
+        }
+        //有用户,直接去首页,不登录
+        this.toNextPage(toUrl)
     },
-    toLoginPage: function (type: any) {
+    toNextPage: function (url: string) {
         wx.navigateTo({
-            url: '../login/login?loginType=' + type,
+            url: url,
         })
     },
 
 
 
 
+
+
 })

+ 14 - 2
miniprogram/pages/login/login.ts

@@ -3,6 +3,7 @@
 import { ConstsData } from "../../utils/const";
 import { loginType } from "../../utils/loginType"
 import { httpUtil } from "../../utils/restful";
+import { storage } from "../../utils/storageUtil";
 
 
 Page({
@@ -178,6 +179,13 @@ Page({
         console.log("登录成功:", res)
         httpUtil.httpData.userId = res.data.data.id;
         ConstsData.AppData.myInfoData = res.data.data
+
+        storage.saveStorage(storage.storageKey.userId, res.data.data.id).then((res) => {
+          console.log("保存成功:", res)
+        }).catch((res) => {
+          console.log("保存失败:", res)
+        })
+
         this.toNextPage();
       } else {
         console.log("登录失败:", res)
@@ -205,11 +213,15 @@ Page({
       userName: this.data.inputPhonePwdLoginNum
     }
     httpUtil.wxPost(httpUtil.interfaces.pwdPhoneLogin, params).then((res: any) => {
-      console.log("res:", res.data)
+
       if (res.data.success) {
-        console.log("res.data.data:", res.data.data.id)
         httpUtil.httpData.userId = res.data.data.id
         ConstsData.AppData.myInfoData = res.data.data
+        storage.saveStorage(storage.storageKey.userId, res.data.data.id).then((res) => {
+          console.log("保存成功:", res)
+        }).catch((res) => {
+          console.log("保存失败:", res)
+        })
         this.toNextPage()
       } else {
         this.showToast(res.data.message)

+ 1 - 1
miniprogram/pages/logs/logs.ts

@@ -1,6 +1,6 @@
 // logs.ts
 // const util = require('../../utils/util.js')
-import { formatTime } from '../../utils/util'
+import { formatTime } from '../../utils/TimeUtil'
 
 Page({
   data: {

+ 4 - 0
miniprogram/pages/register/register.ts

@@ -1,6 +1,7 @@
 // pages/register/register.ts
 import { ConstsData } from "../../utils/const"
 import { httpUtil } from "../../utils/restful";
+import { storage } from "../../utils/storageUtil"
 Page({
 
     /**
@@ -344,6 +345,9 @@ Page({
             httpUtil.httpData.userId = res.data.data.id;
             ConstsData.AppData.myInfoData = res.data.data;
             console.log(" res.data.data:", res.data.data)
+
+            storage.saveStorage(storage.storageKey.userId, res.data.data.id);
+
             wx.navigateTo({
                 url: '../teacher/index/index',
             })

+ 37 - 0
miniprogram/utils/TimeUtil.ts

@@ -0,0 +1,37 @@
+export const TimeUtil = {
+    dateFormat: function (strDate: any, strFormat: any) {
+        return FormatDate(strDate, strFormat);
+    }
+}
+
+function FormatDate(strDate: any, strFormat?: any) {
+    if (!strDate) return;
+    if (!strFormat) strFormat = "yyyy-MM-dd"
+    switch (typeof strDate) {
+        case "string":
+            strDate = new Date(strDate.replace(/-/g, "/"));
+            break;
+        case "number":
+            strDate = new Date(strDate);
+            break;
+    }
+    if (strDate instanceof Date) {
+        const dict: any = {
+            yyyy: strDate.getFullYear(),
+            M: strDate.getMonth() - 1,
+            d: strDate.getDate(),
+            H: strDate.getHours(),
+            m: strDate.getMinutes(),
+            s: strDate.getSeconds(),
+            MM: ("" + (strDate.getMonth() + 101)).substring(1),
+            dd: ("" + (strDate.getDate() + 100)).substring(1),
+            HH: ("" + (strDate.getHours() + 100)).substring(1),
+            mm: ("" + (strDate.getMinutes() + 100)).substring(1),
+            ss: ("" + (strDate.getSeconds() + 100)).substring(1),
+        };
+        return strFormat.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function () {
+            return dict[arguments[0]]
+        })
+    }
+
+}

+ 8 - 1
miniprogram/utils/restful.ts

@@ -47,8 +47,15 @@ const interfaces = {
     //根据deviceId获取设备信息(后面拼接deviceId)
     getDeviceById: '/tch/device/',
 
+    //根据地区,学校,班级获取设备ID
+    getDevideIdByRSC: '/tch/device/site',
+
     //提交设备报修
-    postDeviceFault: '/tch/fault'
+    postDeviceFault: '/tch/fault',
+
+    //根据userId获取提交的报修记录
+    getDeviceFault: '/tch/fault',
+
 
 
 

+ 49 - 0
miniprogram/utils/storageUtil.ts

@@ -0,0 +1,49 @@
+
+
+const storageKey = {
+    userId: 'userId'
+}
+
+function saveStorage(key: any, value: any) {
+    let promise = new Promise((resolve, reject) => {
+        wx.setStorage({
+            key: key,
+            data: value,
+            success(res) {
+                resolve(res)
+            },
+            fail(res) {
+                reject(res)
+            }
+        })
+    })
+    return promise;
+
+}
+function getStorage(key: any) {
+    let promise = new Promise((resolve, reject) => {
+        wx.getStorage({
+            key: key,
+            success(res) {
+                resolve(res)
+            },
+            fail(res) {
+                reject(res)
+            }
+        })
+    })
+    return promise;
+
+}
+
+
+
+export const storage = {
+    storageKey,
+    saveStorage: function (key: any, value: any) {
+        return saveStorage(key, value);
+    },
+    getStorage: function (key: any) {
+        return getStorage(key)
+    }
+}

+ 0 - 19
miniprogram/utils/util.ts

@@ -1,19 +0,0 @@
-export const formatTime = (date: Date) => {
-  const year = date.getFullYear()
-  const month = date.getMonth() + 1
-  const day = date.getDate()
-  const hour = date.getHours()
-  const minute = date.getMinutes()
-  const second = date.getSeconds()
-
-  return (
-    [year, month, day].map(formatNumber).join('/') +
-    ' ' +
-    [hour, minute, second].map(formatNumber).join(':')
-  )
-}
-
-const formatNumber = (n: number) => {
-  const s = n.toString()
-  return s[1] ? s : '0' + s
-}