<template>
  <div class="app-container">
    <div v-show="viewState == 1">
      <div class="tab-header webtop">
        <div>现车车辆列表</div>
        <div>
          <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
        </div>
      </div>
      <div class="webcon">
        <div class="searchcon">
          <el-button size="small" class="searchbtn" @click="clicksearchShow">{{ searchxianshitit }}</el-button>
          <div v-show="isSearchShow" class="search">
            <el-form ref="listQueryform" :inline="true" :model="listQuery" label-width="100px" class="tab-header">
              <el-row>
                <el-form-item label="状态:" class="searchlist">
                  <el-select v-model="listQuery.params.vehicleState" placeholder="请选择" filterable clearable>
                    <el-option v-for="item in vehicleState_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                  </el-select>
                </el-form-item>
                <el-form-item label="车架号:" class="searchlist">
                  <el-input v-model="listQuery.params.vinNo" placeholder="" clearable style="width: 150px"/>
                </el-form-item>
                <el-form-item label="颜色:" class="searchlist">
                  <el-select v-model="listQuery.params.carColor" placeholder="请选择" filterable clearable>
                    <el-option v-for="item in carColor_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                  </el-select>
                </el-form-item>
                <el-form-item label="存放地点:" class="searchlist">
                  <el-input v-model="listQuery.params.location" placeholder="" clearable style="width: 150px"/>
                </el-form-item>
              </el-row>
              <div class="searchbtns">
                <el-button type="primary" @click="handleFilter">查询</el-button>
                <el-button type="primary" @click="handReset">重置</el-button>
              </div>
            </el-form>
          </div>
        </div>
        <div class="listtop">
          <div class="tit">现车列表</div>
          <pageye v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>
        </div>
        <div class="">
          <el-table :key="tableKey" v-loading="listLoading" :data="list" border style="width: 100%">
            <el-table-column width="80px" label="序号" type="index" :index="indexMethod" align="center"/>
            <el-table-column label="状态" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.vehicleStateValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="车架号" align="center">
              <template slot-scope="scope">
                <span class="bluezi" @click="handlink(scope.row)">{{ scope.row.vinNo }}</span>
              </template>
            </el-table-column>
            <el-table-column label="颜色" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.carColor }}</span>
              </template>
            </el-table-column>
            <el-table-column label="合格证" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.certificate }}</span>
              </template>
            </el-table-column>
            <el-table-column label="存放地点" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.location }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="pages">
          <!-- 翻页 -->
          <pagination v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>
        </div>
      </div>
    </div>
    <vehiclecarInfo v-show="viewState == 2" ref="divInfo" @doback="resetState"/>
  </div>
</template>

<script>
import { selExistingCarPageList, dataDictionary } from '@/api/chexingchaxun/modelinquire.js'
import Pagination from '@/components/pagination'
import pageye from '@/components/pagination/pageye'
import vehiclecarInfo from './vehiclecarInfo.vue'

export default {
  name: 'xianchecheliang',
  components: {
    Pagination,
    pageye,
    vehiclecarInfo
  },
  data() {
    return {
      isSearchShow: false,
      searchxianshitit: '显示查询条件',
      viewState: 1,
      tableKey: 0,
      list: [],
      carColor_list: [],
      vehicleState_list: [],
      listLoading: false,
      modelSid: '',
      modelConfigSid: '',
      listQuery: {
        current: 1,
        size: 10,
        params: {
          vehicleState: '',
          vinNo: '',
          carColor: '',
          location: '',
          modelSid: '',
          modelConfigSid: '',
          userSid: window.sessionStorage.getItem('userSid')
        },
        total: 0
      }
    }
  },
  methods: {
    // 搜索条件效果
    clicksearchShow() {
      this.isSearchShow = !this.isSearchShow
      if (this.isSearchShow) {
        this.searchxianshitit = '隐藏查询条件'
      } else {
        this.searchxianshitit = '显示查询条件'
      }
    },
    // ----------功能打开结束--------
    // 数组字典加载
    Dictionary() {
      dataDictionary({ type: 'bodyColor' }).then((res) => {
        if (res.code === '200') {
          this.carColor_list = res.data
        }
      })
      dataDictionary({ type: 'vehicleState' }).then((res) => {
        if (res.code === '200') {
          this.vehicleState_list = res.data
        }
      })
    },
    // 序号
    indexMethod(index) {
      var pagestart = (this.listQuery.current - 1) * this.listQuery.size
      var pageindex = index + 1 + pagestart
      return pageindex
    },
    showInfo(sid, row) {
      this.modelSid = sid
      this.modelConfigSid = row.configSid
      this.listQuery.params.modelSid = sid
      this.listQuery.params.modelConfigSid = row.configSid
      this.Dictionary()
      this.getList()
    },
    // 查询列表信息
    getList() {
      this.listLoading = true
      selExistingCarPageList(this.listQuery).then((response) => {
        this.listLoading = false
        if (response.code === '200') {
          this.listQuery.total = response.data.total
          this.list = response.data.records
        }
      })
    },
    // 查询按钮
    handleFilter() {
      this.getList()
    },
    handReset() {
      this.listQuery = {
        current: 1,
        size: 10,
        params: {
          vehicleState: '',
          vinNo: '',
          carColor: '',
          location: '',
          modelSid: this.modelSid,
          modelConfigSid: this.modelConfigSid,
          userSid: window.sessionStorage.getItem('userSid')
        },
        total: 0
      }
      this.getList()
    },
    handlink(row) {
      this.viewState = 2
      this.$refs['divInfo'].showInfo(this.modelSid, this.modelConfigSid, row)
    },
    handleReturn() {
      this.$emit('doback')
    },
    resetState() {
      this.viewState = 1
      this.handReset()
    }
  }
}
</script>
<style scoped>
.listtop {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #dfe4ed;
  height: 40px;
}

.tit {
  margin-bottom: -10px;
}

.pagination {
  margin-bottom: -10px;
}
.searchbtn {
  border: #2cab69 1px solid;
  color: #2cab69;
}
</style>
