<template>
    <div>
        <crumbs title="产品线管理-产品线详情" linkTo="/admin/LT-CPXGL">
            <el-form :inline="true" class="demo-form-inline">
                <el-form-item label="机构名称：">
                    <el-input size="mini" v-model="filter.orgName" placeholder="机构名称"></el-input>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button size="mini" @click="getDataList">确认</el-button>
                </el-form-item>
            </el-form>
        </crumbs>
        <div class="contents">
            <el-table :data="list"
                      border
                      style="width: 100%">
                <el-table-column
                        type="index"
                        :index="indexMethod"
                        label="编号"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="orderTime"
                        label="申请时间">
                </el-table-column>
                <el-table-column
                        prop="orgName"
                        label="接入机构">
                </el-table-column>
                <el-table-column
                        prop="subNum"
                        label="下属机构接入数量">
                </el-table-column>
                <el-table-column
                        prop="endTime"
                        label="服务到期时间">
                </el-table-column>
            </el-table>
            <el-pagination v-if="total>pageSize"
                           :current-page.sync="currentPage"
                           @current-change="currentChange"
                           background
                           :page-size="pageSize"
                           layout="total,prev, pager, next, jumper"
                           :total="total">
            </el-pagination>
        </div>

    </div>
</template>

<script>
  import api from '@api/admin.js';
  import utils from '@api/utils.js';

  export default {
    name: 'product-detail',
    data: function () {
      return {
        list: [],
        status: [],
        cacheData: {},
        currentPage: 1,
        pageSize: 10,
        total: 0,
        proId:'',
        filter: {
          orgName: ''
        }
      }
    },
    created() {
      this.proId = this.$route.params.productId;
      this.getDataList();
    },
    methods: {
      getDataList() {
        const param = this.getFilterItems();
        api.getProductDetail(param).then((res) => {
          if (res.data.code == '0') {
            const data = res.data.data;
            this.list = data.records;
            this.cacheData[param.current] = data.records;
            this.total = data.total;
          }
        }).catch((error) => {
          console.log(error);
        });
      },
      getFilterItems() {
        const param = {
          productId: this.proId,
          orgName: this.filter.orgName||undefined,
          current: this.currentPage,
          size: this.pageSize
        };
        return param;
      },
      indexMethod(index) {
        return ((this.currentPage - 1) * this.pageSize) + index + 1;
      },
      currentChange(next) {
        this.currentPage = next;
        if (this.cacheData[next]) {       //如果已请求过该页数据，则使用缓存不重复请求
          this.list = this.cacheData[next];
        } else {
          this.getDataList();
        }
      }
    }
  }
</script>

<style lang="less">
    @import "../../less/admin.less";
    .status-span{
        font-size: 14px;
        margin-right:10px;
    }
</style>