# -*- coding:utf-8 -*-
# 作者：齐振鋆
# 日期：2023/2/27
# 描述: 仓库收货
import logging
import allure

from time import sleep
from selenium.common.exceptions import TimeoutException
from component.GuKeYiTiHua import iframe, menu, list_page, button, order_detail_main, modal
from component.GuKeYiTiHua.StorageManage import first_menu

log = logging.getLogger(__name__)


class WarehouseTake(object):
    third_menu = '仓库收货'

    def __init__(self):
        self.iframe = iframe
        self.menu = menu
        self.list_page = list_page
        self.button = button
        self.order_detail_main = order_detail_main
        self.modal = modal

    @allure.step('打开菜单：{}'.format(third_menu))
    def take_menu_open(self):
        self.iframe.out_frame()
        self.menu.open_menu(first_menu, self.third_menu)

    @allure.step('查询：{}'.format(third_menu))
    def take_order_search(self, tap_name='待办', order_code=None, count=1):
        self.list_page.order_search(self.third_menu, tap_name, '订单号', order_code, count)

    @allure.step('订单池收货')
    def take_pool_take(self, order_code):
        log.info('订单池收货')
        self.take_order_search('收货订单池', order_code, count=len(self.menu.dd.get_value('test_data_info')['goods']))
        self.list_page.checked_order(0)
        self.button.click_button(button_name='收货')
        try:
            self.button.click_button("//div[contains(@class, 'is-message-box')]", '确定')
        except TimeoutException:
            pass
        sleep(1)

    @allure.step('{}'.format(third_menu))
    def take_confirm(self, order_code):
        log.info('收货确认')
        self.take_order_search(order_code=order_code)
        self.list_page.open_order('订单号')
        self.button.submit()
        self.list_page.edit_iframe_is_show()
