| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- var app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- defaultSize: 'mini',
- src: null,
- photos: [],
- inputValue: '',
- orgId: '',
- orgName: '',
- // value: "", // 文本的内容
- placeholder: "请输入项目施工说明",
- maxlength: -1, // 最大输入长度,设置为 -1 的时候不限制最大长度
- focus: true,
- weather:'',
- lat:'',
- lng:'',
- address:''
- },
- onLoad: function (options) {
- var img = "/images/add.png";
- var tmpphoto = this.data.photos;
- var tp = {};
- tp['path'] = img;
- tp['type'] = 0;
- tp['fileName'] = '';
- tmpphoto.push(tp);
- this.setData({
- photos: tmpphoto,
- orgId: options.orgId,
- orgName: options.orgName,
- weather: options.weather,
- address: options.address,
- lng: options.lng,
- lat: options.lat
- });
- },
- takePhoto: function (event) {
- console.debug("takePhoto");
- var that = this;
- wx.showActionSheet({
- itemList: ['拍摄', '相册'],
- success: function (res) {
- if (!res.cancel) {
- console.log(res.tapIndex);
- if (res.tapIndex == 0) {
- wx.chooseImage({
- count: 1, // 默认9
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
- success: function (res) {
- // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
- var tempFilePaths = res.tempFilePaths
- console.debug(tempFilePaths);
- wx.uploadFile({
- url: app.globalData.cloudBase + "/Wx/Project/Implementation/Upload/Image/"+that.data.orgId, //仅为示例,非真实的接口地址
- filePath: tempFilePaths[0],
- name: 'image',
- success: function (res) {
- var data = res.data;
- var jsonStr = data.replace(" ", "");
- var json;
- if (typeof jsonStr != 'object') {
- jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
- json = JSON.parse(jsonStr);
- }
- if (json.code == "0") {
- var tmpphoto = that.data.photos;
- var img = tempFilePaths[0];
- console.log("path " + img);
- var tp = {};
- tp['path'] = img;
- tp['type'] = 1;
- tp['fileName'] = json.filename;
- tmpphoto.unshift(tp);
- that.setData({
- photos: tmpphoto
- })
- }
- //console.log("upload back " + res.data);
- // var jsonStr = data.replace(" ", "");
- // var json;
- // if (typeof jsonStr != 'object') {
- // jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
- // json = JSON.parse(jsonStr);
- // }
- // if (json.status === 'ok') {
- // var tmpphoto = that.data.photos;
- // var img = tempFilePaths[0];
- // console.log("path " + img);
- // var tp = {};
- // tp['path'] = img;
- // tp['type'] = 1;
- // tp['fileName'] = json.filename;
- // tmpphoto.unshift(tp);
- // that.setData({
- // photos: tmpphoto
- // })
- // }
- }
- })
- }
- })
- } else if (res.tapIndex == 1) {
- wx.chooseImage({
- count: 1, // 默认9
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
- success: function (res) {
- // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
- var tempFilePaths = res.tempFilePaths
- console.debug(tempFilePaths);
- // var tmpphoto = that.data.photos;
- // var img = tempFilePaths[0];
- // var tp = {};
- // tp['path'] = img;
- // tp['type'] = 1;
- // tp['fileName'] = '';
- // tmpphoto.unshift(tp);
- // that.setData({
- // photos: tmpphoto
- // })
- wx.uploadFile({
- url: app.globalData.cloudBase + "/Wx/Upload/Image", //仅为示例,非真实的接口地址
- filePath: tempFilePaths[0],
- name: 'image',
- success: function (res) {
- var data = res.data;
- var jsonStr = data.replace(" ", "");
- var json;
- if (typeof jsonStr != 'object') {
- jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
- json = JSON.parse(jsonStr);
- }
- if (json.code == "0") {
- var tmpphoto = that.data.photos;
- var img = tempFilePaths[0];
- console.log("path " + img);
- var tp = {};
- tp['path'] = img;
- tp['type'] = 1;
- tp['fileName'] = json.filename;
- tmpphoto.unshift(tp);
- that.setData({
- photos: tmpphoto
- })
- }
- // console.log("upload back " + res.data);
- // var jsonStr = data.replace(" ", "");
- // var json;
- // if (typeof jsonStr != 'object') {
- // jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
- // json = JSON.parse(jsonStr);
- // }
- // if (json.status === 'ok') {
- // var tmpphoto = that.data.photos;
- // var img = tempFilePaths[0];
- // console.log("path " + img);
- // var tp = {};
- // tp['path'] = img;
- // tp['type'] = 1;
- // tp['fileName'] = json.filename;
- // tmpphoto.unshift(tp);
- // that.setData({
- // photos: tmpphoto
- // })
- // }
- }
- })
- }
- })
- }
- }
- }
- })
- },
- editPhoto: function (event) {
- console.debug("editPhoto");
- wx.navigateBack({
- delta: 1
- })
- },
- sendPhoto: function (event) {
- if (this.data.inputValue.length > 0 || (this.data.photos.length - 1) > 0) {
- var that = this;
- try {
- wx.showModal({
- title: '提示',
- content: '确定上报项目情况?',
- success: function (res) {
- if (res.confirm) {
- wx.showNavigationBarLoading()
- var data = {};
- data['orgId'] = that.data.orgId;
- var openid = wx.getStorageSync('openid')
- if (openid) {
- data['openid'] = openid;
- }
- if (that.data.inputValue.length > 0) {
- data['desc'] = that.data.inputValue;
- } else {
- data['desc'] = '';
- }
- if (that.data.address.length > 0) {
- data['address'] = that.data.address;
- } else {
- data['address'] = '';
- }
- data['lat'] = that.data.lat;
- data['lng'] = that.data.lng;
- data['weather'] = that.data.weather;
- var photos = that.data.photos;
- var tmpphotos = [];
- for (var i = 0; i < photos.length; i++) {
- var photo = photos[i];
- if (photo.type !== 0) {
- var photoobj = {
- id: i,
- showBoxId: 0,
- photo: photo.fileName
- }
- tmpphotos.push(photoobj);
- }
- }
- data['photos'] = tmpphotos;
- console.log(data);
- wx.request({
- url: app.globalData.cloudBase + "/Wx/Porject/Report/"+openid,
- data: data,
- method: "POST",
- header: {
- 'content-type': 'application/json' // 默认值
- },
- success: function (res) {
- console.log(res.data)
- if (res.data.code === '0') {
- wx.showModal({
- title: '提示',
- content: '上报成功!',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- wx.navigateBack({
- delta: 1
- })
- }
- }
- })
- } else {
- wx.showModal({
- title: '提示',
- content: '上报失败!',
- showCancel: false,
- success: function (res) {}
- })
- }
- },
- fail: function (res) {
- console.log(res.errMsg)
- }
- })
- } else {
- console.log('用户点击取消')
- }
- }
- });
- } catch (e) {
- console.log(e);
- }
- } else {
- console.debug("sendPhoto fail");
- wx.showToast({
- title: '请检查是否正确录入项目情况!',
- icon: 'none',
- duration: 3000
- })
- }
- },
- bindKeyInput: function (e) {
- this.setData({
- inputValue: e.detail.value
- })
- },
- bindAddressKeyInput: function (e) {
- this.setData({
- address: e.detail.value
- })
- },
- error(e) {
- console.log(e.detail)
- },
-
- })
|