123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- // pagesPublic/pages/work-order/work-order.js
- var dateTimePicker = require('../../../utils/dateTimePicker');
- const FormData = require('../../pages/menu/formData.js');
- const twoHours = 7200000;
- const limit = 10;
- import {
- baseUrl,
- request
- } from "../../../pages/api/canteen-request.js"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- page: 1,
- page2: 1,
- isUser: true,
- currentIndex: 0,
- date: '2023-01-01',
- time: '12:00',
- dateTimeArray: null,
- dateTime: null,
- startYear: 2000,
- endYear: 2250,
- typeList: [],
- list: [],
- repairList: [],
- completeList: [],
- tempFileList: [],
- nodata: false,
- nodata2: false,
- total: 0,
- total2: 0,
- scroll_height:""
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- var windowWidth = wx.getSystemInfoSync().windowWidth;
- var windowHeight = wx.getSystemInfoSync().windowHeight;
- //rpx与px单位之间的换算 : 750/windowWidth = 屏幕的高度(rpx)/windowHeight
- var scroll_height = 750*windowHeight/windowWidth;
- this.setData({
- scroll_height:scroll_height
- })
- // 查询用户所属角色
- request({
- url: '/mini/worker/getUserType',
- method: 'GET',
- data: {
- userId: wx.getStorageSync('userid')
- }
- }).then(res => {
- if (res.result) {
- let userType = res.data;
- if ("0" == userType) {
- // 普通用户
- this.setData({
- isUser: true
- });
- // 获取完整的年月日 时分秒,以及默认显示的数组
- let obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
- // 精确到分的处理,将数组的秒去掉
- let lastArray = obj.dateTimeArray.pop();
- let lastTime = obj.dateTime.pop();
- this.setData({
- dateTime: obj.dateTime,
- dateTimeArray: obj.dateTimeArray
- });
- // 设置所有报修类型
- this.setRepairType();
- } else if ('2' == userType) {
- this.setData({
- isUser: false
- });
- // 设置所有报修类型
- this.setRepairType();
- // 初始化待维修工单
- this.loadTobeRepair();
- // 初始化已完成工单
- // this.loadComplete();
- } else {
- wx.navigateBack();
- }
- } else {
- wx.navigateBack();
- }
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- loadMore(){
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.onPullDownRefresh();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- console.log("下拉刷新...");
- if (this.data.currentIndex == 1) {
- this.setData({ page2: 1 });
- if (this.data.isUser) {
- this.loadMyApplication();
- } else {
- this.loadComplete();
- }
- } else {
- if (!this.data.isUser) {
- this.setData({ page: 1 });
- this.loadTobeRepair();
- }
- }
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- console.log("上拉加载....");
-
- if (this.data.currentIndex == 1) {
- if (this.data.total2 <= limit) {
- return;
- }
- if (this.data.list.length == this.data.total2 || this.data.completeList.length == this.data.total2) {
- return;
- }
- this.setData({ page2: this.data.page2+1 });
- if (this.data.isUser) {
- this.loadMyApplication(true);
- } else {
- this.loadComplete(true);
- }
- } else {
- if (this.data.total <= limit) {
- return;
- }
- if (this.data.repairList.length == this.data.total) {
- return;
- }
- if (!this.data.isUser) {
- this.setData({ page: this.data.page++ });
- this.loadTobeRepair(true);
- }
- }
- },
- /**
- * 点击切换标题
- * @param {*} e
- */
- titleClick(e) {
- this.setData({
- currentIndex: e.currentTarget.dataset.idx
- });
- if (this.data.isUser) {
- if (e.currentTarget.dataset.idx == 1) {
- this.loadMyApplication();
- }
- } else {
- if (e.currentTarget.dataset.idx == 1) {
- this.loadComplete();
- } else {
- this.loadTobeRepair();
- }
- }
- },
- /**
- * 切换swiper-item触发bindchange事件
- * @param {*} e
- */
- pagechange: function (e) {
- // console.info(e)
- // 通过touch判断,改变tab的下标值
- if ("touch" === e.detail.source) {
- // let currentPageIndex = this.data.currentIndex;
- // currentPageIndex = (currentPageIndex + 1) % 2;
- // 拿到当前索引并动态改变
- this.setData({
- currentIndex: e.detail.current
- });
- if (this.data.isUser) {
- if (e.detail.current == 1) {
- this.loadMyApplication();
- }
- } else {
- if (e.detail.current == 1) {
- this.loadComplete();
- } else {
- this.loadTobeRepair();
- }
- }
- }
- },
- /**
- * 报修类型选择
- * @param {*} e
- */
- typePickerChange(e) {
-
- this.setData({
- index: e.detail.value
- });
- },
- /**
- * 提交工单
- * @param {*} e
- */
- submitWorkOrder(e) {
- console.info(e);
- if (!e.detail.value.type) {
- wx.showToast({
- title: '请选择报修类型',
- icon: 'error'
- });
- return;
- }
- if (!e.detail.value.address) {
- wx.showToast({
- title: '请输入地址',
- icon: 'error'
- });
- return;
- }
- if (!e.detail.value.description) {
- wx.showToast({
- title: '请输入问题描述',
- icon: 'error'
- });
- return;
- }
- let tempList = this.data.tempFileList;
- if (!tempList || tempList.length == 0) {
- wx.showToast({
- title: '请上传报修图片',
- icon: 'error'
- });
- return;
- }
- if (!e.detail.value.phone) {
- wx.showToast({
- title: '请输入联系电话',
- icon: 'error'
- });
- return;
- }
- let phone = e.detail.value.phone;
- let reg = /^((0\d{2,3}(-)?\d{7,8})|(1[3-9]\d{9}))$/;
- if (!reg.test(phone)) {
- wx.showToast({
- title: '联系电话格式有误',
- icon: 'error'
- });
- return;
- }
- if (!e.detail.value.arriveTime) {
- wx.showToast({
- title: '请选择上门时间',
- icon: 'error'
- });
- return;
- }
- let arriveTime = e.detail.value.arriveTime;
- let t = new Date(arriveTime).getTime();
- let now = new Date().getTime();
- // 判断预约时间是否在两小时后
- if (t - now < twoHours) {
- wx.showModal({
- content: '您预约的上门时间过于紧急,确定继续预约?',
- complete: (res) => {
- if (res.cancel) {
- return;
- }
- if (res.confirm) {
- this.addOrder(e);
- }
- }
- });
- } else {
- this.addOrder(e);
- }
- },
- addOrder(e) {
- wx.showLoading({
- title: '加载中...',
- });
- let tempList = this.data.tempFileList;
- let formData = new FormData();
- formData.append('repairType', e.detail.value.type);
- formData.append('userDescription', e.detail.value.description);
- formData.append('phoneNum', e.detail.value.phone);
- formData.append('appointmentTime', e.detail.value.arriveTime);
- formData.append('maintenanceAddress', e.detail.value.address);
- formData.append('userId', wx.getStorageSync('userid'));
- for (let i in tempList) {
- formData.appendFile('files', tempList[i]);
- }
- let data = formData.getData();
- request({
- url: '/mini/worker/addOrder',
- method: 'POST',
- data: data.buffer,
- contentType: data.contentType
- }).then(res => {
- console.info(res)
- if (res.result) {
- wx.showToast({
- title: '提交成功',
- icon: 'success',
- mask: true,
- });
- setTimeout(() => {
- wx.navigateBack();
- }, 1500);
- } else {
- wx.showToast({
- title: '提交失败',
- icon: 'error',
- mask: true
- });
- }
- wx.hideLoading();
- });
- },
- /**
- * 上传报修图片
- */
- uploadImage() {
- let that = this;
- wx.chooseMedia({
- success(res) {
- console.info(res);
- if (res.errMsg == 'chooseMedia:ok') {
- let tempList = that.data.tempFileList;
- for (let i in res.tempFiles) {
- tempList.push(res.tempFiles[i].tempFilePath);
- }
- that.setData({
- tempFileList: tempList
- });
- }
- }
- });
- },
- changeDateTime(e) {
- this.setData({ dateTime: e.detail.value });
- },
- changeDateTimeColumn(e) {
- var arr = this.data.dateTime, dateArr = this.data.dateTimeArray;
- arr[e.detail.column] = e.detail.value;
- dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
- this.setData({
- dateTimeArray: dateArr,
- dateTime: arr
- });
- },
- /**
- * 查看工单详情
- * @param {*} e
- */
- toDetail(e) {
- wx.navigateTo({
- url: '../work-order-detail/work-order-detail?id=' + e.currentTarget.dataset.id + '&isuser=' + e.currentTarget.dataset.isuser
- });
- },
- /**
- * 加载我的申请
- */
- loadMyApplication(ispullup) {
- wx.showLoading({
- title: '加载中...'
- });
- request({
- url: '/mini/worker/myOrder',
- method: 'GET',
- data: {
- page: this.data.page2,
- limit: limit,
- userId: wx.getStorageSync('userid'),
- isUser: true
- }
- }).then(res => {
- // console.info(res)
- let data = res.data;
- if (data && data.length > 0) {
- let typeList = this.data.typeList;
- for (let i in data) {
- if (data[i].status == 3) {
- data[i].image = 'status-complete.png';
- } else if (data[i].status == -1) {
- data[i].image = 'status-incomplete.png';
- } else {
- data[i].image = 'status-repair.png';
- }
- for (let j in typeList) {
- if (data[i].repairType == typeList[j].code) {
- data[i].typeName = typeList[j].codeValue;
- break;
- }
- }
- }
- if (ispullup) {
- data = this.data.list.concat(data);
- }
- this.setData({
- list: data,
- total2: res.count,
- nodata: false
- });
- } else {
- if (!ispullup) {
- this.setData({
- list: [],
- nodata: true
- });
- }
- }
- wx.hideLoading();
- });
- },
- /**
- * 加载待维修工单
- */
- loadTobeRepair(ispullup) {
- wx.showLoading({
- title: '加载中...'
- });
- request({
- url: '/mini/worker/myOrder',
- method: 'GET',
- data: {
- page: this.data.page,
- limit: limit,
- userId: wx.getStorageSync('userid'),
- todo: true
- }
- }).then(res => {
- // console.info(res)
- let data = res.data;
- if (data && data.length > 0) {
- let typeList = this.data.typeList;
- for (let i in data) {
- for (let j in typeList) {
- if (data[i].repairType == typeList[j].code) {
- data[i].typeName = typeList[j].codeValue;
- break;
- }
- }
- }
- if (ispullup) {
- data = this.data.repairList.concat(data);
- }
- this.setData({
- repairList: data,
- total: res.count,
- nodata: false
- });
- } else {
- if (!ispullup) {
- this.setData({
- repairList: [],
- nodata: true
- });
- }
- }
- wx.hideLoading();
- });
- },
- /**
- * 加载已完成工单
- */
- loadComplete(ispullup) {
- wx.showLoading({
- title: '加载中...'
- });
- request({
- url: '/mini/worker/myOrder',
- method: 'GET',
- data: {
- page: this.data.page2,
- limit: limit,
- userId: wx.getStorageSync('userid'),
- close: true
- }
- }).then(res => {
- // console.info(res)
- let data = res.data;
- if (data && data.length > 0) {
- let typeList = this.data.typeList;
- for (let i in data) {
- if (data[i].resultPic) {
- request({
- url: '/food/getFoodPicByPicId',
- method: 'GET',
- data: {
- 'picId': data[i].resultPic
- }
- }).then(re => {
- console.info(re)
- if (re.data && re.data.length > 0) {
- let arr = [];
- for (let j in re.data) {
- arr.push(baseUrl + '/' + re.data[j].path);
- }
- data[i].images = arr;
- }
- });
- }
- for (let j in typeList) {
- if (data[i].repairType == typeList[j].code) {
- data[i].typeName = typeList[j].codeValue;
- break;
- }
- }
- }
- if (ispullup) {
- data = this.data.completeList.concat(data);
- }
- setTimeout(() => {
- this.setData({
- completeList: data,
- total2: res.count,
- nodata2: false
- });
- wx.hideLoading();
- }, 1500);
- } else {
- if (!ispullup) {
- this.setData({
- completeList: [],
- nodata2: true
- });
- }
- wx.hideLoading();
- }
- });
- },
- /**
- * 设置报修类型
- */
- setRepairType() {
- request({
- url: '/mini/worker/getDictByType',
- method: 'GET',
- data: {
- types: 'repair_type',
- codes: ''
- }
- }).then(res => {
- // console.info(res)
- if (res.result) {
- let data = res.data;
- this.setData({
- typeList: data
- });
- }
- });
- },
- previewImg(e) {
- wx.previewImage({
- urls: this.data.tempFileList,
- current: e.currentTarget.dataset.src
- });
- }
- })
|