const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
let app = getApp();
const format = require("../utils/util.js");
let config = require("../config/config.js");
let Http = require("../utils/HttpBasics");
let Util = require("../utils/util");
const imgurl = require("../utils/imgurl");
Page({
  data: {
    navigationBarHeight,
    jianUrl: imgurl.jian.url,
    jianBlueUrl: imgurl.jianBlue.url,
    jiaofeiwm: imgurl.jiaofeiwm.url,
    parkUrl: imgurl.park.url,
    guanliHr: imgurl.guanliHr.url,
    qidaiUrl: imgurl.qidai.url,
    addUrl: imgurl.add.url,
    tingcheHr: imgurl.tingcheHr.url,
    cheUrl: imgurl.che.url,
    jiaofei: imgurl.jiaofei.url,
    wentiHr: imgurl.wentiHr.url,
    stopThat: imgurl.stopThat.url,
    park: null,
    carList: [],
    payList: [],
    addCar: null,
    tcq: 2,
    flag: "",
    extraData: {},
    desc: '',
    title: '',
    indicatorDots: true,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    current: 0,
    stopFees: {},
    scroll: true,
    ifHaveCarModular: "",
    canIUse: wx.canIUse("navigator"),
    showTicketModal: false,
    ticketList: [],
    noCoupon: imgurl.noCoupon.url,
    loadingUrl: imgurl.loading.url,
    allow_load: true,
    curPageNum: 1,
    curPageSize: 15,
    curTotalpageNum: 0,
    quantitle: '',
    quanid: '',
    gouHr: imgurl.gouHr.url,
    totalTicketNum: 0,
    remark: '',
    generalPayPath: '',
    generalExtraData: {},
    goHomeUrl: "",
    supportPay: ""
  },
  getMoreList(e) {
    let totalNum = this.data.ticketList.length;
    if (this.data.curPageNum < this.data.curTotalpageNum) {
      this.setData({
        curPageNum: this.data.curPageNum + 1
      })
      this.getTicketList(0, this.data.curPageNum);
    }

  },
  /**
   * 选择使用的优惠券
   */
  choicecoupon: function (e) {
    var that = this;
    wx.showModal({
      title: '确定是否使用停车券',
      content: '使用后无法撤销',
      success(res) {
        if (res.confirm) {
          var quantitle = e.currentTarget.dataset.title;
          var quanid = e.currentTarget.dataset.id;
          that.setData({
            quanid: quanid,
            showTicketModal: false,
          });
          that.bindCoupon(that.data.quanid, quantitle);
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  /* 
   */
  getTicketList(key, pageNum) {
    var that = this;
    if (that.data.allow_load) {
      wx.showLoading({
        title: "加载中"
      });
      Http.get({
        url: config.api.couponOrderCarList,
        data: {
          pageNum: pageNum,
          pageSize: 15,
          couponOrderStatus: key
        }
      }).then(res => {
        that.setData({
          curTotalpageNum: res.data.pages,
          curPageNum: res.data.pageNum,
          totalTicketNum: res.data.total
        })
        res.data.list.map(file => {
          file.expiredTime = format.formatTime(
            file.expiredTime,
            "yyyy-MM-dd hh:mm:ss"
          );
        });
        setTimeout(function () {
          wx.hideLoading();
        }, 1200);
        if (pageNum >= res.data.pages) {
          that.setData({
            allow_load: false
          });
        }
        /**
         * 先赋值后渲染页面
         * concat 不会改变原数组值
         * push   会改变原数组值，但不会一条一条插入，而是整个数组插入
         */
        if (pageNum == 1) {
          that.setData({
            ticketList: res.data.list,
            curPageNum: pageNum
          });
        } else {
          that.setData({
            ticketList: that.data.ticketList.concat(res.data.list)
          });
        }
        // that.data.ticketList = that.data.ticketList.concat(res.data.list);

        wx.hideLoading();
      })
        .catch(err => {
          setTimeout(function () {
            wx.hideLoading();
          }, 1200);
          wx.showToast({
            title: err.errMsg,
            icon: 'none',
            duration: 2000,
            mask: false
          });
        })
    } else { }
  },
  //点击跳转到券详情页面
  gotouse: function (e) {
    wx.navigateTo({
      url: `/pages/passCar/couponDetail/couponDetail?quancode=${e.currentTarget.dataset.quancode
        }`,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    });
  },
  /**
   * 车牌轮播滑动
   */
  onSlideChangeEnd: function (e) {
    var that = this;
    /**
     * 获得当前的车牌号码
     */
    var listCardNum = (that.data.carList)[e.detail.current].carNumber;
    that.setData({
      listCardNum: listCardNum
    });
    /**
     * 获得停车费用
     */
    if (that.data.scroll) {
      that.getStopFee(listCardNum);
    }
  },

  callPay(data) {
    wx.requestPayment({
      timeStamp: data.timeStamp,
      nonceStr: data.nonceStr,
      package: data.package,
      signType: data.signType ? data.signType : "MD5",
      paySign: data.paySign,
      success: res => {
        wx.showLoading({
          title: '订单正在处理中...',
        })
        this.showList()
      },
      fail: res => {
        wx.hideLoading();
        wx.showToast({
          title: '支付失败',
          icon: 'error'
        })
        /**
         * 支付失败，需要更新订单的状态
         */
      },
      complete: res => { }
    });
  },

  //停车费用为0
  paySuccess: function () {
    wx.showModal({
      title: '支付成功',
      content: '请15分钟内离场',
      showCancel: false
    })
  },

  // supportPay等于1时
  goToPay() {
    Http.post({
      url: '/car/createPayOrder',
      data: {
        carNumber: this.data.listCardNum,
        carFee: String(this.data.stopFees.remainingFee * 100)
      }
    }).then(res => {
      console.log(res, 'res');
      const data = res.data.data
      this.callPay(data)
    }).catch(err => {
      console.log(err, 'err');
      wx.showToast({
        title: err.message,
        icon: 'none',
        mask: true
      })
    })
  },

  gotomange: function () {
    Http.get({
      url: config.api.checkPhoneStatus,
      data: {}
    }).then(res => {
      wx.navigateTo({
        url: '/pages/managelicenseplate/managelicenseplate',
      })
    }).catch(err => {
      wx.navigateTo({
        url: `/pages/getphoneInfo/index?mineFlag=passCar`,
      })
    })
  },
  bindfail: function (res) {
    console.log(123)
    console.log(res)
  },
  gotoCarMini: function (e) {
    console.log(478)
    var that = this
    // etcp parkVendor1
    // 泊链停车 parkVendor5
    let data = null
    if (e.target.dataset.flag == 'parkVendor1') {
      data = {
        appId: that.data.etcpAppId,
        extraData: that.data.extraData,
        envVersion: that.data.carMiniVersion,
        path: that.data.payPath
      }
      wx.navigateToMiniProgram(data)
      console.log(data, 'parkVendor1');
    } else if (e.target.dataset.flag == 'parkVendor5') {
      data = {
        appId: that.data.bolinkAppId,
        extraData: that.data.extraData,
        envVersion: that.data.carMiniVersion,
        path: that.data.payPath
      }
      wx.navigateToMiniProgram(data)
      console.log(data, 'parkVendor5');
    }
  },
  showquan: function () {
    Http.get({
      url: config.api.checkPhoneStatus,
      data: {}
    }).then(res => {
      wx.navigateTo({
        url: '/pages/passCar/couponList/couponList',
      })
    }).catch(err => {
      wx.navigateTo({
        url: `/pages/getphoneInfo/index?mineFlag=passCar`,
      })
    })
  },

  showList: function () {
    Http.get({
      url: config.api.checkPhoneStatus,
      data: {}
    }).then(res => {
      wx.navigateTo({
        url: '/pages/passCar/showList/showList',
      })
    }).catch(err => {
      wx.navigateTo({
        url: `/pages/getphoneInfo/index?mineFlag=passCar`,
      })
    })
  },

  gotodetail: function (e) {
    wx.showModal({
      title: '缴费规则',
      content: e.target.dataset.rule,
      showCancel: false,
    })
  },

  onShow: function (options) {
    var that = this;
    Http.get({
      url: config.api.checkPhoneStatus,
      data: {}
    }).then(res => {
      this.setData({
        goHomeUrl: app.globalData.goHomeUrl
      })
      if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 2
        })
      }

      that.setData({
        etcpAppId: extConfig.attr.car.etcp.etcpAppId,
        carMiniVersion: extConfig.attr.car.version,
        etcpCallbackUrl: extConfig.attr.car.etcp.etcpCallbackUrl,
        payPath: extConfig.attr.car.etcp.payPath,
        ifHaveCarModular: extConfig.attr.ifHaveCarModular
      })
      console.log(this.data.ifHaveCarModular, 'ifHaveCarModular');
      if (app.globalData.token) {
        that.getList();
        that.init();
      } else {
        that.init();
      }
      /**
       * 只有用户选择了优惠券
       * 才会进行券和车牌的绑定
       */
      /* if (wx.getStorageSync("chosed") && that.data.quanid) {
        that.getStopFee(that.data.listCardNum);
        that.bindCoupon(that.data.quanid);
        wx.setStorage({
          key: 'chosed',
          data: '',
        })
      }; */
      if (app.globalData.token) {
        // that.initUsrCarList();
        that.initUsrCarList("flags");
        that.setData({
          current: 0
        })
      }

      if (that.data.addCar) {
        // 绑车牌
        if (app.globalData.carLogin) {
          that.bindCar(that.data.addCar);
        } else {
          that.bindCar(that.data.addCar);
        }
        that.setData({
          addCar: null
        });
      }

      this.getTicketList(0, 1);
    }).catch(err => {
      that.setData({
        etcpAppId: extConfig.attr.car.etcp.etcpAppId,
        carMiniVersion: extConfig.attr.car.version,
        etcpCallbackUrl: extConfig.attr.car.etcp.etcpCallbackUrl,
        payPath: extConfig.attr.car.etcp.payPath,
        ifHaveCarModular: extConfig.attr.ifHaveCarModular
      })
      that.initPark();
      that.getParkStatus();
    })
  },

  cancelMove: function () {
    console.log(111)
    return false;
  },
  onHide: function () {
    this.setData({
      allow_load: true,
      showTicketModal: false,
      curPageNum: 1,
      ticketList: []
    })
  },
  onLoad: function (options) {
    var that = this;

    Http.get({
      url: config.api.checkPhoneStatus,
      data: {}
    }).then(res => {
      /**
      * 获得分享小程序的
      * title 
      * desc
      */
      Http.get({
        url: config.api.getWeapNote,
        data: {
          appId: config.weapp.AppId,
        }
      })
        .then(res => {
          let weapNote = JSON.parse(res.data.weapNote);
          that.setData({
            desc: weapNote.carpage.desc,
            title: weapNote.carpage.title
          })
        })
        .catch(err => {
          console.log(err);
        })
      // 登录
      var scene = decodeURIComponent(options.scene);
      that.setData({
        scene: scene
      });
      if (app.globalData.token) { } else {
        // app.getLocation();
        that.userLogin()
      }
    }).catch(err => {
      return
    })
  },
  /**
   * 用户登录
   */
  userLogin: function () {
    var that = this;
    // 登录
    wx.login({
      success: ({
        code
      }) => {
        wx.getSystemInfo({
          success: function (res) {
            that.setData({
              systemInfo: JSON.stringify(res)
            })
          }
        })
        var usrdata = {
          appId: config.weapp.AppId,
          code: code,
          sceneAddress: app.globalData.sceneAddress,
          scene: that.data.scene,
          systemInfo: that.data.systemInfo
        };
        if (app.globalData.locationInfo) {
          usrdata = {
            appId: config.weapp.AppId,
            code: code,
            sceneAddress: app.globalData.sceneAddress,
            latitude: "" + app.globalData.locationInfo.latitude,
            longitude: "" + app.globalData.locationInfo.longitude,
            scene: that.data.scene,
            systemInfo: that.data.systemInfo
          };
        }
        Http.post({
          url: config.api.login,
          data: usrdata
        })
          .then(res => {
            app.globalData.token = res.data.token;
            Http.setToken(res.data.token);
            that.checkUserCarStatus();
            that.getList();
            that.init();
            that.initUsrCarList();
            return Http.get({
              url: config.api.checkUserStatus,
              data: {}
            });
          })
          .then(res => { })
          .catch(err => {
            if (err.code == 11004) {
              // 用户昵称未授权
              wx.redirectTo({
                url: "/pages/getuserinfo/index"
              });
            } else {
              wx.showModal({
                title: '提示',
                content: err.errMsg,
                showCancel: false
              })
            }
          });
      }
    });
  },
  /**
   * 检查用户是否有车
   */
  checkUserCarStatus: function () {
    var that = this;
    Http.get({
      url: config.api.userCarCount,
      data: {}
    }).then(res => {
      if (res.data > 0) {
        // 用户名下有车
        app.globalData.phone = res.data.phone;
        app.globalData.supportCar = true;
        // 共同登录
        that.userCarLogin();
      }
    })
      .catch(err => { })
  },
  jumpToAdd: function () {
    Http.get({
      url: config.api.checkPhoneStatus,
      data: {}
    }).then(res => {
      wx.navigateTo({
        url: `/pages/addPark/addPark?flags=managepalte`
      });
    }).catch(err => {
      wx.showModal({
        title: '提示',
        content: '登陆后方可添加车牌，现在登录？',
        showCancel: true,
        complete: (res) => {
          if (res.cancel) {
            return
          }

          if (res.confirm) {
            wx.navigateTo({
              url: `/pages/getphoneInfo/index?mineFlag=passCar`,
            })
          }
        }
      })

    })
  },
  passc: function () {
    wx.navigateTo({
      url: '/pages/ques/ques',
    })
  },
  goExplain: function () {
    wx.navigateTo({
      url: '/pages/tcExplain/tcExplain',
    })
  },


  /**
   * 券绑定车牌
   */
  bindCoupon: function (quanid, quantitle) {
    wx.showLoading({
      title: '使用中...',
    })
    var that = this;
    /**
     * etcp
     */
    var postCouponData = {
      etcpToken: app.globalData.etcpToken,
      carNumber: that.data.listCardNum,
      couponOrderId: quanid
    };
    if (app.globalData.parkVendor == 2) {
      // 停简单
      postCouponData = {
        carNumber: that.data.listCardNum
      }
    }
    if (app.globalData.parkVendor == 4) {
      // 尚安
      postCouponData = {
        carNumber: that.data.listCardNum,
        couponOrderId: quanid
      }
    }
    if (app.globalData.parkVendor == 5) {
      // 泊链
      postCouponData = {
        carNumber: that.data.listCardNum,
        orderId: that.data.bolinkOrderId,
        couponOrderId: quanid
      }
    }
    if (app.globalData.parkVendor >= 6) {
      console.log(123456789)
      postCouponData = {
        carNumber: that.data.listCardNum,
        // orderId: that.data.bolinkOrderId,
        couponOrderId: quanid,
        parkOrderId: that.data.stopFees.orderId
      }
    }
    Http.post({
      url: config.api.getCarCoupon,
      data: postCouponData
    })
      .then(res => {
        wx.hideLoading()
        // if(res.data){
        that.getStopFee(that.data.listCardNum);
        that.initUsrCarList();
        that.setData({
          quantitle: quantitle, //接口条用成功后在赋值
        })
        // }else{
        // wx.showToast({
        //   title: res.message,
        //   icon: 'none',
        //   duration: 3000,
        //   mask: false
        // });
        // }

      })
      .catch(err => {
        wx.hideLoading()
        if (err.message != undefined) {
          wx.showToast({
            title: err.message,
            icon: 'none',
            duration: 3000,
            mask: false
          });
        }

      })
  },
  /**
   * 选择优惠券
   */
  // gotoquan: function () {
  //   let that = this;
  //   if (that.data.quanid) {
  //     wx.navigateTo({
  //       url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  //     })
  //   } else {
  //     wx.navigateTo({
  //       url: '/pages/passCar/choicecoupon/choicecoupon',
  //     })
  //   }

  // },
  closeTicketModal: function () {
    this.setData({
      showTicketModal: false
    })
  },
  /**
   * 停车券  弹框
   */
  openTicketModal: function () {
    this.setData({
      showTicketModal: true,
      allow_load: true,
      ticketList: [],
      curPageNum: 1,

    })
    this.getTicketList(0, 1);
    /* if (!this.data.ticketList.length){
      this.getTicketList(0, 1);
    } */

  },

  //获取名下停车券列表
  getList() {
    var that = this;
    Http.get({
      url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
      data: {
        pageNum: 1,
        pageSize: 15,
        couponOrderStatus: 0
      }
    }).then(res => {
      that.setData({
        couponList: res.data.list
      });
    })
      .catch(err => {
        console.log(err)
      })
  },


  /**
   * 共同登录
   */
  init: function (carNumber) {
    var that = this;
    app.parkInitCallback = token => {
      that.initPark();
      that.getParkStatus();
      if (!app.globalData.carLogin) {
        Http.get({
          url: config.api.checkUserStatus,
          data: {}
        }).then(res => {
          app.globalData.type = 'pc'
          /**
           * 判断是否授权手机号
           */
          Http.get({
            url: config.api.checkPhoneStatus,
            data: {}
          })
            .then(res => {
              Http.post({
                url: config.api.carInit,
                data: {
                  phone: app.globalData.phone
                }
              }).then(res => {
                app.globalData.carLogin = true;
                app.globalData.parkVendor = res.data.vendor;
                if (res.data.token) {
                  app.globalData.etcpToken = res.data.token;
                }
                if (res.data.supportPay && res.data.supportPay == 1) {
                  that.setData({
                    supportPay: 1
                  })
                } else {
                  that.setData({
                    supportPay: 0
                  })
                }
                /**
                 * 获得停车费用
                 */
                that.initUsrCarList("flags");
              });
            })
            .catch(err => {
              if (err.code == 11005) {
                // 用户手机未授权
                /**
                 * 将值传到用户手机号授权的页面
                 *
                 */
                wx.redirectTo({
                  url: "/pages/getphoneInfo/index"
                });
              } else if (err.code == 11006) {
                // 用户手机已加密
                wx.redirectTo({
                  url: "/pages/phoneinput/phoneinput"
                });
              } else {
                wx.showToast({
                  title: err.errMsg,
                  icon: 'none',
                  duration: 2000,
                  mask: false
                });
              }
            })

        }).catch(err => {
          app.globalData.type = 'pc'
          if (err.code == 11004) {
            // 用户昵称未授权
            wx.redirectTo({
              url: "/pages/getuserinfo/index"
            });
          } else {
            wx.showModal({
              title: '提示',
              content: err.errMsg,
              showCancel: false
            })
          }
        });

      }
    };
    if (app.globalData.token && app.globalData.token != null) {
      app.parkInitCallback(app.globalData.token);
    }
  },

  bindCar: function (carNum) {
    var that = this;
    // ETCP
    var etcpData = {
      etcpToken: app.globalData.etcpToken,
      carNumber: carNum
    };
    var otherData = {
      carNumber: carNum
    };
    var postData = app.globalData.parkVendor == 1 ? etcpData : otherData;
    Http.post({
      url: config.api.bindCar,
      data: postData
    })
      .then(res => {
        that.setData({
          addCar: null
        });
        that.initUsrCarList();
        wx.showModal({
          title: "提示",
          showCancel: false,
          content: "绑车牌成功！",
          success: function () { }
        });
      })
      .catch(error => {
        wx.showModal({
          title: "提示",
          showCancel: false,
          content: error.data.message,
          success: function () { }
        });
      });
  },
  /**
   * 车场信息获取
   */
  initPark: function () {
    var that = this;
    Http.get({
      url: config.api.getParkInfo,
      data: {}
    })
      .then(res => {
        that.setData({
          park: res.data
        })
        if (res.data) {
          app.globalData.parkVendor = res.data.vendorType;
          if (app.globalData.parkVendor == 1) {
            console.log("payPath: " + extConfig.attr.car.etcp.payPath)
            // etcp
            that.setData({
              parkVendor: app.globalData.parkVendor,
              etcpAppId: extConfig.attr.car.etcp.etcpAppId,
              carMiniVersion: extConfig.attr.car.version,
              etcpCallbackUrl: extConfig.attr.car.etcp.etcpCallbackUrl,
              payPath: extConfig.attr.car.etcp.payPath
            })
          } else if (app.globalData.parkVendor == 2) {
            // TJD
            var vendorObj = JSON.parse(res.data.vendorParams)
            that.setData({
              parkVendor: app.globalData.parkVendor,
              tjdAppId: extConfig.attr.car.tjd.tjdAppId,
              carMiniVersion: extConfig.attr.car.version,
              payPath: extConfig.attr.car.tjd.payPath
            })
          } else if (app.globalData.parkVendor == 5) {
            // 泊链
            var vendorObj = JSON.parse(res.data.vendorParams)
            console.log("payPath: " + extConfig.attr.car.bolink.payPath)
            that.setData({
              parkVendor: app.globalData.parkVendor,
              bolinkAppId: extConfig.attr.car.bolink.bolinkAppId,
              carMiniVersion: extConfig.attr.car.version,
              payPath: extConfig.attr.car.bolink.payPath,
              bolinkComId: vendorObj.comid,
              bolinkUnionId: vendorObj.union_id
            })
          }
        }
      })
      .catch(err => {
        console.log(err);
        // wx.showToast({
        //   title: err.message,
        //   icon: 'none',
        //   duration: 2000,
        //   mask: false
        // });
      })
  },

  /**
   * 车场状态获取
   */
  getParkStatus: function () {
    var that = this;
    Http.get({
      url: config.api.getParkStatus,
    })
      .then(res => {
        console.log(res)
      })
      .catch(err => {
        console.log(err)
        // wx.showToast({
        //   title: err.message,
        //   icon:"none"
        // })
      })
  },


  /**
   * 绑定车获取
   */
  initUsrCarList: function (flag) {
    var that = this;
    Http.get({
      url: config.api.getUserCarList,
      data: {}
    }).then(res => {
      that.setData({
        carList: res.data
      });
      /**
       * flag ==flags 
       * 表示从首页onShow进来的
       */
      if (flag == "flags" && res.data.length > 0) {
        var listCardNum = res.data[0].carNumber;
        that.setData({
          listCardNum: listCardNum
        })
        /**
         * 获得停车费用
         */
        that.getStopFee(listCardNum);
      }
    })
      .catch(err => {
        wx.showToast({
          title: err.message,
          icon: 'none',
          duration: 2000,
          mask: false
        });
      })
  },

  /**
   * 获得停车费用修改
   */
  getStopFee: function (carNumber) {
    let that = this;
    let postData =
      app.globalData.parkVendor == 1 ? {
        etcpToken: app.globalData.etcpToken,
        carNumber: carNumber
      } : {
          carNumber: carNumber
        };
    Http.post({
      url: config.api.getCarStopFee,
      data: postData
    })
      .then(res => {
        console.log(res)
        if (app.globalData.parkVendor == 1) { // ETCP
          var extraDataStr = {
            params: {
              token: app.globalData.etcpToken,
              syncId: res.data.orderId,
              payType: 6, // 小程序支付
              CarNumber: carNumber,
              returnUrl: that.data.etcpCallbackUrl,
              source: "FUMAO-001",
              actionId: "1" //操作ID，1:小程序支付
            }
          }
          that.setData({
            parkVendor: app.globalData.parkVendor,
            extraData: extraDataStr,
            stopFees: res.data,
            timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
          });
        } else if (app.globalData.parkVendor == 2) { // TJD // TODO
          var extraDataStr = {
            prePayType: that.data.prePayType,
            channel: res.data.channel,
            isShowDetail: true,
            orderId: res.data.orderId
          }
          that.setData({
            parkVendor: app.globalData.parkVendor,
            extraData: extraDataStr,
            stopFees: {
              orderId: res.data.orderId,
              entranceTime: res.data.start_time,
              remainingFee: res.data.money
            },
            timecha: res.data.duration
          });
        } else if (app.globalData.parkVendor == 5) { // BoLink
          var extraDataStr = {
            union_id: that.data.bolinkUnionId,
            order_id: res.data.order_id,
            park_id: that.data.bolinkComId,
            plate_number: res.data.plate_number,
            money: res.data.money,
            park_name: res.data.park_name
          }
          that.setData({
            parkVendor: app.globalData.parkVendor,
            bolinkOrderId: res.data.order_id,
            extraData: extraDataStr,
            stopFees: {
              orderId: res.data.order_id,
              entranceTime: res.data.start_time,
              remainingFee: res.data.money
            },
            timecha: res.data.duration
          });
        } else { // *#06#

          // var extraDataStr = {
          //   params: {
          //     token: app.globalData.etcpToken,
          //     syncId: res.data.orderId,
          //     payType: 6, // 小程序支付
          //     CarNumber: carNumber,
          //     returnUrl: that.data.etcpCallbackUrl,
          //     source: "FUMAO-001",
          //     actionId: "1",//操作ID，1:小程序支付

          //   },
          // }
          that.setData({
            parkVendor: app.globalData.parkVendor,
            // extraData: extraDataStr,
            stopFees: res.data,
            timecha: Util.timecha(res.data.exitTime, res.data.entranceTime),
            remark: res.data.remark,
            generalAppId: res.data.appId,
            generalPayPath: res.data.payPath,
            generalExtraData: res.data.extraData,
            extraDataFlag: JSON.stringify(res.data.extraData)
          });
          console.log(that.data.extraDataFlag, "123456789")
        }

        that.setData({
          scroll: true
        })
      })
      .catch(error => {
        that.setData({
          stopFees: {},
          scroll: true
        })
      });
  },

  /**
   * 下拉刷新
   */
  onPullDownRefresh: function (e) {
    let that = this;
    that.initUsrCarList("flags");
    that.setData({
      current: 0
    })
    wx.stopPullDownRefresh();
  }
});