"""
    客户详情页面
"""

import re
import time

from PageLocators.customersDetails_page_locs import CustomersDetailsPageLocs as loc
from Common.basepage import Basepage
from TestDatas import global_datas as gd


class CustomersDetailsPage(Basepage):

    # 判断是否跳转到 客户详情 页面
    def is_basicInfo_exist(self):
        return self.get_element(loc.customer_follow_loc, "判断是否进入客户详情页面")

    # 进入 客户跟进 菜单，进行评分操作
    def editor_mark(self):
        time.sleep(1)
        self.click_element(loc.mark_button_loc, "客户跟进页面_点击编辑顾问评分")

        self.click_element(loc.age_select_loc, "展开年龄下拉框")
        self.click_element(loc.age_loc, "选择年龄")
        self.click_element(loc.school_select_loc, "展开学历下拉框")
        self.click_element(loc.school_loc, "选择最高学历")
        self.click_element(loc.elite_school_select_loc, "展开百强名校下拉框")
        self.click_element(loc.elite_school_loc, "选择百强名校")
        self.click_element(loc.work_management_select_loc, "展开工作管理经验下拉框")
        self.click_element(loc.work_management_loc, "选择工作管理经验")
        self.click_element(loc.overseas_work_select_loc, "展开海外工作经验下拉框")
        self.click_element(loc.overseas_work_loc, "选择海外工作经验")
        self.click_element(loc.big_company_work_select_loc, "展开名企工作经验下拉框")
        self.click_element(loc.big_company_work_loc, "选择名企工作经验")
        self.click_element(loc.language_ability_select_loc, "展开语音能力下拉框")
        self.click_element(loc.language_ability_loc, "选择语言能力")
        time.sleep(1)
        self.click_element(loc.family_background_select_loc, "展开家庭背景下拉框")
        self.click_element(loc.family_background_loc, "选择家庭背景")
        self.click_element(loc.family_background_select_loc, "再次点击家庭背景输入框，关闭下拉框")
        self.click_element(loc.save_button_loc, "点击保存按钮")

    # 判断评分操作是否成功，分数需要大于80
    def is_mark_success(self):
        time.sleep(1)
        # 文本内容
        mark = self.get_text(loc.mark_text_loc, "客户跟进页面_获取顾问评分文本")
        # 定义正则表达式
        pattern = r'\d+'
        score = int(re.findall(pattern, mark)[0])
        if score >= 80:
            return True
        else:
            return False

    # 进入合同页面，新建合同
    def add_customer_contract(self):
        time.sleep(1)
        self.click_element(loc.customer_contract_loc, "客户详情页面_点击合同订单按钮")
        time.sleep(3)
        self.click_element(loc.contract_button_loc, "合同订单页面_点击生产合同号按钮")
        self.click_element(loc.contract_select_loc, "生成合同号弹框_点击合同类型下拉框")
        self.click_element(loc.contract_loc, "生成合同号弹框_选择合同类型")
        self.click_element(loc.company_select_loc, "生成合同号弹框_点击签约公司下拉框")
        self.click_element(loc.company_loc, "生成合同号弹框_选择签约公司")
        self.click_element(loc.select_button_loc, "生成合同号弹框_点击选择按钮")
        self.input_text(loc.project_name_loc, "生成合同号弹框_输入项目名称", gd.project_name)
        time.sleep(1)
        self.click_element(loc.verify_button_loc, "生成合同号弹框_点击确认按钮")
        self.click_element(loc.product_loc, "生成合同号弹框_选择产品")
        self.click_element(loc.verify_button_loc, "生成合同号弹框_点击确认按钮")
        self.click_element(loc.ok_button_loc, "生成合同号弹框_点击确定按钮")

    # 判断生成合同是否成功
    def is_contract_success(self):
        time.sleep(2)
        # 获取合同号文本
        contract_text = self.get_text(loc.contract_after_button_loc, "获取合同号文本")
        global contract
        contract = contract_text[0:-4]
        print(contract)
        if len(contract) > 5:
            return contract
        else:
            return False

    # 创建订单
    def add_order(self):
        self.click_element(loc.order_button_loc, "合同订单页面_点击创建订单按钮")
        self.switch_window()
        self.input_text(loc.contract_number_loc, "新建订单页面_输入合同编号", contract)
        self.uploadFile(loc.upload_button_loc, "新建订单页面_上传合同附件", gd.contract_file)
        self.click_element(loc.no_1_loc, "新建订单页面_选择否")
        self.click_element(loc.no_2_loc, "新建订单页面_选择否")
        self.click_element(loc.no_3_loc, "新建订单页面_选择否")
        self.input_text(loc.info_loc, "新建订单页面_输入相关信息", "测试")
        self.click_element(loc.payment_method_select_loc, "新建订单页面_点击付款方式下拉框")
        self.click_element(loc.payment_method_loc, "新建订单页面_选择付款方式")
        self.click_element(loc.submit_button_loc, "新建订单页面_点击提交合同按钮")
        time.sleep(1)
        self.click_element(loc.submit_1_button_loc, "新建订单页面_点击已确认，创单按钮")

    # 判断创建订单是否成功
    def is_order_success(self):
        if self.wait_ele_visible(loc.no_order_loc, "合同订单页面_检查是否成功创建订单"):
            return False
        else:
            return True
