<template>
  <div>
    <!-- 申请归还弹窗 -->
    <el-dialog :title="$t('page.business.resource.gyzj.sqguihuan')" :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.gyzj.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.gyzj.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.gyzj.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.gyzj.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.gyzj.cctj')">
              <el-input type="text" v-model="form.cctj" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.ccwz')">
              <el-input type="text" v-model="form.ccwz" maxlength="50" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.ckjz')">
              <el-input type="text" v-model="form.ckl" maxlength="50" disabled> <template slot="append">{{ form.ckldw
              }}</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.cksj')">
              <el-input type="text" v-model="form.ffrq" maxlength="50" disabled />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.md')">
              <el-input type="text" v-if="form.mdOther != '' && form.mdMcs != ''" :value="form.mdMcs + ',' + form.mdOther"
                disabled />
              <el-input type="text" v-else :value="form.mdMcs + form.mdOther" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.zytj')" prop="ghzytj">
              <BusinessSelect v-model="form.ghzytj" dictType="business_zytj"></BusinessSelect>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.rkwz')" prop="rkwz">
              <BusinessSelect v-model="form.rkwz" dictType="business_ccwz"></BusinessSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.rktj')" prop="rktj">
              <BusinessSelect v-model="form.rktj" dictType="business_cctj"></BusinessSelect>
            </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.gyzj.ghr1Id')">
              <el-input type="text" v-model="nickName" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.ghr1Id') + $t('form.password')" prop="ghr1mm">
              <el-input type="password" v-model="form.ghr1mm" 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.gyzj.ghr2Id')" prop="ghr2Id">
              <SelectDeptUser v-model="form.ghr2Id" key="ghr2Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gyzj.ghr2Id') + $t('form.password')" prop="ghr2mm">
              <el-input type="password" v-model="form.ghr2mm" 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 />
            </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 { sqgh, info } from "@/api/business/gyzj/gyzj"
import { mapGetters } from 'vuex'
import SelectDeptUser from '@/views/business/comps/select/SelectDeptUser';
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';

export default {
  name: "Gh",
  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'
        }],
        ghzytj: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ghr1Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ghr1mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ghr2Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ghr2mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName','name'
    ]),
  },
  created() {
  },
  methods: {
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        qmyy: this.$t('page.business.resource.gyzj.sqguihuan'),
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      let that = this
      info({ id: row.id }).then(response => {
        that.form = _.merge({}, response.data, this.form)
        that.form.ghr2Id=null
        that.open = true
      })
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$modal.loading()
          sqgh(this.form).then(response => {
            this.open = false
            this.$emit('callback')
            this.$modal.closeLoading()
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    }
  }
}
</script>
