'''
@Project ：test_guke 
@File    ：transfer_in.py
@IDE     ：PyCharm 
@Author  ：何凯
@Date    ：2023/3/17 16:00
@desc   :调拨入库单
'''

import logging
from random import randint
import allure
from time import sleep
from component.GuKeYiTiHua import iframe, menu, list_page, button, order_detail_main, order_detail_table, \
    modal
from component.GuKeYiTiHua.Transfer import first_menu
from unit.public.YamlUtil import UtilYaml

log = logging.getLogger(__name__)


class TransferIn(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.order_detail_table = order_detail_table
        # self.modal = modal

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

    @allure.step('查询：{}'.format(third_menu))
    def transfer_in_search(self, tap_name='待办视图', order_code=None, count=1):
        self.list_page.order_search(self.third_menu, tap_name, '调拨出库单号', order_code, count)

    @allure.step('提交：{}'.format(third_menu))
    def transfer_in_code_create(self, order_code=None):
        log.info('调拨入库单提交')
        self.iframe.to_main_iframe()
        self.transfer_in_search(order_code=order_code)
        self.list_page.open_order('订单号')
        self.order_detail_main.choose_tap('主体信息')
        log.info('获取调拨入库单号')
        transfer_in_code = ''
        while transfer_in_code.startswith('OT') is False:
            sleep(1)
            transfer_in_code = self.order_detail_main.get_element_text('调拨入库单号 ')
        self.menu.dd.set_value('transfer_in_code', transfer_in_code)
        UtilYaml(self.menu.dd.get_value('extract_path')).write_yaml({'transfer_in_code': transfer_in_code})
        self.button.submit()
        self.list_page.edit_iframe_is_show()

    def transfer_in_code_cancel(self, order_code=None):
        log.info('调拨入库单整单取消')
        self.transfer_in_search(tap_name='已办视图',order_code=order_code,count=1)
        self.list_page.checked_order(0)
        self.button.click_button(button_name='整单取消')
        self.button.click_button(root_str="//div[contains(@class,'is-message-box')]", button_name="是")

