<template>
  <a-modal
    v-model="visible"
    title="启动任务列表"
    :width="500"
    wrapClassName="batch_start_task"
    okText="确定"
    cancelText="取消"
    @ok="startSubmit"
  >
    <div class="task_list">
      <p class="title"><a-icon type="info-circle" theme="filled" style="color:#2D5AFA"/>&nbsp;请确认是否启动以下任务：</p>
      <vxe-table
        ref="taskList"
        show-overflow
        show-header-overflow
        border="inner"
        resizable
        :row-config="{ isHover: true }"
        :data="dataList"
        height="400"
      >
        <vxe-column
          type="checkbox"
          width="60"
          align="center"
          key="checkbox"
        ></vxe-column>
        <vxe-column field="jobDesc" title="任务名称"> </vxe-column>
      </vxe-table>
    </div>
  </a-modal>
</template>

<script>
const $dispatchcenter = require("@/api/dispatchcenter");

export default {
  props: {
    show: [Boolean],
    info: [Object, Array]
  },
  data() {
    return {
      dataList: []
    };
  },
  computed: {
    visible: {
      get() {
        return this.show;
      },
      set(val) {
        this.$emit("update:show", val)
      }
    }
  },
  watch: {
    visible(val) {
      if(val) {
        this.dataList = this.info;
        this.$nextTick(() => {
          this.$refs.taskList.setAllCheckboxRow(true);
        })
      }
    }
  },
  created() {},
  methods: {
    startSubmit() {
      let list = this.$refs.taskList.getCheckboxRecords();
      if(list.length == 0) {
        this.$message.warn("请选择数据");
        return false;
      } else {
        let params = list.map(item => {
          let p = item.executorParam ? item.executorParam.split(",") : [];
          return {
            jobId: item.jobInfoId,
            jobType: item.jobType,
            executorParam: `${p[0] || ""},${p[1] || ""},${p[2] || undefined},${p[3] || ""}`,
            transforms: [],
            executeLocation: undefined
          }
        })
        console.log(params)
        $dispatchcenter.batchStart(params).then(() => {
          this.visible = false;
          this.$message.success("批量启动任务成功");
          this.$emit("callback");
        })
      }

    }
  }
};
</script>
<style lang="less" scoped>
.batch_start_task {
  .title {
    font-size: 16px;
    margin-bottom: 6px;
  }
}
</style>