<template>
  <div id="shareholders">
    <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="120px">
              <el-col :span="8" class="one_1">
                <el-form-item label="股东类型">
                  <el-select v-model="searchForm.stock_type" placeholder="请选择" style="width: 100%">
                    <el-option v-for="item in stock_typeList" :key="item" :label="item" :value="item"> </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.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="联系电话">
                  <el-input v-model="searchForm.phone"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="性别">
                  <el-select v-model="searchForm.gender" placeholder="请选择" style="width: 100%">
                    <el-option v-for="item in genderList" :key="item" :label="item" :value="item"> </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.card"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="现住址省市县">
                  <el-input v-model="searchForm.onhouse_city"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="股东经济类型">
                  <el-input v-model="searchForm.money_type"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="所占股份百分比">
                  <el-input v-model="searchForm.shares_num"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="one_1">
                <el-form-item label="出资金额">
                  <el-input v-model="searchForm.out_money"></el-input>
                </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="stock_type">
            <el-input v-model="info.stock_type" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="info.name" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="证件号码" prop="card">
            <el-input v-model="info.card" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="性别" prop="gender">
            <el-input v-model="info.gender" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="出生日期" prop="birth">
            <el-input v-model="info.birth" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="phone">
            <el-input v-model="info.phone" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="现住址省市县" prop="onhouse_city">
            <el-input v-model="info.onhouse_city" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="股东经济类型" prop="money_type">
            <el-input v-model="info.money_type" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所占股份百分比" prop="shares_num">
            <el-input v-model="info.shares_num" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="出资金额" prop="out_money">
            <el-input v-model="info.out_money" 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_shareholders');
const _ = require('lodash');
export default {
  name: 'shareholders',
  props: {
    title: { type: String },
  },
  components: {},
  data: function () {
    return {
      // 查询
      searchForm: {},
      // 股东类型
      stock_typeList: ['法人股东'],
      // 性别
      genderList: gender,
      list: [],
      total: 0,
      fields: [
        { label: '股东类型', model: 'stock_type' },
        { label: '姓名', model: 'name' },
        { label: '性别', model: 'gender' },
        { label: '证件号码', model: 'card' },
        { label: '出生日期', model: 'birth' },
        { label: '现住址省市县', model: 'onhouse_city' },
        { label: '联系电话', model: 'phone' },
        { label: '所占股份百分比', model: 'shares_num' },
        { label: '出资金额', model: 'out_money' },
      ],
      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>
