<template>
  <div>
    <!-- 入库弹窗 -->
    <el-dialog :title="$t('page.business.resource.mjy.ruku')" :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" show-password> </div>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.mc')">
              <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')">
              <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.sxrq')">
              <el-input type="text" v-model="form.sxrq" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.nd')">
              <el-input type="text" v-model="form.nd" maxlength="50" disabled> <template slot="append">{{ form.nddw
              }}</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.sswjj')">
              <el-input type="text" v-model="form.studyMc" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.ssbd')">
              <el-input type="text" v-model="form.bdMc" 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.rkwz')" prop="rkwz">
              <BusinessSelect v-model="form.rkwz" dictType="business_ccwz" @change="rkwzChange"></BusinessSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.rktj')" prop="rktj">
              <BusinessSelect v-model="form.rktj" dictType="business_cctj"></BusinessSelect>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.zytj')" prop="zytj">
              <BusinessSelect v-model="form.zytj" dictType="business_zytj"></BusinessSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.rkmz')" prop="rkl">
              <el-input type="number" v-model="form.rkl" 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('form.remark')" prop="remark">
              <el-input type="textarea" v-model="form.remark" :rows="5" maxlength="500"
                :placeholder="$t('form.placeholderInput')">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.qmr1Id')" prop="qmr1Id">
              <SelectDeptUser v-model="form.qmr1Id" key="qmr1Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.qmr1Id') + $t('form.password')" prop="qmr1mm">
              <el-input  type="password" show-password v-model="form.qmr1mm" maxlength="20"
                :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.mjy.qmr2Id')" prop="qmr2Id">
              <SelectDeptUser v-model="form.qmr2Id" key="qmr2Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.qmr2Id') + $t('form.password')" prop="qmr2mm">
              <el-input  type="password" show-password v-model="form.qmr2mm" maxlength="20"
                :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.mjy.jsr1Id')" >
              <el-input type="text" v-model="nickName" maxlength="50" disabled
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.jsr1Id') + $t('form.password')" prop="jsr1mm">
              <el-input  type="password" show-password v-model="form.jsr1mm" maxlength="20"
                :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.mjy.jsr2Id')" prop="jsr2Id">
              <SelectDeptUser v-model="form.jsr2Id" key="jsr2Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.jsr2Id') + $t('form.password')" prop="jsr2mm">
              <el-input  type="password" show-password v-model="form.jsr2mm" 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.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-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 { rk, info } from "@/api/business/mjy/mjy"
import { mapGetters } from 'vuex'
import SelectDeptUser from '@/views/business/comps/select/SelectDeptUser';
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';

export default {
  name: "Rk",
  components: { SelectDeptUser, BusinessSelect },
  data() {
    return {
      isBatch: false,
      ids: [],
      selectList: [],
      open: false,
      form: {},
      rules: {
        rkwz: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        rktj: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        zytj: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        rkl: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        qmr1Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        qmr1mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        qmr2Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        qmr2mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        jsr1Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        jsr1mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        jsr2Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        jsr2mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName', 'name'
    ]),
  },
  created() {
  },
  methods: {
     rkwzChange(val){
      this.form.rktj=val.wc
    },
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        id: null,
        rkwz: null,
        rktj: null,
        zytj: null,
        rkl: null,
        qmr1Id: null,
        qmr1mm: null,
        qmr2Id: null,
        qmr2mm: null,
        jsr1Id: null,
        jsr1mm: null,
        jsr2Id: null,
        jsr2mm: null,
        qmyy: this.$t('page.business.resource.mjy.mjyrk'),
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      let that = this
      info({ id: row.id }).then(response => {
        that.form = _.merge({}, that.form, response.data)
        that.form.rkl=that.form.kc
        that.open = true
      })
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$modal.loading()
          rk(this.form).then(response => {
            this.open = false
            this.$emit('callback')
            this.$modal.closeLoading()
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    }
  }
}
</script>
