G<template>
  <div>
    <!-- 发放弹窗 -->
    <el-dialog :title="$t('page.business.resource.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.resource.mjy.mc')" align="left" prop="mc"
                  :show-overflow-tooltip="true" width="100px" />
                <el-table-column :label="$t('page.business.resource.mjy.bh')" align="left" prop="bh"
                  :show-overflow-tooltip="true" width="100px" />
                <el-table-column :label="$t('page.business.resource.mjy.nd')" align="center">
                  <template slot-scope="scope">
                    {{ scope.row.nd }}{{ scope.row.nddw }}
                  </template>
                </el-table-column>
                <el-table-column :label="$t('page.business.resource.mjy.sxrq')" align="center" prop="sxrq"
                  width="150px" />
                <el-table-column :label="$t('page.business.resource.mjy.cctj')" align="center" prop="cctj"
                  width="130px" />
                <el-table-column :label="$t('page.business.resource.mjy.ccwz')" align="center" prop="ccwz"
                  width="130px" />
                <el-table-column :label="$t('page.business.resource.mjy.ckl')" align="center">
                  <template slot-scope="scope">
                    {{ scope.row.kc }}{{ scope.row.kcdw }}
                  </template>
                </el-table-column>
                <el-table-column :label="$t('page.business.resource.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.resource.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.resource.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 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="12">
              <el-form-item :label="$t('page.business.resource.mjy.mc')">
                <el-input type="text" v-model="form.mc" maxlength="50" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.mjy.bh')">
                <el-input type="text" v-model="form.bh" maxlength="50" disabled />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.mjy.sxrq')">
                <el-input type="text" v-model="form.sxrq" maxlength="50" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.mjy.nd')">
                <el-input type="text" v-model="form.nd" maxlength="50" disabled> <template slot="append">{{ form.nddw
                    }}</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.mjy.cctj')">
                <el-input type="text" v-model="form.cctj" maxlength="50" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.mjy.ccwz')">
                <el-input type="text" v-model="form.ccwz" maxlength="50" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.mjy.ckjz')">
                <el-input type="text" v-model="form.ckl" maxlength="50" disabled> <template slot="append">{{ form.ckldw
                    }}</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.mjy.zytj')" prop="zytj">
                <el-input type="text" v-model="form.zytj" maxlength="50" :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.md')" prop="xmId">
                <el-input type="text" v-model="form.xmId" maxlength="50" :placeholder="$t('form.placeholderInput')" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('page.business.resource.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('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>
        </div>

        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.lqr1')" 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.lqr1') + $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.resource.mjy.lqr2')" 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.lqr2') + $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.resource.mjy.ffr1')" prop="ffr1Id">
              <SelectDeptUser v-model="form.ffr1Id" key="ffr1Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.ffr1') + $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.resource.mjy.ffr2')" prop="ffr2Id">
              <SelectDeptUser v-model="form.ffr2Id" key="ffr2Id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.resource.mjy.ffr2') + $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="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-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 { ff, plff } from "@/api/business/mjy/mjy"
import { mapGetters } from 'vuex'
import SelectList from "./SelectList";
import SelectDeptUser from '@/views/business/comps/select/SelectDeptUser';

export default {
  name: "Ff",
  components: { SelectList, SelectDeptUser },
  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'
        }],
        qmrmm: [{
          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) {
        let a = item
        a.ckmzdw = a.kcdw
        a.zytj = null
        a.ckmz = null
        a.xmIds = null
        a.remark = null
        tmp.push(a)
      })
      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: '领取发放',
        qmrmm: 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.form.sxrq = row.sxrq
      this.form.nd = row.nd
      this.form.nddw = row.nddw
      this.form.cctj = row.cctj
      this.form.ccwz = row.ccwz
      this.form.ckl = row.ckl
      this.form.ckldw = row.ckldw
      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 {
              this.$modal.loading()
              plff(params).then(response => {
                this.open = false
                this.$emit('callback')
                this.$modal.closeLoading()
              }).finally(() => {
                this.$modal.closeLoading()
              })
            }
          } else {
            this.$modal.loading()
            ff(params).then(response => {
              this.open = false
              this.$emit('callback')
              this.$modal.closeLoading()
            }).finally(() => {
              this.$modal.closeLoading()
            })
          }
        }
      })
    }
  }
}
</script>
