<template>
  <div class="app-container">
    <div style="background-color: #fff;padding: 20px;border-radius: 10px; padding-bottom: 0;">
                  <p style="margin: 0; font-weight: 800;font-size: 16px;color: #343434;display: flex;align-items: center;margin-bottom: 20px;border-left: 6px solid #03BF8A;margin-left: -20px;">
                    <!-- <img src="../../../assets/images/icon_htgl_btzs.png" alt="" style="width: 16px;height: 20px;"> -->
                   <span style="margin-left: 10px;">搜索条件</span>
                  </p>
                  <div style="padding-bottom: 0;margin-bottom: 20px;">
    <el-form class="qucheu" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="任务编号" prop="taskNum">
        <el-input
          v-model="queryParams.taskNum"
          placeholder="请输入任务编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item style="border: 0;">
        <el-button style="background-color: #03BF8A; border-color: #03BF8A;" type="primary"  size="mini" @click="handleQuery">搜索</el-button>
        <el-button  size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </div>
    </div>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manage:taskManage:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manage:taskManage:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manage:taskManage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          size="mini"
          @click="handleExport"
          v-hasPermi="['manage:taskManage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :height="tableMaxHeight" v-loading="loading" :data="taskManageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="任务编号" align="center" prop="taskNum" />
      <el-table-column label="任务描述" align="center" prop="taskDetails" />
      <el-table-column label="通道ID" align="center" prop="channelId" />
      <el-table-column label="视频地址" align="center" prop="videoAddress" />
      <el-table-column label="上报地址" align="center" prop="reportAddress" />
      <el-table-column label="算法编号" align="center" prop="algorithmSet" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
                                   style="width: 42px;height: 26px;
                                   background: #E5F9F3;
                                          border-radius: 4px;border: 1px solid #03BF8A;color: #03BF8A;
                                   "
                                  type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manage:taskManage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
                                   type="text"
                                   style="width: 42px;height: 26px;background: #FFF1EA;
                                          border-radius: 4px;border: 1px solid #FE570E;color: #FE570E;"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manage:taskManage:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改任务管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="任务编号" prop="taskNum">
              <el-input v-model="form.taskNum" placeholder="请输入任务编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="视频地址" prop="videoAddress">
              <el-input v-model="form.videoAddress" placeholder="请输入视频地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上报地址" prop="reportAddress">
              <el-input v-model="form.reportAddress" placeholder="请输入上报地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="通道编号" prop="channelId">
               <el-select style="width: 100%;" v-model="form.channelId" placeholder="请选择通道ID">
                  <el-option
                  v-for="dict in channelNumberList "
                  :key="dict.channelId"
                  :label="dict.channelNum"
                  :value="dict.channelId"
                  ></el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="算法编号" prop="algorithmSet">
              <el-select multiple  style="width: 100%;" v-model="form.algorithmSet" placeholder="请选择算法编号">
                                <el-option
                                v-for="dict in dict.type.algorithm_settings"
                                :key="dict.value"
                                :label="dict.label"
                                :value="dict.value"
                                ></el-option>
               </el-select>
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="任务描述" prop="taskDetails">
              <el-input v-model="form.taskDetails"  placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark"  placeholder="请输入内容" />
            </el-form-item>
          </el-col>

        </el-row>


        <!-- <el-form-item label="通道ID" prop="channelId">
          <el-input v-model="form.channelId" placeholder="请输入通道ID" />
        </el-form-item> -->





      </el-form>
      <div slot="footer" class="dialog-footer">
         <el-button style="background-color:#03BF8A ; border-color: #03BF8A;" type="primary" @click="submitForm">确 定</el-button>
                <el-button style="background-color:#DDEBE7 ; border-color: #DDEBE7; color: #475669;" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTaskManage, getTaskManage, delTaskManage, addTaskManage, updateTaskManage } from "@/api/manage/taskManage"
import { listChannelNumber, getChannelNumber, delChannelNumber, addChannelNumber, updateChannelNumber } from "@/api/system/channelNumber"
export default {
  name: "TaskManage",
  dicts: ['algorithm_settings'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务管理表格数据
      taskManageList: [],
      channelNumberList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskNum: null,
        taskDetails: null,
        channelId: null,
        videoAddress: null,
        reportAddress: null,
        algorithmSet: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        taskNum: [
                  { required: true, message: "不能为空", trigger: "blur" }
                ],
        algorithmSet: [
                  { required: true, message: "不能为空", trigger: "blur" }
                ],
      },
      tableMaxHeight:'200',
    }
  },
  created() {
    this.getList()
    this.getListt()
   window.onresize = () => {
      	      this.changeTableMaxHeight()
      	    }
      	    this.changeTableMaxHeight()
    },
    mounted() {
    	window.onresize = () => {
    	          this.changeTableMaxHeight()
    	        }
    	        this.changeTableMaxHeight()
    },
  methods: {
    /** 查询任务管理列表 */
    getList() {
      this.loading = true
      listTaskManage(this.queryParams).then(response => {
        this.taskManageList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 查询通道管理列表 */
    getListt() {
      this.loading = true
      let snge={
        pageNum: 1,
        pageSize: 200,
      }
      listChannelNumber(snge).then(response => {
        this.channelNumberList = response.rows
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        taskId: null,
        taskNum: null,
        taskDetails: null,
        channelId: null,
        videoAddress: null,
        reportAddress: null,
        algorithmSet: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.taskId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加任务管理"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const taskId = row.taskId || this.ids
      getTaskManage(taskId).then(response => {
        this.form = response.data
        if(this.form.algorithmSet != null){
          if(this.form.algorithmSet.length !=0){
            this.form.algorithmSet = this.form.algorithmSet.split(',')
          }
        }
        this.open = true
        this.title = "修改任务管理"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.form.algorithmSet != null){
            if(this.form.algorithmSet.length !=0){
              this.form.algorithmSet = this.form.algorithmSet.join(',')
            }
          }
          if (this.form.taskId != null) {
            updateTaskManage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addTaskManage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const taskIds = row.taskId || this.ids
      this.$modal.confirm('是否确认删除任务管理编号为"' + taskIds + '"的数据项？').then(function() {
        return delTaskManage(taskIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('manage/taskManage/export', {
        ...this.queryParams
      }, `taskManage_${new Date().getTime()}.xlsx`)
    },
    // 获取屏幕高度
            showFilterForm () {
                  this.filterActive = !this.filterActive
                  this.changeTableMaxHeight()
                },

                changeTableMaxHeight () {
                  let height = document.body.offsetHeight // 网页可视区域高度
                  // if (this.filterActive) {
                  //   this.tableMaxHeight = height - 320
                  // } else {
                    this.tableMaxHeight = height - 250
                  // }
                  console.log(height)
                }
  }
}
</script>
<style lang="scss">
  .el-table .el-table__header-wrapper th, .el-table .el-table__fixed-header-wrapper th{
    background-color:#F5F6F8;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner{
    background-color: #03BF8A;
    border-color: #03BF8A;
  }
  .el-checkbox__input.is-indeterminate .el-checkbox__inner{
    background-color: #03BF8A;
    border-color: #03BF8A;
  }
  .qucheu{
    .el-form-item--small.el-form-item{
      border: 1px  solid #E6E6E6;
    }
    .el-input__inner{
      border:0;
    }
  }


</style>
