<template>
  <div class="generalizationScenarioListPanel">
    <search-layout :needBox="true">
      <template slot="searchItem1">
        <span class="label">场景名称</span>
        <el-input
          v-model="searchParams.sceneName"
          size="small"
          clearable
          placeholder="请输入"
          maxlength="60"
          @keyup.enter.native="doSearch"
        >
        </el-input>
      </template>
      <template slot="searchItem1">
        <span class="label">主车动作</span>
        <el-select
          v-model="searchParams.mainBehavior[0][1]"
          size="small"
          clearable
        >
          <el-option
            v-for="item in ['汇入']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem2">
        <span class="label">他车动作</span>
        <el-select
          v-model="searchParams.otherBehavior[0][1]"
          size="small"
          clearable
        >
          <el-option
            v-for="item in ['直行']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem2">
        <span class="label">天气</span>
        <el-select v-model="searchParams.weather[0][1]" size="small" clearable>
          <el-option
            v-for="item in ['晴']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem3">
        <span class="label">道路类型</span>
        <el-select v-model="searchParams.roadType[0][1]" size="small" clearable>
          <el-option
            v-for="item in ['高速']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem3">
        <span class="label">道路几何-平面</span>
        <el-select
          v-model="searchParams.roadGeometryPlane[0][1]"
          size="small"
          clearable
        >
          <el-option
            v-for="item in ['直道']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem4">
        <span class="label">道路几何-纵断面</span>
        <el-select
          v-model="searchParams.roadGeometryVertical[0][1]"
          size="small"
          clearable
        >
          <el-option
            v-for="item in ['上坡']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem4">
        <span class="label">智能驾驶</span>
        <el-select
          v-model="searchParams.autoDriveFunction[0][1]"
          size="small"
          clearable
        >
          <el-option
            v-for="item in ['ACC', 'AEB']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem5">
        <span class="label">运行区域</span>
        <el-select
          v-model="searchParams.operationArea[0][1]"
          size="small"
          clearable
        >
          <el-option
            v-for="item in ['主路']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <!-- 复杂度 -->
      <template slot="searchItem5">
        <span class="label">复杂度</span>
        <el-input
          v-model="searchParams.minComplexity"
          size="small"
          clearable
          placeholder="请输入"
          maxlength="60"
          style="width: 100px"
        >
        </el-input>
        <span class="dateSeparator">至</span>
        <el-input
          v-model="searchParams.maxComplexity"
          size="small"
          clearable
          placeholder="请输入"
          maxlength="60"
          style="width: 100px"
        >
        </el-input>
      </template>
      <!-- 危险度 -->
      <template slot="searchItem6">
        <span class="label">危险度</span>
        <el-input
          v-model="searchParams.minRisk"
          size="small"
          clearable
          placeholder="请输入"
          maxlength="60"
          style="width: 100px"
        >
        </el-input>
        <span class="dateSeparator">至</span>
        <el-input
          v-model="searchParams.maxRisk"
          size="small"
          clearable
          placeholder="请输入"
          maxlength="60"
          style="width: 100px"
        >
        </el-input>
      </template>
      <template slot="searchItem6">
        <span class="label">复杂度等级</span>
        <el-select
          v-model="searchParams.complexityLevel"
          size="small"
          clearable
        >
          <el-option
            v-for="item in ['S', 'AA', 'A', 'B', 'C']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem7">
        <span class="label">危险度等级</span>
        <el-select v-model="searchParams.riskLevel" size="small" clearable>
          <el-option
            v-for="item in ['S', 'AA', 'A', 'B', 'C']"
            :label="item"
            :value="item"
            :key="item"
          ></el-option>
        </el-select>
      </template>
      <template slot="searchItem7">
        <span class="label">标签</span>
        <el-input
          v-model="searchParams.label"
          size="small"
          clearable
          placeholder="请输入"
          maxlength="60"
        >
        </el-input>
      </template>
      <template slot="searchItem8">
        <span class="label">场景描述</span>
        <el-input
          v-model="searchParams.sceneDescription"
          size="small"
          clearable
          placeholder="请输入"
          maxlength="60"
        >
        </el-input>
      </template>
      <template slot="searchBtn1">
        <el-button type="primary" @click="doSearch">查询</el-button>
      </template>
      <template slot="searchBtn2">
        <el-button type="primary" @click="doReset">重置</el-button>
      </template>
    </search-layout>
    <tableList
      ref="table"
      style="margin: 40px 30px 30px"
      :columns="columns"
      :getDataWay="getDataWay"
      :pagination="pagination"
      index
      indexFixed
    >
      <el-table-column
        label="操作"
        slot="cgInfos"
        align="center"
        width="180"
        fixed="right"
      >
        <template v-slot="scope">
          <span @click="viewRow(scope.row)" class="elIcon"> 查看 </span>
          <span @click="editHandle(scope.row)" class="elIcon"> 编辑 </span>
          <span @click="jumpScene(scope.row)" class="elIcon"> 场景评价 </span>
        </template>
      </el-table-column>
    </tableList>
    <el-dialog
      v-if="generalizationVisible"
      :visible.sync="generalizationVisible"
      :title="generalizationDiaTitle"
      width="90%"
      class="generalizationDia"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :before-close="generalizationCancel"
    >
      <div>
        <generalization-detail
          ref="generalizationDetail"
          :disabled="true"
          :id="generalizationId"
          :genUrlType="1"
        ></generalization-detail>
      </div>
    </el-dialog>
    <!-- 查看视频弹窗 -->
    <el-dialog
      :title="videoDiaTitle"
      :visible.sync="dialogVisible"
      width="690px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :destroy-on-close="true"
    >
      <div class="videoBox">
        <video :src="videoSrc" controls></video>
      </div>
    </el-dialog>
    <!-- 编辑表格 -->
    <el-dialog
      title="编辑"
      :visible.sync="editVisible"
      width="780px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form
        ref="editInfo"
        :model="editInfo"
        label-width="150px"
        style="display: flex; flex-wrap: wrap; justify-content: space-between"
      >
        <el-form-item label="场景名称">
          <el-input v-model="editInfo.sceneName" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="场景描述">
          <el-input v-model="editInfo.sceneDescription"></el-input>
        </el-form-item>
        <el-form-item label="主车动作">
          <el-select v-model="editInfo.mainBehavior">
            <el-option
              v-for="item in ['汇入']"
              :label="item"
              :value="item"
              :key="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="他车动作">
          <el-select v-model="editInfo.otherBehavior">
            <el-option
              v-for="item in ['直行']"
              :label="item"
              :value="item"
              :key="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="天气">
          <el-select v-model="editInfo.weather">
            <el-option
              v-for="item in ['晴']"
              :label="item"
              :value="item"
              :key="item"
            ></el-option
          ></el-select>
        </el-form-item>
        <el-form-item label="道路类型">
          <el-select v-model="editInfo.roadType">
            <el-option
              v-for="item in ['高速']"
              :label="item"
              :value="item"
              :key="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="道路几何-平面">
          <el-select v-model="editInfo.roadGeometryPlane">
            <el-option
              v-for="item in ['直道']"
              :label="item"
              :value="item"
              :key="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="道路几何-纵断面">
          <el-select v-model="editInfo.roadGeometryVertical">
            <el-option
              v-for="item in ['上坡']"
              :label="item"
              :value="item"
              :key="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="自动驾驶功能">
          <el-select v-model="editInfo.autoDriveFunction">
            <el-option
              v-for="item in ['ACC', 'AEB']"
              :label="item"
              :value="item"
              :key="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="运行区域">
          <el-select v-model="editInfo.operationArea">
            <el-option
              v-for="item in ['主路']"
              :label="item"
              :value="item"
              :key="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签">
          <el-input v-model="editInfo.label"></el-input>
        </el-form-item>
      </el-form>
      <div style="width: 100%; display: flex; justify-content: center">
        <el-button @click="editVisible = false">取消</el-button>
        <el-button type="primary" @click="editUpdate">更新</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import searchLayout from '@/components/grid/searchLayout'
import tableList from '@/components/grid/TableList'
import { mapState } from 'vuex'
export default {
  name: 'benchmarkScenarioList', // 基准场景库
  components: { searchLayout, tableList },
  data() {
    return {
      //搜索参数
      searchParams: {
        sceneName: '', // 场景名称
        share: '0',
        mainBehavior: [['mainBehavior', '']], // 主车动作
        otherBehavior: [['otherBehavior', '']],
        weather: [['weather', '']],
        roadType: [['roadType', '']],
        roadGeometryPlane: [['roadGeometryPlane', '']],
        roadGeometryVertical: [['roadGeometryVertical', '']],
        autoDriveFunction: [['autoDriveFunction', '']],
        operationArea: [['operationArea', '']],
        minComplexity: '',
        maxComplexity: '',
        minRisk: '',
        maxRisk: '',
        complexityLevel: '',
        riskLevel: '',
        sceneDescription: '',
        label: '',
      },
      //  编辑信息
      editVisible: false,
      //  编辑内容数据回填
      editInfo: {
        sceneName: '', //场景名称
        sceneDescription: '', // 场景描述
        mainBehavior: '', //主车动作
        weather: '', // 天气
        roadGeometryPlane: '', // 道路几何-平面
        autoDriveFunction: '', // 自动驾驶功能
        label: '', // 标签
        otherBehavior: '', // 他车动作
        roadType: '', // 道路类型
        roadGeometryVertical: '', // 道路几何-纵断面
        operationArea: '', // 运行区域
      },
      fileNameList: [
        {
          label: '汇入',
          value: '',
        },
      ],
      scenarioRoadTypeList: [],
      // scenarioWeatherList: [],
      props: {
        multiple: true,
        label: 'dictName',
        value: 'dictCode',
      },
      columns: [
        //表格列
        {
          label: '场景名称',
          prop: 'sceneName',
          fixed: 'left',
        },
        {
          label: '主车动作',
          prop: 'mainBehavior',
        },
        {
          label: '他车动作',
          prop: 'otherBehavior',
        },
        {
          label: '天气',
          prop: 'weather',
        },
        {
          label: '道路类型',
          prop: 'roadType',
        },
        {
          label: '道路几何-平面',
          prop: 'roadGeometryPlane',
        },
        {
          label: '道路几何-纵断面',
          prop: 'roadGeometryVertical',
        },
        {
          label: '支持智驾功能',
          prop: 'autoDriveFunction',
        },
        {
          label: '运行区域',
          prop: 'operationArea',
        },
        {
          label: '复杂度',
          prop: 'complexity',
        },
        {
          label: '复杂度等级',
          prop: 'complexityLevel',
        },
        {
          label: '危险度',
          prop: 'risk',
        },
        {
          label: '危险度等级',
          prop: 'riskLevel',
        },
        {
          label: '便签',
          prop: 'label',
        },
        {
          label: '场景描述',
          prop: 'sceneDescription',
        },
        {
          label: '操作',
          prop: 'cgInfos',
          template: true,
        },
      ],
      pagination: {
        //分页使用
        currentPage: 1,
        pageSize: 10,
        position: 'right',
        pageSizes: [10, 30, 50, 100, 200],
        layout: 'sizes, total, prev, pager, next, jumper',
      },
      getDataWay: {
        //加载表格数据
        dataType: 'url',
        type: 'post',
        data: this.$api.sceneLibrary.querybenchmarkList,
        param: {
          share: '0',
        },
      },
      generalizationVisible: false, // 泛化dialog
      generalizationId: '', // 泛化详情id
      generalizationDiaTitle: '',
      //  视频弹窗信息
      dialogVisible: false,
      autoplay: false,
      videoSrc: '',
      objectPath: '',
      videoDiaTitle: '',
    }
  },

  computed: {
    ...mapState(['fileHost', 'fileUrl']),
  },

  methods: {
    // 编辑弹窗更新
     editUpdate() {
      this.$axios({
        method: 'post',
        url: this.$api.sceneLibrary.saveSceneReferenceById,
        data: {...this.editInfo},
      }).then(res=>{
        if(res.code ==200){
          this.editVisible = false
          this.$message.success("更新成功");
        }else{
          this.$message.error(res.message || "更新失败");
        }
      })
    },
    // 搜索查询
    doSearch() {
      this.searchParams.share = '0'
      const specialParams = [
        'mainBehavior',
        'otherBehavior',
        'weather',
        'roadType',
        'roadGeometryPlane',
        'roadGeometryVertical',
        'autoDriveFunction',
        'operationArea',
      ]
      const obj = JSON.parse(JSON.stringify(this.searchParams))
      Object.keys(obj).forEach((item) => {
        if(specialParams.includes(item)){
          if(!obj[item][0][1]){
            obj[item] = []
          }
        }
      })
      this.refreshList(obj)
    },
    //刷新table
    refreshList(param) {
      param
        ? this.$refs['table'].loadData(param)
        : this.$refs['table'].loadData()
    },
    doReset() {
      this.searchParams = {
        sceneName: '', // 场景名称
        share: '0',
        mainBehavior: [['mainBehavior', '']], // 主车动作
        otherBehavior: [['otherBehavior', '']],
        weather: [['weather', '']],
        roadType: [['roadType', '']],
        roadGeometryPlane: [['roadGeometryPlane', '']],
        roadGeometryVertical: [['roadGeometryVertical', '']],
        autoDriveFunction: [['autoDriveFunction', '']],
        operationArea: [['operationArea', '']],
        minComplexity: '',
        maxComplexity: '',
        minRisk: '',
        maxRisk: '',
        complexityLevel: '',
        riskLevel: '',
        sceneDescription: '',
        label: '',
      }
      this.doSearch()
    },
    pageControl(data) {
      this.activeName = data.name
      this.doSearch()
    },
    viewRow(row) {
      this.dialogVisible = true
      this.videoSrc = 'https://media.w3.org/2010/05/sintel/trailer.mp4'
    },
    // 编辑
    editHandle(e) {
      this.editInfo = JSON.parse(JSON.stringify(e))
      this.editVisible = true
    },
    // 跳转场景评价
    jumpScene(row) {
      this.$store.commit("getSceneId",row.sceneId);
      this.$router.push({
        path: '/sceneEvaluation',
        query:{id:row.sceneId}
      })
    },
  },

  async mounted() {

  },
}
</script>

<style lang='less' scoped>
@import './common/util.less';

.generalizationScenarioListPanel {
  .inputBox {
    .label {
      min-width: 90px;
    }
  }

  .btnsPanel {
    text-align: right;
  }

  .generalizationDia {
    /deep/ .el-dialog__body {
      position: relative;
      padding: 20px 60px;

      .changeBtn {
        position: absolute;
        top: 20px;
        right: 60px;
      }
    }
  }
}
</style>