#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@File    :   push_page.py
@Time    :   2024/11/28 16:24:19
@Author  :   dulip3ng
@Version :   1.0
@Desc    :   None
'''
from pages.locator.push_page_locator import PushPageLocator
from pages.base_page import BasePage

class PushPage(BasePage):
    """
    选单，下拉独立页面页面模型
    """

    def _pick_bill(self, bill_name:str):
        """
        选择单据，精确匹配
        :param bill_name: 单据名称
        :return:
        """
        self.page.locator(PushPageLocator.BILL_ARGSLOC % bill_name).click()

    def _select_bill_type(self, bill_type:str):
        """
        选择单据类型，精确匹配
        :param bill_type: 单据类型名称，可选参数
        :return:
        """
        self.page.locator(PushPageLocator.BILL_TYPE_LOC).click()
        self.page.locator(PushPageLocator.SELECT_ITEM_ARGS_LOC % bill_type).click()

    def _select_convert_rule(self, rule_name:str):
        """
        选择单据转换规则，精确匹配
        :param rule_name: 转换规则名称，可选参数
        :return:
        """
        self.page.locator(PushPageLocator.CONVERT_RULE_LOC).click()
        self.page.locator(PushPageLocator.SELECT_ITEM_ARGS_LOC % rule_name).click()

    def _select_target_org(self, org_name:str):
        """
        选择目标组织，精确匹配
        :param org_name:
        :return:
        """
        self.page.locator(PushPageLocator.TARGET_ORG_LOC).click()
        self.page.locator(PushPageLocator.SELECT_ITEM_ARGS_LOC % org_name).click()

    def _click_ok_button(self):
        """
        点击下推页面确定按钮
        :return:
        """
        self.page.locator(PushPageLocator.OK_BUTTON_LOC).click()

    def push_draw_bill(self, bill_name:str, rule_name:str=None, bill_type:str=None, org_name:str=None):
        """
        设置单据，单据类型，转换规则，目标组织进行下推操作

        **用法：**

        PushPage.push_draw_bill("生产订单")

        PushPage.push_draw_bill("生产订单", "犀牛销售订单2生产订单", "直接入库-普通生产", "制衣事业部")

        :param bill_name: 下游单据名称，精确匹配，必填
        :param rule_name: 转换规则，精确匹配，可选
        :param bill_type: 单据类型，精确匹配，可选
        :param org_name: 目标组织名，精确匹配，可选
        :return:
        """
        self._pick_bill(bill_name)
        if rule_name:   self._select_convert_rule(rule_name)
        if bill_type:   self._select_bill_type(bill_type)
        if org_name:    self._select_target_org(org_name)
        self._click_ok_button()


