<template>
  <div>
    <div style="width: 80%;background-color: #545c64;margin: 0 auto;display: flex;justify-content:space-around;">
      <el-menu
        :default-active="activeIndex2"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b">
        <el-menu-item index="1">门到门</el-menu-item>
        <el-menu-item index="2">门到港</el-menu-item>
        <el-menu-item index="3">港到门</el-menu-item>
        <el-menu-item index="4">港到港</el-menu-item>
      </el-menu>
    </div>
    <div class="outermost">
      <div v-if="selection === '1'">
        <el-input placeholder="请输入发货地址">
          <template slot="prepend">发货地址</template>
          <el-button slot="append" icon="el-icon-d-caret" @click="whether = !whether">
            {{ whether === false ? '指定港口' : '取消指定港口' }}
          </el-button>
        </el-input>
        <el-input placeholder="请输入货物名称">
          <template slot="prepend">货物名称</template>
        </el-input>
        <el-input placeholder="请输入收货地址">
          <template slot="prepend">收货地址</template>
        </el-input>
        <el-input placeholder="请输入预计装货时间">
          <template slot="prepend">预计装货时间</template>
        </el-input>
        <el-input placeholder="请输入起运港口" v-if="whether === true">
          <template slot="prepend">起运港口</template>
        </el-input>
        <el-input placeholder="请输入目的港口" v-if="whether === true">
          <template slot="prepend">目的港口</template>
        </el-input>
        <button style="width: 400px;height: 0;border: none;padding: 0;"></button>
        <button style="width: 400px;height: 0;border: none;padding: 0;"></button>
      </div>
      <div v-if="selection === '2'">
        <el-input placeholder="请输入发货地址">
          <template slot="prepend">发货地址</template>
          <el-button slot="append" icon="el-icon-d-caret" @click="whether = !whether">
            {{ whether === false ? '指定港口' : '取消指定港口' }}
          </el-button>
        </el-input>
        <el-input placeholder="请输入货物名称">
          <template slot="prepend">货物名称</template>
        </el-input>
        <el-input placeholder="请输入预计装货时间">
          <template slot="prepend">预计装货时间</template>
        </el-input>
        <el-input placeholder="请输入起运港口" v-if="whether === true">
          <template slot="prepend">起运港口</template>
        </el-input>
        <el-input placeholder="请输入目的港口" v-if="whether === true">
          <template slot="prepend">目的港口</template>
        </el-input>
        <button style="width: 400px;height: 0;border: none;padding: 0;"></button>
        <button style="width: 400px;height: 0;border: none;padding: 0;"></button>
      </div>
      <div v-if="selection === '3'">
        <el-input placeholder="请输入起运港口">
          <template slot="prepend">起运港口</template>
        </el-input>
        <el-input placeholder="请输入目的港口" v-if="whether === true">
          <template slot="prepend">目的港口</template>
        </el-input>
        <el-input placeholder="请输入货物名称">
          <template slot="prepend">货物名称</template>
        </el-input>
        <el-input placeholder="请输入收货地址">
          <template slot="prepend">收货地址</template>
          <el-button slot="append" icon="el-icon-d-caret" @click="whether = !whether">
            {{ whether === false ? '指定港口' : '取消指定港口' }}
          </el-button>
        </el-input>
        <el-input placeholder="请输入预计装货时间">
          <template slot="prepend">预计装货时间</template>
        </el-input>
        <button style="width: 400px;height: 0;border: none;padding: 0;"></button>
        <button style="width: 400px;height: 0;border: none;padding: 0;"></button>
      </div>
      <div v-if="selection === '4'">
        <div style="width: 400px;align-items: center;display: flex;">
          <el-button disabled style="border: 1px solid #DCDFE6;color:#95989d;background-color: #f5f7fa;border-top-right-radius:0;border-bottom-right-radius:0">起运港口</el-button>
          <el-select
            v-model="portToPort.fPortofloadid"
            filterable
            remote
            @change="handleQuery"
            style="width: 100%;"
            class="elSelect"
            :remote-method="handleQuery"
            placeholder="请输入模糊查找起运港口"
          >
            <el-scrollbar>
              <el-option
                v-for="(dict, index) in fMblnoOptions"
                :key="dict.fId"
                :label="dict.fName"
                :value="dict.fId"
              ></el-option>
            </el-scrollbar>
          </el-select>
        </div>

        <div style="width: 400px;align-items: center;display: flex;">
          <el-button disabled style="border: 1px solid #DCDFE6;color:#95989d;background-color: #f5f7fa;border-top-right-radius:0;border-bottom-right-radius:0">目的港口</el-button>
          <el-select
            v-model="portToPort.fPortofloadid"
            filterable
            remote
            @change="handleQuery"
            style="width: 100%;"
            class="elSelect"
            :remote-method="handleQuery"
            placeholder="请输入模糊查找目的港口"
          >
            <el-scrollbar>
              <el-option
                v-for="(dict, index) in fMblnoOptions"
                :key="dict.fId"
                :label="dict.fName"
                :value="dict.fId"
              ></el-option>
            </el-scrollbar>
          </el-select>
        </div>
<!--        <el-input placeholder="请输入目的港口" v-model="portToPort.fDistinationid">-->
<!--          <template slot="prepend">目的港口</template>-->
<!--        </el-input>-->
        <el-input placeholder="请输入货物名称">
          <template slot="prepend">货物名称</template>
        </el-input>
        <el-input placeholder="请输入预计装货时间" v-model="portToPort.fEta">
          <template slot="prepend">预计装货时间</template>
        </el-input>
        <button class="stealthbutton"></button>
        <button class="stealthbutton"></button>
      </div>
      <div>
        <el-button type="primary" v-if="activeIndex2 === '1'||activeIndex2 === '2'||activeIndex2 === '3'" disabled>船期查询</el-button>
        <el-button type="primary" @click="schedule" v-else>船期查询</el-button>
      </div>
      <el-divider>查询船期</el-divider>
      <div style="margin: 0 auto;" v-if="detailedList.length === 0">
        <i class="el-icon-s-release" style="font-size: 100px;color: #b7b7b7"></i>
        <p>暂无数据</p>
      </div>
      <div style="width: 100%;" v-for="(item,index) in detailedList" :key="index">
        <div
             style="width: 100%;padding: 10px;margin-left: -10px;display: flex;justify-content: space-around;border: 1px solid #E8E8E8;box-shadow: 0 2px 7px 0 rgba(71,71,71,.2);">
          <div style="width: 50%;line-height: 40px;">
            <div
              style="background-color: #f10724;width: 80px;margin-top: 15px;margin-right: 5px;margin-left: 5px;height: 30px;line-height: 30px;border-radius: 20px;color: #ffffff;float: left">
              {{item.portofloadidName}}
            </div>
            <div style="width: 40px;height: 60px;float: left">
              <div style="width: 100%;height: 30px;">
                <img style="width: 50%;" src="../../assets/ship.png" alt="">
              </div>
              <div style="width: 100%;height: 30px;line-height: 30px;border-top: 1px solid #f33434">
                驳
              </div>
            </div>
            <div
              style="background-color: #f10724;width: 80px;margin-top: 15px;margin-right: 5px;margin-left: 5px;height: 30px;line-height: 30px;border-radius: 20px;color: #ffffff;float: left">
              {{item.portoftransshipmentName}}
            </div>
            <div style="width: 40px;height: 60px;float: left">
              <div style="width: 100%;height: 30px;">
                <img style="width: 50%;" src="../../assets/ship.png" alt="">
              </div>
              <div style="width: 100%;height: 30px;line-height: 30px;border-top: 1px solid #f33434">
                驳
              </div>
            </div>
            <div
              style="background-color: #f10724;width: 80px;margin-top: 15px;margin-right: 5px;margin-left: 5px;height: 30px;line-height: 30px;border-radius: 20px;color: #ffffff;float: left">
              {{item.portofdischargeidName}}
            </div>
          </div>
          <div
            style="width: 25%;margin: 0 auto;display: flex;align-items: center;justify-content: center;border-left: 1px solid #E8E8E8">
            <div>
              <span style="color: #999999">全程运输时长：</span>
              <span style="font-weight:bold">{{item.fDays}}天</span>
              <br>
              <span style="color: #999999">单证有效时间：</span>
              <span style="font-weight:bold">{{item.closing}}天</span>
            </div>
          </div>
          <div style="width: 30%;border-left: 1px solid #E8E8E8;display:flex;justify-content: space-around">
            <div>
              <div>20GP</div>
              <div style="color:#bc1920 ">
                <span>￥</span>
                <span style="font-size: 20px;">{{item.twenty}}</span>
                <span>起</span>
              </div>
            </div>
            <div>
              <div>40HC</div>
              <div style="color:#bc1920 ">
                <span>￥</span>
                <span style="font-size: 20px;">{{ item.fortyHc }}</span>
                <span>起</span>
              </div>
            </div>
            <div>
              <div>40RH</div>
              <div style="color:#bc1920 ">
                <span>￥</span>
                <span>{{ item.fortyRh }}</span>
                <span>起</span>
              </div>
            </div>
          </div>
          <div class="query">
            <el-button type="primary" @click="item.introduction = !item.introduction">{{item.introduction === false?'查看船期':'关闭列表'}}</el-button>
          </div>
        </div>
        <div style="width: 98%;background-color: #99a9bf;margin: 0 auto" v-if="item.introduction === true">
          <div style="float: left;padding: 5px;color:#ffffff;">
            <span>{{item.portofloadidName}}</span>
            →
            <span>{{ item.portofdischargeidName }}</span>
          </div>
          <div style="border: 1px solid #EBEEF5">
            <el-table
              :data="item.freight"
              style="width: 100%"
              :header-cell-style="{textAlign: 'center'}"
              :cell-style="{ textAlign: 'center' }">
              <el-table-column
                prop="fEta"
                label="预计开航">
              </el-table-column>
              <el-table-column
                prop="fEtd"
                label="预计抵港">
              </el-table-column>
              <el-table-column
                prop="fCutoffdate"
                label="截港日期">
              </el-table-column>
              <el-table-column
                prop="pidName"
                label="船名航次">
              </el-table-column>
              <el-table-column
                prop="twenty"
                label="20GP">
              </el-table-column>
              <el-table-column
                prop="fortyHc"
                label="40HC">
              </el-table-column>
              <el-table-column
                prop="fortyRh"
                label="40RH">
              </el-table-column>
              <el-table-column
                label="操作">
                <el-button type="primary">订舱</el-button>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { request } from '../../request/request';
import Cookies from 'js-cookie';

export default {
  name: 'inquiryAndOrder',
  data() {
    return {
      fMblnoOptions:[],
      portToPort:{
        fPortofloadid:'',
        fDistinationid:'',
        fEta:'',
        portofloadidName:''
      },
      detailedList:[],
      value1: '',
      selection: '1',
      whether: false,
      activeIndex: '1',
      activeIndex2: '4',
      labelPosition: 'right',
      formLabelAlign: {
        name: '',
        region: '',
        type: ''
      },
      list:[],
      tableData: []
    };
  },
  methods: {
    handleSelect(key, keyPath) {
      this.whether = false;
      this.activeIndex2 = key
      console.log(key, keyPath);
      this.selection = key;
    },
    schedule(){
      console.log(this.detailedList);
      // v-if="selection === '1'"
      // switch (this.selection){
      //   case '1':
      //     break
      //   case '2':
      //     break
      //   case '3':
      //     break
      //   case '4':
      //     break
      //   default:
      //     break
      // }

      request({
        url: '/shipping/voyage/freightList',
        method: 'get',
        params: this.portToPort
      }).then(res => {
        // console.log(res);
        this.detailedList = []
        this.list = res.data.rows
        res.data.rows.map(((item, index)=> {
          this.detailedList.push(Object.assign({},item,{introduction:false}))
        }))
        // console.log(this.detailedList);
      }).catch(err => {
        console.log(err);
      })
    },
    handleQuery(){
      // this.fMblnoOptions
      request({
        url: '/shipping/address/selectPortName',
        method: 'get',
        params: {
          fName:this.portToPort.fPortofloadid
        }
      }).then(res => {
        console.log(res);
        this.fMblnoOptions = res.data.rows
        console.log(this.fMblnoOptions);
      }).catch(err => {
        console.log(err);
      })
    }
  }
};
</script>

<style scoped lang="scss">
.query {
  width: 15%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid #E8E8E8
}

.outermost {
  width: 80%;
  margin: auto auto 100px auto;
  padding-top: 20px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.stealthbutton {
  width: 400px;
  height: 0;
  border: none;
  padding: 0;
}

.outermost > div:nth-child(1) {
  width: 80%;
  display: flex;
  display: -webkit-flex;
  justify-content: space-around;
  flex-direction: row;
  flex-wrap: wrap;
}

.outermost > div:nth-child(2) {
  width: 20%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center
}

.outermost > div:nth-child(1) > .el-input {
  width: 400px;
  margin-top: 5px;
  margin-bottom: 5px;
}
</style>
