<template>
  <div id="unit" class="flex-row" style="width: 100%">
    <div class="flex binary-left" style="flex: 1; width:60%">
      <transfer-audit v-ref:list @select-changed="selected"></transfer-audit>
    </div>
    <div class="flex binary-left" style="width:40%">
      <transfer-audit-dispose-basics
        :row="row"
        :img-info="imgInfo"
        :user-info="userInfo"
        :title="title">
      </transfer-audit-dispose-basics>
    </div>
  </div>
</template>

<script>
  export default {
    title: '第三方过户预约审核',
    data () {
      return {
        row: {},
        title: '',
        imgInfo: [],
        userInfo: []
      }
    },
    ready () {
    },
    methods: {
      async selected(data) {
        console.log("data?", data)
        this.userInfo = []
        this.imgInfo = []
        this.title = data.val.f_operate_type + '处理'
        this.row = data.val
        // 普通预约信息字段
        this.userInfo.push({
          key: data.val.f_describe,
          value: data.val
        })
        let ywh = data.val.f_serial_number
        //todo 根据业务号获取影像资料列表
        let res = await this.$resetget(`datums/contentPageList?ywh=${ywh}`, {resolveMsg: null, rejectMsg: '获取数据错误！'})
        let now = new Date().getTime()+""
        let param = {ywh: ywh, ids: [], timestamp: now}
        let imgList = []
        let img = {}
        console.log("res.data",res.data.data)
        if (res.data.data.length) {
          for (let item of res.data.data) {
            img = item
            console.log("图片名",img.name)
            if (img.name.indexOf("买方身份证（买方提供）") !== -1 || img.name.indexOf("网签备案合同") !== -1 || img.name.indexOf("不动产权证") !== -1){
              imgList.push(
                {
                  name:img.name,
                  id:img.uid,
                  fileType:img.fileType
                }
              )
              param.ids.push(img.uid)
            }
          }
        }
        console.log("param.ids",param.ids)
        if (param.ids.length) {
         await this.$resetpost('rs/content/getContent', param, {resolveMsg: null, rejectMsg: '获取数据错误'}).then((res) => {
            if (res.data.data.length) {
              // 分别出图片字段和普通预约信息字段
              for (let item of res.data.data) {
                console.log("item",item)
                for (let img of imgList){
                  if (item.id===img.id){
                    this.imgInfo.push({
                      key: img.name + img.id,
                      value: 'data:image/'+`${img.fileType}`+';base64,'+item.pageContent
                    })
                  }
                }
              }
            }
          })
        }
      },
      init () {
        this.row = {},
        this.title = '',
        this.imgInfo= [],
        this.userInfo= []
      }
    },
    events: {
      'refresh' () {
        this.$refs.list.$refs.paged.$refs.criteria.search()
        this.init()
      }
    }
  }
</script>
<style>
</style>
