<template>
  <div>
    <!-- 处置供试品弹窗 -->
    <el-dialog :title="$t('page.business.resource.gsp.cz')" :visible.sync="open" width="500px" append-to-body
      :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <template>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('page.business.resource.gsp.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.gsp.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>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('page.business.resource.gsp.czfs')" prop="czfs">
                <BusinessSelect v-model="form.czfs" dictType="system_business_czfs"></BusinessSelect>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('page.business.resource.gsp.czl')" prop="czl">
                <el-input type="number" v-model="form.czl" maxlength="50" :placeholder="$t('form.placeholderInput')">
                  <template slot="append">{{ form.kcdw }}</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('page.business.resource.gsp.yuanyin')" prop="remark">
                <el-input type="textarea" :rows="2" v-model="form.remark" maxlength="500"
                  :placeholder="$t('form.placeholderInput')" />
              </el-form-item>
            </el-col>
          </el-row>
        </template>
        <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.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 { cz } from "@/api/business/gsp/gsp"
import { mapGetters } from 'vuex'
import SelectList from "./SelectList";
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';
export default {
  name: "GspCz",
  components: { SelectList, BusinessSelect },
  data() {
    return {
      ids: [],
      selectList: [],
      open: false,
      form: {},
      rules: {
        czfs: [
          { required: true, message: this.$t('page.business.resource.sj.sjczfs') + this.$t('form.notEmpty'), trigger: "change" },
          { min: 0, max: 50, message: this.$t('page.business.resource.sj.sjczfs') + this.$t('form.lengthLimit') + '50', trigger: 'blur' }
        ],
        czl: [
          { required: true, message: this.$t('page.business.resource.sj.czl') + this.$t('form.notEmpty'), trigger: "change" },
        ],
        remark: [
          { required: true, message: this.$t('page.business.resource.sj.yuanyin') + this.$t('form.notEmpty'), trigger: "change" },
        ],
        qmrmm: [
          { required: true, message: this.$t('form.signerPsw') + this.$t('form.notEmpty'), trigger: "change" },
        ]

      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName'
    ]),
  },
  created() {
  },
  methods: {
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        id: null,
        ids: null,
        mc: null,
        bh: null,
        qmyy: this.$t('page.business.resource.gsp.cz'),
        kcdw: '',
        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.form.kcdw = row.kcdw
      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          cz(this.form).then(response => {
            this.open = false
            this.$emit('callback')
          })
        }
      })
    }
  }
}
</script>
