def __init__(self, *args, **kwargs): super(InvestPlanPage, self).__init__(*args, **kwargs) layout = QVBoxLayout() layout.setContentsMargins(QMargins(0, 0, 0, 5)) layout.setSpacing(2) self.table = InvestPlanTable() layout.addWidget(self.table) # 无数据的显示 self.no_data_label = QLabel('暂无投资方案数据...', styleSheet='color:rgb(200,100,50)', alignment=Qt.AlignCenter) self.no_data_label.hide() layout.addWidget(self.no_data_label) # 页码控制布局 self.paginator = Paginator() self.paginator.setMargins(0, 10, 3, 0) self.paginator.clicked.connect(self.getCurrentPlanContents) layout.addWidget(self.paginator, alignment=Qt.AlignCenter) self.setLayout(layout)
class HedgePlanPage(QWidget): def __init__(self, *args, **kwargs): super(HedgePlanPage, self).__init__(*args, **kwargs) layout = QVBoxLayout() layout.setContentsMargins(QMargins(0, 0, 0, 5)) layout.setSpacing(5) self.table = InvestPlanTable() layout.addWidget(self.table) # 无数据的显示 self.no_data_label = QLabel('暂无套保方案数据...', styleSheet='color:rgb(200,100,50)', alignment=Qt.AlignCenter) self.no_data_label.hide() layout.addWidget(self.no_data_label) # 页码控制布局 self.paginator = Paginator() self.paginator.setMargins(0, 10, 3, 0) self.paginator.clicked.connect(self.getCurrentPlanContents) layout.addWidget(self.paginator, alignment=Qt.AlignCenter) self.setLayout(layout) # 请求数据 def getCurrentPlanContents(self): current_page = self.paginator.current_page try: url = settings.SERVER_ADDR + 'strategy/hedgeplan/?page='+str(current_page) r = requests.get(url=url) response = json.loads(r.content.decode('utf-8')) if r.status_code != 200: raise ValueError(response['message']) except Exception as e: self.network_message_label.setText(str(e)) else: if response['records']: self.paginator.setTotalPages(response['total_page']) self.table.showRowContents(response['records']) self.table.show() self.paginator.show() self.no_data_label.hide() else: self.no_data_label.show() self.table.hide() self.paginator.hide()