<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">
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.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.gsp.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.gsp.ph')">
              <el-input type="text" v-model="form.ph" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.gg')">
              <el-input type="text" v-model="form.gg" maxlength="50" disabled> <template slot="append">{{ form.ggdw
                  }}</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.jsrq')">
              <el-input type="text" v-model="form.jsrq" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.ckjz')">
              <el-input type="text" v-model="form.kc" maxlength="50" disabled>
                <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.gsp.yxq')">
              <el-input type="text" v-model="form.yxq" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.lqsj')">
              <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.gsp.md')">
              <el-input type="text" v-model="form.md" maxlength="50" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.gsp.zytj')" prop="ghzytj">
              <el-input type="text" v-model="form.ghzytj" maxlength="50" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.rkl')" prop="rkl">
              <el-input type="text" 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="2" 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" :name="form.ghr1Mc" @change="userSelectGhr1"/>
            </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')">
              <SelectDeptUser v-model="form.ghr2Id" key="ghr2Id" :name="form.ghr2Mc" @change="userSelectGhr2"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.ghr2Id') + $t('form.password')">
              <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')" prop="jsr1Id">
              <SelectDeptUser v-model="form.jsr1Id" key="jsr1Id" :name="form.jsr1Mc" @change="userSelectJsr1" />
            </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')">
              <SelectDeptUser v-model="form.jsr2Id" key="jsr2Id" :name="form.jsr2Mc" @change="userSelectJsr2"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.jsr2Id') + $t('form.password')">
              <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="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-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/gsp/gsp"
import { mapGetters } from 'vuex'
import SelectDeptUser from '@/views/business/comps/select/SelectDeptUser';

export default {
  name: "GspGh",
  components: { SelectDeptUser },
  data() {
    return {
      isBatch: false,
      ids: [],
      selectList: [],
      open: false,
      form: {},
      rules: {
        ghzytj: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        rkl: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ghr1Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ghr1mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        jsr1Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        jsr1mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],

      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName'
    ]),
  },
  created() {
  },
  methods: {
    userSelectGhr1(val) {
      this.form.ghr1Id = val.id;
      this.form.ghr1Mc = val.name;
    },
    userSelectGhr2(val) {
      this.form.ghr2Id = val.id;
      this.form.ghr2Mc = val.name;
    },
    userSelectJsr1(val) {
      this.form.jsr1Id = val.id
      this.form.jsr1Mc = val.name
    },
    userSelectJsr2(val) {
      this.form.jsr2Id = val.id
      this.form.jsr2Mc = val.name
    },
    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.gsp.gh'),
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      this.form.id = row.id
      this.form.mc = row.mc
      this.form.bh = row.bh
      this.form.ph = row.ph
      this.form.gg = row.gg
      this.form.ggdw = row.ggdw
      this.form.yxq = row.yxq
      this.form.jsrq = row.jsrq
      this.form.ffrq = row.ffrq
      this.form.cctj = row.cctj
      this.form.kc = row.kc
      this.form.kcdw = row.kcdw
      this.form.zysx = row.zysx
      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {

          gh(this.form).then(response => {
            this.open = false
            this.$emit('callback')
          })
        }
      })
    }
  }
}
</script>
