<template>
  <div>
    <!-- 归还弹窗 -->
    <el-dialog :title="$t('page.business.resource.mjy.guihuan')" :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')">
              <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.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.mjy.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.mjy.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.mjy.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.mjy.ckmz')">
              <el-input type="text" v-model="form.ckmz" maxlength="50" disabled> <template slot="append">{{ form.ckmzdw
              }}</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.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-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"></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="ghzytj">
              <BusinessSelect v-model="form.ghzytj" dictType="business_zytj"></BusinessSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.rkmz')" prop="rkmz">
              <el-input type="number" v-model="form.rkmz" maxlength="50" @change="rklChange"
                :placeholder="$t('form.placeholderInput')">
                <template slot="append">{{ form.kcdw }}</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.jsl')" prop="jsl">
              <el-input type="number" v-model="form.jsl" maxlength="50" disabled
                :placeholder="$t('form.placeholderInput')">
                <template slot="append">{{ form.kcdw }}</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.syl')" prop="syl">
              <el-input type="number" v-model="form.syl" 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.ghr1Id')" prop="ghr1Id">
              <SelectDeptUser v-model="form.ghr1Id" key="ghr1Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.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.mjy.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.mjy.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="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" 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" 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 { gh, 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: "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'
        }],
        rkmz: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        jsl: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        syl: [{
          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'
        }],
        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: {
    rklChange() {
      if (!isNaN(this.form.rkmz)) {
        this.form.jsl = _.subtract(parseFloat(this.form.ckmz), parseFloat(this.form.rkmz))
      } else {
        this.form.jsl = ''
      }
    },
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        id: null,
        rkwz: null,
        rktj: null,
        ghzytj: null,
        rkmz: null,
        jsl: null,
        syl: null,
        ghr1Id: null,
        ghr1mm: null,
        ghr2Id: null,
        ghr2mm: null,
        jsr1Id: null,
        jsr1mm: null,
        jsr2Id: null,
        jsr2mm: null,
        qmyy: this.$t('page.business.resource.mjy.guihuan'),
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      let that = this
      info({ id: row.id }).then(response => {
        that.form = _.merge({}, this.form, response.data)
        that.open = true
      })
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$modal.loading()
          gh(this.form).then(response => {
            this.open = false
            this.$emit('callback')
            this.$modal.closeLoading()
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    }
  }
}
</script>
