<template>
  <div>
    <!-- 新增弹窗 -->
    <el-dialog :title="$t('form.add')" :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.ph')" prop="ph">
              <el-input type="text" v-model="form.ph" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- 规格 -->
          <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="business_nddw,business_zldw,business_tjdw"></BusinessSelect>
          </el-col>
          <!-- 入库时间 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.rksj')" prop="rksj">
              <el-date-picker v-model="form.rksj" 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="8">
            <el-form-item :label="$t('page.business.resource.gsp.rkl')" prop="rkl">
              <el-input type="number" v-model="form.rkl" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <!-- 库存量单位 -->
          <el-col :span="4">
            <BusinessSelect v-model="form.rkdw"
              dictType="business_nddw,business_zldw,business_tjdw"></BusinessSelect>
          </el-col>
          <!-- 存储条件 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.cctj')" prop="cctj">
              <BusinessSelect v-model="form.cctj" dictType="business_cctj"></BusinessSelect>
            </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="qmbz">
              <el-input type="textarea" v-model="form.qmbz" :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 { xz } from "@/api/business/gsp/gspRkjl"
import { mapGetters } from 'vuex'
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';

export default {
  name: "Xz",
  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'
        }],
        rkl: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        yxq: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        rksj: [{
          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 = {
        id: null,
        mc: null,
        bh: null,
        nd: null,
        nddw: null,
        sxrq: null,
        cctj: null,
        ccwz: null,
        qmrmm: null,
        qmyy: this.$t('page.business.resource.gsp.xzgsprkjl'),
        bjbz: ''
      }
      this.resetForm("form")
    },
    show() {
      this.reset()

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