<template>
  <div>
    <!-- 修改库存弹窗 -->
    <el-dialog :title="$t('page.business.resource.mjy.xgkc')" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" v-if="open">
        <div class="sbzdtcma"> <input type="text"> <input type="password"> </div>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.mc')" prop="mcbj">
              <el-input type="text" v-model="form.mc" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.bh')" prop="glyj">
              <el-input type="text" v-model="form.bh" maxlength="50" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.kc')" prop="kc">
              <el-input type="number" v-model="form.kc" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.kcdw')" prop="kcdw">
              <BusinessSelect v-model="form.kcdw" dictType="business_tjdw"></BusinessSelect>
            </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.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-row>
          <el-col :span="24">
            <el-form-item :label="$t('form.remark')" >
              <el-input type="textarea" v-model="form.kcbjbz" :rows="5" 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 { xgkc } from "@/api/business/mjy/mjy"
import { mapGetters } from 'vuex'
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';
import SelectList from "./SelectList";

export default {
  name: "Xgkc",
  components: { SelectList,BusinessSelect },
  data() {
    return {
      open: false,
      form: {},
      rules: {
        kc: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        kcdw: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName','name'
    ]),
  },
  created() {
  },
  methods: {
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        id: null,
        mc: null,
        bh: null,
        kc: null,
        kcdw: null,
        qmrmm: null,
        qmyy: this.$t('page.business.resource.mjy.xgkc'),
        kcbjbz: ''
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      this.form.id = row.id
      this.form.mc = row.mc
      this.form.bh = row.bh
      this.form.kc = row.kc
      this.form.kcdw = row.kcdw
      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$modal.loading()
          xgkc(this.form).then(response => {
            this.open = false
            this.$emit('callback')
           this.$modal.closeLoading()
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    }
  }
}
</script>
