<template>
  <div>
    <!-- 钥匙发放弹窗 -->
    <el-dialog :title="$t('page.business.resource.mjy.ysff')" :visible.sync="open" width="1200px" append-to-body
      :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="140px" v-if="open">
        <div class="sbzdtcma"> <input type="text"> <input type="password"> </div>
        <div>
          <el-row style="margin:10px 0px;">
            <el-col :span="24">
              <el-table :data="selectList" border>
                <el-table-column :label="$t('page.business.resource.mjy.mc')" align="left" prop="mc"
                  :show-overflow-tooltip="true" />
                <el-table-column :label="$t('page.business.resource.mjy.bh')" align="left" prop="bh"
                  :show-overflow-tooltip="true" />
                <el-table-column :label="$t('page.business.resource.mjy.ckl')" align="center">
                  <template slot-scope="scope">
                    {{ scope.row.ckl }}{{ scope.row.ckldw }}
                  </template>
                </el-table-column>

                <el-table-column :label="$t('page.business.resource.mjy.ffzytj')" align="center" prop="ffzytj"
                  width="150px" />
                <el-table-column :label="$t('page.business.resource.mjy.ckmz')" align="center" prop="ckmz"
                  width="150px" />
                <el-table-column :label="$t('page.business.resource.mjy.ckmzdw')" align="center" prop="ckmzdw"
                  width="150px" />
                <el-table-column :label="$t('page.business.resource.mjy.lqr1')" align="center" prop="lqr1Mc"
                  width="150px" />
                <el-table-column :label="$t('page.business.resource.mjy.lqr2')" align="center" prop="lqr2Mc"
                  width="150px" />
                <el-table-column :label="$t('page.business.resource.mjy.ffr1')" align="center" prop="ffr1Mc"
                  width="150px" />
                <el-table-column :label="$t('page.business.resource.mjy.ffr2')" align="center" prop="ffr2Mc"
                  width="150px" />
                <el-table-column :label="$t('form.remark')" align="center" prop="ffbz" width="150px" />
                <el-table-column :label="$t('page.business.resource.mjy.md')" align="center" prop="ffxmMc"
                  width="150px" />
              </el-table>
            </el-col>
          </el-row>
        </div>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.zcg')" prop="zcgId">
              <SelectZcg v-model="form.zcgId"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('form.qmyy')" prop="qmyy">
              <el-input type="text" v-model="form.qmyy" 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.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.yslqr1')" prop="lqr1Id">
              <SelectDeptUser v-model="form.lqr1Id" key="lqr1Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.yslqr1')+$t('form.password')" prop="lqr1mm">
              <el-input type="password" v-model="form.lqr1mm" maxlength="20" :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.yslqr2')" prop="lqr2Id">
              <SelectDeptUser v-model="form.lqr2Id" key="lqr2Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.yslqr2')+$t('form.password')" prop="lqr2mm">
              <el-input type="password" v-model="form.lqr2mm" maxlength="20" :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.ffr')">
              <el-input type="text" v-model="nickName" maxlength="50" :placeholder="$t('form.placeholderInput')"
                disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('form.password')" prop="ffrmm">
              <el-input type="password" v-model="form.ffrmm" maxlength="20"  :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 { ysff } from "@/api/business/mjy/mjy"
import { mapGetters } from 'vuex'
import SelectDeptUser from '@/views/business/comps/select/SelectDeptUser';
import SelectZcg from '@/views/business/comps/select/SelectZcg';

export default {
  name: "Ysff",
  components: { SelectDeptUser,SelectZcg},
  data() {
    return {
      ids: [],
      selectList: [],
      open: false,
      form: {},
      rules: {
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        zcgId: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lqr2mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lqr1mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lqr1Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lqr2Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ffrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName','name'
    ]),
  },
  created() {
  },
  methods: {
    showBatch(val) {
      this.reset()
      this.isBatch = true
      this.form.ids = val.map(item => item.id)
      this.selectList = val
      this.open = true
    },
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        ids: null,
        qmyy: this.$t('page.business.resource.mjy.ysff'),
        zcgId: null,
        qmrmm: null,
        remark: null,
        lqr1Id: null,
        lqr2Id: null,
        lqr1mm: null,
        lqr2mm: null,
        ffrId: null,
        ffrmm: null,
      }
      this.resetForm("form")
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let params = this.form
          params.list = this.selectList
          this.$modal.loading()
          ysff(params).then(response => {
            this.open = false
            this.$emit('callback')
            this.$modal.closeLoading()
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    }
  }
}
</script>
