<template>
    <el-dialog :visible.sync="dialogVisible"  center :title="$t('traceMgr.batchFilling')" style="height: 60%" :width="'35%'" append-to-body close-on-press-escape :close-on-click-modal="true">
        <el-form :size="'small'" :model="this" :rules="rules"   validate-on-rule-change  ref="form" label-width="125px">
            <el-row>
                <el-col :span="3">
                    <el-form-item >   </el-form-item>
                </el-col>
                <el-col :span="17">
                    <el-form-item :label="$t('common.TheRegionalCommissionerStatus')"  prop="status" >
                      <select-commissioner-status :queryParas="{sysStatuCode:item.keyId}"
                                                  v-model="status" ></select-commissioner-status>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="3">
                    <el-form-item >   </el-form-item>
                </el-col>
                <el-col :span="17">
                <el-form-item :label="$t('common.TheRegionalCommissionerRemarks')"  prop="remark" >
                    <el-input type="textarea" :rows="4"  placeholder="" v-model="remark" oninput="if(value.length>11)value=value.slice(0,100)"></el-input>
                </el-form-item>
                </el-col>
            </el-row>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button  type="primary" size="medium" :loading="buttonStatus" @click="saveInfo()">{{$t('common.saveBtn')}}</el-button>
            <el-button  type="button" size="medium"  @click="dialogVisible=false">{{$t('common.closeButton')}}</el-button>
        </div>
    </el-dialog>
</template>
<script>
import { BaseSelect, SelectDictionary } from 'newepoch-components'
import authcenterApi from '@/api/authcenterApi.js'
import tracemgrApi from '@/api/tracemgrApi.js'
import SelectCommissionerStatus from '@/components/tracemgr/common/SelectCommissionerStatus'
export default {
  components: {
    BaseSelect,
    SelectDictionary,
    authcenterApi,
    tracemgrApi,
    SelectCommissionerStatus
  },
  props: {
    reload: {
      type: Function
    },
    item: {
      type: Object
    },
    processParas: {
      type: Object
    },
    visible: {
      type: Boolean
    },
    title: {
      type: String
    },
    url: {
      type: String
    },
    needComplete: {
      type: Boolean
    },
    apportionData: {
      type: Function,
      default: null
    },
    gradeId: { type: String }
  },
  data () {
    return {
      remark: '',
      status: '',
      rules: {
        status: [
          { required: true, message: this.$i18n.messages[this.$i18n.locale].traceMgr.Peoplestatus + '！' }
        ],
        remark: [
          { required: true, message: this.$i18n.messages[this.$i18n.locale].traceMgr.inputMemo }
        ]
      },
      buttonStatus: false,
      gradeIndexsArray: []
    }
  },
  computed: {
    dialogVisible: {
      get: function () {
        this.getComp()
        return this.visible
      },
      set: function (val) {
        this.$emit('update:visible', val)
      }
    },
    getTitle: {
      get: function () {
        return this.title
      },
      set: function (val) {
        this.$emit('update:title', val)
      }
    },
    xhr () {
      return this.$xhr
    }
  },
  watch: {
    visible: {
      handler: function (newValue) {
        if (newValue) {
          let $this = this
          $this.$nextTick(() => {
            this.$refs['form'].clearValidate()
          })
        }
      }
    }
  },
  methods: {
    getComp: function () {
      if (!this.visible) {
      }
    },
    completed: function () {
      // 业务界面完成成功时回调，关闭dialog
      this.dialogVisible = false
      // 刷新列表数据
      this.$parent.handleFilter()
    },
    saveInfo: function () {
      let $this = this
      $this.$refs['form'].validate((valid) => {
        if (valid) {
          this.toSave()
        }
      })
    },
    toSave: function () {
      let orderArr = []
      this.item.data.forEach(item => {
        // 封装数据
        orderArr.push({
          keyId: item.assetInfoId,
          assetCode: item.assetCode,
          assetPoolId: item.assetPoolId,
          coreAreaAttache: item.coreAreaAttache,
          status: this.status,
          remark: this.remark,
          dealPersonType: '2'
        })
      })
      this.buttonStatus = true
      tracemgrApi['batchOperationApi'].batchSave(orderArr).then(res => {
        this.buttonStatus = false
        if (res.data) {
          this.success(this.$i18n.messages[this.$i18n.locale].complianceCheck.saveSucMsg)
          this.dialogVisible = false
          this.reload()
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.dontDown)
          this.status = ''
          this.remark = ''
        }
      }, res => {
        this.buttonStatus = false
      })
    }
  }
}
</script>
