<template>
  <div id="car">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-col :span="24" class="title">{{ title }}</el-col>
          <el-col :span="24" class="form">
            <el-form ref="searchForm" :model="searchForm" label-width="140px">
              <el-col :span="8" class="one_1">
                <el-form-item label="号码种类">
                  <el-select v-model="searchForm.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" class="one_1">
                <el-form-item label="车牌号码">
                  <el-input v-model="searchForm.car_num"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="专用运钞车防护级别">
                  <el-select v-model="searchForm.car_level" clearable placeholder="请选择" style="width: 100%">
                    <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 :span="8" class="one_1">
                <el-form-item label="出产日期">
                  <el-date-picker
                    v-model="searchForm['start@put_date']"
                    placeholder="请选择"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    type="date"
                    style="width: 100%"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="至">
                  <el-date-picker
                    v-model="searchForm['end@put_date']"
                    placeholder="请选择"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    type="date"
                    style="width: 100%"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="专用运钞车产品分类">
                  <el-select v-model="searchForm.car_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" class="one_1">
                <el-form-item label="报废日期">
                  <el-date-picker
                    v-model="searchForm['start@cancel_date']"
                    placeholder="请选择"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    type="date"
                    style="width: 100%"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="至">
                  <el-date-picker
                    v-model="searchForm['end@cancel_date']"
                    placeholder="请选择"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    type="date"
                    style="width: 100%"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="btn">
                <el-button type="primary" size="mini" @click="search()">查询</el-button>
              </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 :title="title" :close-on-click-modal="false" :visible.sync="dialog" center :destroy-on-close="true" @closed="toClose">
      <el-form ref="info" :model="info" label-width="auto">
        <el-col :span="12">
          <el-form-item label="保安服务公司" prop="company">
            <el-input v-model="info.company" placeholder="请输入保安服务公司" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="管辖单位" prop="tube_company">
            <el-input v-model="info.tube_company" placeholder="请输入管辖单位" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="号码种类" prop="num_type">
            <el-input v-model="info.num_type" placeholder="请输入号码种类" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="车牌号码" prop="car_num">
            <el-input v-model="info.car_num" placeholder="请输入车牌号码" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="专用运钞车产品分类" prop="car_type">
            <el-input v-model="info.car_type" placeholder="请输入专用运钞车产品分类" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="专用运钞车防护级别" prop="car_level">
            <el-input v-model="info.car_level" placeholder="请输入专用运钞车防护级别" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发动机号" prop="engine">
            <el-input v-model="info.engine" placeholder="请输入发动机号" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="出产日期" prop="put_date">
            <el-input v-model="info.put_date" placeholder="请输入出产日期" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="车架号" prop="frame_num">
            <el-input v-model="info.frame_num" placeholder="请输入车架号" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="报废日期" prop="cancel_date">
            <el-input v-model="info.cancel_date" placeholder="请输入报废日期" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="制造单位名称" prop="make_company">
            <el-input v-model="info.make_company" placeholder="请输入制造单位名称" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="报废原因" prop="cancel_reason">
            <el-input v-model="info.cancel_reason" placeholder="请输入报废原因" type="textarea" rows="2" readonly></el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
const { gender } = require('@common/src/layout/deploy/dict');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('company_car');
const _ = require('lodash');
export default {
  name: 'car',
  props: {
    title: { type: String },
  },
  components: {},
  data: function () {
    return {
      // 查询
      searchForm: {},
      list: [],
      total: 0,
      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' }],
      // 弹框
      dialog: false,
      // 详情
      info: {},
    };
  },
  async created() {
    if (this.id) await this.search();
  },
  methods: {
    ...mapActions(['query', 'fetch', 'create', 'update']),
    async search({ skip, limit } = {}) {
      const condition = _.cloneDeep(this.searchForm);
      const res = await this.query({ skip, limit, ...condition, company_id: this.id });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 查看详情
    async toView({ data }) {
      let res = await this.fetch({ id: data.id });
      if (this.$checkRes(res)) {
        this.$set(this, `info`, res.data);
        this.$set(this, `dialog`, true);
      }
    },
    // 关闭弹框
    toClose() {
      this.$set(this, `dialog`, false);
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.one {
  .title {
    font-weight: bold;
    font-size: 18px;
    padding: 10px 0;
    border-bottom: 1px solid #cccccc;
    margin: 0 0 10px 0;
  }
  .form {
    .one_1 {
      padding: 0 10px;
      /deep/.el-form-item {
        margin: 0;
      }
    }
    .btn {
      text-align: right;
      margin: 10px 0 0 0;
      padding: 0 10px;
    }
  }
}
/deep/.el-dialog__body {
  max-height: 430px;
  overflow: auto;
}
.dialog {
  .btn {
    text-align: center;
  }
}
</style>
