const Parser = require('../xml/xmldom/dom-parser')
var app = getApp();

Page({
  data: {
    btn:'未选中',
    hname:'',//房产名称
    wyjfid:0,//费用id
    ownername:'',//客户名称
    money:0,//消费金额
    table:[]//接口返回数据对象
  },
  selectmoney:function(e){
    //选择房产进行缴费
    this.setData({
      btn:'立即缴费',
      wyjfid:e.target.dataset.farerowid,
      money:e.target.dataset.nneedpaymny,
      hname:e.target.dataset.hname,
      ownername:e.target.dataset.ownername
    })
  },
  btnJiaoFei:function(){
    //缴费事件
//     var method='Insertfdc_pm_owner';
//     var wsdlurl= app.webUrl;
//     var targetNamespace='http://tempuri.org/';
//     var datacopy= '<?xml version="1.0" encoding="utf-8"?>';
//     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/">';
//     // datacopy += '<soap:Header/>';
//     datacopy += '<soap:Header><MySoapHeader xmlns="http://tempuri.org/">';
//     datacopy += '<UserName>admin</UserName>';
//     datacopy += '<PassWord>admin123</PassWord>';
//     datacopy += '</MySoapHeader></soap:Header>';
//     datacopy += '<soap:Body>';
//     datacopy += '<Insertfdc_pm_owner xmlns="http://tempuri.org/">';
//     datacopy += `<farwarid>${this.data.wyjfid}</farwarid>`;
//     datacopy += `<money>${this.data.money}</money>`;
//     datacopy += `<ownername>${this.data.ownername}</ownername>`;
//     datacopy += `<hname>${this.data.hname}</hname>`;
//     datacopy += '</Insertfdc_pm_owner>';
//     datacopy += '</soap:Body>';
//     datacopy += '</soap:Envelope>';
//     wx.request({
//       url: wsdlurl,
//       data: datacopy, 
//       method: 'POST', 
//       header: { 
//         'Content-Type':'text/xml; charset=utf-8',
//         'SOAPAction':targetNamespace+method,
//       }, 
//       success:function(res){
//         var XMLParser = new Parser.DOMParser();
//         var doc = XMLParser.parseFromString(res.data);
//         var Insertfdc_pm_ownerResult =doc.getElementsByTagName("Insertfdc_pm_ownerResult")[0].firstChild.nodeValue;
//         console.log(Insertfdc_pm_ownerResult);
//       }
//     })
  },
  onShow:function(options){
    
  },
  onLoad:function(optitons){
    var sum = optitons.sessionPhone.split(',');
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 1000
    })
    var that = this;
    //页面初始化 optitons为页面跳转所带来的多参数
    for (let index = 0; index < sum.length-1; index++) {
      var method='Getfdc_pm_unfare';
      var wsdlurl= app.webUrl;
      var targetNamespace='http://tempuri.org/';
      var datacopy= '<?xml version="1.0" encoding="utf-8"?>';
      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/">';
      datacopy += '<soap:Header><MySoapHeader xmlns="http://tempuri.org/">';
      datacopy += '<UserName>admin</UserName>';
      datacopy += '<PassWord>admin123</PassWord>';
      datacopy += '</MySoapHeader></soap:Header>';
      datacopy += '<soap:Body>';
      datacopy += '<Getfdc_pm_unfare xmlns="http://tempuri.org/">';
      datacopy += `<weixinid>${optitons.openid}</weixinid>`;
      datacopy += `<ownerid>${sum[index]}</ownerid>`;
      datacopy += '</Getfdc_pm_unfare >';
      datacopy += '</soap:Body>';
      datacopy += '</soap:Envelope>';
      wx.request({
        url: wsdlurl,
        data: datacopy, 
        method: 'POST', 
        header: { 
          'Content-Type':'text/xml; charset=utf-8',
          'SOAPAction':targetNamespace+method,
        }, 
        success:function(res){
          var XMLParser = new Parser.DOMParser();
          var doc = XMLParser.parseFromString(res.data);
          var Getfdc_pm_unfareResult = JSON.parse(doc.getElementsByTagName("Getfdc_pm_unfareResult")[0].firstChild.nodeValue)
          if(Getfdc_pm_unfareResult.ok!=false){
            that.setData({
              table:Getfdc_pm_unfareResult.Table
            })
          }
        }
      })
    }
  },
  onReady:function(options){
    //页面渲染完成
  },

  onHide:function(options){
    //页面隐藏
  },
  onUnload:function(options){
    //页面关闭
  },
})

