| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- // pages/workorder/index.js
- const api = require('../../api/index.js');
-
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- array:['日常','故障','其他'],
- namelist:[],
- typelist:['日常','故障','其他'],
- devicedata:[],
- index:1,
- nameindex:'',
- typeindex:0,
- deviceindex:'',
- date:'',
- partnerAvite:[],
- priority:'1',
- workorderContent:'',
- switchtype:true,
- datestart:'',
- dateend:''
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- console.log(options.name);
- this.setData({
- index:options.name
- })
- this.getselectinformationall()
- this.getselectdevicelist()
- },
- onworkorder(){
-
- if (this.data.workorderName==''||this.data.workorderAddress==''||this.data.dateend==''||this.data.datestart==''||this.data.nameindex==''||this.data.deviceindex=='') {
- wx.showToast({
- title: '请填写完整工单',
- icon: 'none'
- });
- return
- }
-
- if (!this.data.switchtype) {
- return
- }
- this.setData({
- switchtype:false
- })
- let data = {
- workorderName:this.data.workorderName,
- workorderAddress:this.data.workorderAddress,
- workorderImg:this.data.partnerAvite.length>0?this.data.partnerAvite.toString():'',
- workorderContent:this.data.workorderContent,
- workoderPartner:this.data.namelist[this.data.nameindex].partnerId,
- workorderEndtime:this.data.dateend, // 开始时间
- workorderStarttime:this.data.datestart, // 结束时间
- workorderGrade:this.data.priority,
- type:(this.data.index*1)+1,
- deviceId:this.data.devicedata[this.data.deviceindex].deviceId
- }
- api.request(`/workoder/createworkorder`, 'POST',data)
- .then((res) => {
- console.log(res);
- if (res.code==200) {
- // this.requestSubscribeMessage();
- // this.loadMessages();
- this.setData({
- switchtype:true
- })
- wx.switchTab({
- url: '/pages/index/index',
- })
- }
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- this.setData({
- switchtype:true
- })
- });
- },
-
- // 用户信息
- getselectinformationall(){
- let data = {
-
- }
- api.request(`/partner/selectinformationall`, 'POST',data)
- .then((res) => {
- console.log(res);
- this.setData({
- namelist:res.data
- })
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- // 设备列表
- getselectdevicelist(){
- let data = {
- }
- api.request(`/device/selectdevicelist`, 'POST',data)
- .then((res) => {
- console.log(res);
- this.setData({
- devicedata:res.data
- })
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- onPeakprice(e){
- console.log(e.detail.value);
- this.setData({
- workorderName:e.detail.value
- })
- },
- onaddress(e){
- console.log(e.detail.value);
- this.setData({
- workorderAddress:e.detail.value
- })
- },
- ontextarea(e){
- console.log(e);
- this.setData({
- workorderContent:e.detail.value
- })
- },
- bindPickerChange(e){
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- nameindex: e.detail.value
- })
- },
- binddeviceChange(e){
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- deviceindex: e.detail.value,
- workorderAddress:this.data.devicedata[e.detail.value].devicesName
- })
- },
- bindeventChange(e){
- this.setData({
- index: e.detail.value
- })
- },
- // 开始时间
- bindstartChange: function(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- datestart: e.detail.value
- })
- },
- // 结束时间
- bindendChange: function(e) {
- const selectedEnd = e.detail.value;
- console.log('picker发送选择改变,携带值为', e.detail.value)
- const { datestart } = this.data;
-
- // 检查结束时间是否早于开始时间
- if (datestart && selectedEnd < datestart) {
- wx.showToast({
- title: '结束时间不能早于开始时间',
- icon: 'none',
- duration: 2000
- });
- return; // 不更新结束时间
- }
-
- // 验证通过,更新结束时间
- this.setData({
- dateend: selectedEnd
- });
-
- },
- // 工单优先级
- onradio(e){
- console.log(e.detail.value);
- this.setData({
- priority:e.detail.value
- })
- },
- // 预览图片
- previewImage(e) {
- const src = e.currentTarget.dataset.src;
- wx.previewImage({
- current: src, // 当前显示图片的http链接
- urls: [src] // 需要预览的图片http链接列表
- });
- },
- bindCancel(e){
- console.log(e.currentTarget.dataset.index);
- let index = e.currentTarget.dataset.index
- // 使用 filter 方法创建新数组(推荐)
- const newPartnerAvite = this.data.partnerAvite.filter((item, i) => i !== index);
-
- this.setData({
- partnerAvite: newPartnerAvite
- });
- },
- // 上传头像--项目--文件1
- bindtoImage(){
- let _this = this
- // 先检查隐私授权状态
- wx.getPrivacySetting({
- success: (res) => {
- if (res.needAuthorization) {
- // 弹出隐私协议弹窗
- wx.requirePrivacyAuthorize({
- success: () => {
- console.log('用户已同意隐私协议');
- _this.choosetoImage(); // 继续执行上传
- },
- fail: () => {
- console.log('用户拒绝了隐私协议');
- wx.showToast({
- title: '需同意隐私协议才能使用',
- icon: 'none'
- });
- }
- });
- } else {
- _this.choosetoImage(); // 已授权,直接上传
- }
- }
- });
- },
- // 上传头像图片
- choosetoImage() {
- let _this = this
- wx.chooseMedia({
- count: 1,
- mediaType: ['image','video'],
- sourceType: ['album', 'camera'],
- success(res) {
- console.log(res);
- const tempFiles = res.tempFiles;
- _this.setData({
- imageList: tempFiles.map(file => file.tempFilePath),
- });
- _this.uploadtoImages(tempFiles);
- },
- fail(err) {
- console.error("选择失败:", err);
- }
- })
- },
- // 上传到服务器
- uploadtoImages(files) {
- let _this =this
- const token = wx.getStorageSync('token');
- files.forEach((file) => {
- wx.uploadFile({
- url: 'https://esos-iot.bjdexn.cn:8443/config/upload/webPost',
- filePath: file.tempFilePath,
- name: 'file',
- formData: {
- file:file.tempFilePath
- },
- header: {
- 'Authorization': 'Bearer ' + token // Also add to header if needed
- },
- success: (res) => {
- console.log(res);
- const obj = JSON.parse(res.data);
- this.data.partnerAvite.push(obj.data.partnerAvite)
- this.setData({
- partnerAvite:this.data.partnerAvite
- })
- },
- fail: (err) => {
- console.error('上传失败', err);
- },
- });
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|