<template>
  <div>

    <div>
      <div ref="lxHeader">
        <lx-header icon="md-apps" :text="$route.meta.title" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content">
            <div class="searchwrap" style="display: flex;align-items: center;">
              <div>
                <el-input v-model="select.company_name" placeholder="请输入企业名称"></el-input>
              </div>
              <div>
                <el-button type="primary" size="small" @click="select.page=1,getList()">查询</el-button>
                <el-button type="primary" size="small" @click="resetSelect">重置</el-button>

              </div>
              <div>
                <el-button type="primary" size="small" @click="editCompany('add')">新增</el-button>
              </div>
            </div>
          </div>

        </lx-header>
      </div>
    </div>

    <div>
      <xy-table :list="list" :total="total" @pageIndexChange="pageIndexChange" @pageSizeChange="pageSizeChange"
        :table-item="table_item">
        <template v-slot:company_name>
          <el-table-column align='left' label="企业名称" width="240" header-align="center">
            <template slot-scope="scope">
              <div @click="toQicc(scope.row.company_name)" style="color:blue;cursor: pointer;text-decoration: underline;">
                {{scope.row.company_name}}
              </div>
            </template>
          </el-table-column>
        </template>
        <template v-slot:company_legal_representative>
          <el-table-column align='center' label="法人代表" width="120" header-align="center">
            <template slot-scope="scope">
              <div @click="toQicc(scope.row.company_name)" style="color:blue;cursor: pointer;text-decoration: underline;">
                {{scope.row.company_legal_representative}}
              </div>
            </template>
          </el-table-column>
        </template>
        <template v-slot:company_shareholder>
          <el-table-column align='center' label="股东信息" width="120" header-align="center">
            <template slot-scope="scope">
              <div @click="toQicc(item.company_name)" style="color:blue;cursor: pointer;text-decoration: underline;">
                {{scope.row.company_shareholder}}
              </div>
            </template>
          </el-table-column>
        </template>
        <template v-slot:company_attribute>
          <el-table-column align='center' label="行业类型" width="120" header-align="center">
            <template slot-scope="scope">
              <div v-for="item in formSelect.company_industry">
                <el-tag v-if="item.value===scope.row.company_attribute"
                  :type="item.remark?item.remark:''">{{scope.row.company_attribute}}</el-tag>
              </div>
            </template>
          </el-table-column>
        </template>
        <template v-slot:company_tag>
          <el-table-column align='center' label="行业标签" width="120" header-align="center">
            <template slot-scope="scope">
              <div v-for="item in formSelect.company_tag">
                <el-tag v-if="item.value===scope.row.company_tag"
                  :type="item.remark?item.remark:''">{{scope.row.company_tag}}</el-tag>
              </div>
            </template>
          </el-table-column>
        </template>
        <template v-slot:users>
          <el-table-column align='left' label="校友信息" width="240" header-align="center">
            <template slot-scope="scope">
              <template v-if="scope.row.users && scope.row.users.length>0">
                <div v-for="item in scope.row.users">
                  <div>
                    校友：{{item.name}}
                  </div>
                  <div>
                    职务：{{item.company_position}}
                  </div>
                  <div v-if="item.course_signs && item.course_signs.length>0">
                    课程：
                    <template  v-for="(item1,index) in item.course_signs">

                      <span>{{item1.course.name}}</span>
                      <span v-if="(index+1)<item.course_signs.length">、</span>
                    </template>
                  </div>
                </div>
              </template>

            </template>
          </el-table-column>
        </template>

        <template v-slot:btns>
          <el-table-column align='center' fixed="right" label="操作" width="180" header-align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="editCompany('editor',scope.row.id)">编辑</el-button>
              <el-popconfirm style="margin:0 10px" @confirm="deleteList(scope.row.id)" title="确定删除吗？">
                <el-button type="danger" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </template>
      </xy-table>
    </div>

    <add-company ref="addCompany" @refresh="getList"></add-company>
  </div>
</template>

<script>
  import addCompany from './components/addCompany.vue';
  import {
    index,
    destroy
  } from "@/api/student/schoolmateCompany.js"
  import formMixin from "@/mixin/formMixin.js";
  export default {
    mixins: [formMixin],
    components: {
      addCompany
    },
    data() {
      return {
        select: {
          company_name: '',
          page: 1,
          page_size: 10
        },
        list: [],
        total: 0,
        table_item: [{
          prop: 'company_name',
          label: '企业名称',
          align: 'left',
          width: 240,
        }, {
          prop: 'company_attribute',
          label: '行业类型',
          align: 'center',
          width: 120
        }, {
          prop: 'company_tag',
          label: '标签',
          align: 'center',
          width: 160,
        }, {
          prop: 'company_scale',
          label: '企业规模',
          align: 'center',
          width: 120,
        }, {
          prop: 'company_date',
          label: '成立时间',
          align: 'center',
          width: 120,
        }, {
          prop: 'company_legal_representative',
          label: '法人代表',
          align: 'center',
          width: 120,
        }, {
          prop: 'company_shareholder',
          label: '股东信息',
          align: 'center',
          width: 120,
        }, {
          prop: 'management_platform',
          label: '管理平台',
          align: 'center',
          width: 120,
        }, {
          prop: 'project_manager',
          label: '项目经理',
          align: 'center',
          width: 120,
        }, {
          prop: 'users',
          label: '校友信息',
          align: 'center',
          width: 240,
        }]

      }
    },
    created() {
      this.getList()
    },
    methods: {
      toQicc(company_name) {
        var url = 'https://www.qcc.com/web/search?key='
        if(company_name){
          window.open(url+company_name, '_blank')
        }
        // 'https://www.qcc.com/firm/ffb3379dc6b254336ecd31fc20d1dd30.html'
        // https://www.qcc.com/firm/0a07162e2b34a5ee8046d46a1a446ed2.html
      },
      pageIndexChange(e) {
        this.select.page = e
        this.getList()
      },
      pageSizeChange(e) {
        this.select.page_size = e
        this.select.page = 1
        this.getList()
      },
      editCompany(type, id) {
        if (type == 'editor') {
          this.$refs.addCompany.id = id
        }
        this.$refs.addCompany.type = type
        this.$refs.addCompany.isShow = true
      },
      resetSelect() {

        this.select.company_name = ''
        this.select.page = 1
        this.getList()
      },
      async getList() {
        const res = await index({
          page_size: this.select.page_size,
          page: this.select.page,
          filter: [{
            key: 'company_name',
            op: 'like',
            value: this.select.company_name
          }]
        })

        this.list = res.data
        this.total = res.total
      },
      deleteList(id) {
        var that = this;
        destroy({
          id: id
        }).then(response => {
          this.$Message.success('操作成功');
          this.getList()
        }).catch(error => {
          console.log(error)
          reject(error)
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .searchwrap {
    display: flex;
    align-items: center;

    &>div {
      display: flex;
      align-items: center;
      margin-right: 10px;

      span {
        min-width: 70px;
      }
    }
  }
</style>
