<template>
  <div>
    <div class="edit-container">
      <div class="edit-top">
        <div class="left-top">
          <img src="@/assets/images/back.png" @click="cancel()" />
          <div class="left-title"></div>
        </div>
        <div class="center-top">
        </div>
        <div class="right-top">
          <el-button @click="cancel()">{{ $t('form.close') }}</el-button>
          <el-button type="primary" v-if="form.bdzt === 5 && form.tbzt === 1" @click="openApprove = true">{{
            $t('page.business.study.studyFormFill.tb') }}</el-button>
        </div>
      </div>
       <el-button type="primary" @click="exportExcel">后台导出
        </el-button>
        <el-button type="primary" @click="dcqbjcgj">{{ $t('page.business.study.studyFormFill.dcqbjcgj') }}
        </el-button>
        <el-button type="primary" @click="dcqbjcgj">{{ $t('page.business.study.studyFormFill.dcqbjcgj') }}
        </el-button>
        <el-button type="primary" @click="dclcjcgj">{{ $t('page.business.study.studyFormFill.dclcjcgj') }}
        </el-button>
        <el-button type="primary" @click="dcbjjcgj">{{ $t('page.business.study.studyFormFill.dcbjjcgj') }}
        </el-button>
        <el-button type="primary" @click="dcxgjcgj">{{ $t('page.business.study.studyFormFill.dcxgjcgj') }}
        </el-button>
        <el-button type="primary" @click="dcbhsjgj">{{ $t('page.business.study.studyFormFill.dcbhsjgj') }}
        </el-button>
      <div class="edit-content ">
        <div class="content"  style="width: 100%;">
          <vue-html2pdf :show-layout="false" pdf-content-width="100%" :float-layout="false"
            pdf-orientation="landscape" :enable-download="true" :preview-modal="true" ref="html2Pdf">
            <section slot="pdf-content">
              <TemplateTable ref="templateTable" :sn="form.templateSn" :templateData="form" fillType="detail" />
              <div class="content-title">
                <div class="line"></div>
                <div class="subtitle"> {{ $t('page.business.study.studyFormFill.qmxx') }}</div>
              </div>
              <div class="pal">
                <el-table :data="qmxxList" v-loading="loadingQmxx">
                  <el-table-column :label="$t('page.business.study.studyFormFill.qmr')" align="center" prop="qmrMc"
                    width="150px" />
                  <el-table-column :label="$t('page.business.study.studyFormFill.qmyy')" align="center"
                    :prop="$i18n.locale === 'zh_CN' ? 'qmyy' : 'qmyyEn'" width="150px" />
                  <el-table-column :label="$t('page.business.study.studyFormFill.qmsj')" align="center"
                    prop="createTime" width="150px" />
                  <el-table-column :label="$t('page.business.study.studyFormFill.bzyy')" align="center" prop="remark"
                    :show-overflow-tooltip="true" />
                </el-table>
              </div>
              <!-- <div class="pal">
            <pagination v-show="totalQmxx > 0" :total="totalQmxx" :page.sync="queryParamsQmxx.pageNum"
              :limit.sync="queryParamsQmxx.pageSize" @pagination="getQmxxList" />
          </div> -->
              <div class="content-title">
                <div class="line"></div>
                <div class="subtitle"> {{ $t('page.business.study.studyFormFill.jcgj') }}</div>
              </div>
              <JcgjList ref="jcgjList" @handleQuery="getJjcgjList" :showXg="true" />
              <!-- 
          <pagination v-show="jcgjTotal > 0" small layout="prev, pager, next" :total="jcgjTotal"
            @pagination="getJjcgjList" /> -->
            </section>

          </vue-html2pdf>
        </div>
      </div>
    </div>

    <!-- 填报 -->
    <el-dialog :title="$t('page.business.study.studyFormFill.cjjl')" :visible.sync="openApprove" width="500px"
      append-to-body :close-on-click-modal="false">
      <el-form ref="formApprove" :model="formApprove" :rules="rulesApprove" label-width="120px">
        <el-alert :title="$t('page.business.study.studyFormFill.ts')" :closable="false" type="success">
        </el-alert>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('form.qmyy')" prop="qmyy">
              <el-input type="text" :value="formApprove.qmyy" maxlength="50" disabled
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('form.remark')" prop="remark">
              <el-input type="textarea" v-model="formApprove.remark" :rows="5" maxlength="500"
                :placeholder="$t('form.placeholderInput')">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('form.signer')">
              <el-input type="text" v-model="nickName" maxlength="50" disabled
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('form.password')" prop="qmrmm">
              <el-input type="password" v-model="formApprove.qmrmm" maxlength="20"
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="approve">{{ $t('form.confirm') }}</el-button>
        <el-button @click="openApprove = false">{{ $t('form.cancel') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { studyFormFill_tb, studyFormFill_info, studyFormFill_jcgj, studyFormFill_qmxx, studyFormFill_exportDetail } from "@/api/business/study/studyFormFill"
import { mapGetters } from 'vuex'
import JcgjList from "@/views/business/comps/common/JcgjList";
import TemplateTable from '@/views/business/comps/template/TemplateTable';
import VueHtml2pdf from 'vue-html2pdf'
export default {
  name: "Xq",
  components: { JcgjList, TemplateTable, VueHtml2pdf },
  data() {
    return {
      openApprove: false,
      formApprove: {
        id: null,
        qmyy: this.$t('page.business.study.studyFormFill.cjjl'),
        remark: '',
        qmrmm: '',
      },
      rulesApprove: {
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]
      },
      qmxxList: [],
      totalQmxx: 0,
      loadingQmxx: true,
      queryParamsQmxx: {
        formId: null,
        pageNum: 1,
        pageSize: 9999
      },
      open: false,
      showIndex: 1,
      form: {},
      rules: {
        bdmc: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        templateId: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]

      },
      jcgjTotal: 0,
      jcgjList: [],
      queryParamsJcgj: {
        pageNum: 1,
        formId: null,
        pageSize: 9999,
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName', 'name'
    ]),
  },
  created() {
  },
  methods: {
    exportExcel() {
      this.$modal.loading()
      studyFormFill_exportDetail(this.queryParamsJcgj).then(response => {
        window.open(this.baseUrl + response.msg)
        this.$modal.closeLoading()
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    dcqbjcgj() {
      this.$refs.html2Pdf.generatePdf()
    },
    dclcjcgj() {
      this.$refs.html2Pdf.generatePdf()
    },
    dcbjjcgj() {
      this.$refs.html2Pdf.generatePdf()
    },
    dcxgjcgj() {
      this.$refs.html2Pdf.generatePdf()
    },
    dcbhsjgj() {
      this.$refs.html2Pdf.generatePdf()
    },
    getJjcgjList(val) {
      this.$modal.loading()
      studyFormFill_jcgj(_.merge({}, this.queryParamsJcgj, val)).then(response => {
        this.jcgjList = response.rows
        this.jcgjTotal = response.total
        this.$refs.jcgjList.init(this.jcgjList)
        this.$modal.closeLoading()
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    getQmxxList() {
      this.loadingQmxx = true
      studyFormFill_qmxx(this.queryParamsQmxx).then(response => {
        this.qmxxList = response.rows
        this.totalQmxx = response.total
        this.loadingQmxx = false
      })
    },
    cancel() {
      this.$emit('close')
    },
    reset() {
      this.form = {
        id: null,
        studyId: null,
        bdbh: null,
        bdmc: null,
        bdsm: null,
        templateId: null,
        templateMc: null,
        bdnr: null
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      this.$modal.loading()
      debugger
      this.formApprove.id = row.id
      this.queryParamsJcgj.formId = row.id
      this.queryParamsQmxx.formId = row.id
      studyFormFill_info({ id: row.id }).then(response => {
        this.form = response.data
        this.getQmxxList()
        this.getJjcgjList()
        this.$modal.closeLoading()
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    approve() {
      this.$refs["formApprove"].validate(valid => {
        if (valid) {
          this.$modal.loading()
          studyFormFill_tb(this.formApprove).then(response => {
            this.$emit('close')
            this.openApprove = false
            this.$modal.closeLoading()
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    }
  }
}
</script>
