<template>
  <div class="dashboard-container">
    <div class="dashboard-text">
      <div style="padding: 15px; background: #fff; margin-top: -15px">
        <el-row :gutter="24" type="flex" style="flex-wrap: wrap">
          <!-- <el-select
            v-model="queryParams.railwayCode"
            placeholder="请选择线路"
            style="width: 220px; padding: 0 10px"
            clearable
          >
            <el-option
              v-for="item in lineWayData"
              :key="item.railwayCode"
              :label="item.railwayName"
              :value="item.railwayCode"
            />
          </el-select> -->
          <el-input placeholder="请输入摄像机编码" style="width: 220px; padding: 0 10px" v-model="queryParams.cameraCode"></el-input>
          <el-input placeholder="请输入测点名称" style="width: 220px; padding: 0 10px" v-model="queryParams.stationName"></el-input>
          <el-select
            v-model="queryParams.lineDir"
            placeholder="请选择行别"
            style="width: 220px; padding: 0 10px"
            clearable
          >
            <el-option
              v-for="item in lineDir"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            />
          </el-select>
          <el-select v-model="queryParams.online" clearable placeholder="请选择摄像机状态">
            <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <div
            v-if="searchShow == true" 
            :span="6"
            justify="end"
            style="display: flex; margin-top: 2px"
            type="flex"
          >
            <div
              class="search_btn"
              style="margin-left: 10px; cursor: pointer"
              @click="handleQuery"
            >
              查询
            </div>
            <div
              class="reset_btn"
              style="margin-left: 10px; cursor: pointer"
              @click="reset"
            >
              重置
            </div>
            <el-button v-if="searchShow == false" type="text" style="color: #2766dd !important;margin-left:10px"
              icon="el-icon-arrow-up" @click="searchShow = true">收起</el-button>
            <el-button v-if="searchShow == true" type="text" style="color:#2766DD;margin-left:10px"
              icon="el-icon-arrow-down" @click="searchShow = false">展开</el-button>
          </div>
        </el-row>
        <el-row :gutter="24" type="flex" style="flex-wrap: wrap">
          <div :span="5" v-if="searchShow == false" style="display: flex; align-items: center; margin-top: 2px">
                <el-input
                  style="width:200px;margin-left:10px"
                  v-model="queryParams.beginMileBD"
                  placeholder="请输入起始里程"
                  autocomplete="off"
                  oninput="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')"
                  >
                    <template slot="append">km</template>
                </el-input>
            </div>
            <div :span="5" v-if="searchShow == false" style="display: flex; align-items: center; margin-top: 2px">
                <el-input
                  style="width:200px;margin-left:20px"
                  v-model="queryParams.endMileBD"
                  placeholder="请输入结束里程"
                  autocomplete="off"
                  oninput="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')"
                  >
                    <template slot="append">km</template>
                </el-input>
            </div>
              <el-col style="width:210px"></el-col>
              <el-col style="width:210px"></el-col>
          <div v-if="searchShow == false" :span="6">
            <div class="search-btn" style="display: flex;">
              <!-- <el-button class="search" @click="handleQuery">搜索</el-button>
              <el-button class="reset" @click="reset">重置</el-button> -->
              <div class="search_btn" style="margin-top: 10px;" @click="handleQuery">查询</div>
              <div class="reset_btn" style="margin-left:10px;margin-top: 10px;" @click="reset">重置</div>
              <el-button v-if="searchShow == false" type="text" icon="el-icon-arrow-up"
                style="color: #2766dd !important;margin-left:10px;margin-top: 10px;"
                @click="searchShow = true">收起</el-button>
              <el-button v-if="searchShow == true" type="text" icon="el-icon-arrow-down"
                @click="searchShow = false">展开</el-button>
            </div>
          </div>
        </el-row>
      </div>

      <div style="padding: 0 20px 20px 20px; background: #fff; margin-top: 15px">
        <div style="width: 100%;height: 30px;">
            <div class="btn" style="margin-right: -3px;" @click="reset()">刷新</div>
        </div>
        <el-table
          :data="tableData"
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            prop="cameraCode"
            label="摄像机编码"
            align="center"
            fixed="left"
          />
          <el-table-column prop="stationName" label="测点名称" show-overflow-tooltip="true" align="center" />
          <el-table-column prop="lineDir" width="195" label="行别" align="center">
            <templats slot-scope="scope">
              <span v-if="scope.row.lineDir == 1">上行</span>
              <span v-if="scope.row.lineDir == 2">下行</span>
            </templats>
          </el-table-column>
          <el-table-column
            prop="installMiles"
            label="安装里程位置(km)"
            align="center"
            width="185"
          ></el-table-column>
          <el-table-column
            prop="onlineName"
            label="状态"
            width="185"
            align="center"
          >
          <template slot-scope="scope">
            <div class="Deactivate" v-if="scope.row.onlineName == '离线'">{{ scope.row.onlineName }}</div>
                        <div class="startUsing" v-else>{{ scope.row.onlineName }}</div>
          </template>
        </el-table-column>
          <el-table-column
          fixed="right"
            prop="createTime"
            label="更新时间"
            align="center"
            width="195"
          />
        </el-table>

        <el-row type="flex" justify="end" style="margin-top: 10px">
          <el-pagination
            :page-sizes="[10, 15, 20]"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </el-row>
      </div>
    </div>
  </div>
</template>
  
  <script>
import { getToken } from "@/utils/auth";
import { mapGetters } from "vuex";
import {
  getCameraDataList,
  getLineDir,
  getRecording,
  getStartRecording,
  getLineWayList,
  getWorkSetion,
  getLineData,
} from "@/api/account/camera";

export default {
  name: "Cart",
  computed: {
    ...mapGetters(["name"]),
  },
  data() {
    return {
      searchShow: true,
        statusOptions: [
        {
          label: '离线',
          value: '1'
        },
        {
          label: '在线',
          value: '2'
        }
      ],
      pjjwd: "",
      pjJkfw: "",
      // 导入
      dataForm: {
        name: "",
        file: null,
      },
      searchShow: true,
      startStatus: "",
      disabledSave: false,
      enter: 0,
      queryParams: {
        line: "",
        worksSection: "",
        lineDistinction: "",
        startMileage: "",
        finishtMileage: "",
        railwayCode: "",
        deptName: "",
        deptId: "",
        lineDir: "",
        beginMile: "",
        endMile: "",
        beginMileBD:"",
        endMileBD:"",
        online:"",
        pageNum: 1,
        pageSize: 10,
        cameraCode:'',
        stationName:''
      },
      ids: [],
      title: "",
      tableData: [],
      workSetiData: [],
      getLineData: [],
      total: 0,
      form: {
        lineDirName: "",
        railwayCode: "",
        cameraCode: "",
        channel: "",
        deptId: "",
        deptName: "",
        lineDir: "",
        installMileBD: "",
        beginMileBD: "",
        endMileBD: "",
        installLongitude: "",
        installLatitude: "",
        cardNum: "",
        startRecording: "",
        remark: "",
      },
      detailData: {},
      lineWayData: [],
      ids: [],
      fileList: [],
      cameraCodeValue: "",
      dialogType: "",
      headers: { Authorization: getToken() },
      action:
        "http://124.70.58.209:18819/hazard/service/baseCameraManagement/importBaseAccountManagement",
    };
  },
  watch: {
    "form.deptName": {
      handler(val) {
        this.$set(this.form, "deptName", val);
        this.optionProps.map((item, index) => {
          if (val == item.value) {
            this.$set(this.form, "deptId", item.value);
          }
        });
      },
      deep: true, // 深层监听
    },
  },
  created() {    
    if(this.$route.params.pageNum){
      this.queryParams.online = this.$route.params.onLine
    }
    this.getCameraList();
    this.getWorkSetion();
    this.getLineWayList();
    this.getLineTypeList();
  },
  methods: {
    changeValue(val) {},
    // 行别下拉
    getLineTypeList() {
      getLineDir({}).then((res) => {
        this.lineDir = res.data;
      });
    },
    handleStatusChange(row) {
      if (row.startRecording == "2") {
        getRecording(row.id).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "关闭成功",
              type: "success",
            });
          } else {
            this.$message({
              message: res.msg,
              type: "error",
            });
            this.getCameraList();
          }
        });
      } else if (row.startRecording == "1") {
        getStartRecording(row.id).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "开启成功",
              type: "success",
            });
          } else {
            this.$message({
              message: res.msg,
              type: "error",
            });
            this.getCameraList();
          }
        });
      }
    },
    handleSelectionChange(val) {
      this.ids = val.map((item) => item.id);
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getCameraList();
    },
    reset() {
      this.queryParams.beginMileBD=""
      this.queryParams.endMileBD = ""
      this.queryParams.online=""
      this.queryParams.deptName = "";
      this.queryParams.deptId = "";
      this.queryParams.railwayCode = "";
      this.queryParams.lineDir = "";
      this.queryParams.beginMile = "";
      this.queryParams.endMile = "";
      this.queryParams.cameraCode = "";
      this.queryParams.stationName = "";
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;      
      this.getCameraList();
    },
    getLineWayList() {
      getLineWayList({}).then((res) => {
        this.lineWayData = res.data;
      });
    },
    handleNodeHandleClick(a) {
      this.queryParams.deptName = a.label;
      this.queryParams.deptId = a.id;
    },
    handleNodeClick(v) {
      this.form.deptId = v.id;
      this.form.deptName = v.label;
    },
    getWorkSetion: function () {
      getWorkSetion({}).then((response) => {
        this.workSetiData = response.data;
      });
      getLineData({}).then((response) => {
        this.getLineData = response.data;
      });
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getCameraList();
    },
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.getCameraList();
    },
    getCameraList() {
      delete this.queryParams.ids;
      console.log(
        this.queryParams,
        "this.queryParamsthis.queryParamsthis.queryParams"
      );
      getCameraDataList(this.queryParams).then((response) => {
        if (!this.queryParams.pageNum || !this.queryParams.pageSize) {
          this.queryParams.pageNum = 1;
          this.queryParams.pageSize = 10;
          getCameraDataList(this.queryParams).then((res) => {
            this.tableData = res.data.records;
            this.total = res.data.total;
          });
        }
        if (
          response.data.records.length == 0 &&
          this.queryParams.pageNum != 1
        ) {
          this.queryParams.pageNum = this.queryParams.pageNum - 1;
          getCameraDataList(this.queryParams).then((res) => {
            this.tableData = res.data.records;
            this.total = response.data.total;
          });
        }
        this.tableData = response.data.records;
        this.total = response.data.total;
        if (this.tableData.length > 0) {
          if (this.tableData[0].isStartRecording == 1) {
            this.startStatus = 1;
          }
        } else {
          this.queryParams.pageNum = 1;
          this.queryParams.pageSize = 10;
          this.total = response.data.total;
          return;
          this.startStatus = 0;
        }
      });
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 45px 30px 30px;
  }

  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
.cardHeadr {
  margin-top: -20px;
  display: flex;
  justify-content: space-between;
}

.search_btn {
  cursor: pointer;
  background-color: #2766dd;
  color: #f7f8fb;
  font-size: 14px;
  width: 80px;
  height: 40px;
  text-align: center;
  line-height: 40px;
}
.search_btna {
  cursor: pointer;
  background-color: #2766dd !important;
  color: #fff;
  font-size: 14px;
  width: 80px;
  height: 40px;
  text-align: center;
}

.search_btna,
.search_btn:hover {
  background-color: #4d85f4;
}

.reset_btn {
  cursor: pointer;
  color: #565656;
  font-size: 14px;
  border: 1px solid #d7d7d7;
  width: 80px;
  height: 40px;
  text-align: center;
  line-height: 40px;
}

.reset_btn:hover {
  color: #1f9fff;
  border: 1px solid #1f9fff;
  background: none;
}

.addBtn {
  margin: 15px 20px 15px 0;
  cursor: pointer;
  text-align: center;
  width: 98px;
  height: 34px;
  border-radius: 2px;
  border: 1px solid #abc7fd;
  line-height: 34px;
  font-weight: 400;
  font-size: 14px;
  color: #2250c8;
  background-color: #e7eeff;
}

.addBtn:hover {
  color: #ffffff;
  background-color: #2250c8;
  border: 1px solid #2250c8;
}
.addBtn:active {
  color: #ffffff;
  background-color: #194da4;
  border: 1px solid #194da4;
}
.operateBtn {
  display: flex;
  justify-content: center;
  color: #2866dd;
  div {
    font-size: 14px;
    margin: 0 5px;
    cursor: pointer;
  }
}

.el-tooltip__popper {
  max-width: 30%;
  padding-bottom: 5px !important;
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 15;
  -webkit-box-orient: vertical;
}
.el-tooltip__popper,
.el-tooltip__popper.is-dark {
  background: rgb(48, 65, 86) !important;
  color: #fff !important;
  line-height: 24px;
}
.xzmba {
  color: #2766dd;
  text-decoration: underline;
  cursor: pointer;
}
.hxj {
  width: 100%;
  text-align: center;
  padding: 0 !important;
}
::v-deep .el-dialog__header {
  padding: 0 20px 10px !important;
}
::v-deep .el-dialog__body {
  padding: 20px 20px !important;
}
::v-deep .el-upload__tip {
  margin-top: -17px;
}
::v-deep .el-upload-dragger .el-upload__text {
  margin-top: -10px;
}
.dialog-footer {
  text-align: center;
}
.detailDia {
  div {
    padding-left: 100px;
  }
}
::v-deep .el-input__inner,
.el-input--suffix .el-input__inner {
  padding-right: 0 !important;
}
::v-deep .el-input.is-disabled .el-input__inner {
  color: #606266;
}
::v-deep .el-textarea .el-input__count {
  bottom: -40px;
}
::v-deep .el-input__icon {
  line-height: 47px;
}
::v-deep .el-select .el-input .el-select__caret {
  line-height: 20px !important;
}
.btn {
      margin: 15px 20px 15px 0;
      cursor: pointer;
      float: left;
      text-align: center;
      width: 98px;
      height: 34px;
      border-radius: 2px;
      border: 1px solid #ABC7FD;
      line-height: 34px;
      font-weight: 400;
      font-size: 14px;
      color: #2250C8;
      background-color: #E7EEFF;
    }

    .btn:hover {
      color: #FFFFFF;
      background-color: #2250C8;
      border: 1px solid #2250C8;
    }

    .btn:active {
      color: #FFFFFF;
      background-color: #194DA4;
      border: 1px solid #194DA4;
    }
    .startUsing {
      width: 54px;
      height: 24px;
      margin: 14.5px auto 0;
      line-height: 24px;
      text-align: center;
      font-size: 12px;
      color: #00974D;
      border-radius: 4px;
      background-color: #E7FAF0;
      border: 1px solid #BEFDDD;
    }

    .Deactivate {
      width: 54px;
      height: 24px;
      margin: 14.5px auto 0;
      line-height: 24px;
      text-align: center;
      font-size: 12px;
      color: #FF9933;
      border-radius: 4px;
      background-color: #FFF3E8;
      border: 1px solid #FDE6CF;
    }
</style>
  