<template>
    <div class="page">
        <LayoutTable :data="tableData" :config="tableConfig">
                    </LayoutTable>


        <drawer-show ref="drawerform" @ok="getData" />
    </div>
</template>

<script>
    /** 表单弹出框模式需引入 */
    import drawerShow from "./drawershow";
    import table from "@/assets/mixins/table";
    export default {
        name: "CompanyList",
        components: {
            drawerShow
},
        mixins: [table],
        created() {
        },
        methods: {
            renderTable(tableData) {
                return (
                    <el-table stripe data={tableData} class="total-table">
                    {this.columnSet.map((item) => this.renderTableColumn(item))}
                    </el-table>
                );
            },
            renderTableColumn(options) {
                return (
                    <el-table-column
                        prop={options.prop}
                        label={options.label}
                        width={options.width}
                        formatter={options.formatter}
                    >
                    </el-table-column>
                 );
            },
            /** 重写新增方法 */
            toAdd(row) {
                this.$refs.drawerform.add(row);
            },
            /** 重写编辑方法 */
            toEdit(row) {
                this.$refs.drawerform.edit(row);
            },
            /** 重写查看方法 */
            toView(row) {
                this.$refs.drawerform.view(row);
            },

        },
        data() {
            return {
                /** 子表列元素 */
                columnSet:[
                    {label: "标签Id", prop: "labelId", formatter: this.formatter},
                    {label: "公司Id", prop: "companyId", formatter: this.formatter},
                    {label: "标签名称", prop: "labelName"},
                    {label: "备注", prop: "remark"},
                ],
                config: {
                    search: [
                        {
                            name: "companyName",
                            type: "text",
                            label: "公司名称",
                            fuzzy: true
                        },
                        {
                            name: "companyCode",
                            type: "text",
                            label: "公司编码",
                            fuzzy: true
                        },
                    ],
                    columns: [
                        {type: "selection", width: 60},
                        {type: "index",label: "序号",width: 50},

                        {label: "公司名称", prop: "companyName"},

                        {label: "公司编码", prop: "companyCode"},

                        {label: "注册号", prop: "registrationNumber"},

                        {label: "法定代表人", prop: "legalRepresentative"},

                        {label: "注册资本", prop: "registeredCapital"},

                        {label: "公司类型", prop: "companyType"},

                        {label: "经营范围", prop: "businessScope"},

                        {label: "经营地址", prop: "businessAdress"},

                        {label: "所在地", prop: "location"},

                        {label: "联系电话", prop: "contactPhone"},

                        {label: "电子邮件地址", prop: "email"},

                        {label: "公司网站", prop: "website"},

                        {label: "税务登记号", prop: "taxRegistrationNumber"},

                        {label: "社会信用代码", prop: "socialCreditCode"},

                        {label: "商标信息", prop: "trademarkInfo"},

                        {label: "网站历史备案信息", prop: "websiteRegistrationInfo"},

                        {label: "员工总数", prop: "totalEmployees",formatter: this.formatter},

                        {label: "软件著作权数量", prop: "softNum",formatter: this.formatter},

                        {label: "专利数量", prop: "patentNum",formatter: this.formatter},

                        {label: "历史发展", prop: "hisDevelop"},

                        {label: "创建用户", prop: "createUserId", formatter: this.formatter},
                        {label: "公司标注",
                          width: 120,
                          prop: "subColumns",
                          formatter: (row) => {
                              let widthsize = this.columnSet.reduce((pre, cur) => {
                                  return pre + Number(cur.width);
                              }, 50);
                              return (
                                  <el-popover placement="right" width={widthsize} trigger="click">
                                      {this.renderTable(row.companyLabelsList)}
                                      <el-button type="text" slot="reference">详细</el-button>
                                  </el-popover>
                              );
                          },
                        },
                        {
                            label: "操作",
                            width: 240,
                            formatter: row => {
                                return (
                                    <table-buttons noAdd row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
                            );
                            }
                        }
                    ]
                }
            };
        }
    };
</script>