CreateAgvTask.vue 10.6 KB
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="14">
            <a-form-model-item label="出发工位">
              <a-select
                show-search
                placeholder="请选择出发工位"
                option-filter-prop="children"
                v-model="model.fromPort">
                <a-select-option v-for="item in portList" :key="item.name" :value="item.code">{{
                    item.name
                  }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="14">
            <a-form-model-item label="到达工位">
              <a-select
                show-search
                placeholder="请选择到达工位"
                option-filter-prop="children"
                v-model="model.toPort">
                <a-select-option v-for="item in portList" :key="item.name" :value="item.code">{{
                    item.name
                  }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="emptyDate" icon="reload" style="margin-left: 8px">重置点位</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'createAgvTask:flush'" @click="flush()" type="primary" icon="plus">刷新数据</a-button>
      <a-button v-has="'createAgvTask:createAgvTask'" @click="createAgvTask" type="primary" icon="plus">生成任务</a-button>
<!--      <a-button v-has="'agvTask:export'" type="primary" icon="download" @click="handleExportXls('AGV任务')">导出-->
<!--      </a-button>-->
<!--      <a-upload v-has="'agvTask:import'" name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"-->
<!--                :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--        <j-super-query :fieldList="superFieldList" v-has="'taskHeader:superQuery'"-->
<!--                       @handleSuperQuery="handleSuperQuery"/>-->

<!--      </a-upload>-->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
      <!--        <a-menu slot="overlay">-->
      <!--          <a-menu-item key="1" v-has="'agvTask:delete'" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
      <!--        </a-menu>-->
      <!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
      <!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a> 项-->
      <!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--      </div>-->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :rowClassName="rowClassName"
        class="j-table-force-nowrap"
        @change="handleTableChange">

      </a-table>
    </div>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import AgvTaskModal from './modules/AgvTaskModal'
import AgvTaskDetailList from "@views/system/task/AgvTaskDetailList.vue";
import {getAction} from "@api/manage";
import {completeAgv, createAgvTask, flush} from "@api/api";

export default {
  name: 'CreateAgvTask',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    AgvTaskDetailList,
    AgvTaskModal
  },
  data() {
    return {
      description: '创建AGV任务管理页面',
      firstLoad:0,
      portList: [],
      model:{},
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '物料编码',
          align: "center",
          dataIndex: 'code'
        },
        {
          title: '类别',
          align: "center",
          dataIndex: 'type'
        },
        {
          title: '登记时间',
          align: "center",
          dataIndex: 'checkTime'
        },
        {
          title: '创建人',
          align: "center",
          dataIndex: 'createBy'
        },
        {
          title: '创建日期',
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: '更新人',
          align: "center",
          dataIndex: 'updateBy'
        },
        {
          title: '更新日期',
          align: "center",
          dataIndex: 'updateTime'
        },
      ],
      url: {
        list: "/config/material/list",
        selectAgvPort: "/config/agvPort/agvPortList",
        executeJob: "/sys/quartzJob/execute",
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
    this.selectAgvPort();
  },
  mounted() {
    if(this.firstLoad == 0) {
      this.firstLoad = 1;
      return;
    }
    //页面没加载完,此时methods里的方法找不到,使用定时器模拟点击
    let timeSearch=setInterval(()=>{
      let eleSearch= document.getElementById("search");
      if (eleSearch!=null){
        //调用成功,清除定时器
        clearInterval(timeSearch)
        eleSearch.click();
      }
    },200)
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    createAgvTask() {
      if (this.model.fromPort === "" || this.model.fromPort === undefined) {
        return this.$message.error("出发工位不能为空")
      }
      if (this.model.toPort === "" || this.model.toPort === undefined) {
        return this.$message.error("目标工位不能为空")
      }
      if (this.selectedRowKeys.length < 1) {
        return this.$message.error("没有选择物料数据")
      }
      let params = {
        materialId : this.selectedRowKeys.join(","),
        toPort : this.model.toPort,
        fromPort : this.model.fromPort
      }
      console.log(params)
      createAgvTask(params).then((res) => {
        this.loading = false;
        if (res.success) {
          this.$message.success(res.message);
        } else {
          this.$message.error(res.message);
        }
        this.searchQuery();
      });
    },
    flush() {
      flush().then((res) => {
        if (res.success) {
          this.$message.success(res.message);
        } else {
          this.$message.error(res.message);
        }
        this.searchQuery();
      });
    },
    emptyDate() {
      this.model = {}
    },
    selectAgvPort() {
      getAction(this.url.selectAgvPort).then((res) => {
        if (res.success) {
          this.portList = res.result;
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false;
      })

    },
    rowClassName(record, index) {
      return index === this.selectIndex ? 'Rowactive' : ''
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      this.onClearSelected()
      var params = this.getQueryParams();//查询条件
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    },
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      //这种筛选方式只支持单选
      if (filters && Object.keys(filters).length > 0 && filters.taskType_dictText) {
        this.filters.taskType = filters.taskType_dictText[0];
      }
      if (filters && Object.keys(filters).length > 0 && filters.status_dictText) {
        this.filters.status = filters.status_dictText[0];
      }
      this.ipagination = pagination;
      this.loadData();
    },
    initDictConfig() {
    },
    clickThenSelect(record,index) {
      return {
        on: {
          click: () => {
            this.selectIndex=index
            this.onSelectChange(record.id.toString().split(","), [record]);
          }
        }
      }
    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'code', text: '物料编码', dictCode: ''})
      fieldList.push({type: 'datetime', value: 'checkTime', text: '登记时间', dictCode: ''})
      fieldList.push({type: 'string', value: 'name', text: '物料名称', dictCode: ''})
      fieldList.push({type: 'string', value: 'type', text: '类别', dictCode: ''})
      fieldList.push({type: 'string', value: 'createBy', text: '创建人', dictCode: ''})
      fieldList.push({type: 'datetime', value: 'createTime', text: '创建日期'})
      fieldList.push({type: 'string', value: 'updateBy', text: '更新人', dictCode: ''})
      fieldList.push({type: 'datetime', value: 'updateTime', text: '更新日期'})
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>