<template>
  <div>
    <!-- 签名弹窗 -->
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :title="title" :visible.sync="open"
      width="500px" append-to-body>
      <el-form ref="signForm" :model="form" :rules="rules" label-width="120px" v-if="open">
        <div class="sbzdtcma"> <input type="text"> <input type="password" > </div>
        <el-row>
          <el-col :span="24" v-if="showDate">
            <el-form-item :label="$t('page.business.study.study.jysj')" prop="jyksrq">
              <el-date-picker v-model="dateArr" clearable type="daterange" range-separator="-"
                :start-placeholder="$t('form.startDate')" :end-placeholder="$t('form.endDate')"
                value-format="yyyy-MM-dd" style="width: 100%" @change="changeDate" />
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item :label="$t('form.qmyy')" prop="qmyy">
              <el-input type="text" v-model="form.qmyy" maxlength="50" disabled
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item :label="isReson ? $t('form.reason') : $t('form.remark')" prop="remark">
              <el-input type="textarea" v-model="form.remark" :rows="2" maxlength="500"
                :placeholder="$t('form.placeholderInput')">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item :label="$t('form.signer')">
              <el-input type="text" v-model="form.qmrMc" maxlength="50" disabled
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item :label="$t('form.password')" prop="qmrmm">
              <div class="sbzdtcma"> <input type="text"></div>
              <el-input type="password" @contextmenu.native.prevent @copy.native.prevent @cut.native.prevent  show-password v-model="form.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="save">{{ $t('form.confirm') }}</el-button>
        <el-button @click="cancel">{{ $t('form.cancel') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "Sign",
  components: {},
  data() {
    return {
      title: '',
      open: false,
      form: {
        qmyy: '',
        remark: '',
        qmrId: '',
        qmrMc: '',
        qmrMcEn: '',
        qmrmm: '',

        startDate: '',
        endDate: ''
      },
      dateArr: [],
      showDate: false,
      rules: {
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        startDate: [{
          required: true,
          message: ' ',
          trigger: 'change'
        }]
      },

      isReson: false
    }
  },
  computed: {
  },
  created() {
  },
  methods: {
    show(title, qmyy, showDate, selectedDate, isReson, reasonRequired) {
      this.showDate = showDate == undefined ? false : showDate
      this.dateArr = selectedDate || []
      this.title = title
      this.form = {
        qmyy: qmyy,
        remark: '',
        qmrId: this.$store.getters.id,
        qmrMc: this.$store.getters.nickName,
        qmrMcEn: this.$store.getters.name,
        qmrmm: '',
        jyksrq: selectedDate && selectedDate.length > 0 ? selectedDate[0] : '',
        jyjsrq: selectedDate && selectedDate.length > 0 ? selectedDate[1] : ''
      }
      
      this.open = true

      this.isReson = isReson || false
      if (reasonRequired) {
        this.rules = {
          qmrmm: [{
            required: true,
            message: ' ',
            trigger: 'blur'
          }],
          jyksrq: [{
            required: true,
            message: ' ',
            trigger: 'change'
          }],
          remark: [{
            required: true,
            message: ' ',
            trigger: 'blur'
          }]
        }
      } else {
        this.rules = {
          qmrmm: [{
            required: true,
            message: ' ',
            trigger: 'blur'
          }],
          startDate: [{
            required: true,
            message: ' ',
            trigger: 'change'
          }]
        }
      }
      this.clearFormValidate("signForm")
    },
    cancel() {
      this.open = false
    },
    changeDate(val) {
      this.form.jyksrq = val && val.length > 0 ? val[0] : ''
      this.form.jyjsrq = val && val.length > 1 ? val[1] : ''
    },
    save() {
      this.$refs["signForm"].validate(valid => {
        if (valid) {
          this.$emit('callback', this.form)
          this.open = false
        }
      })
    }
  }
}
</script>
