src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue
@@ -10,13 +10,14 @@
                <a-row :gutter="24">
                  <a-col :md="7" :sm="7">
                    <a-form-item label="文件名称">
                      <a-input placeholder="请输入文件名称" v-model="queryParam.docName"></a-input>
                      <a-input placeholder="请输入文件名称" v-model="queryParam.docName" allow-clear></a-input>
                    </a-form-item>
                  </a-col>
                  <a-col :md="11" :sm="11">
                    <a-form-item label="上传时间">
                      <a-range-picker v-model="queryParam.collectTime"></a-range-picker>
                      <a-range-picker v-model="date" value-format="YYYY-MM-DD"
                                      @change="handleDateChange" allow-clear></a-range-picker>
                    </a-form-item>
                  </a-col>
@@ -30,6 +31,7 @@
            <a-table :columns="columns" :data-source="dataSource" bordered :pagination="false" :loading="loading"
                     :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                     @change="handleTableChange"
                     :scroll="{y:456}" :size="size" rowKey="docId">
            </a-table>
@@ -55,10 +57,10 @@
                  <a-tree blockNode checkable :checkedKeys="checkedKeys" :expandedKeys.sync="expandedKeys"
                          :autoExpandParent="autoExpandParent" @select="handleTreeNodeSelect"
                          :treeData="treeDataSource" @check="handleTreeNodeCheck" @expand="handleTreeNodeExpand">
                    <template slot="title" slot-scope="{ label, parentId, entity, key:treeKey,type}">
                     <span v-if="label.indexOf(searchValue) > -1">{{ label.substr(0, label.indexOf(searchValue)) }}<span
                       class="replaceSearch">{{ searchValue }}</span>{{ label.substr(label.indexOf(searchValue) + searchValue.length) }}</span>
                      <span v-else>{{ label }}</span>
                    <template slot="title" slot-scope="{ title, parentId, entity, key:treeKey,type}">
                     <span v-if="title.indexOf(searchValue) > -1">{{ title.substr(0, title.indexOf(searchValue)) }}<span
                       class="replaceSearch">{{ searchValue }}</span>{{ title.substr(title.indexOf(searchValue) + searchValue.length) }}</span>
                      <span v-else>{{ title }}</span>
                    </template>
                  </a-tree>
                </div>
@@ -83,6 +85,7 @@
  import { getAction } from '@/api/manage'
  import dncApi from '@/api/dnc'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { mapActions } from 'vuex'
  export default {
    name: 'NcDocumentAssignModal',
@@ -112,11 +115,43 @@
              return parseInt(index) + 1
            }
          },
          { title: '文件名称', dataIndex: 'docName', align: 'center', width: 300 },
          {
            title: '文件名称',
            dataIndex: 'docName',
            key: 'docName',
            align: 'center',
            width: 300,
            sorter: true
          },
          { title: '设备编号', dataIndex: 'docCode', align: 'center' },
          { title: '出库状态', dataIndex: 'pullStatus_dictText', align: 'center' },
          { title: '状  态', dataIndex: 'docStatus_dictText', align: 'center' },
          { title: '上传时间', dataIndex: 'createTime', align: 'center', width: 200 }
          {
            title: '出库状态',
            dataIndex: 'pullStatus_dictText',
            key: 'pullStatus',
            align: 'center',
            filters: [
              { text: '未出库', value: 1 },
              { text: '已出库', value: 2 }
            ]
          },
          {
            title: '状  态',
            dataIndex: 'docStatus_dictText',
            key: 'docStatus',
            align: 'center',
            filters: [
              { text: '设计', value: 1 },
              { text: '发布', value: 2 },
              { text: '归档', value: 3 }
            ]
          },
          {
            title: '创建时间',
            dataIndex: 'createTime',
            align: 'center',
            width: 200,
            sorter: true
          }
        ],
        searchValue: '',
        searchInput: '',
@@ -127,6 +162,7 @@
        expandedKeys: [],
        autoExpandParent: true,
        isExpandAllTreeNode: false,
        date: [],
        url: {
          list: '/nc/doc/find/list'
        }
@@ -150,6 +186,9 @@
      }
    },
    methods: {
      ...mapActions(['QueryProduction']),
      // 获取当前工序或工步对应文档列表
      loadData() {
        this.dataSource = []
        if (!this.url.list) {
@@ -157,14 +196,11 @@
          return
        }
        var params = this.getQueryParams()//查询条件
        if (!params) {
          return false
        }
        if (!params) return false
        const { attributionType, attributionId, param } = this.currentDocumentInfo
        params.attributionType = attributionType
        params.attributionId = attributionId
        params.docClassCode = param
        console.log('params', params)
        this.loading = true
        getAction(this.url.list, params).then((res) => {
          if (res.success) this.dataSource = res.result
@@ -174,16 +210,18 @@
        })
      },
      // 获取DNC设备树
      getDocumentAssignDeviceTreeByApi() {
        this.spinning = true
        this.treeDataSource = []
        dncApi.getDocumentAssignDeviceTreeApi(this.currentDocumentInfo)
        this.QueryProduction('DNC')
          .then(res => {
            if (res.success) {
              this.dataList = []
              this.allTreeKeys = []
              this.treeDataSource = res.list
              this.treeDataSource = res.result
              this.generateList(this.treeDataSource)
              this.expandedKeys = this.allTreeKeys
            } else {
              this.$message.warn(res.message)
            }
@@ -193,15 +231,42 @@
          })
      },
      // 时间选择器选择完成后触发
      handleDateChange(value) {
        this.queryParam.startTime = value[0]
        this.queryParam.endTime = value[1]
      },
      /**
       * 表格分页、排序改变、筛选时触发
       * @param pagination 分页器选项
       * @param filters 筛选选项
       * @param sorter 排序选项
       */
      handleTableChange(pagination, filters, sorter) {
        if (sorter.order) {
          this.isorter.column = sorter.field
          this.isorter.order = sorter.order === 'ascend' ? 'asc' : 'desc'
        } else {
          this.isorter.column = 'createTime'
          this.isorter.order = 'desc'
        }
        for (let key in filters) {
          this.filters[key] = filters[key].join(',')
        }
        this.loadData()
      },
      // 指派到设备窗口点击确定指派设备后触发
      handleAssignDocumentToDevice() {
        const { checkedKeys, selectedRowKeys, dataList, $confirm, $notification, currentDocumentInfo, queryParam: { applyReason }, $set } = this
        const { publishFileId, attributionId } = currentDocumentInfo
        const { checkedKeys, selectedRowKeys, dataList, $confirm, $notification, currentDocumentInfo, queryParam: { applyReason }, $destroyAll, $bus } = this
        const { publishFileId, attributionId, attributionType } = currentDocumentInfo
        const paramsArray = []
        // 过滤分组Id仅放入设备Id
        // 过滤车间key仅放入设备key
        const treeCheckedDeviceKeys = []
        checkedKeys.forEach(checkedKey => {
          const deviceId = dataList.find(item => item.key === checkedKey && item.type === 2)
          if (deviceId) treeCheckedDeviceKeys.push(deviceId.key)
          const device = dataList.find(item => item.key === checkedKey && item.type === 2)
          if (device) treeCheckedDeviceKeys.push(device.key)
        })
        if (treeCheckedDeviceKeys.length === 0 || selectedRowKeys.length === 0) {
@@ -218,13 +283,15 @@
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            // 双重循环确定每一组设备与文档的参数
            treeCheckedDeviceKeys.forEach(deviceId => {
              selectedRowKeys.forEach(docId => {
                paramsArray.push({
                  docId,
                  deviceId,
                  fileId: publishFileId,
                  processId: attributionId,
                  attributionId,
                  attributionType,
                  applyReason
                })
              })
@@ -234,7 +301,7 @@
              dncApi.assignDocumentToDeviceApi(item)
                .then(res => {
                  if (res.success) {
                    this.$bus.$emit('reloadMainBottomTableData', 'useDocumentEquipment')
                    $bus.$emit('reloadMainBottomTableData', 'useDocumentEquipment')
                    $notification.success({
                      message: '消息',
                      description: res.message
@@ -252,13 +319,15 @@
                    description: err.message
                  })
                })
                .finally(() => {
                  $destroyAll()
                })
            })
            console.log('paramsArray', paramsArray)
          },
          onCancel: () => {
            $destroyAll()
          }
        })
        // console.log('table', this.selectedRowKeys)
        // console.log('treeCheckedDeviceKeys', treeCheckedDeviceKeys)
        // console.log('currentDocumentInfo', this.currentDocumentInfo)
      },
      /* 输入查询内容变化时触发 */
@@ -302,6 +371,11 @@
        this.checkedKeys = checkedKeys
      },
      /**
       * 树节点选中时触发(模拟树节点复选框选中时的效果)
       * @param selectedKeys 选中节点key
       * @param {node} node 节点对象
       */
      handleTreeNodeSelect(selectedKeys, { node }) {
        node.$el.childNodes[1].click()
      },
@@ -330,14 +404,13 @@
      /**
       * 递归获得所有树节点key
       * @param data
       * @param data 设备树数据
       */
      generateList(data) {
        for (let i = 0; i < data.length; i++) {
          data[i].key = data[i].id
          const node = data[i]
          const key = node.id
          const title = node.label
          const key = node.key
          const title = node.title
          const type = node.type
          this.dataList.push({ key, title, type })
          this.allTreeKeys.push(key)
@@ -350,6 +423,8 @@
        this.expandedKeys = []
        this.selectedRowKeys = []
        this.checkedKeys = []
        this.filters = {}
        this.isorter = Object.assign({}, this.defaultSorter)
      }
    }
  }