G<template>
  <div>
    <!-- 发放弹窗 -->
    <el-dialog :title="$t('page.business.zykgl.mjy.fafang')" :visible.sync="open" width="1200px" append-to-body
      :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <div :style="isBatch ? 'display:block' : 'display:none'">
          <el-row style="margin:10px 0px;">
            <el-col :span="24">
              <el-table :data="selectList" border>
                <el-table-column :label="$t('page.business.zykgl.mjy.mc')" align="left" prop="mc"
                  :show-overflow-tooltip="true" width="120px" />
                <el-table-column :label="$t('page.business.zykgl.mjy.bh')" align="left" prop="bh"
                  :show-overflow-tooltip="true" width="120px" />
                <el-table-column :label="$t('page.business.zykgl.mjy.zytj')" align="center" width="250px">
                  <template slot-scope="scope">
                    <el-input type="text" v-model="scope.row.zytj" maxlength="50"
                      :placeholder="$t('form.placeholderInput')" />
                  </template>
                </el-table-column>
                <el-table-column :label="$t('page.business.zykgl.mjy.ckmz')" align="center" width="250px">
                  <template slot-scope="scope">
                    <el-input type="text" v-model="scope.row.ckmz" maxlength="50"
                      :placeholder="$t('form.placeholderInput')"><template slot="append">{{ scope.row.ckmzdw }}</template>
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column :label="$t('page.business.zykgl.mjy.md')" align="center" width="250px">
                  <template slot-scope="scope">
                    <el-input type="text" v-model="scope.row.xmId" maxlength="50"
                      :placeholder="$t('form.placeholderInput')" />
                  </template>
                </el-table-column>
                <el-table-column :label="$t('form.remark')" align="center" width="250px">
                  <template slot-scope="scope">
                    <el-input type="text" v-model="scope.row.remark" maxlength="50"
                      :placeholder="$t('form.placeholderInput')" />
                  </template>
                </el-table-column>
                <el-table-column :label="$t('form.operate')" align="center" width="100px" fixed="right">
                  <template slot-scope="scope">
                    <el-button size="mini" type="text" @click="handleSc(scope.row)">{{
                      $t('form.delete') }}</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
          </el-row>
        </div>
        <div v-if="!isBatch">
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('page.business.zykgl.mjy.mc')" prop="mc">
                <el-input type="text" v-model="form.mc" 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('page.business.zykgl.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.zykgl.mjy.zytj')" prop="zytj">
                <el-input type="text" v-model="form.zytj" maxlength="50" :placeholder="$t('form.placeholderInput')" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.zykgl.mjy.ckmz')" prop="ckmz">
                <el-input type="number" v-model="form.ckmz" maxlength="20" :placeholder="$t('form.placeholderInput')">
                  <template slot="append">{{ form.ckmzdw }}</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('page.business.zykgl.mjy.md')" prop="xmId">
                <el-input type="text" v-model="form.xmId" maxlength="50" :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="2" maxlength="500"
                  :placeholder="$t('form.placeholderInput')">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.zykgl.mjy.lqr1')" prop="lqr1Id">
              <el-input type="text" v-model="form.lqr1Id" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('form.password')" prop="lqr1mm">
              <el-input type="password" v-model="form.lqr1mm" 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.zykgl.mjy.lqr2')" prop="lqr2Id">
              <el-input type="text" v-model="form.lqr2Id" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('form.password')" prop="lqr2mm">
              <el-input type="password" v-model="form.lqr2mm" 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.zykgl.mjy.ffr1')" prop="ffr1Id">
              <el-input type="text" v-model="form.ffr1Id" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('form.password')" prop="ffr1mm">
              <el-input type="password" v-model="form.ffr1mm" 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.zykgl.mjy.ffr2')" prop="ffr2Id">
              <el-input type="text" v-model="form.ffr2Id" maxlength="50" :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('form.password')" prop="ffr2mm">
              <el-input type="password" v-model="form.ffr2mm" 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.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 { mjy_ff, mjy_plff } from "@/api/business/mjy/mjy"
import { mapGetters } from 'vuex'
import SelectList from "./SelectList";

export default {
  name: "MjyBj",
  components: { SelectList },
  data() {
    return {
      isBatch: false,
      ids: [],
      selectList: [],
      open: false,
      form: {},
      rules: {
        ffr2mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ffr2Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ffr1mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ffr1Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lqr2mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lqr1mm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lqr2Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lqr1Id: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        xmId: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ckmzdw: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        sdrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        ckmz: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        xmId: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        zytj: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }]


      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName'
    ]),
  },
  created() {
  },
  methods: {
    handleSc(row) {
      const that = this
      this.$modal.confirm(this.$t('form.confirmDelete')).then(function () {
        return delDept(row.deptId)
      }).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)
      let tmp = []
      _.forEach(val, function (item) {
        tmp.push({
          id: item.id,
          mc: item.mc,
          bh: item.bh,
          ckmzdw: item.kcdw,
          zytj: null,
          ckmz: null,
          xmId: null,
          remark: null,
        })
      })
      this.selectList = tmp
      this.open = true
    },
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        id: null,
        ids: null,
        mc: null,
        bh: null,
        ckmzdw: null,
        zytj: null,
        xmId: null,
        ckmz: null,
        lqr1Id: null,
        lqr2Id: null,
        lqr1mm: null,
        lqr2mm: null,
        ffr1Id: null,
        ffr1mm: null,
        ffr2Id: null,
        ffr2mm: null,
        xmId: null,
        qmyy: '领取发放',
        sdrmm: null,
        remark: 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.form.ckmzdw = row.kcdw
      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let params = this.form
          if (this.isBatch) {
            params.list = this.selectList
            if (this.selectList.length <= 0) {
              this.$modal.msgError("请选择要操作的麻精药")
            } else {
              mjy_plff(params).then(response => {
                this.open = false
                this.$emit('callback')
              })
            }
          } else {
            mjy_ff(params).then(response => {
              this.open = false
              this.$emit('callback')
            })
          }
        }
      })
    }
  }
}
</script>
