from src.pageobject.basepage import Page
from selenium.webdriver.common.by import By


# 登录页面
class LoginPage(Page):
    # 元素集

    # 手机号登录按钮
    phone_login = (By.ID, "rc-tabs-0-tab-2")
    # 账号输入框
    account_input = (By.ID, "xmphone")
    # 密码输入框
    password_input = (By.ID, "xmpwd")
    # 登录按钮
    login_button = (By.CLASS_NAME, "submit")
    # 选择环境窗口的关闭按钮
    close_env_window_btn = (By.XPATH, "//span[@class='anticon anticon-close ant-modal-close-icon']")

    # 取消按钮
    cancel_btn = (By.XPATH, """//span[text()="{}"]""".format("取 消"))
    # 验证元素
    # 店铺名称
    store_name = (By.XPATH, """//div[@class="inst"]""")

    def __init__(self, driver):
        Page.__init__(self, driver)

    # 点击手机号登录，展示输入框
    def click_phone_login(self):
        self.click(self.phone_login)

    # 输入账号
    def input_account(self, account):
        self.input_text(self.account_input, account)

    # 输入密码
    def input_password(self, password):
        self.input_text(self.password_input, password)

    # 点击登录
    def click_login(self):
        self.click(self.login_button)

    # 手机号码登录窗口可显示操作

    def phone_input_execute_script(self):
        self.excute_script_dominance("form xm_phone_login")

    # 关闭环境选择窗口
    def click_close_env_window(self):
        self.click(self.close_env_window_btn)
