<template>
  <!-- 在途运输信息选择页面 -->
  <div class="inTransit">

    <el-form :inline="true">
  <el-form-item>
    <label class="el-form-item__label" style="width: auto;">时间段</label>
         <el-date-picker
      v-model="dateValue"
      type="daterange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期">
    </el-date-picker>
  </el-form-item>
  <el-form-item>
     <label class="el-form-item__label" style="width: auto;">产品分类</label>
      <el-select v-model="inputValue" placeholder="产品分类">
        <el-option
          v-for="item in inputValues"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <!-- <label class="el-form-item__label" style="width: auto;">产品分类</label>
      <el-autocomplete
        popper-class="my-autocomplete"
        v-model="inputValue"
        :fetch-suggestions="querySearch"
        placeholder="请输入内容" 
      >
        <i class="el-icon-edit el-input__icon" slot="suffix"> </i>
      </el-autocomplete> -->
  </el-form-item>
  <el-form-item>
      <label class="el-form-item__label" style="width: auto;">车牌号</label>
      <el-input v-model="capacityNumber1" placeholder="请输入内容"></el-input>
  </el-form-item>
  <el-form-item>
      <label class="el-form-item__label" style="width: auto;">收货单位</label>
      <el-input v-model="consigneeCompanyName1" placeholder="请输入内容"></el-input>
  </el-form-item> 
  <el-form-item>
      <label class="el-form-item__label" style="width: auto;">承运单位</label>
      <el-input v-model="carrierName" placeholder="请输入内容"></el-input>
  </el-form-item> 
   <el-form-item>
     <label class="el-form-item__label" style="width: auto;">门岗名称</label>
      <el-select v-model="gatepostName" placeholder="门岗名称">
        <el-option
          v-for="item in gatepostNames1"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <!-- <label class="el-form-item__label" style="width: auto;">门岗名称</label>
       <el-autocomplete
            popper-class="my-autocomplete"
            v-model="gatepostName"
            :fetch-suggestions="querySearch2"
            placeholder="请输入内容" 
          >
            <i class="el-icon-edit el-input__icon" slot="suffix"> </i>
          </el-autocomplete> -->
  </el-form-item> 
  <el-form-item>
    <label class="el-form-item__label" style="width: auto;">报警类型</label>
      <el-select v-model="exceptionType" placeholder="报警类型">
        <el-option
          v-for="item in exceptionTypes"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <!-- <label class="el-form-item__label" style="width: auto;">报警类型</label>
       <el-autocomplete
            popper-class="my-autocomplete"
            v-model="exceptionType"
            :fetch-suggestions="querySearch3"
            placeholder="请输入内容" 
          >
            <i class="el-icon-edit el-input__icon" slot="suffix"> </i>
          </el-autocomplete> -->
  </el-form-item> 
  <el-form-item>
    <el-button type="primary" @click="onSearch"><i class="el-icon-search"></i>查询</el-button>
    <el-button type="primary" @click="exportData">导出</el-button>
  </el-form-item>
</el-form>
  
    <!-- 执行中 -->
<el-tabs v-model="activeName" >
    <el-tab-pane label="执行中" name="first">
    <dilTable ref="tab" v-bind.sync="option">
      <el-table-column fixed="right" label="操作" width="110">
        <template slot-scope="scope">
          <el-button @click="click(scope.row)" type="text" size="small" style="font-size: 17px"
            >实时轨迹</el-button
          >
        </template>
      </el-table-column>
    </dilTable>
    </el-tab-pane>
    <!-- 已结束 -->
      <el-tab-pane label="已结束" name="second">
        <dilTable ref="tab2" v-bind.sync="option2">
         <el-table-column fixed="right" label="操作" width="220">
        <template slot-scope="scope">
          <el-button @click="historyclick(scope.row)" type="text" size="small" style="font-size: 17px">历史轨迹</el-button>
          <el-button @click="allDistanceclick(scope.row.orderNumber)" type="text" size="small" style="font-size: 17px">总距离</el-button>
        </template>
      </el-table-column>
        </dilTable>
      </el-tab-pane>
      <!-- 有异常 -->
      <el-tab-pane label="有异常" name="third">
        <dilTable ref="tab3" v-bind.sync="option3">
         <el-table-column fixed="right" label="操作" width="220">
        <template slot-scope="scope">
           <el-button @click="click(scope.row)" type="text" size="small" style="font-size: 17px"
            >实时轨迹</el-button
          >
          <el-button @click="inTransitAlarmclick(scope.row.orderNumber)" type="text" size="small" style="font-size: 17px">运输报警</el-button>
        </template>
      </el-table-column>
        </dilTable>
      </el-tab-pane>
    </el-tabs>
    <div style="height: 100%">
      <vxe-modal width="1237" height="731" v-model="value7" show-zoom resize>
            <template #default>
              
              <PathView v-bind.sync="pathOption"></PathView>
            </template>
      </vxe-modal>
    </div>
    <!-- <div style="height: 100%">
      <vxe-modal width="1237" height="731" v-model="value6" show-zoom resize>
            <template #default>
              
              <inTransitOrderMileage v-bind.sync="mileOption"></inTransitOrderMileage>
            </template>
          </vxe-modal>
    </div>
     <div style="height: 100%">
      <vxe-modal width="1237" height="731" v-model="value5" show-zoom resize>
            <template #default>
              
              <inTransitAlarm v-bind.sync="alarmOption"></inTransitAlarm>
            </template>
          </vxe-modal>
    </div> -->
         
  </div>
</template>


<script>
import { sjTime } from "@/utils/sharedJsFile";

//PathView组件注册
// import PageTitle from "@/offSiteTransportation/mapTest.vue";
import PathView from "./mapTest.vue"
// import InTransitOrderMileage from "@/views/TMS/tms-offsite/inTransitOrderMileage.vue"
// import inTransitAlarm from "@/views/TMS/tms-offsite/inTransitAlarm.vue"
export default {
  name: "inTransit",
    components: { 
      PathView,
      // InTransitOrderMileage,
      // inTransitAlarm
  },
  data() {
    return {
      
      exceptionTypes:[{
          value: '全部类型',
          label: '全部类型'
        }, {
          value: '离线',
          label: '离线'
        },{
          value: '停车',
          label: '停车'
        },{
          value: '偏离',
          label: '偏离'
        }],
        inputValues:[{
          value: '螺纹钢',
          label: '螺纹钢'
        }, {
          value: '微粉',
          label: '微粉'
        },{
          value: '带钢',
          label: '带钢'
        },{
          value: '钢坯',
          label: '钢坯'
        },{
          value: '其他',
          label: '其他'
        }],
       gatepostNames1: [{
          value: '信钢北门出口',
          label: '信钢北门出口'
        }, {
          value: '科创微粉出口',
          label: '科创微粉出口'
        },{
          value: '象屿库',
          label: '象屿库'
        },{
          value: '智同库',
          label: '智同库'
        },{
          value: '中联厂出口',      
          label: '中联厂出口'
        }],
      dateValue:[new Date(), new Date()],
      inputValue:"螺纹钢",
      exceptionType:"全部类型",
      selectOrderNumber:"",
      capacityNumber1:"",
      carrierName:"",
       gatepostName:"",
       value7:false,
       value6:false,
       value5:false,
       dialogVisible:false,
      consigneeCompanyName1:"",
      status: "",
      state: "",
      activeName: "first",
      option: {       
        // 表格请求数据的地址
        requestUrl: "/api/v1/otms/getInTransitTransportation?apiId=468",
      },
       option2: {
        // 表格请求数据的地址
        // requestUrl: "/api/v1/tms/getFinishTruckOrderInfo?apiId=160",
      },
      pathOption:{
           orderNumber:'',
        capacityNumber:'',
      },
      mileOption:{
        orderNumber:''
      },
      alarmOption:{
        orderNumber:''
      },
       option3: {
        // 表格请求数据的地址
        // requestUrl: "/api/v1/tms/getHaveAbnormalTruckOrderInfo?apiId=160",
      }
    };
  },
  mounted() {
    console.log("nijfdsojfosafj")
    this.restaurants = this.loadAll();
    // this.onSearch();
    
  },
  methods: {
    showPathView(data){
      this.dialogVisible=!this.dialogVisible;
      this.selectOrderNumber=data.orderNumber;
    },
    querySearch(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      cb(results);
    },
     querySearch2(queryString, cb) {
      var restaurants = [
        { value: "信钢北门出口"},
        { value: "科创微粉出口"},
        { value: "象屿库"},
        { value: "智同库"},
      ];
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      cb(results);
    },
     querySearch3(queryString, cb) {
      var restaurants = [
        { value: "离线"},
        { value: "停车"},
        { value: "偏离"},
        { value: "全部类型"},
      ];
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },
    loadAll() {
      return [
        { value: "螺纹钢"},
         { value: "微粉"},
        { value: "带钢"},
        { value: "钢坯"},
        { value: "其他"},
      ];
    },
    exportData(){
        

        let tHeader = [];
        let filterVal = [];
        if(this.activeName=="first"){
          this.$refs.tab.dataColumnData.filter( (item,i) =>{
                    tHeader.push(item.label);
                        filterVal.push(item.prop);
                    } )
            this.export2Excel(tHeader,filterVal,this.$refs.tab.dataTabel,'执行中表格');
        }else if(this.activeName=="second"){
            this.$refs.tab2.dataColumnData.filter( (item,i) =>{
              tHeader.push(item.label);
                  filterVal.push(item.prop);
              } )
          this.export2Excel(tHeader,filterVal,this.$refs.tab2.dataTabel,'已完成表格');
        } else if(this.activeName=="third"){
            this.$refs.tab3.dataColumnData.filter( (item,i) =>{
                      tHeader.push(item.label);
                          filterVal.push(item.prop);
                      } )
            this.export2Excel(tHeader,filterVal,this.$refs.tab3.dataTabel,'有异常表格');
        }
        
        
    },
    export2Excel(tHeader,filterVal,dataTabel,exeName) {
      var that = this;
       this.downloadLoading = true
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/assets/excel/Export2Excel.js"); //这里必须使用绝对路径，使用@/+存放export2Excel的路径
        console.log("export_json_to_excel",export_json_to_excel)
        let list = dataTabel;
        let data = that.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, exeName); // 导出的表格名称
      });
    },
    //3.格式转换
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) => filterVal.map((j) => v[j]));
    },
    onSearch(){
  
      if(this.activeName=="first"){
      //改变执行中条件
      this.$refs.tab.setDataRequestQuery({"startTime":sjTime(this.dateValue[0]),
                      "endTime": sjTime(this.dateValue[1]),
                      "productClassification": this.inputValue,
                      "capacityNumber1": this.capacityNumber1,
                      "carrierName1":this.carrierName,
                      "gatepostName1":this.gatepostName,
                      "consigneeCompanyName1": this.consigneeCompanyName1});
      }
      if(this.activeName=="second"){
      //改变已完成条件              
      this.$refs.tab2.setDataRequestQuery({"startTime":sjTime(this.dateValue[0]),
                      "endTime": sjTime(this.dateValue[1]),
                      "productClassification": this.inputValue,
                      "capacityNumber1": this.capacityNumber1,
                      "carrierName1":this.carrierName,
                      "gatepostName1":this.gatepostName,
                      "consigneeCompanyName1": this.consigneeCompanyName1});
      }
      if(this.activeName=="third"){
      //改变有异常条件              
      this.$refs.tab3.setDataRequestQuery({"startTime":sjTime(this.dateValue[0]),
                      "endTime": sjTime(this.dateValue[1]),
                      "productClassification": this.inputValue,
                      "capacityNumber1": this.capacityNumber1,
                      "carrierName1":this.carrierName,
                      "abnormalType":this.exceptionType=="全部类型"?"":this.exceptionType,
                      "gatepostName1":this.gatepostName,
                      "consigneeCompanyName1": this.consigneeCompanyName1});
      }                              
    },


    //other
    click(row) {
      console.log(row,"row")
        this.pathOption.orderNumber=row.orderNumber;
        this.pathOption.capacityNumber=row.capacityNumber;
        this.value7=true;
      // this.$router.push("/offsite/pathView?orderNumber="+row.orderNumber+"&capacityNumber="+row.capacityNumber);
    },
    historyclick(row){
      this.pathOption.orderNumber=row.orderNumber;
        this.pathOption.capacityNumber=row.capacityNumber;
        this.value7=true;
      //this.$router.push("/offsite/pathView?orderNumber="+row.orderNumber+"&capacityNumber="+row.capacityNumber);
    },
    allDistanceclick(orderNumber){
      //this.$router.push("/offsite/inTransitOrderMileage?orderNumber="+orderNumber);
    
      this.mileOption.orderNumber=orderNumber;
      this.value6=true;
    },
    inTransitAlarmclick(orderNumber){
      // this.$router.push("/offsite/inTransitAlarm?orderNumber="+orderNumber);
      this.alarmOption.orderNumber=orderNumber;
      this.value5=true;
    },
    },
};
</script>
<style lang='scss' scoped>
.homeworkPath {
  .top {
    padding: 20px 30px;
  }
}
</style>