<!--module/diet/pages/delivery-address/delivery-address.wxml-->
<t-navbar title="新增收货地址" left-arrow />

<scroll-view class="add-address-scroll" scroll-y>
  <!-- 智能粘贴 -->
  <view class="smart-fill">
    <view class="smart-title">快速智能填写</view>
    <view class="smart-paste-box">
      <t-textarea
        class="smart-paste-input {{smartPasteFocus ? 'smart-paste-input-focus' : 'smart-paste-input-blur'}}"
        placeholder="{{smartPastePlaceholder}}"
        value="{{smartPasteValue}}"
        focus="{{smartPasteFocus}}"
        bind:focus="onSmartPasteFocus"
        bind:blur="onSmartPasteBlur"
        bind:change="onSmartPasteInput"
        autosize
      />
      <view class="smart-paste-btns-bottom" wx:if="{{smartPasteFocus}}">
        <button
          class="smart-btn smart-btn-clear"
          catchtap="onClearSmartPaste"
        >清空</button>
        <button
          class="smart-btn smart-btn-recognize {{!smartPasteValue ? 'smart-btn-recognize-disabled' : ''}}"
          catchtap="onRecognizeSmartPaste"
          disabled="{{!smartPasteValue}}"
        >识别</button>
      </view>
    </view>
  </view>

  <!-- 表单 -->
  <view class="form-box">
    <view class="form-item">
      <view class="form-label">收货人</view>
      <t-input
        class="form-input"
        placeholder="请输入收货人姓名"
        value="{{formData.liaison}}"
        data-field="formData.liaison"
        bind:change="onInput"
        clearable="{{focusName}}"
        focus="{{focusName}}"
        bind:focus="onFocusInput"
        bind:blur="onBlurInput"
      />
    </view>
    <view class="form-item">
      <view class="form-label">手机号</view>
      <t-input
        class="form-input"
        placeholder="请输入收货人手机号"
        value="{{formData.phone}}"
        data-field="formData.phone"
        bind:change="onInput"
        focus="{{focusPhone}}"
         clearable="{{focusPhone}}"
        bind:focus="onFocusPhone"
        bind:blur="onBlurPhone"
        maxlength="11"
      />
    </view>
    <view class="form-item" bindtap="onShowRegionPicker">
      <view class="form-label">所在地区</view>
      <t-input
        class="form-input"
        placeholder="请选择省市区"
        value="{{region}}"
        readonly
        suffixIcon="{{ { name: 'chevron-right', ariaLabel: '右箭头' ,size:'20px'} }}"
      />
    </view>
  

    <view class="form-item address-detail-item">
      <view class="form-label">详细地址</view>
      <t-textarea
        class="form-detail"
        placeholder="如道路、门牌号、小区、楼栋号、单元等"
        value="{{formData.detailAddress}}"
        maxlength="50"
        data-field="formData.detailAddress"
        bind:change="onInput"
        show-limit
        autofocus
        focus="{{focusDetail}}"
          clearable="{{focusDetail}}"
        bind:focus="onFocusDetail"
        bind:blur="onBlurDetail"
        autosize
      />
    </view>
  </view>

  <!-- 隐私提示 -->
  <view class="privacy-tip">
    <text>为了保护你的个人隐私，请不要在详细地址中填写手机号</text>
  </view>

  <!-- 标签 -->
  <view class="tag-box">
    <view class="form-label">标签</view>
    <t-tag wx:for="{{tagList}}" wx:key="item" bindtap="onTagSelect" data-tag="{{item}}" class="tagsList {{selectedTag === item ? 'selected' : ''}}" >{{item}}</t-tag>
  </view>

  <!-- 默认地址 -->
  <view class="default-box">
    <view class="form-label">设为默认</view>
    <t-switch value="{{formData.isDefault==='Y'}}" bindchange="onDefaultChange" />
  </view>
</scroll-view>

<van-popup show="{{ regionPickerVisible }}" position="bottom" bind:close="onRegionCancel">
  <van-area
    area-list="{{ areaList }}"
    bind:confirm="onRegionConfirm"
    bind:cancel="onRegionCancel"
  />
</van-popup>


<!-- 底部按钮 -->
<view class="save-btn-box">
  <button class="save-btn delete-btn" block bindtap="onDelete" wx:if="{{id}}">删除</button>
  <button class="save-btn" block bindtap="onSave" loading="{{saving}}" disabled="{{saving}}">保存</button>
</view>
