| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- // pages/createorder/index.js
- const api = require('../../api/index.js');
-
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- cartype:1,
- index:0,
- objectArray: [],
- objdriver: [],
- driverindex:0,
- date: '',
- time: '', // 初始时间
- userdata:[],
- userindex:0,
- addressindex:'',
- address: [],
- items: [
- {value: 1, name: '光伏'},
- {value: 2, name: '风电'},
- {value: 3, name: '网电'},
- ],
- greenelectricity:0,
- workorderpower:'',
- orderdata:[],
- orderid:'',
- createtype:false,
- workorderindex:0,
- // 充放电记录列表,初始包含一行默认数据
- putDischargeList: [
- {
- type: '充电',
- power: '200',
- startTime: '9:00',
- endTime: '12:00'
- }
- ],
- chargeDischargeList: [
- {
- type: '放电',
- power: '200',
- startTime: '9:00',
- endTime: '12:00'
- }
- ]
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- console.log(options);
- this.setData({
- userdata: wx.getStorageSync('user') || {},
- });
- this.getaddress()
-
- if (options.order!='') {
- this.setData({
- orderid:options.order
- })
- this.getoneworkorder()
- }
-
- // this.getdriver()
- // this.getvehicle()
- },
- workordertype(e){
- console.log(e);
- this.setData({
- workorderindex:e.currentTarget.dataset.index
- })
- },
- // 工单详情
- getoneworkorder() {
- const data = {
- workorderId: this.data.orderid
- };
-
- api.request(`/sysworkorder/selectworkorderId`, 'post', data, { isPublic: false })
- .then((data) => {
- if (data.code == 200) {
-
- this.setData({
- workorderElectricity:data.data.workorderElectricity,
- workorderpower:data.data.workorderPower,
- greenelectricity:data.data.greenelectricity,
- date:data.data.workorderStarttime.slice(0,10),
- time:data.data.workorderStarttime.slice(11,16),
- })
- for (let index = 0; index < this.data.address.length; index++) {
- if (data.data.addressId==this.data.address[index].addressId) {
- this.setData({
- addressindex:index
- })
- }
- }
-
- }
- })
- .catch((err) => {
- console.error('获取工单信息失败:', err);
- this.showInfo('获取工单信息失败');
- });
- },
- // 司机
- getdriver(){
- let data ={
-
- }
- api.request(`/sysdriver/selectdriverall`, 'post',data,{ isPublic: false })
- .then((data) => {
- console.log(data.data);
- let obj = []
-
- for (let index = 0; index < data.data.length; index++) {
- let carType = ''
- if (data.data[index].operationType==1) {
- carType = '空闲'
- }else if(data.data[index].operationType==2){
- carType = '工作中'
- }else if(data.data[index].operationType==3){
- carType = '维护中'
- }
- obj.push({
- id:data.data[index].operationId,
- name:data.data[index].operationName,
- subtitle:data.data[index].operationName + ' / ' + carType
- })
- }
- this.setData({
- objdriver:obj
- })
- })
- .catch((err) => {
-
- console.error('请求失败:', err);
- });
- },
- // 车型
- getvehicle(){
- let data ={}
- api.request(`/syscar/selectcarall`, 'post',data,{ isPublic: false })
- .then((data) => {
- let obj = []
- for (let index = 0; index < data.data.length; index++) {
- let carType = ''
- if (data.data[index].carType==1) {
- carType = '空闲'
- }else if(data.data[index].carType==2){
- carType = '工作中'
- }else if(data.data[index].carType==3){
- carType = '维护中'
- }
- obj.push({
- id:data.data[index].carId,
- name:data.data[index].carId + ' / ' + data.data[index].carMondel,
- subtitle:data.data[index].carId + ' / ' + data.data[index].carMondel + ' / ' + carType
-
- })
- }
- this.setData({
- objectArray:obj
- })
- console.log(this.data.objectArray);
- })
- .catch((err) => {
-
- console.error('请求失败:', err);
- });
- },
-
- // 地址
- getaddress(){
- let data ={
- operationId:''
- }
- api.request(`/sysaddress/selectaddress`, 'post',data,{ isPublic: false })
- .then((data) => {
- console.log(data.data);
- for (let index = 0; index < data.data.length; index++) {
- if (data.data[index].isDefault) {
- this.setData({
- addressindex:index
- })
- }
- }
- this.setData({
- address:data.data
- })
- })
- .catch((err) => {
- console.error('请求失败:', err);
- });
- },
- oncar(e){
- console.log(e.currentTarget.dataset.index);
- this.setData({
- cartype:e.currentTarget.dataset.index
- })
- },
- bindDateChange(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- date: e.detail.value
- })
- },
- // 时间选择变化
- bindTimeChange(e) {
- this.setData({ time: e.detail.value });
- },
- // 需求电量
- bindKeyInput (e) {
- this.setData({
- workorderElectricity: e.detail.value
- })
- },
- bindintentionInput (e) {
- this.setData({
- workorderpower: e.detail.value
- })
- },
- details(){
-
- if (this.data.createtype) {
- return
- }
- this.setData({
- createtype:true
- })
- if (this.data.workorderElectricity==''||this.data.date==''||this.data.time==''||this.data.workorderpower=='') {
- wx.showToast({
- title: '请填写完整消息',
- icon: 'none'
- });
- return
- }
- let data ={
- addressId:this.data.address[this.data.addressindex].addressId,
- workorderElectricity:this.data.workorderElectricity,
- greenelectricity:this.data.greenelectricity,
- workorderStarttime:this.data.date+' '+this.data.time,
- workorderpower:this.data.workorderpower
- }
- api.request(`/sysworkorder/addworkorder`, 'post',data,{ isPublic: false })
- .then((data) => {
- console.log(data);
-
- wx.switchTab({
- url: '/pages/tool/index',
- })
- this.setData({
- createtype:false
- })
- })
- .catch((err) => {
- this.setData({
- createtype:false
- })
- console.error('请求失败:', err);
- });
-
- },
- // 编辑
- editdetails(){
- if (this.data.workorderElectricity==''||this.data.date==''||this.data.time==''||this.data.workorderpower=='') {
- wx.showToast({
- title: '请填写完整消息',
- icon: 'none'
- });
- return
- }
- let data ={
- workorderId:this.data.orderid,
- addressId:this.data.address[this.data.addressindex].addressId,
- workorderElectricity:this.data.workorderElectricity,
- greenelectricity:this.data.greenelectricity,
- workorderStarttime:this.data.date+' '+this.data.time,
- workorderpower:this.data.workorderpower
- }
- api.request(`/sysworkorder/updateworkorder`, 'post',data,{ isPublic: false })
- .then((data) => {
- console.log(data);
- wx.switchTab({
- url: '/pages/tool/index',
- })
-
- })
- .catch((err) => {
-
- console.error('请求失败:', err);
- });
-
- },
- // 司机
- bindectArrayChange(e){
- console.log(e.detail.value);
- this.setData({
- index:e.detail.value
- })
- },
- // 车型
- binddriverChange(e){
- console.log(e.detail.value);
- this.setData({
- driverindex:e.detail.value
- })
- },
- // 用户
- binduserChange(e){
- console.log(e);
- this.setData({
- userindex:e.detail.value
- })
- },
- // 地址
- bindPickerChange(e){
- console.log(e);
- this.setData({
- addressindex:e.detail.value
- })
- },
- radioChange(e) {
- console.log('radio发生change事件,携带value值为:', e.detail.value)
-
- // const items = this.data.items
- // for (let i = 0, len = items.length; i < len; ++i) {
- // items[i].checked = items[i].value === e.detail.value
- // }
-
- this.setData({
- greenelectricity:e.detail.value
- })
- console.log(this.data.greenelectricity);
- },
- toconfigure(){
- wx.navigateTo({
- url: '/package-order/pages/address/index',
- });
- },
- /**
- * 添加新的时间段行
- */
- addRow(e) {
- if (e.currentTarget.dataset.name == 'put') {
- // 新增行的默认值(时间为空,引导用户选择)
- const newRow = {
- type: '放电',
- power: '',
- startTime: '',
- endTime: ''
- };
-
- const newList = [...this.data.putDischargeList, newRow];
- this.setData({
- putDischargeList: newList
- });
- }else{
- // 新增行的默认值(时间为空,引导用户选择)
- const newRow = {
- type: '充电',
- power: '',
- startTime: '',
- endTime: ''
- };
-
- const newList = [...this.data.chargeDischargeList, newRow];
- this.setData({
- chargeDischargeList: newList
- });
- }
-
- },
-
- /**
- * 删除指定行
- */
- deleteRow(e) {
- if (e.currentTarget.dataset.name= 'put') {
- const index = e.currentTarget.dataset.index;
- const list = [...this.data.putDischargeList];
-
- if (list.length <= 1) {
- wx.showToast({
- title: '至少保留一条记录',
- icon: 'none'
- });
- return;
- }
-
- list.splice(index, 1);
- this.setData({
- putDischargeList: list
- });
- }else{
- const index = e.currentTarget.dataset.index;
- const list = [...this.data.chargeDischargeList];
-
- if (list.length <= 1) {
- wx.showToast({
- title: '至少保留一条记录',
- icon: 'none'
- });
- return;
- }
-
- list.splice(index, 1);
- this.setData({
- chargeDischargeList: list
- });
- }
-
- },
-
- /**
- * 修改充放电类型
- */
- changeType(e) {
- const index = e.currentTarget.dataset.index;
- const typeIndex = e.detail.value;
- const type = typeIndex === '0' ? '充电' : '放电';
-
- const list = [...this.data.putDischargeList];
- list[index].type = type;
-
- this.setData({
- putDischargeList: list
- });
- },
-
- /**
- * 更新电量
- */
- updatePower(e) {
- if (e.currentTarget.dataset.name=='put') {
- console.log(e);
- const index = e.currentTarget.dataset.index;
- const value = e.detail.value;
-
- const list = [...this.data.putDischargeList];
- list[index].power = value;
-
- this.setData({
- putDischargeList: list
- });
- }else{
- const index = e.currentTarget.dataset.index;
- const value = e.detail.value;
-
- const list = [...this.data.chargeDischargeList];
- list[index].power = value;
-
- this.setData({
- chargeDischargeList: list
- });
- }
-
- },
-
- /**
- * 更新开始时间(选择器版)
- */
- updateStartTime(e) {
- console.log(e);
- if (e.currentTarget.dataset.name=='put') {
- const index = e.currentTarget.dataset.index;
- const value = e.detail.value; // 格式为 HH:MM
-
- const list = [...this.data.putDischargeList];
- list[index].startTime = value;
-
- this.setData({
- putDischargeList: list
- });
- }else{
- const index = e.currentTarget.dataset.index;
- const value = e.detail.value; // 格式为 HH:MM
-
- const list = [...this.data.chargeDischargeList];
- list[index].startTime = value;
-
- this.setData({
- chargeDischargeList: list
- });
- }
-
- },
-
- /**
- * 更新结束时间(选择器版)
- */
- updateEndTime(e) {
- if (e.currentTarget.dataset.name=='put') {
- const index = e.currentTarget.dataset.index;
- const value = e.detail.value; // 格式为 HH:MM
-
- const list = [...this.data.putDischargeList];
- // 简单校验:结束时间不能早于开始时间
- if (list[index].startTime && value) {
- const start = new Date(`2000-01-01 ${list[index].startTime}`);
- const end = new Date(`2000-01-01 ${value}`);
- if (end < start) {
- wx.showToast({
- title: '结束时间不能早于开始时间',
- icon: 'none'
- });
- return;
- }
- }
-
- list[index].endTime = value;
- this.setData({
- putDischargeList: list
- });
- }else{
- const index = e.currentTarget.dataset.index;
- const value = e.detail.value; // 格式为 HH:MM
-
- const list = [...this.data.chargeDischargeList];
- // 简单校验:结束时间不能早于开始时间
- if (list[index].startTime && value) {
- const start = new Date(`2000-01-01 ${list[index].startTime}`);
- const end = new Date(`2000-01-01 ${value}`);
- if (end < start) {
- wx.showToast({
- title: '结束时间不能早于开始时间',
- icon: 'none'
- });
- return;
- }
- }
-
- list[index].endTime = value;
- this.setData({
- chargeDischargeList: list
- });
- }
-
- },
-
- /**
- * 获取所有充放电数据(提交时调用)
- */
- getAllData() {
- const data = this.data.putDischargeList;
- // 数据验证
- for (let i = 0; i < data.length; i++) {
- const item = data[i];
- if (!item.power) {
- wx.showToast({
- title: `第${i+1}行电量不能为空`,
- icon: 'none'
- });
- return null;
- }
- if (!item.startTime) {
- wx.showToast({
- title: `第${i+1}行请选择开始时间`,
- icon: 'none'
- });
- return null;
- }
- if (!item.endTime) {
- wx.showToast({
- title: `第${i+1}行请选择结束时间`,
- icon: 'none'
- });
- return null;
- }
- }
- return data;
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.getaddress()
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
- //
|