<template>
  <div id="list">
    <el-row>
      <el-col :span="1"><i class="el-icon-s-home"></i></el-col>
      <el-col :span="23" style="margin-top:0.3rem">
        <el-breadcrumb separator=">">
          <el-breadcrumb-item :to="{ path: '/' }"><span style="color:#666666">网站首页</span></el-breadcrumb-item>
          <el-breadcrumb-item>
            <a href="/"><span style="color:#666666">招聘信息</span></a>
          </el-breadcrumb-item>
          <el-breadcrumb-item><span style="color:#999999">岗位</span></el-breadcrumb-item>
        </el-breadcrumb>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="10" style="margin-top: 1rem; width:50%">
        <el-input size="mini" placeholder="请输入企业名称" v-model="searchInfo.corpname" @keyup.enter.native="search()">
          <el-button slot="append" icon="el-icon-search" @click="search()"></el-button>
        </el-input>
      </el-col>
    </el-row>
    <el-row class="rowstyle" v-for="(item, index) in list" :key="index">
      <el-col :span="3">
        <div class="block"><el-avatar shape="square" :size="75" :src="squareUrl"></el-avatar></div>
      </el-col>
      <el-col :span="10" class="info">
        <el-row>
          <el-col :span="24">
            <el-link class="title" @click="$router.push({ path: '/jobs/detail', query: { id: item.id } })">
              {{ item.job_name }}
            </el-link>
          </el-col>
          <el-col class="money" :span="24">{{ item.salary.text }}</el-col>
          <el-col class="word" :span="24">
            <span>{{ item.city }}/{{ item.xl_req }}/{{ item.job_number }}人</span>
          </el-col>
        </el-row>
      </el-col>
      <el-col :span="11" class="info">
        <el-row>
          <el-col class="word" :span="24">{{ item.corpname }}</el-col>
          <el-col class="word" :span="24">{{ item.category }}</el-col>
          <el-col class="word" :span="24">
            {{ item.end_date }}
          </el-col>
        </el-row>
      </el-col>
    </el-row>
    <el-row style="margin-top:1rem;" type="flex" justify="end">
      <el-pagination @current-change="search" :current-page="currentPage" :page-size="$limit" layout="total, prev, pager, next, jumper" :total="totalRow">
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex';

export default {
  name: 'list',
  props: {},
  components: {},
  data: () => ({
    squareUrl: '',
    searchInfo: {},
    currentPage: 1,
    totalRow: 0,
    list: [],
  }),
  created() {
    this.search();
    // console.log(this.$route.params.type === 'official' ? 0 : 1);
  },
  computed: {
    type() {
      return this.$route.params.type === 'official' ? 0 : 1;
    },
  },
  watch: {
    type: 'search',
  },
  methods: {
    ...mapActions(['postOperation']),
    async search(page) {
      let skip = 0;
      if (page) {
        skip = (page - 1) * this.$limit;
      }
      let newData = { skip: skip, limit: this.$limit, ...this.searchInfo, is_publish: 1 }; //schid: 99991,
      newData['is_practice'] = this.type;
      let result = await this.postOperation({ type: 'list', data: newData });
      if (`${result.errcode}` === '0') {
        //给this=>vue的实例下在中的list属性，赋予result.data的值
        this.$set(this, `list`, result.data);
        this.$set(this, `totalRow`, result.total);
      } else {
        this.$message.error(result.errmsg ? result.errmsg : 'error');
      }
    },
  },
};
</script>

<style lang="less" scoped>
.rowstyle {
  border-bottom-style: solid;
  border-width: 1px;
  border-color: #ebeef5;
  font-size: small;
  padding: 1rem 0;
  .el-col {
    margin-top: 0.5rem;
  }
  .info {
    .title {
      font-size: 1rem;
      color: #850000;
    }
    .money {
      font-size: 0.9rem;
      color: #f40;
    }
    .word {
      font-size: 0.85rem;
      color: #666666;
    }
  }
}
</style>
