<template>
  <div id="equipment">
    <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-input v-model="searchForm.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="位置">
                  <el-input v-model="searchForm.local"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="状态">
                  <el-select v-model="searchForm.status" clearable placeholder="请选择" style="width: 100%">
                    <el-option label="启用" value="0"></el-option>
                    <el-option label="撤销" value="1"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6" class="one_1">
                <el-form-item label="启用日期">
                  <el-date-picker
                    v-model="searchForm['start@enable_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="6" class="one_1">
                <el-form-item label="至">
                  <el-date-picker
                    v-model="searchForm['end@enable_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="6" class="one_1">
                <el-form-item label="撤销日期">
                  <el-date-picker
                    v-model="searchForm['start@revoke_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="6" class="one_1">
                <el-form-item label="至">
                  <el-date-picker
                    v-model="searchForm['end@revoke_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="name">
            <el-input v-model="info.name" placeholder="请输入装备名称" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="数量" prop="num">
            <el-input v-model="info.num" placeholder="请输入数量" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="规格" prop="specs">
            <el-input v-model="info.specs" placeholder="请输入规格" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="型号" prop="model">
            <el-input v-model="info.model" placeholder="请输入型号" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="启用日期" prop="enable_date">
            <el-input v-model="info.enable_date" placeholder="请输入启用日期" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="撤销日期" prop="revoke_date">
            <el-input v-model="info.revoke_date" placeholder="请输入撤销日期" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="位置" prop="local">
            <el-input v-model="info.local" type="textarea" rows="2" placeholder="请输入位置" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="info.remark" type="textarea" rows="2" placeholder="请输入备注" 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_equipment');
const _ = require('lodash');
export default {
  name: 'equipment',
  props: {
    title: { type: String },
  },
  components: {},
  data: function () {
    return {
      // 查询
      searchForm: {},
      list: [],
      total: 0,
      fields: [
        { label: '装备名称', model: 'name' },
        { label: '位置', model: 'local' },
        { label: '规格', model: 'specs' },
        { label: '启用日期', model: 'enable_date' },
        { label: '撤销日期', model: 'revoke_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>
