<template>
  <div>
    <!-- 编辑弹窗 -->
    <el-dialog :title="$t('form.edit')" :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')" prop="mc">
              <el-input type="text" v-model="form.mc" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.bh')" prop="glyj">
              <el-input type="text" v-model="form.bh" maxlength="50" disabled
                :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.nd')" prop="nd">
              <el-input type="number" v-model="form.nd" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.nddw')" prop="nddw">
              <BusinessSelect v-model="form.nddw" dictType="business_nddw"></BusinessSelect>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.sxrq')" prop="sxrq">
                <el-date-picker style="width: 100%;" v-model="form.sxrq" type="datetime"
                :placeholder="$t('form.placeholderSelect')" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.cctj')" prop="cctj">
              <BusinessSelect v-model="form.cctj" dictType="business_cctj"></BusinessSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.ccwz')" prop="ccwz">
              <BusinessSelect v-model="form.ccwz" dictType="business_ccwz"></BusinessSelect>
            </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-col :span="12">
            <el-form-item :label="$t('form.signer')">
              <el-input type="text" v-model="nickName" 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.password')" prop="qmrmm">
              <el-input type="password" v-model="form.qmrmm" autocomplete="off"  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.remark')" prop="bjbz">
              <el-input type="textarea" v-model="form.bjbz" :rows="5" maxlength="500"
                :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 { bj } from "@/api/business/mjy/mjy"
import { mapGetters } from 'vuex'
import SelectList from "./SelectList";
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';

export default {
  name: "Bj",
  components: { SelectList, BusinessSelect },
  data() {
    return {
      open: false,
      form: {},
      rules: {
        mc: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        bh: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        nd: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        nddw: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        sxrq: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        cctj: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ccwz: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName','name'
    ]),
  },
  created() {
  },
  methods: {
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        id: null,
        mc: null,
        bh: null,
        nd: null,
        nddw: null,
        sxrq: null,
        cctj: null,
        ccwz: null,
        qmrmm: null,
        qmyy: this.$t('form.edit'),
        bjbz: ''
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      this.form.id = row.id
      this.form.mc = row.mc
      this.form.bh = row.bh
      this.form.nd = row.nd
      this.form.nddw = row.nddw
      this.form.sxrq = row.sxrq
      this.form.cctj = row.cctj
      this.form.ccwz = row.ccwz
      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$modal.loading()
          bj(this.form).then(response => {
            this.open = false
            this.$emit('callback')
            this.$modal.closeLoading()
          }).finally(() => {
            this.$modal.closeLoading()
          })
        }
      })
    }
  }
}
</script>
