var newmark = startmark = 0
var status = 0
function touchstart(e, ins) {
  var pageX = (e.touches[0] || e.changedTouches[0]).pageX
  startmark = newmark = pageX
}

function touchmove(e, ins) {
  var pageX = (e.touches[0] || e.changedTouches[0]).pageX
  console.log('pageX', pageX);
  newmark = pageX
  // var data = ins.getData()
  var data = {
    windowWidth: e.target.dataset.width
  }
  if (startmark < pageX) {
    if (data.windowWidth * 0.4 > Math.abs(newmark - startmark)) {
      console.log('newmark - startmark',newmark - startmark)
      ins.selectComponent('.page-top').setStyle({
        transform: 'translateX(' + Math.min(data.windowWidth * 0.4, ((status == 1 ? data.windowWidth * 0.4 : 0) + newmark - startmark)) + 'px)'
      })
    }
  }
  if (startmark > pageX) {
    ins.selectComponent('.page-top').setStyle({
      transform: 'translateX(' + Math.max(0, ((status == 1 ? data.windowWidth * 0.4 : 0) + newmark - startmark)) + 'px)'
    })
  }
}
function touchend(e, ins) {
  var pageX = (e.touches[0] || e.changedTouches[0]).pageX
  newmark = pageX
  // var data = ins.getData()
  var data = {
    windowWidth: e.target.dataset.width
  }
  if (startmark < pageX) {
    if (data.windowWidth * 0.2 < Math.abs(newmark - startmark)) {
      ins.selectComponent('.page-top').setStyle({
        transform: 'translateX(' + (data.windowWidth * 0.4) + 'px)'
      })
      status = 1 // 展开状态
    } else {
      ins.selectComponent('.page-top').setStyle({
        transform: 'translateX(0px)'
      })
      status = 0 // 收起状态
    }
  }
  if (startmark > newmark) {
    ins.selectComponent('.page-top').setStyle({
      transform: 'translateX(0px)'
    })
    status = 0 // 收起状态
  }
}
module.exports = {
  touchstart: touchstart,
  touchmove: touchmove,
  touchend: touchend
}