<!--subpages/addMattresses/addMattresses.wxml-->
<view class="container">

    <view class="notice-view">
        <image src="/subpages/images/ic_notice_tips.png" class="notice-icon"></image>
        <view class="marquee-container">
            <text class="marquee-text marquee-text-animation">温馨提示：增加床垫设备之前，请将手机连接室内WIFI，并且保持蓝牙打开状态。</text>
        </view>
    </view>

    <view class="w-card">
        <van-field model:value="{{ placeOfUse }}" center title-width="150rpx" label="使用地点：" placeholder="可填写卧室等地点"
            clearable border="{{ true }}" maxlength="5" />
        <van-field model:value="{{ usingHuman }}" center title-width="150rpx" label="使用人：" placeholder="可填写本人或者其他人名称"
            clearable border="{{ true }}" maxlength="5" />
        <van-field model:value="{{ sn }}" center title-width="150rpx" clearable label="SN：" placeholder=""
            border="{{ true }}" readonly="{{ true }}" use-button-slot>
            <!-- <view slot="button" class="lysb-btn" bindtap="bindViewBlue">
                <image src="/subpages/images/ic_ly.png" class="ly-icon"></image>
                <text>蓝牙识别</text>
            </view> -->
            <view slot="button" class="lysb-new-btn" bindtap="bindViewBlue">
                <text>蓝牙识别</text>
                <van-icon name="arrow" />
            </view>
        </van-field><van-field model:value="{{ ssid }}" center title-width="150rpx" label="WIFI：" placeholder="AIDSLEEP"
            clearable border="{{ true }}" />
        <van-field model:value="{{ password }}" center title-width="150rpx" label="WIFI密码：" placeholder="请输入密码"
            clearable border="{{ false }}" />
    </view>
    <text class="commit-btn" bindtap="commitData">提交配置</text>

    <!-- 选择蓝牙 -->
    <van-popup show="{{ showBluetoothList }}" round position="bottom" custom-style="height: 50%;background:#F7F7F7;"
        close-on-click-overlay="{{false}}" bind:close="onClose">
        <view class="bluetooth-view">
            <view class="bluetoothList">
                <view wx:for="{{deviceList}}" wx:key="index" class="bluetooth-item" data-index="{{index}}"
                    bindtap="checkBluetoothSelectIndex">
                    <image src="/subpages/images/ic_bluetooth.png" class="bluetooth-icon"></image>
                    <view class="bluetooth-content">
                        <text class="bluetooth-title">{{item.name}}</text>
                        <text class="bluetooth-rssi">RSSI: {{item.RSSI}}</text>
                    </view>
                    <image src="{{bluetoothSelectIndex == index ? activeIcon : normalIcon}}" class="bluetooth-radio">
                    </image>
                </view>

            </view>
            <text class="sure-btn" bindtap="commitBluetooth">确定</text>
        </view>
    </van-popup>

    <!-- 蓝牙识别+配置弹窗 -->
    <van-popup show="{{ showBluetoothConnected }}" close-on-click-overlay="{{false}}" round bind:close="onClose">

        <view class="bluetoothConnectedView">
            <view wx:if="{{!isBluetoothConnected}}" class="circle-view">
                <van-circle type="2d" value="{{ value }}" color="{{ gradientColor }}" size="114" stroke-width="7"
                    layer-color="#EBEEF5">
                    <view class="circle-content">
                        <text class="circle-text">{{value}}%</text>
                        <text class="circle-loading">连接中...</text>
                    </view>
                </van-circle>
            </view>
            <view wx:if="{{isBluetoothConnected}}" class="circle-view">
                <image src="/subpages/images/ic_bluetooth_connected.png" class="bluetooth-connected-icon"></image>
                <text class="bluetoothConnected-tips">连接成功</text>
            </view>
            <view class="loading-list">
                <view wx:for="{{statusDefault}}" wx:key="index" class="loading-item"
                    wx:if="{{bluetoothConnectedStep >= index}}">
                    <image wx:if="{{bluetoothConnectedStep > index}}" src="/subpages/images/ic_loading_yes.png"
                        class="bluetooth-connected-yes"></image>
                    <van-loading wx:else color="#53DAFF" size="28rpx" />
                    <text class="loading-title">{{item}}</text>
                </view>
            </view>
            <view wx:if="{{!isBluetoothConnected}}" style="height: 50rpx;"></view>
            <text wx:else class="bluetoothConnectedView-btn" bindtap="closeEndDialog">确定</text>
        </view>
    </van-popup>

</view>