<template>
    <div class="eibs-tab">
        <el-form
            ref="paramsForm"
            label-position="right"
            label-width="110px"
            size="small"
        >
            <c-col :span="24" style="margin-top: 10px">
                <!-- ================左=============== -->
                <c-col :span="8">
                    <c-col :span="24">
                        <el-form-item
                            label="Start Processing"
                            prop="wfetsk.tsklist.strflg"
                            style="width: 100%"
                        >
                            <c-select
                                v-model="model.wfetsk.tsklist.strflg"
                                style="width: 100%"
                                placeholder="请选择Automatic Start Flag"
                            >
                                <el-option
                                    v-for="item in codes.strflg"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </c-select>
                        </el-form-item>
                    </c-col>

                    <c-col :span="24">
                        <el-form-item
                            label="Ref No"
                            prop="wfetsk.refno"
                            style="width: 100%"
                        >
                            <c-input
                                v-model="model.wfetsk.refno"
                                placeholder="请输入"
                            ></c-input>
                        </el-form-item>
                    </c-col>
                </c-col>

                <!-- ================中=============== -->
                <c-col :span="8">
                    <c-col :span="24"
                        ><el-form-item
                            label="Initialization File"
                            prop="wfetsk.tsklist.ininam"
                            style="width: 100%"
                        >
                            <c-input
                                v-model="model.wfetsk.tsklist.ininam"
                                placeholder=""
                                style="width: 100%"
                            ></c-input>
                        </el-form-item>
                    </c-col>

                    <c-col :span="24">
                        <el-form-item
                            label="Restart Period"
                            prop="wfetsk.tsklist.redotime"
                            style="width: 100%"
                        >
                            <c-input
                                v-model="model.wfetsk.tsklist.redotime"
                                placeholder="请输入Redotime"
                                style="width: 100%"
                            ></c-input>
                        </el-form-item>
                    </c-col>
                </c-col>

                <!-- ================右=============== -->
                <c-col :span="8">
                    <c-col :span="14">
                        <el-form-item
                            label="Started"
                            prop="wfetsk.tsklist.jobstrdat"
                            style="width: 100%"
                        >
                            <c-date-picker
                                type="date"
                                v-model="model.wfetsk.tsklist.jobstrdat"
                                disabled
                                style="width: 100%"
                                placeholder="请选择"
                            ></c-date-picker>
                        </el-form-item>
                    </c-col>
                    <c-col :span="4" :offset="1">
                        <el-form-item
                            label="h"
                            prop="wfetsk.tsklist.jobstrtimhh"
                            label-width="25px"
                            style="width: 100%"
                        >
                            <c-input
                                v-model="model.wfetsk.tsklist.jobstrtimhh"
                                disabled
                                placeholder="请输入"
                                style="width: 100%"
                            ></c-input>
                        </el-form-item>
                    </c-col>
                    <c-col :span="4" :offset="1">
                        <el-form-item
                            label="min"
                            label-width="25px"
                            style="width: 100%"
                        >
                            <c-input
                                v-model="model.wfetsk.tsklist.jobstrtimmm"
                                placeholder="请输入"
                                disabled
                                style="width: 100%"
                            ></c-input>
                        </el-form-item>
                    </c-col>

                    <c-col :span="14">
                        <el-form-item
                            label="Termination"
                            prop="wfetsk.tsklist.terflg"
                            style="width: 100%"
                        >
                            <c-select
                                v-model="model.wfetsk.tsklist.terflg"
                                style="width: 100%"
                                placeholder="请选择Automatic Termination Flag"
                            >
                                <el-option
                                    v-for="item in codes.terflg"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </c-select>
                        </el-form-item>
                    </c-col>
                    <c-col :span="4" :offset="1">
                        <el-form-item
                            label="h"
                            prop="wfetsk.tsklist.downtimehh"
                            label-width="25px"
                            style="width: 100%"
                        >
                            <c-input
                                v-model="model.wfetsk.tsklist.downtimehh"
                                disabled
                                placeholder="请输入"
                            ></c-input>
                        </el-form-item>
                    </c-col>

                    <c-col :span="4" :offset="1">
                        <el-form-item label="min" prop="" label-width="25px" style="width: 100%">
                            <c-input
                                v-model="model.wfetsk.tsklist.downtimemm"
                                disabled
                                placeholder=""
                                style="width: 100%"
                            ></c-input>
                        </el-form-item>
                    </c-col>
                </c-col>
            </c-col>
            <c-col :span="24" style="text-align: right">
                <c-button
                    size="small"
                    type="primary"
                    style="margin-left: 0"
                    :disabled="buttonFlag"
                    @click="Update"
                    >Update</c-button
                >
                <c-button
                    size="small"
                    type="primary"
                    style="margin-left: 0"
                    :disabled="buttonFlag"
                    @click="Start"
                    >Start</c-button
                >
                <c-button
                    size="small"
                    type="primary"
                    style="margin-left: 0"
                    :disabled="!buttonFlag"
                    @click="Stop"
                    >Stop</c-button
                >
            </c-col>
        </el-form>

        <c-col :span="24" style="margin-top:12px">
            <div style="border-bottom: 10px solid rgb(232, 232, 232)"></div>
        </c-col>

        <!-- <c-col :span="16">
          <span
            v-text="model.wfetsk.tsklist.ininam"
            data-path=".wfetsk.tsklist.ininam"
          >
            Initialization File
          </span>
        </c-col> -->
        <!-- <c-col :span="12">
      <el-form-item label="Automatic Start Flag" prop="wfetsk.tsklist.strflg">
        <c-select
          v-model="model.wfetsk.tsklist.strflg"
          style="width: 100%"
          placeholder="请选择Automatic Start Flag"
        >
        </c-select>
      </el-form-item>
    </c-col>

    <c-col :span="12">
      <c-button size="small" type="primary" @click="onTsklistButstr">
        &Start
      </c-button>
    </c-col>

    <c-col :span="12">
      <c-button size="small" type="primary" @click="onTsklistButstp">
        S&top
      </c-button>
    </c-col>

    <c-col :span="12">
      <span
        v-text="model.wfetsk.tsklist.bcklab"
        data-path=".wfetsk.tsklist.bcklab"
      >
      </span>
    </c-col>

    <c-col :span="12">
      <span v-text="model.wfetsk.labetyextkey" data-path=".wfetsk.labetyextkey">
      </span>
    </c-col>

    <c-col :span="12">
      <el-form-item label="Selected Entity ID" prop="wfetsk.seletyextkey">
        <c-select
          v-model="model.wfetsk.seletyextkey"
          style="width: 100%"
          placeholder="请选择Selected Entity ID"
        >
        </c-select>
      </el-form-item>
    </c-col>

    <c-col :span="12">
      <span
        v-text="model.wfetsk.tsklist.timzonlab"
        data-path=".wfetsk.tsklist.timzonlab"
      >
      </span>
    </c-col>

    <c-col :span="12">
      <span v-text="model.wfetsk.labetgextkey" data-path=".wfetsk.labetgextkey">
      </span>
    </c-col>

    <c-col :span="12">
      <el-form-item label="Selected Entity Group" prop="wfetsk.seletgextkey">
        <c-input
          v-model="model.wfetsk.seletgextkey"
          maxlength="8"
          placeholder="请输入Selected Entity Group"
        ></c-input>
      </el-form-item>
    </c-col>

    <c-col :span="12">
      <el-form-item label="Stream of WFE entries" prop="wfetsk.wfestm">
        <c-input
          v-model="model.wfetsk.wfestm"
          placeholder="请输入Stream of WFE entries"
        ></c-input>
      </el-form-item>
    </c-col>

    <c-col :span="12">
      <c-button size="small" type="primary" @click="onTsklistButexe">
        &Do Entry
      </c-button>
    </c-col>

    <c-col :span="12">
      <c-button size="small" type="primary" @click="onTsklistButupd">
        &Upd. List
      </c-button>
    </c-col>

    <c-col :span="12">
      <c-button size="small" type="primary" @click="onLogdspButdsp">
        &View Log
      </c-button>
    </c-col>

    <c-col :span="12">
      <c-button size="small" type="primary" @click="onTsklistButexi">
        E&xit
      </c-button>
    </c-col> -->
        <c-col :span="24">
            <c-istream-table :list="stmData.data" :columns="stmData.columns">
                <el-table-column fixed="right" label="操作">
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="primary"
                            :disabled="buttonFlag"
                            @click="Entry(scope.$index, scope.row)"
                            >Entry</el-button
                        >
                    </template>
                </el-table-column>
            </c-istream-table>
        </c-col>
    </div>
</template>
<script>
import Api from "~/service/Api";
import commonProcess from "~/mixin/commonProcess";
import CodeTable from "~/config/CodeTable";
import Event from "~/model/Mgrtsk/Event";
import Utils from "~/utils/index";

export default {
    inject: ["root"],
    props: ["model", "codes"],
    mixins: [commonProcess],
    data() {
        return {
            stmData: {
                columns: [
                    '8 1 "Entity" 100 1 0',
                    '7 2 "Object Identification" 390 1 0',
                    '6 3 "Ident" 100 1 0',
                    '1 4 "Service" 100 1 0 3 SRVTXT',
                    '2 5 "Status" 100 1 0 2 WFE:STA',
                    '3 6 "Retries" 100 2 20:1 1 FormatRTR',
                    '4 7 "Target" 200 20 30 1',
                ],
                data: [],
            },
            buttonFlag: false,
            timer: null,
        };
    },
    methods: {
        ...Event,
        Entry(idx, row) {
            const selIds = [idx + 1];
            const selDst = "wfetsk.wfestm"; //列表对应后台模型中的stream
            let params = { selDst, selIds };
            this.executeRule("wfetsk.tsklist.butexe", params).then((res) => {
                if (res.respCode == SUCCESS) {
                    Utils.copyValueFromVO(this.model, res.data);
                } else {
                    const h = this.$createElement;
                    const msg = res.respMsg || "请求执行失败!";
                    this.$notify.error({
                        title: "错误",
                        message: h(
                            "p",
                            { style: "word-break:break-all;" },
                            msg
                        ),
                    });
                }
            });
        },
        Update() {
            let rtnmsg = this.executeRule("wfetsk.tsklist.butupd");
            if (rtnmsg.respCode == SUCCESS) {
                //TODO 处理数据逻辑
            }
        },
        Start() {
            this.buttonFlag = true;
            let rtnmsg = this.executeRule("wfetsk.tsklist.butstr");
            if (rtnmsg.respCode == SUCCESS) {
                //TODO 处理数据逻辑
            }
            //定时任务
            var timeVal = this.model.wfetsk.tsklist.redotime * 1000;
            var that = this;
            this.timer = setInterval(function () {
                let rtnmsg = that.executeRule("wfetsk.tsklist.butstr");
                if (rtnmsg.respCode == SUCCESS) {
                    //TODO 处理数据逻辑
                }
            }, timeVal);
        },
        Stop() {
            this.buttonFlag = false;
            clearInterval(this.timer);
            let rtnmsg = this.executeRule("wfetsk.tsklist.butstp");
            if (rtnmsg.respCode == SUCCESS) {
                //TODO 处理数据逻辑
            }
        },
    },
    created: function () {},
    watch: {
        "model.wfetsk.wfestm": function () {
            this.stmData.data = this.model.wfetsk.wfestm.rows;
        },
    },
};
</script>
<style scope>
/* .m-table-search-form .el-form-item__content {
  width: calc(100% - 110px);
} */
</style>
