<template>
  <div>
    <!-- 借阅弹窗 -->
    <el-dialog :title="$t('page.business.resource.mjy.jieyue')" :visible.sync="open" width="500px" append-to-body
      :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <!-- <div :style="isBatch ? 'display:block' : 'display:none'">
          <el-alert :title="$t('page.business.resource.mjy.jdts')" type="error" :closable="false">
          </el-alert>
          <el-row style="margin:10px 0px;">
            <el-col :span="24">
              <SelectList :value="selectList" />
            </el-col>
          </el-row>
        </div>
        <div v-if="!isBatch">
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('page.business.resource.mjy.mc')" prop="mc">
                <el-input type="text" v-model="form.mc" 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('page.business.resource.mjy.bh')" prop="glyj">
                <el-input type="text" v-model="form.bh" maxlength="50" disabled
                  :placeholder="$t('form.placeholderInput')" />
              </el-form-item>
            </el-col>
          </el-row>
        </div> -->
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('page.business.resource.mjy.jysj') + '：'" prop="startDate">
              <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: 250px;" />
            </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">
              <el-input type="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>
import { jy } from "@/api/business/gsp/gsp"
import { mapGetters } from 'vuex'
import SelectList from "./SelectList";

export default {
  name: "Jy",
  components: { SelectList },
  data() {
    return {
      isBatch: false,
      ids: [],
      selectList: [],
      daterange: [],
      open: false,
      form: {},
      rules: {
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        endDate: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        startDate: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName'
    ]),
  },
  created() {
  },
  methods: {
    showBatch(val) {
      this.reset()
      this.isBatch = true
      this.form.ids = val.map(item => item.id)
      this.selectList = val
      this.open = true
    },
    cancel() {
      this.open = false
    },
    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 = ''
      }
    },

    reset() {
      this.form = {
        id: null,
        ids: null,
        mc: null,
        bh: null,
        startDate: null,
        endDate: null,
        qmyy: this.$t('page.business.resource.gsp.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.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          jy(this.form).then(response => {
            this.open = false
            this.$emit('callback')
          })

        }
      })
    }
  }
}
</script>
