<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.cancel') }}</el-button>
          <el-button type="danger" @click="showReject">{{ $t('page.business.study.studyFormPre.reject') }}</el-button>
          <el-button type="primary" @click="showApprove">{{ $t('page.business.study.studyFormPre.approve')
            }}</el-button>
        </div>
      </div>
      <div class="edit-content ">
        <TemplateTable ref="templateTable" :sn="form.templateSn" :templateData="form" fillType="audit" />
      </div>
    </div>
    <!-- 通过 -->
    <el-dialog :title="$t('page.business.study.studyFormPre.shtg')" :visible.sync="openApprove" width="500px"
      append-to-body :close-on-click-modal="false">
      <el-form ref="formApprove" :model="formApprove" :rules="rulesApprove" label-width="120px">
        <div class="sbzdtcma"> <input type="text"> <input type="password"> </div>
        <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>

    <!-- 拒绝 -->
    <el-dialog :title="$t('page.business.study.studyFormPre.shjj')" :visible.sync="openReject" width="500px"
      append-to-body :close-on-click-modal="false">
      <el-form ref="formReject" :model="formReject" :rules="rulesReject" label-width="120px">
        <div class="sbzdtcma"> <input type="text"> <input type="password"> </div>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('form.qmyy')" prop="qmyy">
              <el-input type="text" :value="formReject.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="formReject.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="formReject.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="reject">{{ $t('form.confirm') }}</el-button>
        <el-button @click="openReject = false">{{ $t('form.cancel') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { studyFormPre_tg, studyFormPre_jj, studyFormPre_info } from "@/api/business/study/studyFormPre"
import TemplateTable from '@/views/business/comps/template/TemplateTable';
import { mapGetters } from 'vuex'

export default {
  name: "Sh",
  components: { TemplateTable },
  data() {
    return {
      showIndex: 1,
      form: {},
      rules: {
        bdmc: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        templateId: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]

      },
      openApprove: false,
      formApprove: {
        id: null,
        qmyy: this.$t('page.business.study.studyFormPre.shtg'),
        remark: '',
        qmrmm: '',
      },
      rulesApprove: {
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]
      },
      openReject: false,
      formReject: {
        id: null,
        qmyy: this.$t('page.business.study.studyFormPre.shjj'),
        remark: '',
        qmrmm: '',
      },
      rulesReject: {
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        remark: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName','name'
    ]),
  },
  created() {
  },
  methods: {
    cancel() {
      this.$emit('close')
    },
    reset() {
      this.form = {
        id: null,
        studyId: null,
        qmyy: null,
        remark: null,
        qmrmm: null
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      this.$modal.loading()
      studyFormPre_info({ id: row.id }).then(response => {
        this.form = response.data
        this.open = true
        this.$modal.closeLoading()
      }).finally(() => {
        this.$modal.closeLoading()
      })
    },
    showApprove() {
      this.formApprove.id = this.form.id
      this.openApprove = true
    },
    approve() {
      this.$refs["formApprove"].validate(valid => {
        if (valid) {
          this.$modal.loading()
          studyFormPre_tg(this.formApprove).then(response => {
            this.openApprove = false
            this.$modal.closeLoading()
            this.$emit('close')
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    },
    showReject() {
      this.formReject.id = this.form.id
      this.openReject = true
    },
    reject() {
      this.$refs["formReject"].validate(valid => {
        if (valid) {
          this.$modal.loading()
          studyFormPre_jj(this.formReject).then(response => {
            this.openReject = false
            this.$modal.closeLoading()
            this.$emit('close')
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    }
  }
}
</script>
