tanghaolin
2024-07-04 cc461d250428674b40f5916412ffa514be421c38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// repair/addTask/index.js
var Constant = require('../../utils/constant.js');
var app = getApp();
import Request from "../../utils/api"
Page({
  data: {
    taskformid: 0,
    StatueType: '',
    currentCorpID: 1,
    currentEmployeeID: 0,
    contentTitle: "",
    imageList: [], //图片
    formType:null,
    logicID:0
  },
 
  onLoad: function (options) {
     console.log(options,17)
    var that = this;
 
    var userInfo = app.globalData.userInfo;
    if (userInfo) {
      this.setData({
        taskformid: options.taskformid,
        currentCorpID: userInfo.CorpID,
        currentEmployeeID: userInfo.EmployeeID,
        StatueType: options.StatueType,
        formType:options.formType?options.formType:null,
        logicID:options.logicID
      });
    }
  },
 
  //
  inputContentTitle: function (e) {
    this.setData({
      contentTitle: e.detail.value
    })
  },
 
  //提交
  formSubmit: function () {
    var that = this;
 
    var imageList = that.data.imageList;
    console.log(imageList,44)
    if (imageList.length == 0 || that.data.taskformid == 0) {
      wx.showToast({
        title: '请选择图片',
        icon: 'none',
        duration: 2000
      });
      return
    }
 
    wx.showLoading({
      title: '上传中...',
      mask: true
    });
 
    //var sysInfo = app.globalData.sysInfo;
    //var userInfo = app.globalData.userInfo;
        //上传图片     
        that.uploadNextImageFile(that.data.taskformid, 0);
  },
 
  //迭代上传
  uploadNextImageFile: function (taskFileId, index_image) {
    console.log("taskFileId:"+taskFileId)
    var that = this;
    var image_count = this.data.imageList.length;
    var logicID=this.data.logicID
    let tokenInfo = wx.getStorageSync('AccessToken')
    if (index_image >= image_count)
      return;
    var url_image = this.data.imageList[index_image];
    let requestUrl = ""
    let params={}
    if(that.data.formType&& that.data.formType == "requestForm"){
      requestUrl = "Repair/Request/Form/UploadFile@V1.0"  //报修单图片上传
      params={
        'FormID' :taskFileId
      }
    }
    if(that.data.formType&& that.data.formType == "taskForm"){
      
      requestUrl = "Repair/Task/Form/UploadFile@V1.0"  //维修单图片上传
      params={
        'FormID' :taskFileId,
        'LogID':logicID
      }
    }
    wx.uploadFile({
      url: Constant.BASE_SERVER_URL + requestUrl,
      filePath: url_image,
      header:{
        "Authorization":'Bearer ' + tokenInfo.Token
      },
      formData: params,
      name: 'file',
      success: function (res) { //上传完成
        //  console.log(JSON.parse(res.data))
        if (index_image < image_count - 1) {
          index_image++;
          that.uploadNextImageFile(taskFileId, index_image); //迭代下一张
          return;
        }
 
        wx.hideLoading();
        var pages = getCurrentPages();
        var currPage = pages[pages.length - 1]; //当前页面
        var prevPage = pages[pages.length - 2]; //上一个页面
 
        //直接调用上一个页面对象的告诉它要刷新页面
        prevPage.refreshTaskFileList();
 
        that.setData({
          imageList: [],
          contentTitle: ""
        });
        wx.showToast({
          title: "上传成功,还可以继续上传",
          icon: 'none'
        });
 
        wx.navigateBack({
          delta: 1
        });
      }
    });
 
  },
 
  //图片上传
  chooseImage: function () {
    var that = this;
    var imageList = this.data.imageList;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      count: 9, //最多
      success: function (res) {
        var imgPaths = res.tempFilePaths;
        for (var i = 0; i < imgPaths.length; i++) {
          var imgPath = res.tempFilePaths[i];
          imageList.push(imgPath)
        };
        that.setData({
          imageList: imageList
        })
      }
    })
  },
  //查看图片
  previewImage: function (e) {
    var currentSrc = e.target.dataset.src
    wx.previewImage({
      current: currentSrc,
      urls: this.data.imageList
    })
  },
  //删除图片
  deleteImage: function (e) {
    var that = this;
    var imageList = that.data.imageList;
    var index = e.currentTarget.dataset.index; //获取当前长按图片下标
    wx.showModal({
      title: '系统提醒',
      content: '确定要删除此图片吗?',
      success: function (res) {
        if (res.confirm) {
          imageList.splice(index, 1);
        } else if (res.cancel) {
          return false;
        }
        that.setData({
          imageList: imageList
        });
      }
    })
  },
  //一键清空
  onImageDel() {
    var that = this;
    wx.showModal({
      title: '系统提醒',
      content: '确定要删除全部图片吗?',
      success: function (res) {
        if (res.confirm) {
          that.setData({
            imageList: []
          });
        } else if (res.cancel) {
          return false;
        }
 
      }
    });
  },
 
 
  onShow: function (e) {},
  onShareAppMessage: function () {
    return Constant.Share;
  },
})