<template>
  <div>
    <!-- 借阅弹窗 -->
    <el-dialog :title="$t('page.business.resource.sj.jieyue')" :visible.sync="open" width="500px" append-to-body
      :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" v-show="open">
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('page.business.resource.sj.jieyuesj')" prop="qmyy">
              <el-date-picker v-model="daterange" class="chat-histogram-daterange" type="daterange" range-separator="-"
                :start-placeholder="$t('form.startDate')" :end-placeholder="$t('form.endDate')"
                value-format="yyyy-MM-dd"  @change="daterangeChange" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('form.qmyy')" prop="qmyy">
              <el-input type="text" :value="form.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="form.remark" :rows="2" 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">
              <div class="sbzdtcma"> <input type="text"></div>
              <el-input type="password" v-model="form.qmrmm"  autocomplete="off" auto-complete="new-password" show-password 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>
import { sj_jy } from "@/api/business/sj/sj"
import { mapGetters } from 'vuex'
import SelectList from "./SelectList";

export default {
  name: "SjJy",
  components: { SelectList },
  data() {
    return {
      isBatch: false,
      ids: [],
      selectList: [],
      open: false,
      form: {},
      daterange: [],
      rules: {
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName','name'
    ]),
  },
  created() {
  },
  methods: {
    daterangeChange() {
      if (this.daterange != null && this.daterange.length > 0) {
        this.form.startDate = this.daterange[0]
        this.form.endDate = this.daterange[1];
      } else {
        this.form.startDate = ''
        this.form.endDate = ''
      }
    },
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        id: null,
        ids: null,
        mc: null,
        bh: null,
        qmyy: this.$t('page.business.resource.sj.sqjy'),
        qmrmm: null
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      this.isBatch = false
      this.form.ids = []
      this.selectList = []
      this.form.id = row.id
      this.form.mc = row.mc
      this.form.bh = row.bh
      this.daterange = []
      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          sj_jy(this.form).then(response => {
            this.open = false
            this.$emit('callback')
          })
        }
      })
    }
  }
}
</script>
