<template>
  <div>
      <el-dialog :visible.sync="inner_value" :before-close="beforeCloseDialog" width="500px">
              <el-form   label-width="90px" size="mini" :inline="true">
                      <el-form-item label="格式" prop="sGroup">
                        <BaseSelectPlugn
                            v-model="parm.formatNameList"
                            :Global_data_select="Global_data_select"
                            url="pbWebReportFormat/sName,sName"
                            id="sName" label="sName"
                          >
                          </BaseSelectPlugn>
                      </el-form-item>
              </el-form>
              <div slot="footer" style="width: 100%">
                  <el-row>
                      <el-button-group style="float: right">
                          <el-button size="mini" @click="cleanFile">取消</el-button>
                          <el-button size="mini" @click="submit(1)" type="primary">预览</el-button>
                          <el-button size="mini" @click='submit(2)' type="primary">打印</el-button>
                           <el-button size="mini" @click='submit(3)' type="primary">打印PDF</el-button>
                      </el-button-group>
                  </el-row>
              </div>
      </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'base-web_report_look',
  props: {
    value: {
      type: Boolean,
      required: true
    },
    report_data: {
      required: true
    }
  },
  watch: {
    value(value) {
      this.inner_value = value
    }
  },
  data() {
    return {
      inner_value: false,
      Global_data_select: [],
      parm: {
      }
    }
  },
  mountd() {
    this.inner_value = this.value
  },
  methods: {
    beforeCloseDialog() {
      this.$emit('input', false)
    },
    cleanFile() {
      this.$emit('input', false)
    },
    submit(flage) {
      if (!this.parm.formatNameList) {
        this.$message.error('请选择格式')
        return
      }
      const parm = Object.assign(this.parm, this.report_data)
      let url = ''
      if (flage === 1) {
        url = 'look'
      } else if (flage === 2) {
        url = 'print'
      } else {
        url = 'pdf_print'
      }
      this.$API.post(`mesAPI/web_report/${url}/`, {}, {}, parm).then(res => {
        window.open(res.data)
      })
    }
  }
}
</script>
