
const app = getApp()
const {ossUrl} = require("../../../utils/util.js")
Page({
  data: {
    userInfo:{},
    signModel: false,
    from: 0,
    size: 20,
    form:{},
    list: []
  },
  onLoad: function( options ){
    app.getUserInfo( userInfo =>{
      this.setData({userInfo})
      this.loadData( )
    })
  },
  preview( e){
    let url = e.currentTarget.dataset.url;
    this.doPreview( url );
  },
  doPreview( url ){
    let nurl = ossUrl+ url.split("#")[1]
    wx.previewImage({
      urls: [nurl],
    })
  },
  makeSign( e) {
    let index = +e.currentTarget.dataset.index;
    let item = this.data.list[index];
    item.index = index
    let form = Object.assign( {}, item)
    form.temp = item
    this.setData({form,signModel:true})
  },
  cancelPrint(){
    this.setData({signModel:false});
  },
  printCert(e){
    let param = {
      id: +this.data.form.id, 
      rzCode: this.data.form.rzCode
    }
    app.formPost('Cert.printCert', param).then(res => {
      if( res.code == 200){
        let { url } = res.data;
        if( url )this.doPreview( url )
      }
    })
  },
  updateRzcode(e){
    this.setData({ "form.rzCode": e.detail.detail.value})
  },
  loadData: function(  ) {
    let param ={ from: this.data.from, size: this.data.size }
    app.formPost('Cert.GetCertList', param).then(res => {
      if( res.code == 200){
        let { from, list} = res.data
        this.setData({from,list})
      }
    })
  }

})