DxPartUsageCondition.vue 3.46 KB
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
/**
* @Description: 使用情况
* @author 李亦康
* @date 2020/10/22
*/
<template>
  <div class="usage-condition">
    <dee-table
      :options="options"
      :data="tableData"
      :columns="columns"
    />
  </div>
</template>

<script>
import { post } from '@/utils/http'
export default {
  name: 'DxPartUsageCondition',
  displayName: '使用情况',
  modelRelationObjs: ['DxPart'],
  components: {},
  props: {
    basicData: {
      type: Object,
      required: true,
      default: () => {
      }
    }
  },
  data() {
    return {
      options: {
        defaultExpandAll: false,
        'tree-props': { children: 'source', hasChildren: 'source' },
        'row-key': 'uid',
        lazy: true,
        load: this.loadNode
      },
      tableData: [],
      columns: [
        { title: '编号', key: 'number', headerAlign: 'center' },
        { title: '名称', key: 'name', headerAlign: 'center' },
        { title: '版本', key: 'displayVersion', headerAlign: 'center' },
        { title: '视图', key: 'dxView.name', headerAlign: 'center' },
        { title: '上下文', key: 'dxContext.name', headerAlign: 'center' },
        { title: '在该产品下的装配数量', key: 'amount', headerAlign: 'center' }
      ]
    }
  },
  computed: {},
  watch: {
    basicData: {
      immediate: true,
      deep: true,
      handler: function(val) {
        // this.tableData = [{ ...val, source: [], uid: this.$utils.guid() }]
        this.loadNode(val)
      }
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    getAmountByLink(links, partData) {
      if (!links || !links.length) {
        return null
      }
      const link = links.find(l => l.targetId === partData.masterId)
      return (link && link.amount) || null
    },
    loadNode(data, node, resolve) {
      if (!data.id) {
        resolve([])
        return
      }
      post(`/DxPart/collectRefPart?direction=UPPER&id=${data.id}`, {
        'indices': ['DxPart'],
        'pageFrom': 1,
        'pageSize': 50,
        'openProps': [{
          'name': 'sourceUsageLinks',
          'pageFrom': 1,
          'pageSize': 50
        }, {
          'name': 'targetUsageLinks',
          'pageFrom': 1,
          'pageSize': 50
        }],
        'sortItem': [{
          'fieldName': 'modifyTime',
          'sortOrder': 'desc'
        }],
        'specSearchVersionType': 'VERSION_NEWEST',
        'searchItems': {
          'operator': 'AND',
          'items': [],
          'children': [{
            'operator': 'AND',
            'items': [{
              'fieldName': 'checkOuted',
              'operator': 'NEQ',
              'value': true
            }]
          }]
        }
      }).then(res => {
        const list = []
        if (res.items && res.items.content && res.items.content[0]) {
          res.items.content.forEach(x => {
            list.push({
              uid: this.$utils.guid(),
              id: x.id,
              number: x.number,
              name: x.name,
              masterId: x.masterId,
              displayVersion: x.displayVersion,
              amount: this.getAmountByLink(x.sourceUsageLinks, data),
              dxView: x.dxView,
              dxContext: x.dxContext,
              source: x.targetUsageLinks ? [] : null
            })
          })
        }
        if (!node) {
          this.tableData = list
        } else {
          resolve(list)
        }
      })
    }
  }
}
</script>
<style lang='scss'>
.usage-condition {
  margin-top: 10px;
  margin-bottom: 20px;
}
</style>