reportDetail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. var app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. defaultSize: 'mini',
  8. src: null,
  9. photos: [],
  10. inputValue: '',
  11. orgId: null,
  12. orgName: null,
  13. // value: "", // 文本的内容
  14. placeholder: "",
  15. maxlength: -1, // 最大输入长度,设置为 -1 的时候不限制最大长度
  16. focus: true,
  17. id: '',
  18. url:'',
  19. showPopup:false,
  20. modalHidden:true
  21. },
  22. onLoad: function (options) {
  23. const id = options.id;
  24. // var img = "/images/add.png";
  25. // var tmpphoto = this.data.photos;
  26. // var tp = {};
  27. // tp['path'] = img;
  28. // tp['type'] = 0;
  29. //tp['fileName'] = '';
  30. //tmpphoto.push(tp);
  31. //console.debug("fffffffffffffffffff");
  32. this.setData({
  33. // photos: tmpphoto,
  34. // orgId: options.orgId,
  35. // orgName: options.orgName
  36. id: id
  37. });
  38. this.detailInfo(id);
  39. },
  40. buttonTap: function() {
  41. this.setData({
  42. modalHidden: false
  43. })
  44. },
  45. /**
  46. * 点击取消
  47. */
  48. modalCandel: function() {
  49. // do something
  50. this.setData({
  51. modalHidden: true
  52. })
  53. },
  54. /**
  55. * 点击确认
  56. */
  57. modalConfirm: function() {
  58. // do something
  59. this.setData({
  60. modalHidden: true
  61. })
  62. }
  63. ,
  64. detailInfo: function (id) {
  65. var that = this;
  66. var url = app.globalData.cloudBase + "/Wx/Work/Report/" + id;
  67. wx.request({
  68. url: url,
  69. method: 'GET',
  70. header: {
  71. "Content-Type": "json"
  72. },
  73. // data: {
  74. // openid: openid
  75. // }
  76. // ,
  77. success: function (res) {
  78. console.debug(res.data);
  79. if (res.data.code === "0") {
  80. var photos = res.data.data.photos;
  81. var tmpphoto = that.data.photos;
  82. if (null != photos) {
  83. for (var i = 0; i < photos.length; i++) {
  84. var p = photos[i]
  85. var tp = {};
  86. tp['path'] = app.globalData.cloudBase + "/ts/source/img/" + p.photo;
  87. tp['type'] = 1;
  88. tp['fileName'] = p.photo;
  89. tmpphoto.unshift(tp);
  90. }
  91. }
  92. that.setData({
  93. inputValue: res.data.data.info,
  94. photos: tmpphoto
  95. });
  96. }
  97. },
  98. fail: function (error) {
  99. console.log(error)
  100. }
  101. })
  102. },
  103. imageViewEvent:function(e){
  104. var photo = e.currentTarget.dataset.photo;
  105. var image_path =app.globalData.cloudBase + "/ts/source/img/" +photo;
  106. this.setData({
  107. url: image_path,
  108. modalHidden: false
  109. });
  110. },
  111. takePhoto: function (event) {
  112. console.debug("takePhoto");
  113. var that = this;
  114. wx.showActionSheet({
  115. itemList: ['拍摄', '相册'],
  116. success: function (res) {
  117. if (!res.cancel) {
  118. console.log(res.tapIndex);
  119. if (res.tapIndex == 0) {
  120. wx.chooseImage({
  121. count: 1, // 默认9
  122. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  123. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  124. success: function (res) {
  125. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  126. var tempFilePaths = res.tempFilePaths
  127. console.debug(tempFilePaths);
  128. wx.uploadFile({
  129. url: app.globalData.cloudBase + "/Wx/Upload/Image", //仅为示例,非真实的接口地址
  130. filePath: tempFilePaths[0],
  131. name: 'image',
  132. success: function (res) {
  133. var data = res.data;
  134. var jsonStr = data.replace(" ", "");
  135. var json;
  136. if (typeof jsonStr != 'object') {
  137. jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
  138. json = JSON.parse(jsonStr);
  139. }
  140. if (json.code == "0") {
  141. var tmpphoto = that.data.photos;
  142. var img = tempFilePaths[0];
  143. console.log("path " + img);
  144. var tp = {};
  145. tp['path'] = img;
  146. tp['type'] = 1;
  147. tp['fileName'] = json.filename;
  148. tmpphoto.unshift(tp);
  149. that.setData({
  150. photos: tmpphoto
  151. })
  152. }
  153. //console.log("upload back " + res.data);
  154. // var jsonStr = data.replace(" ", "");
  155. // var json;
  156. // if (typeof jsonStr != 'object') {
  157. // jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
  158. // json = JSON.parse(jsonStr);
  159. // }
  160. // if (json.status === 'ok') {
  161. // var tmpphoto = that.data.photos;
  162. // var img = tempFilePaths[0];
  163. // console.log("path " + img);
  164. // var tp = {};
  165. // tp['path'] = img;
  166. // tp['type'] = 1;
  167. // tp['fileName'] = json.filename;
  168. // tmpphoto.unshift(tp);
  169. // that.setData({
  170. // photos: tmpphoto
  171. // })
  172. // }
  173. }
  174. })
  175. }
  176. })
  177. } else if (res.tapIndex == 1) {
  178. wx.chooseImage({
  179. count: 1, // 默认9
  180. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  181. sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
  182. success: function (res) {
  183. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  184. var tempFilePaths = res.tempFilePaths
  185. console.debug(tempFilePaths);
  186. // var tmpphoto = that.data.photos;
  187. // var img = tempFilePaths[0];
  188. // var tp = {};
  189. // tp['path'] = img;
  190. // tp['type'] = 1;
  191. // tp['fileName'] = '';
  192. // tmpphoto.unshift(tp);
  193. // that.setData({
  194. // photos: tmpphoto
  195. // })
  196. wx.uploadFile({
  197. url: app.globalData.cloudBase + "/Wx/Upload/Image", //仅为示例,非真实的接口地址
  198. filePath: tempFilePaths[0],
  199. name: 'image',
  200. success: function (res) {
  201. var data = res.data;
  202. var jsonStr = data.replace(" ", "");
  203. var json;
  204. if (typeof jsonStr != 'object') {
  205. jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
  206. json = JSON.parse(jsonStr);
  207. }
  208. if (json.code == "0") {
  209. var tmpphoto = that.data.photos;
  210. var img = tempFilePaths[0];
  211. console.log("path " + img);
  212. var tp = {};
  213. tp['path'] = img;
  214. tp['type'] = 1;
  215. tp['fileName'] = json.filename;
  216. tmpphoto.unshift(tp);
  217. that.setData({
  218. photos: tmpphoto
  219. })
  220. }
  221. // console.log("upload back " + res.data);
  222. // var jsonStr = data.replace(" ", "");
  223. // var json;
  224. // if (typeof jsonStr != 'object') {
  225. // jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
  226. // json = JSON.parse(jsonStr);
  227. // }
  228. // if (json.status === 'ok') {
  229. // var tmpphoto = that.data.photos;
  230. // var img = tempFilePaths[0];
  231. // console.log("path " + img);
  232. // var tp = {};
  233. // tp['path'] = img;
  234. // tp['type'] = 1;
  235. // tp['fileName'] = json.filename;
  236. // tmpphoto.unshift(tp);
  237. // that.setData({
  238. // photos: tmpphoto
  239. // })
  240. // }
  241. }
  242. })
  243. }
  244. })
  245. }
  246. }
  247. }
  248. })
  249. },
  250. editPhoto: function (event) {
  251. console.debug("editPhoto");
  252. wx.navigateBack({
  253. delta: 1
  254. })
  255. },
  256. sendPhoto: function (event) {
  257. if (this.data.inputValue.length > 0 || (this.data.photos.length - 1) > 0) {
  258. var that = this;
  259. try {
  260. wx.showModal({
  261. title: '提示',
  262. content: '确定上报项目情况?',
  263. success: function (res) {
  264. if (res.confirm) {
  265. wx.showNavigationBarLoading()
  266. var data = {};
  267. data['orgId'] = that.data.orgId;
  268. var openid = wx.getStorageSync('openid')
  269. if (openid) {
  270. data['openid'] = openid;
  271. }
  272. if (that.data.inputValue.length > 0) {
  273. data['desc'] = that.data.inputValue;
  274. } else {
  275. data['desc'] = '';
  276. }
  277. var photos = that.data.photos;
  278. var tmpphotos = [];
  279. for (var i = 0; i < photos.length; i++) {
  280. var photo = photos[i];
  281. if (photo.type !== 0) {
  282. var photoobj = {
  283. id: i,
  284. showBoxId: 0,
  285. photo: photo.fileName
  286. }
  287. tmpphotos.push(photoobj);
  288. }
  289. }
  290. data['photos'] = tmpphotos;
  291. console.log(data);
  292. wx.request({
  293. url: app.globalData.cloudBase + "/Wx/Porject/Report/" + openid,
  294. data: data,
  295. method: "POST",
  296. header: {
  297. 'content-type': 'application/json' // 默认值
  298. },
  299. success: function (res) {
  300. console.log(res.data)
  301. if (res.data.code === '0') {
  302. wx.showModal({
  303. title: '提示',
  304. content: '上报成功!',
  305. showCancel: false,
  306. success: function (res) {
  307. if (res.confirm) {
  308. wx.navigateBack({
  309. delta: 1
  310. })
  311. }
  312. }
  313. })
  314. } else {
  315. wx.showModal({
  316. title: '提示',
  317. content: '上报失败!',
  318. showCancel: false,
  319. success: function (res) {}
  320. })
  321. }
  322. },
  323. fail: function (res) {
  324. console.log(res.errMsg)
  325. }
  326. })
  327. } else {
  328. console.log('用户点击取消')
  329. }
  330. }
  331. });
  332. } catch (e) {
  333. console.log(e);
  334. }
  335. } else {
  336. console.debug("sendPhoto fail");
  337. wx.showToast({
  338. title: '请检查是否正确录入项目情况!',
  339. icon: 'none',
  340. duration: 3000
  341. })
  342. }
  343. },
  344. bindKeyInput: function (e) {
  345. this.setData({
  346. inputValue: e.detail.value
  347. })
  348. },
  349. error(e) {
  350. console.log(e.detail)
  351. }
  352. })