baoxiu.js 8.3 KB

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