zenglf
2023-09-18 92ff846fb659c62037a32b1d8c15eae9df9d9b54
src/views/eam/modules/equipmentReturn/EquipmentUnloadingReturnDetailModal.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,468 @@
<template>
  <a-modal
    :title='title'
    :width='1200'
    :visible='visible'
    :maskClosable='false'
    @ok='handleOk'
    cancelText='关闭'
    @cancel='handleCancel'
    :confirmLoading='confirmLoading'
  >
    <a-spin :spinning='confirmLoading'>
      <a-form-model :form='form' ref='form' :model='model' :rules='validatorRules'>
        <a-row :span='24'>
          <a-col :span='12'>
            <a-form-model-item label='单据号' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='num'>
              <a-input v-model='model.num' placeholder='请输入单据号' :disabled="disableSubmit"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='业务类型' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='businessType'>
              <j-dict-select-tag
                allow-clear
                v-model='model.businessType'
                :placeholder="disableSubmit?'':'请选择类型'"
                :triggerChange='true'
                :disabled="disableSubmit"
                dictCode='business_type'
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :span='24'>
          <a-col :span='12'>
            <a-form-model-item label='使用部门' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='useDepartId'>
              <a-select
                placeholder='请选择'
                v-model='model.useDepartId'
                :disabled="disableSubmit"
                :options='this.departVoList'
                style='width: 100%'
              />
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='备注' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='remark'>
              <a-textarea v-model='model.remark'  placeholder='请输入备注' :disabled="disableSubmit"></a-textarea>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
    <a-button
      type='primary'
      :style="{ marginRight: '8px',marginBottom:'8px' }"
      :loading='confirmLoading'
      :disabled="disableSubmit"
      @click='selectInspectionProjects()'
    >设备信息
    </a-button>
    <a-table
      ref='table'
      bordered
      size='middle'
      rowKey='id'
      :columns='columns'
      :dataSource='dataSource'
      :scroll='{ x: 1450, y: 1000 }'
    >
      <template
        v-for='col in columns'
        :slot='col.dataIndex'
        slot-scope='text, record, index'
      >
        <div :key='col.dataIndex'>
          <a-date-picker
            :value='text'
            :disabled="disableSubmit"
            v-if="col.dataIndex == 'actualReturnDate'"
            format='YYYY-MM-DD HH:mm:ss'
            @change='(e)=>handleChange(e, record.key, col, index)'
          />
        </div>
      </template>
      <span
        slot='action'
        slot-scope='text, record, index'
      >
        <a-popconfirm
          title='确定删除吗?'
          :disabled="disableSubmit"
          @confirm='() => handleDelete(text,record, index)'
        >
          <a>删除</a>
        </a-popconfirm>
      </span>
    </a-table>
    <template slot='footer'>
      <a-button
        :style="{marginRight: '8px'}"
        @click='handleCancel()'
      >
        å…³é—­
      </a-button>
      <a-button
        @click='handleOk()'
        type='primary'
        :disabled="disableSubmit"
        :loading='confirmLoading'
      >确定
      </a-button>
    </template>
    <j-select-equipment-modal ref='equipmentUnloadingBorrowModalForm'></j-select-equipment-modal>
  </a-modal>
</template>
<script>
import { getAction, postAction, requestPut } from '@/api/manage'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import Tooltip from 'ant-design-vue/es/tooltip'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import JSelectEquipmentModal from '@views/common/JSelectEquipmentModal'
export default {
  name: 'EquipmentUnloadingReturnDetailModal',
  components: {
    JMultiSelectTag,
    Tooltip,
    JSelectEquipmentModal
  },
  data() {
    return {
      replaceFields: {
        value: 'key'
      },
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          },
          width: 100
        },
        {
          title: '设备编码',
          align: 'center',
          width: 100,
          dataIndex: 'equipmentNum'
        },
        {
          title: '设备名称',
          align: 'center',
          width: 150,
          dataIndex: 'equipmentName'
        },
        {
          title: '规格',
          width: 100,
          align: 'center',
          dataIndex: 'specification'
        },
        {
          title: '型号',
          width: 100,
          align: 'center',
          dataIndex: 'model'
        },
        {
          title: '技术状态',
          align: 'center',
          width: 100,
          dataIndex: 'technicalStatus'
        },
        {
          title: '实际领借日期',
          align: 'center',
          width: 150,
          dataIndex: 'actualBorrowDate'
        },
        {
          title: '实际归还日期',
          align: 'center',
          width: 150,
          dataIndex: 'actualReturnDate',
          scopedSlots: {
            customRender: 'actualReturnDate'
          }
        },
        {
          title: '责任班组',
          align: 'center',
          dataIndex: 'responsibilityTeamName'
        },
        {
          title: '责任人',
          align: 'center',
          dataIndex: 'responsibilityUserName'
        },
        {
          title: '操作',
          align: 'center',
          fixed: 'right',
          width: 150,
          dataIndex: 'action',
          scopedSlots: {
            customRender: 'action'
          }
        }
      ],
      title: '操作',
      visible: false,
      visible4Confirm: false,
      disableSubmit: false,
      codeDisable: true,
      model: {},
      dateFormat: 'YYYY-MM-DD HH:mm:ss',
      workOrder: {
        value: '',
        text: '',
        title: ''
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        num: [
          { required: true, message: '请输入单号!' },
          { validator: (rule, value, callback) => validateDuplicateValue('mom_eam_equipment_unloading', 'num', value, this.model.id, callback) }
        ],
        businessType: [
          { required: true, message: '请选择业务类型!' }
        ],
        useDepartId: [
          { required: true, message: '请选择使用部门!' }
        ]
      },
      url: {
        add: '/eam/equipmentUnloading/add',
        edit: '/eam/equipmentUnloading/edit',
        departVoList: 'eam/equipmentUnloadingReturnDetail/getDepart'
      },
      departVoList: [],
      dataSource: []
    }
  },
  created() {
    //备份model原始值
    this.getInDepartList()
  },
  mounted() {
    this.$bus.$on('selectionRows', (data) => {
      for (let i = 0; i < data.length; i++) {
        this.dataSource.push({
          id: data[i].id,
          equipmentId: data[i].id,
          equipmentNum: data[i].num,
          equipmentName: data[i].name,
          model: data[i].model,
          specification: data[i].specification,
          technicalStatus: data[i].technologyStatus_dictText,
          responsibilityTeamId: data[i].teamId,
          responsibilityUserId: data[i].functionary,
          actualBorrowDate:data[i].updateTime,
          responsibilityUserName:data[i].functionary_dictText,
          responsibilityTeamName:data[i].teamId_dictText,
        })
      }
    })
  },
  methods: {
    /*获取部门列表*/
    getInDepartList() {
      getAction(this.url.departVoList).then((res) => {
        if (res.success) {
          this.departVoList = res.result
        } else {
          this.$message.warn(res.message)
        }
      })
    },
    //选择点检项目
    selectInspectionProjects: function() {
      let ids = []
      for (let i = 0; i < this.dataSource.length; i++) {
        ids.push(this.dataSource[i].equipmentId)
      }
      this.$refs.equipmentUnloadingBorrowModalForm.showModals(ids)
      this.$refs.equipmentUnloadingBorrowModalForm.title = '选择设备信息'
      this.$refs.equipmentUnloadingBorrowModalForm.disableSubmit = false
    },
    add() {
      this.model.unloadingType = 'return'
      this.edit(this.model, { equipmentUnloadingReturnDetailList: [] })
    },
    edit(record) {
      let that = this
      that.dataSource = []
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      if (record.equipmentUnloadingReturnDetailList != undefined) {
        const temp = [...record.equipmentUnloadingReturnDetailList]
        that.dataSource = temp
      }
      that.$nextTick(() => {
        that.form.setFieldsValue(pick(that.model, 'num', 'inEnterpriseId', 'outEnterpriseId', 'remark'))
      })
      if (record.id) {
        this.codeDisable = true
      } else {
        this.codeDisable = false
      }
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    handleChange(value, key, column, index) {
      let that = this
      const temp = [...that.dataSource]
      const target = temp.filter(item => key === item.key)[index]
      if (target) {
         if(column.dataIndex == 'actualReturnDate'){
          target[column.dataIndex] = value
        }
        //显示带过来的数据
        that.dataSource = temp
      }
    },
    handleOk() {
      const that = this
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let formData = Object.assign(this.model, valid)
          formData.equipmentUnloadingReturnDetailList = that.dataSource
          if (that.dataSource.length ===0){
            that.confirmLoading = false
            that.$message.warning("请添加归还明细")
            return
          }
          for (let annItem of that.dataSource) {
            if (annItem.actualReturnDate == undefined || annItem.actualReturnDate == null || annItem.actualReturnDate == '') {
              that.$message.warning('请填写实际归还时间')
              that.confirmLoading = false
              return
            }
          }
          let obj
          if (!this.model.id) {
            obj = postAction(this.url.add, formData)
          } else {
            obj = requestPut(this.url.edit, formData, { id: this.model.id })
          }
          obj.then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            this.model = {}
            that.confirmLoading = false
            this.$set(this.model, 'auditStatus', 'notSubmitted')
            that.close()
          })
        }
      })
    },
    handleDelete(text, record, index) {
      this.dataSource.splice(index, 1)
    }
  }
}
</script>
<style lang='less' scoped>
/deep/ .frozenRowClass {
  color: #c9c9c9;
}
.fontweight {
  font-weight: bold;
}
.ant-btn {
  padding: 0 10px;
  margin-left: 3px;
}
.ant-form-item-control {
  line-height: 0px;
}
/** ä¸»è¡¨å•行间距 */
.ant-form .ant-form-item {
  margin-bottom: 10px;
}
/** Tab页面行间距 */
.ant-tabs-content .ant-form-item {
  margin-bottom: 0px;
}
</style>