<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-col :span="24" class="one_1"> 车辆信息查询选项 </el-col>
          <el-col :span="24" class="one_2">
            <el-form ref="searchFrom" :model="searchFrom" label-width="140px">
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="号码种类">
                    <el-select v-model="searchFrom.num_type" clearable placeholder="请选择" style="width: 100%">
                      <el-option label="蓝牌" value="蓝牌"> </el-option>
                      <el-option label="黄牌" value="黄牌"> </el-option>
                      <el-option label="绿牌" value="绿牌"> </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="车牌号码">
                    <el-input v-model="searchFrom.car_num"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="专用运钞车防护级别">
                    <el-select v-model="searchFrom.car_level" clearable placeholder="请选择">
                      <el-option label="A级" value="A级"> </el-option>
                      <el-option label="B级" value="B级"> </el-option>
                      <el-option label="C级" value="C级"> </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="出产日期">
                    <el-date-picker v-model="searchFrom['start@put_date']" placeholder="请选择" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="至">
                    <el-date-picker v-model="searchFrom['end@put_date']" placeholder="请选择" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="专用运钞车产品分类">
                    <el-select v-model="searchFrom.car_type" clearable placeholder="请选择">
                      <el-option label="大型运钞车" value="大型运钞车"> </el-option>
                      <el-option label="中型运钞车" value="中型运钞车"> </el-option>
                      <el-option label="小型运钞车" value="小型运钞车"> </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="报废日期">
                    <el-date-picker v-model="searchFrom['start@cancel_date']" placeholder="请选择" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="至">
                    <el-date-picker v-model="searchFrom['end@cancel_date']" placeholder="请选择" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8" class="btn">
                  <el-button type="primary" size="mini" @click="search()">查询</el-button>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
        </el-col>
        <el-col :span="24" class="two">
          <data-table @query="search" :fields="fields" :opera="opera" :data="list" :total="total" @view="toView"> </data-table>
        </el-col>
      </el-col>
    </el-row>

    <el-dialog class="twoDialog" title="信息详情" :visible.sync="twoShow" width="50%" :before-close="twoClose" :close-on-click-modal="false">
      <info-1 :info="info"></info-1>
    </el-dialog>
  </div>
</template>

<script>
import info1 from './parts/info-1.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: company_car } = createNamespacedHelpers('company_car');
export default {
  name: 'index',
  props: {},
  components: { info1 },
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '车辆号码', model: 'car_num' },
        { label: '号码种类', model: 'num_type' },
        { label: '专用运钞车产品分类', model: 'car_type' },
        { label: '专用运钞车防护级别', model: 'car_level' },
        { label: '出产日期', model: 'put_date' },
        { label: '报废日期', model: 'cancel_date' },
      ],
      opera: [{ label: '详情', method: 'view' }],
      list: [],
      total: 0,

      // 详情
      twoShow: false,
      info: {},
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...company_car(['query', 'create', 'update']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchFrom);
      let res = await this.query({ skip, limit, ...condition, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },

    // 详情
    toView({ data }) {
      this.$set(this, `info`, data);
      this.twoShow = true;
    },
    // 关闭详情
    twoClose() {
      this.twoShow = false;
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    .one_1 {
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #ccc;
      margin: 0 0 10px 0;
      font-size: 18px;
      font-weight: bold;
    }
    .one_2 {
      .one_2txt {
        border: 1px solid #ccc;
        /deep/.el-form-item {
          margin: 0;
        }
        /deep/.el-date-editor.el-input,
        .el-date-editor.el-input__inner {
          width: 100%;
        }
        /deep/.el-select {
          width: 100%;
        }
        .btn {
          text-align: right;
          padding: 5px 5px;
        }
      }
    }
  }
}
/deep/.el-dialog__body {
  padding: 10px;
}
</style>
