<template>
  <div class="app-container">
    <sticky style="margin-bottom: 10px;">
      <btn ref="btn" />
    </sticky>
    <el-form ref="ysjl" :model="ysjl" class="el-form" label-position="right" label-width="130px">
      <fieldset>
        <legend>位置图</legend>
        <span v-if="state === 'create'" style="color: red;font-size: 26px;">请在原始记录保存后上传检测位置图</span>
        <pictureUpload v-else ref="picture" :info="info" @changed="changed" />
        <el-form-item label="" prop="jianyanrenyuan" style="display: none;">
          <el-input v-model="ysjl.jianyanrenyuan" type="text" />
        </el-form-item>
      </fieldset>
    </el-form>
  </div>
</template>
<script>
import Sticky from '@/components/Sticky'
import pictureUpload from '@/components/Upload'
import btn from '@/views/common/FxButton'
export default {
  name: 'GdZbgDxt',
  components: { Sticky, btn, pictureUpload },
  data() {
    return {
      ysjl: {},
      param: {},
      fileList: [],
      state: '',
      edit: false,
      info: {
        ysjlId: this.$route.query.id,
        jyxm: this.$route.query.jyxm,
        limit: 1,
        multiple: false
      }
    }
  },
  watch: {
    state: function(val) {
      this.$refs.picture.stateChange(val)
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      this.api({
        url: '/fx',
        method: 'get',
        params: {
          ysjlId: this.$route.query.id,
          jyxm: this.$route.query.jyxm
        }
      }).then(data => {
        this.ysjl = data.ysjl
        this.state = 'create'
        if (data.param !== null && data.param !== undefined) {
          // 有无损原始记录参数
          this.state = 'update'
          this.param = data.param
          this.fileList = JSON.parse(data.param.imagePath) === null ? JSON.parse('[]') : JSON.parse(data.param.imagePath)
          if (this.fileList.length > 0) {
            for (let i = 0; i < this.fileList.length; i++) {
              this.fileList[i].url = process.env.VUE_APP_IMG_URL + '8000/wzt/' + this.fileList[i].name
            }
          }
        }
        if (this.ysjl.flowstatus === 4) {
          this.state = 'finish'
          this.edit = true
        }
        this.$refs.btn.getParentInfo(this.ysjl, this.param, null, null, this.state, this.$route.query.jyxm)
        this.$refs.picture.getChange(this.ysjl.shebeizhongleidaima, this.state, this.fileList, 1)
      })
    },
    handleSelectionChange(val) {
      this.delRowIndex = []
      for (let i = 0; i < val.length; i++) {
        this.delRowIndex.push(val[i].index)
      }
    },
    changed(item) {
      this.param.imagePath = item
    }
  }
}
</script>
