tousu.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. const Parser = require('../xml/xmldom/dom-parser')
  2. var app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl:app.imgUrl,
  9. hname:'',//房产
  10. datatimestart:'',//日期起始
  11. datatimeend:'',//日期结束
  12. dfdapplydate:'',//派单时间
  13. txtdrequiredate:'',//完成时间
  14. txtvcontent:'',// 投诉内容
  15. hddhcode:'',//房产编号
  16. ownerid:'', //房主ID
  17. txtvplace:'',//投诉地址
  18. txtvtel:'', //投诉电话
  19. owername:'', //房主姓名
  20. table:[],//上传图片的对象
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. console.warn('onload',options);
  27. var timestamp = Date.parse(new Date());
  28. var date = new Date(timestamp);
  29. var Y =date.getFullYear();
  30. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
  31. var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); 
  32. var that = this;
  33. that.setData({
  34. datatimestart:Y + '-'  + M+ '-' + D,
  35. dfdapplydate:Y + '-'  + M+ '-' + D,
  36. txtdrequiredate:Y + '-'  + M+ '-' + D,
  37. datatimeend:Y + 2 + '-' + M + '-' + D,
  38. hname:options.hname,
  39. ownerid:options.ownerid,
  40. txtvtel:options.phone,
  41. owername:options.ownername,
  42. hddhcode:options.hcode,
  43. })
  44. },
  45. bindDateChangeb:function(e){
  46. this.setData({
  47. txtdrequiredate: e.detail.value
  48. })
  49. },
  50. // 选择日期
  51. bindDateChange: function(e) {
  52. this.setData({
  53. dfdapplydate: e.detail.value
  54. })
  55. },
  56. // 删除图片
  57. removeImage(e) {
  58. var index = e.target.dataset.index;
  59. var imgs = this.data.table;
  60. imgs.splice(index,1);
  61. this.setData({
  62. table:imgs,
  63. })
  64. },
  65. // 选择图片
  66. chooseImage:function(e){
  67. var that = this;
  68. wx.chooseImage({
  69. count:3,
  70. sizeType:['original','compressed'],
  71. sourceType:['album','camera'],
  72. success(res){
  73. that.setData({
  74. table: res.tempFilePaths
  75. });
  76. }
  77. })
  78. },
  79. ceShibtnJiaoFei:function(e){
  80. },
  81. // 点击提交投诉
  82. btnJiaoFei: function (e) {
  83. var that= this;
  84. if(this.data.txtvtel==''){
  85. wx.showToast({
  86. title: '请填写手机号',
  87. icon: 'none',
  88. duration: 2000
  89. })
  90. return;
  91. }
  92. if(this.data.txtvplace==''){
  93. wx.showToast({
  94. title: '请填写投诉地址',
  95. icon: 'none',
  96. duration: 2000
  97. })
  98. return;
  99. }
  100. let fileurl = "";// 图片名称
  101. if(this.data.table.length>0){
  102. // 拼接多(单)个图片名称
  103. for (let index = 0; index < this.data.table.length; index++) {
  104. if(this.data.table[index].substring(0,11)=='http://tmp/'){
  105. fileurl += this.data.table[index].substring(11)+',';
  106. }
  107. if(this.data.table[index].substring(0,9)=='wxfile://'){
  108. fileurl += this.data.table[index].substring(9)+',';
  109. }
  110. }
  111. }
  112. var method='Insertfdc_pm_repair ';
  113. var wsdlurl= app.webUrl;
  114. var targetNamespace='http://tempuri.org/';
  115. var datacopy= '<?xml version="1.0" encoding="utf-8"?>';
  116. datacopy += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
  117. datacopy += '<soap:Header><MySoapHeader xmlns="http://tempuri.org/">';
  118. datacopy += `<UserName>${app.UserName}</UserName>`;
  119. datacopy += `<PassWord>${app.PassWord}</PassWord>`;
  120. datacopy += '</MySoapHeader></soap:Header>';
  121. datacopy += '<soap:Body>';
  122. datacopy += '<Insertfdc_pm_repair xmlns="http://tempuri.org/">';
  123. datacopy += `<dfdapplydate>${this.data.dfdapplydate}</dfdapplydate>`;
  124. datacopy += `<txtdrequiredate>${this.data.txtdrequiredate}</txtdrequiredate>`;
  125. datacopy += `<hddhcode>${this.data.hddhcode}</hddhcode>`;
  126. datacopy += `<hddownerid>${this.data.ownerid}</hddownerid>`;
  127. datacopy += `<txtvcontent>${this.data.txtvcontent}</txtvcontent>`;
  128. datacopy += `<txtvplace>${this.data.txtvplace}</txtvplace>`;
  129. datacopy += `<txtvtel>${this.data.txtvtel}</txtvtel>`;
  130. datacopy += `<fileurl>${fileurl}</fileurl>`;
  131.     datacopy += '</Insertfdc_pm_repair>';
  132.     datacopy += '</soap:Body>';
  133.     datacopy += '</soap:Envelope>';
  134. wx.request({
  135. url: wsdlurl,
  136. data: datacopy,
  137. method: 'POST',
  138. header: {
  139. 'Content-Type':'text/xml; charset=utf-8',
  140. 'SOAPAction':targetNamespace+method,
  141. },
  142. success:function(res){
  143. console.warn('Insertfdc_pm_repair',res);
  144. var XMLParser = new Parser.DOMParser();
  145. var doc = XMLParser.parseFromString(res.data);
  146. var Insertfdc_pm_repairResult = doc.getElementsByTagName("Insertfdc_pm_repairResult")[0].firstChild.nodeValue;
  147. console.warn('Insertfdc_pm_repairResult',Insertfdc_pm_repairResult);
  148. if(Insertfdc_pm_repairResult=='保存成功!'){
  149. wx.showToast({
  150. title: '提交成功!',
  151. icon: 'success',
  152. duration: 1000
  153. })
  154. // 图片上传
  155. for (let index = 0; index < that.data.table.length; index++) {
  156. wx.uploadFile({
  157. filePath: that.data.table[index],
  158. name: 'name',
  159. url: app.coreUrl+ 'InsertPicture',
  160. header:{
  161. 'content-type':'multipart/form-data'
  162. },
  163. name:'upload',
  164. success:function(res){
  165. console.warn('上传图片',res.data);
  166. if(res.data=='"上传成功"'){
  167. wx.navigateBack({
  168. delta: 2
  169. })
  170. }
  171. else{
  172. wx.showToast({ //上传失败,弹出错误提示
  173. title: res.data,
  174. icon: 'none',
  175. duration: 3000
  176. });
  177. }
  178. },
  179. })
  180. }
  181. } else {
  182. wx.showToast({
  183. title: Insertfdc_pm_repairResult,
  184. icon: 'none',
  185. duration: 2000
  186. })
  187. }
  188. }
  189. })
  190. },
  191. // 修改投诉地址
  192. updateTxtvplace: function (e) {
  193. this.setData({
  194. txtvplace: e.detail.value
  195. })
  196. },
  197. // 编辑投诉人电话
  198. updateTxtvtel: function (e) {
  199. this.setData({
  200. txtvtel: e.detail.value
  201. })
  202. },
  203. // 编辑投诉人电话
  204. updateTxtvcontent: function (e) {
  205. this.setData({
  206. txtvcontent: e.detail.value
  207. })
  208. },
  209. // 预览图片
  210. handleImagePreview: function (e) {
  211. var idx = e.target.dataset.index;
  212. var imag = this.data.table;
  213. wx.previewImage({
  214. current: imag[idx], //当前预览的图片
  215. urls: imag, //所有要预览的图片
  216. })
  217. },
  218. /**
  219. * 生命周期函数--监听页面卸载
  220. */
  221. onUnload: function () {
  222. },
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh: function () {
  227. },
  228. /**
  229. * 页面上拉触底事件的处理函数
  230. */
  231. onReachBottom: function () {
  232. },
  233. /**
  234. * 用户点击右上角分享
  235. */
  236. onShareAppMessage: function () {
  237. }
  238. })