# -*- coding:utf-8 -*-
# 作者：齐振鋆
# 日期：2023/3/4
# 描述:

import logging

from page.GuKeYiTiHua.Public.errorMsg import ErrorMessage
from page.GuKeYiTiHua.Public.iFrame import IframeElement
from unit.public.UI.BasePage import BasePage

log = logging.getLogger(__name__)


class ButtonElement(BasePage):
    em = ErrorMessage()
    iframe = IframeElement()

    def click_button(self, root_str='', button_name='保存', end_str="/ancestor::button"):
        """点击按钮，默认为保存"""
        log.info('点击：【{}】按钮'.format(button_name))
        self.click("{}//*[text()='{}']{}".format(root_str, button_name, end_str))
        self.em.check_message()

    def new(self):
        self.click_button(button_name='新建')
        self.iframe.to_edit_iframe()


    def all_delivery(self):
        """整单发货"""
        self.click_button(button_name='整单发货')

    def save(self):
        """保存"""
        self.click_button(button_name='保存')

    def submit(self):
        """提交"""
        self.click_button(button_name='提交')

    def nullify(self):
        """作废"""
        self.click_button(button_name='作废')

    def send(self):
        """发送"""
        self.click_button(button_name='发送')

    def transact(self):
        """办理"""
        self.click_button(button_name='办理')

    def scan_bar(self):
        """扫码"""
        self.click("//button[text()='扫码']")

    def all_cancel(self):
        """整单取消"""
        self.click_button(button_name='整单取消')

    def red_flush(self):
        """红冲"""
        self.click_button(button_name='红冲')
        self.iframe.to_transfer_out_iframe()

    def all_red_flush(self):
        """整单红冲"""
        self.click_button(button_name='整单红冲')