<template>
  <div>
    <Modal v-model="repairerNamesActModal" width="430">
      <p slot="header">
        {{ modalTitle }}
      </p>
      <Row>
        <!--维护实际时间-->
        <Col span="24" />
        <Form
          id="edit-time-names-forms"
          ref="formObj"
          :model="formObj"
          :rules="ruleValidate"
          inline
          onsubmit="return false"
          :label-width="130"
        >
          <Form-item label="维护报废负责人" prop="scrapNameAct">
            <Select
              v-model="formObj.scrapNameAct"
              filterable
              clearable
              placeholder="请选择报废负责人"
              style="width:245px"
              @on-result="_repairerNamesActChange"
            >
              <Option v-for="item in checkActNameList" :key="item.name" :value="item.name">
                {{ item.name }}
              </Option>
            </Select>
          </Form-item>
        </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button type="ghost" style="margin-left: 8px" @click="_cancel">
          取消
        </Button>
        <Button type="info" @click="_ok">
          确定
        </Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import Global from '../../../../api/config'

const defVal = {
  scrapNameAct: ''
}
export default {
  name: 'LmsMaintainStartTimeAct',

  data() {
    return {
      repairerNamesActModal: false,
      modalTitle: '',
      types: '',
      selectIds: [],
      checkActNameList: [],
      formObj: defVal,
      detailId: '',
      ruleValidate: {
        scrapNameAct: [
          {
            required: true,
            message: '维护报废负责人不能为空',
            trigger: 'change'
          }
        ]
      }
    }
  },
  methods: {
    _open(ids, detailId) {
      this.formObj = defVal
      this.$refs.formObj.resetFields()
      this.detailId = detailId
      this.modalTitle = '维护报废负责人'
      this._openSearchEquipMaintainer()
      this.repairerNamesActModal = true
      this.selectIds = ids
    },
    _cancel() {
      this.repairerNamesActModal = false
    },
    _ok() {
      this.$refs.formObj.validate(valid => {
        if (valid) {
          this._resultChange('保存成功!')
        }
      })
    },
    _resultChange(msg) {
      this.repairerNamesActModal = false
      this.$Message.success(msg)
      this.$emit('on-result-change', this.formObj.scrapNameAct, 'scrapNameAct')
    },
    _openSearchEquipMaintainer() {
      this.$store.dispatch('LmsMarshalManage/userPage').then(() => {
        const registrantList = this.$store.state.LmsMarshalManage.userPage
          .records
        const maintainerArray = []
        for (let i = 0; i < registrantList.length; i++) {
          maintainerArray.push({ name: registrantList[i].realname })
        }
        if (maintainerArray.indexOf(this.formObj.realname) === -1) {
          maintainerArray.push({ name: Global.getUserInfo().realname })
        }
        this.checkActNameList = maintainerArray
      })
    },
    _repairerNamesActChange(data) {
      this.formObj.scrapNameAct = data
    }
  }
}
</script>

<style scoped>
</style>
