<template>
  <div>
    <!-- 处置试剂弹窗 -->
    <el-dialog :title="$t('page.business.resource.sj.cz')" :visible.sync="open" width="1200px" append-to-body
      :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row style="margin:10px 0px;">
          <el-col :span="24">
            <el-table :data="selectList" border>
              <el-table-column :label="$t('page.business.resource.sj.mc')" align="left" prop="mc"
                :show-overflow-tooltip="true" width="120px" />
              <el-table-column :label="$t('page.business.resource.sj.bh')" align="left" prop="bh"
                :show-overflow-tooltip="true" width="120px" />
              <el-table-column :label="$t('page.business.resource.sj.sjczfs')" align="center" width="250px">
                <template slot-scope="scope">
                  <BusinessSelect v-model="scope.row.czfs" dictType="system_business_czfs"></BusinessSelect>
                </template>
              </el-table-column>
              <el-table-column :label="$t('page.business.resource.sj.yuanyin')" align="center">
                <template slot-scope="scope">
                  <el-input type="text" v-model="scope.row.czyy" maxlength="50"
                    :placeholder="$t('form.placeholderInput')" />
                </template>
              </el-table-column>
              <el-table-column :label="$t('page.business.resource.sj.czl')" align="center">
                <template slot-scope="scope">
                  <el-input type="text" v-model="scope.row.czl" maxlength="50"
                    :placeholder="$t('form.placeholderInput')"> <template slot="append">{{ scope.row.kcdw }}</template>
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column :label="$t('form.operate')" align="center" width="150px">
                <template slot-scope="scope">
                  <el-button type="text" @click="handleSc(scope.row)">{{
                    $t('form.delete') }}</el-button>
                </template>
              </el-table-column>
            </el-table>
          </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" maxlength="20"
                :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 { sj_plcz } from "@/api/business/sj/sj"
import { mapGetters } from 'vuex'
import SelectList from "./SelectList";
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';
export default {
  name: "CzBatch",
  components: { SelectList, BusinessSelect },
  data() {
    return {
      ids: [],
      selectList: [],
      open: false,
      form: {},
      rules: {
        czfs: [
          { required: true, message: this.$t('page.business.resource.sj.sjczfs') + this.$t('form.notEmpty'), trigger: "change" },
          { min: 0, max: 50, message: this.$t('page.business.resource.sj.sjczfs') + this.$t('form.lengthLimit') + '50', trigger: 'blur' }
        ],
        czl: [
          { required: true, message: this.$t('page.business.resource.sj.czl') + this.$t('form.notEmpty'), trigger: "change" },
        ],
        remark: [
          { required: true, message: this.$t('page.business.resource.sj.yuanyin') + this.$t('form.notEmpty'), trigger: "change" },
        ],
        qmrmm: [
          { required: true, message: this.$t('form.signerPsw') + this.$t('form.notEmpty'), trigger: "change" },
        ]

      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName'
    ]),
  },
  created() {
  },
  methods: {
    // 删除
    handleSc(row) {
      const that = this
      this.$modal.confirm(this.$t('form.confirmDelete')).then(() => {
        const _index = _.findIndex(that.selectList, function (o) { return o.id === row.id })
        if (_index > -1) {
          that.selectList.splice(_index, 1)
          that.form.ids = that.selectList.map(item => item.id)
        }
      }).catch(() => { })
    },
    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.business.resource.gsp.cz'),
        kcdw: '',
        qmrmm: null
      }
      this.resetForm("form")
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          sj_plcz(this.form).then(response => {
            this.open = false
            this.$emit('callback')
          })
        }
      })
    }
  }
}
</script>
