<template>
  <div class="livingview">
    <div class="title">
      <!-- 实例编号:{{ mainRuleForm.task_code ? mainRuleForm.task_code : "" }} -->
    </div>
    <div class="form">
      <BaseNewForm
        :spanNumber="24"
        :formRow="mainFormRow"
        :ruleForm="mainRuleForm"
        :isFunBtn="false"
        :lookFlag="true"
      ></BaseNewForm>
    </div>
    <div class="state" v-if="mainRuleForm.result">
      <div class="left">执行结果：</div>
      <span class="right success">{{ mainRuleForm.result }}</span>
    </div>
    <div class="table">
      <div class="screen">
        <div class="title">筛选</div>
        <div class="btn">
          <el-button type="success" round size="mini" @click="screenHanlde(1)"
            >正常</el-button
          >
          <el-button type="info" round size="mini" @click="screenHanlde(2)"
            >删除</el-button
          >
          <el-button type="info" round size="mini" @click="screenHanlde(3)"
            >全部</el-button
          >
        </div>
      </div>
      <div class="main">
        <BaseTable
          ref="mainTable"
          :tableData="tableData"
          :tableColumn="tableColumn"
          :showIndex="true"
          :tabLoading="mainTabLoading"
          @onFunc="tableButtonHandle"
          :border="false"
        >
          <template #sts="{ row }">
            <template v-if="row['sts'] == 'Y'">
              <span class="success">{{ "正常" }}</span>
            </template>
            <template v-else>
              <span class="fail">{{ "删除" }}</span>
            </template>
          </template>
          <template v-slot:repair_pust="{ row }">
            <el-checkbox
              v-model="repair_pust_dist[row['repair_pust']]"
              :disabled="true"
            ></el-checkbox>
          </template>
        </BaseTable>
      </div>
    </div>
    <div class="footer">
      <el-button @click="$router.back()">取消</el-button>
    </div>
  </div>
</template>

<script>
import BaseNewForm from "./compoments/baseNewForm";
import BaseTable from "./compoments/baseTable.vue";
import { getApiModuleApi } from "@/api/apiChunks/index.js";
export default {
  data() {
    return {
      mainTabLoading: false,
      mainFormRow: [
        {
          elCol: [
            {
              type: "input",
              title: "任务名称",
              id: "task_name",
              row: 8,
            },
            {
              type: "input",
              title: "任务类型",
              id: "task_classes",
              row: 8,
            },
            {
              type: "select",
              title: "任务分类",
              id: "3",
              row: 8,
              options: [
                {
                  label: "测试",
                  id: 44,
                },
              ],
            },
          ],
        },
        {
          elCol: [
            {
              type: "input",
              title: "开始时间",
              id: "start_time",
              row: 8,
            },
            {
              type: "input",
              title: "结束时间",
              id: "end_time",
              row: 8,
            },
            {
              type: "input",
              title: "耗时",
              id: "diff_time",
              row: 8,
            },
          ],
        },
        {
          elCol: [
            {
              type: "input",
              title: "原始查询条件",
              id: "8",
              row: 24,
            },
          ],
        },
      ],
      mainRuleForm: {
        task_code: "",
      },
      repair_pust_dist: {
        Y: true,
        N: false,
      },
      tableColumn: [
        {
          id: "sts",
          title: "状态",
        },
        {
          id: "root_app_bill",
          title: "源系统单据",
        },
        {
          id: "root_app_new_data",
          title: "源系统数据详情",
          tooltip: true,
        },
        {
          id: "new_transmit_info",
          title: "最新传输信息",
          tooltip: true,
        },
        {
          id: "new_push_date",
          title: "最新推送时间",
          tooltip: true,
        },
        {
          id: "repair_pust",
          title: "补推标记",
          type: "check",
        },
      ],
      tableData: [],
    };
  },
  components: {
    BaseNewForm,
    BaseTable,
  },
  computed: {
    // 操作框的宽度
    funWidth() {
      return this.funData.length * 70;
    },
  },
  methods: {
    async screenHanlde(type) {
      this.mainTabLoading = true;
      const res = await getApiModuleApi(
        {
          tl: "integrationTaskLogService",
          as: "integrationTaskLog",
          dj: "queryTaskLogDetail",
        },
        {
          type: type,
          task_linving_id: this.$route.query.id,
        }
      );
      this.mainTabLoading = false;
      if (res.status == 200) {
        this.tableData = res.attribute;
      }
    },
    // 初始化界面
    async initPageHandle(id) {
      const res = await getApiModuleApi(
        {
          tl: "integrationTaskLogService",
          as: "integrationTaskLog",
          dj: "queryTaskLogOne",
        },
        {
          id,
        }
      );
      console.log(res);
      if (res.status == 200) {
        this.tableData = res.attribute.details;
        this.mainRuleForm = res.attribute.main;
      }
    },
    tableButtonHandle() {},
  },
  mounted() {
    if (this.$route.query.id) {
      this.initPageHandle(this.$route.query.id);
    }
  },
};
</script>

<style scoped lang="scss">
.livingview {
  width: 100%;
  padding: 20px;
  background-color: #fff;
  border-radius: 20px;
  > .title {
    color: red;
    font-weight: 300;
    margin-bottom: 20px;
  }
  .state {
    margin-top: 20px;
    width: 300px;
    display: flex;
    align-items: center;
  }
  .table {
    background-color: #fff;
    margin-top: 30px;
    > .screen {
      display: flex;
      align-items: center;
      margin-bottom: 30px;
      > .title {
        color: #000;
        font-size: 18px;
        margin-right: 20px;
      }
    }
  }
  .success {
    background-color: #7ec050;
    color: #fff;
    padding: 5px 15px;
    border-radius: 15px;
    font-size: 14px;
  }
  .fail {
    background-color: #919398;
    color: #fff;
    padding: 5px 15px;
    border-radius: 15px;
    font-size: 14px;
  }
  .footer {
    position: fixed;
    bottom: 10px;
    right: 20px;
    background-color: #fff;
    padding: 20px;
    border-radius: 20px;
    display: flex;
    justify-content: flex-end;
  }
}
</style>