# -*- coding:utf-8 -*-
# 作者：齐振鋆
# 日期：2023/3/4
# 描述: 选配类还回出库
import logging
import allure

from component.GuKeYiTiHua import iframe, menu, list_page, order_detail_main
from component.GuKeYiTiHua.SurgeryFollow import first_menu
from unit.public.YamlUtil import UtilYaml

log = logging.getLogger(__name__)


class ApolegamyBack(object):
    third_menu = '选配类还回出库'

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

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

    @allure.step('查询：{}'.format(third_menu))
    def apolegamy_back_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 get_apolegamy_out_code(self, order_code):
        self.list_page.open_order(order_code=order_code)
        fh_code = self.order_detail_main.get_element_text('还回出库单号 ')
        UtilYaml(self.menu.dd.get_value('extract_path')).write_yaml({'fh_code': fh_code})
        log.info('还回出库单号：【{}】'.format(fh_code))
        self.menu.dd.set_value('fh_code', fh_code)
