123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- // pagesPublic/pages/work-order/work-order.js
- var dateTimePicker = require('../../../utils/dateTimePicker');
- const FormData = require('../../pages/menu/formData.js');
- import {
- baseUrl,
- request
- } from "../../../pages/api/canteen-request.js"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isUser: true,
- currentIndex: 0,
- date: '2023-10-01',
- time: '12:00',
- dateTimeArray: null,
- dateTime: null,
- startYear: 2000,
- endYear: 2250,
- typeList: ['报修类型一', '报修类型二', '报修类型三'],
- list: [{ type: '维修类型一', address: '食堂二楼楼梯地砖', time: '2022-03-15 13:45' }, { type: '维修类型一', address: '食堂二楼楼梯地砖', time: '2022-03-15 13:45' }],
- tempFileList: []
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // 获取完整的年月日 时分秒,以及默认显示的数组
- var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
- // 精确到分的处理,将数组的秒去掉
- // var lastArray = obj.dateTimeArray.pop();
- // var lastTime = obj.dateTime.pop();
- this.setData({
- dateTime: obj.dateTime,
- dateTimeArray: obj.dateTimeArray
- });
- // 查询所有报修类型
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 点击切换标题
- * @param {*} e
- */
- titleClick(e) {
- this.setData({
- currentIndex: e.currentTarget.dataset.idx
- });
- },
- /**
- * 切换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
- });
- }
- },
- /**
- * 报修类型选择
- * @param {*} e
- */
- typePickerChange(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- 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;
- }
- if (!e.detail.value.phone) {
- wx.showToast({
- title: '请输入联系电话',
- icon: 'error'
- });
- return;
- }
- if (!e.detail.value.arriveTime) {
- wx.showToast({
- title: '请选择上门时间',
- icon: 'error'
- });
- return;
- }
- let tempList = this.data.tempFileList;
- if (!tempList || tempList.length == 0) {
- wx.showToast({
- title: '请上传报修图片',
- icon: 'error'
- });
- return;
- }
- 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);
- 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 => {
- if (res.data.result) {
- wx.showToast({
- title: '提交成功',
- icon: 'success'
- });
- wx.navigateBack();
- } else {
- wx.showToast({
- title: '提交失败',
- icon: 'error'
- });
- }
- });
- },
- /**
- * 上传报修图片
- */
- 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',
- });
- },
- toRepairDetail() {
- wx.navigateTo({
- url: '../work-order-detail/work-order-detail',
- });
- }
- })
|