<template>
  <div class="auto">
    <form>
      <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
        <div class="col-xs-4 col-sm-4 col-md-4">
          <label for="f_userinfo_code" class="font text-left">小区名称：</label>
        </div>
        <div class="col-xs-8 col-sm-8 col-md-8" >
          <input id="f_userinfo_code" class="search_input input-font" :disabled="true"
                 v-model=row.f_residential_area />
        </div>
      </div>
      <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
        <div class="col-xs-4 col-sm-4 col-md-4">
          <label for="f_userinfo_code" class="font text-left">街道：</label>
        </div>
        <div class="col-xs-8 col-sm-8 col-md-8" >
          <input id="f_userinfo_code" class="search_input input-font" :disabled="true"
                 v-model=row.f_street />
        </div>
      </div>
      <div class="auto col-xs-12 col-sm-12">
        <div class="panel" style="padding: 10px 10px 5px 10px;">
          <div class="panel-body panel-self">
            <div class="row">
              <div id="photo" align="center">
                <p>请拍摄宣传照片</p>
                <!--<img-area :model="model.imgs"></img-area>-->
                <safecheck-picture-area  :model="model.imgs" show="true"></safecheck-picture-area>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id="submitbutton" align="center">
        <button @click.stop.prevent="save(true)" class="btn btn-lg btn-font btn-color">保存</button>
        <button @click.stop.prevent="upload" class="btn btn-lg btn-font btn-color">上传</button>
      </div>
    </form>
    <back-page :need-back='true' @flag="$back()"></back-page>
  </div>
</template>

<script>
  import Vue from 'vue'
  import co from 'co'
  import * as Util from '../Util'
   export default {
     title:"拍照上传",
     props:['row','pictureinfo'],
     data(){
          return {
            //存放照片
            model:{
              imgs:[],
            },
          }
     },
    ready(){
       console.log('this.pictureinfo===>'+JSON.stringify(this.pictureinfo))
       if(this.pictureinfo.length>0) {
         // 存在未上传的宣传单
         this.model.imgs = this.pictureinfo[0].f_all_imgs
       }else{
         this.model.imgs = []
       }
    },
    methods:{
      // back(){
      //   this.$back()
      // },
      logicWithHint(logic, data, callback, backresult) {
        HostApp.logicWithHint({
          // logic别名，key必须为logic
          'logic': logic,
          // 回调执行方法名，key必须为callback
          'callback': callback,
          // logic执行需要的业务参数
          'data': data,
          // 固定key，代表是否将logic执行结果作为参数传入回调方法，1代表true，0代表false，
          // 执行回调方法传入key为backresult+
          // 如需额外拼接参数，写在logic返回值的params，例如xxlogic返回:{"params": "success"}
          'backresult': backresult
        })
      },
      save(temp){
        console.log('this.model.imgs.length'+this.model.imgs.length )
          if(this.model.imgs.length ==0){
            this.$showMessage('请至少拍摄一张照片')
            return
          }
          let data = {
            f_checker_id : Vue.user.id,
            f_checker_name : Vue.user.name,
            f_area_id : this.row.id,
            f_publicity_time:Util.toStandardTimeString(),
            f_residential_area:this.row.f_residential_area,
            f_street:this.row.f_street,
            f_address:this.row.f_area_address,
            f_isupload:'未上传',
            f_create_time:Util.toStandardTimeString(),
            f_all_imgs:this.model.imgs
          }
          let id = ''
          if(this.picinfo){
            id = this.pictureinfo.id
          }
        let ret = this.$androidUtil.bzLogic('saveAreaPublicity', {data:data,id:id})
        if(ret.code == 200 && temp){
            this.$showMessage('保存成功！')
        }
        if(!temp){
            HostApp.__this__ = this
            console.log('开始上传')
            this.logicWithHint('UpAreaPublicity',data,'javascript:HostApp.__this__.upAreaPublicityCallBack()',1)
        }
      },
      upAreaPublicityCallBack(jo){
        if (jo.state == 'ok') {
          let result = JSON.parse(jo.result)
          if (result.code === 200) {
            this.$showMessage('上传成功！')
            this.$back()
          }
        } else {
          this.$showMessage('请求数据失败，请检查网络状况是否正常！')
        }
      },
      upload(){
        this.save(false)
        // let ret = this.$androidUtil.bzLogic('uploadData', {rows: [{f_serial_num: this.info.id}]})
        // if (ret.state == 0) {
        //   this.$showMessage('上传成功')
        // } else {
        //   this.$showMessage('上传失败')
        // }
      },
      uploadCallBack(jo){
        if (jo.state == 'ok') {
          let ret = JSON.parse(jo.result)
          if (ret.state == 0) {
          console.log('上传成功')
            this.$back()
            this.$showMessage('上传成功')
          } else {
            this.$showMessage('上传失败')
          }
        }
      },
    },
  }
</script>

<style scoped>
  .search_input {
    border: 0;
    outline: none;
  }
</style>
