<template>
  <div>
    <!-- 编辑弹窗 -->
    <el-dialog :title="$t('form.edit')" :visible.sync="open" width="700px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <template>
          <el-row>
            <!-- 名称 -->
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.sj.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.sj.bh')" prop="bh">
                <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="8">
              <el-form-item :label="$t('page.business.resource.sj.nd')" prop="nd">
                <el-input type="text" v-model="form.nd" maxlength="50" :placeholder="$t('form.placeholderInput')" />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <BusinessSelect dictType="system_business_zldw" v-model="form.nndw" />
            </el-col>
            <el-col :span="12">
              <!-- 失效日 -->
              <el-form-item :label="$t('page.business.resource.sj.sxr')" prop="sxr">
                <el-date-picker v-model="form.sxr" type="datetime" format="yyyy-MM-dd HH:mm"
                  value-format="yyyy-MM-dd HH:mm:ss" :placeholder="$t('form.placeholderInput')">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </template>
        <el-row>
          <el-col :span="12">
            <!-- 存储条件 -->
            <el-form-item :label="$t('page.business.resource.sj.cctj')" prop="cctj">
              <BusinessSelect dictType="system_business_cctj" v-model="form.cctj" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 存储位置 -->
            <el-form-item :label="$t('page.business.resource.sj.ccwz')" prop="ccwz">
              <BusinessSelect dictType="system_business_ccwz" v-model="form.ccwz" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('form.qmyy')">
              <el-input type="text" v-model="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="sdrmm">
              <el-input type="text" v-model="form.sdrmm" 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="qmbz">
              <el-input type="textarea" v-model="form.qmbz" :rows="2" 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 { sj_bj } from "@/api/business/sj/sj"
import { mapGetters } from 'vuex'
import SelectList from "./SelectList";
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';

export default {
  name: "SjBj",
  components: { SelectList, BusinessSelect },
  data() {
    return {
      isBatch: false,
      ids: [],
      selectList: [],
      open: false,
      form: {},
      rules: {
        sdrmm: [{
          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 = {
        id: null,
        ids: null,
        mc: null,
        bh: null,
        qmyy: this.$t('page.form.edit'),
        sdrmm: null
      }
      this.resetForm("form")
    },
    show(row) {
      this.reset()
      this.isBatch = false
      this.form.ids = []
      this.selectList = []
      this.form.id = row.id
      this.form.mc = row.mc
      this.form.bh = row.bh
      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          sj_bj(this.form).then(response => {
            this.open = false
            this.$emit('callback')
          })
        }
      })
    }
  }
}
</script>
