<template>
  <div>
    <!-- 编辑弹窗 -->
    <el-dialog :title="$t('form.edit')" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <!-- 名称 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.mc')" prop="mc">
              <el-input type="text" v-model="form.mc" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <!-- 编号 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.bh')" prop="bh">
              <el-input type="text" v-model="form.bh" maxlength="50" disabled :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- 批号 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.ph')" prop="ph">
              <el-input type="text" v-model="form.ph" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <!-- 规格 -->
          <el-col :span="8">
            <el-form-item :label="$t('page.business.resource.gsp.gg')" prop="gg">
              <el-input type="text" v-model="form.gg" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <!-- 规格单位 -->
          <el-col :span="4">
            <BusinessSelect v-model="form.ggdw"
              dictType="system_business_nddw,system_business_zldw,system_business_tjdw"></BusinessSelect>
          </el-col>
        </el-row>
        <el-row>
          <!-- 有效期 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.yxq')" prop="yxq">
              <el-date-picker v-model="form.yxq" type="datetime" format="yyyy-MM-dd HH:mm"
                value-format="yyyy-MM-dd HH:mm:ss" :placeholder="$t('form.placeholderInput')">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!-- 存储条件 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.cctj')" prop="cctj">
              <BusinessSelect v-model="form.cctj" dictType="system_business_cctj"></BusinessSelect>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- 接收日期 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.jsrq')" prop="jsrq">
              <el-date-picker v-model="form.jsrq" type="datetime" format="yyyy-MM-dd HH:mm"
                value-format="yyyy-MM-dd HH:mm:ss" :placeholder="$t('form.placeholderInput')">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- 注意事项 -->
          <el-col :span="24">
            <el-form-item :label="$t('page.business.resource.gsp.zysx')" prop="zysx">
              <el-input type="textarea" :rows="2" v-model="form.zysx" maxlength="500"
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <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-col :span="12">
            <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.signerPsw')" prop="qmrmm">
              <el-input type="password" v-model="form.qmrmm" maxlength="20"
                :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="bjbz">
              <el-input type="textarea" v-model="form.bjbz" :rows="2" maxlength="500"
                :placeholder="$t('form.placeholderInput')">
              </el-input>
            </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 { edit, info } from "@/api/business/gsp/gsp"
import { mapGetters } from 'vuex'
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';

export default {
  name: "Bj",
  components: { BusinessSelect },
  data() {
    return {
      open: false,
      form: {},
      rules: {
        mc: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        bh: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ph: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        gg: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        kc: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        yxq: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        jsrq: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        cctj: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        zysx: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName'
    ]),
  },
  created() {
  },
  methods: {
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        qmyy: this.$t('page.business.resource.gsp.bjgsp'),
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      info({id: row.id}).then(response => {
        this.form = response.data;
      })

      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          edit(this.form).then(response => {
            this.open = false
            this.$emit('callback')
          })
        }
      })
    }
  }
}
</script>
