customEvents.js 3.57 KB
/**
 * @Description: 工艺资源页自定义事件
 * @author wx
 * @date 2021/4/13
 */
import {
  checkoutResourceOverride,
  checkinResource,
  undoCheckoutResourceOverride,
  saveResource
} from '../../../api/resource'
export function changeCustomEvent(view) {
  // #region 详情页主工具栏事件
  // 检出
  this['DxProcessResource-checkOut'] = function(e) {
    if (!this.checkoutState.checkout) {
      checkoutResourceOverride(this.modelName, e.el.propForm.id).then((res) => {
        this.$utils.showMessageSuccess(res.message)
        this.refreshNodeData(res.items)
      }).catch((e) => {
      })
    } else {
      this.$utils.showMessageWarning('此对象已检出!')
    }
  }.bind(view)
  // 检入
  this['DxProcessResource-checkIn'] = function(e) {
    if (this.checkoutState.checkout) {
      checkinResource(this.modelName, e.el.propForm.id)
        .then((res) => {
          this.$utils.showMessageSuccess(res.message)
          this.refreshNodeData(res.items, 'checkIn')
        })
        .catch((e) => {
        })
    } else {
      this.$utils.showMessageWarning('此对象不是检出状态!')
    }
  }.bind(view)
  // 撤销检出
  this['DxProcessResource-cancelCheckOut'] = function(e) {
    if (this.checkoutState.checkout) {
      undoCheckoutResourceOverride(this.modelName, e.el.propForm.id).then((res) => {
        this.$utils.showMessageSuccess(res.message)
        this.refreshNodeData(res.items)
      }).catch((e) => {
      })
    } else {
      this.$utils.showMessageWarning('此对象未检出!')
    }
  }.bind(view)
  // 编辑
  this['DxProcessResource-edit'] = function(e) {
    if (!this.checkoutState.checkout) {
      this.$utils.showMessageWarning('请先进行检出操作!')
      return
    }
    if (!this.checkoutState.isCheckouter) {
      this.$utils.showMessageWarning(`该对象由${this.checkoutState.lockerName}检出`)
      return
    }
    this.$router.push({ path: '/resource/edit', query: { id: e.el.propForm.id, subTypeName: this.typeName || this.basicData.subTypeName, modelName: this.modelName }})
  }.bind(view)
  // 添加工艺资源相关零件
  this['ResourceRelatedPartAdd'] = function(e) {
    if (this.checkoutState.checkout) {
      if (!this.checkoutState.isCheckouter) {
        this.$utils.showMessageWarning(`该对象由${this.checkoutState.lockerName}检出`)
        return
      }
      this.showDialog = true
      this.dialogTitle = '添加工艺资源的相关零件'
      this.componentName = 'deeAddModelCaseDialog'
      this.obj = e.el
    } else {
      this.$utils.showMessageWarning('请先进行检出操作!')
    }
  }.bind(view)
  // 移除工艺资源相关零件
  this['ResourceRelatedPartRemove'] = function(e) {
    if (this.checkoutState.checkout) {
      if (!this.checkoutState.isCheckouter) {
        this.$utils.showMessageWarning(`该对象由${this.checkoutState.lockerName}检出`)
        return
      }
      if (e.el.selectedData.length < 1) {
        this.$utils.showMessageWarning('请选择要删除的项')
        return
      }
      const params = {
        'operator': 'NO_CHANGE',
        'id': this.basicData.id,
        'sourceDxResPartLink': e.el.selectedData.map(r => {
          return {
            'operator': 'REMOVE',
            'id': r.id
          }
        })
      }
      saveResource(params, this.basicData.subTypeName).then(res => {
        this.$utils.showMessageSuccess('删除成功!')
        e.el.selectedData = []
        e.el.getTableData()
      }).catch(e => {
      })
    } else {
      this.$utils.showMessageWarning('请先进行检出操作!')
    }
  }.bind(view)
}