<!-- pages/merchant-regular-dispatch/merchant-regular-dispatch.wxml -->
<view class="page sj-form-theme">
  <view class="balance-card">
    <text class="balance-label">{{balanceLabel}}</text>
    <view class="balance-row">
      <text class="balance-value">{{sjyue}}</text>
      <text class="balance-unit">元</text>
    </view>
    <text class="balance-tip">{{balanceTip}}</text>
  </view>

  <view class="card">
    <view class="card-header">
      <view class="card-dot"></view>
      <text class="card-title">选择订单类型</text>
    </view>
    <scroll-view class="type-scroll" scroll-x="true" enable-flex>
      <view
        class="type-chip {{selectedTypeId === item.id ? 'type-chip--active' : ''}}"
        wx:for="{{shangpinList}}"
        wx:key="id"
        data-id="{{item.id}}"
        data-item="{{item}}"
        bindtap="onSelectType"
      >
        {{item.jieshao}}
      </view>
    </scroll-view>
  </view>

  <view class="card">
    <view class="card-header">
      <view class="card-dot"></view>
      <text class="card-title">选择订单模板</text>
    </view>

    <view class="field">
      <view class="field-head">
        <text class="field-label">订单介绍</text>
        <text class="field-required">*</text>
      </view>
      <view class="field-picker" bindtap="openTemplateSheet">
        <text class="{{dingdanJieshao ? '' : 'field-picker-ph'}}">{{dingdanJieshao || '点击选择模板'}}</text>
        <text class="field-picker-arrow">▸</text>
      </view>
    </view>

    <view class="field" wx:if="{{dingdanJieshao}}">
      <view class="field-head">
        <text class="field-label">订单价格</text>
        <text class="field-required">*</text>
      </view>
      <view class="price-display">
        <text class="price-prefix">¥</text>
        <text class="price-value">{{jiage || '0.00'}}</text>
      </view>
      <view class="template-meta" wx:if="{{selectedLabelName || commissionEnabled}}">
        <text class="template-meta-label" wx:if="{{selectedLabelName}}">标签：{{selectedLabelName}}</text>
        <text class="template-meta-label" wx:if="{{commissionEnabled}}">押金：¥{{commissionValue}}</text>
      </view>
    </view>
  </view>

  <view class="card">
    <view class="card-header">
      <view class="card-dot"></view>
      <text class="card-title">填写订单信息</text>
    </view>

    <view class="field">
      <view class="field-head">
        <text class="field-label">订单备注</text>
        <text class="field-optional">选填</text>
        <text class="field-count">{{dingdanBeizhu.length}}/50</text>
      </view>
      <input
        class="field-input"
        placeholder="选填，补充其他信息"
        maxlength="50"
        value="{{dingdanBeizhu}}"
        bindinput="onDingdanBeizhuInput"
      />
    </view>

    <view class="field">
      <view class="field-head">
        <text class="field-label">老板昵称/ID</text>
        <text class="field-required">*</text>
        <text class="field-count">{{laobanName.length}}/15</text>
      </view>
      <input
        class="field-input"
        placeholder="请输入老板昵称或ID"
        maxlength="15"
        value="{{laobanName}}"
        bindinput="onLaobanNameInput"
      />
    </view>

    <view class="field">
      <view class="field-head">
        <text class="field-label">拼多多订单号</text>
        <text class="field-optional">选填</text>
      </view>
      <input
        class="field-input"
        placeholder="外部平台订单号"
        maxlength="64"
        value="{{waibuDingdanId}}"
        bindinput="onWaibuDingdanIdInput"
      />
    </view>

    <view class="field">
      <view class="field-head">
        <text class="field-label">指定UID</text>
        <text class="field-optional">选填</text>
      </view>
      <input
        class="field-input"
        placeholder="指定某位接单员接单"
        maxlength="10"
        value="{{zhidingUid}}"
        bindinput="onZhidingUidInput"
      />
    </view>
  </view>

  <view class="bottom-space"></view>

  <view class="submit-bar">
    <view
      class="submit-btn {{isSubmitting ? 'submit-btn--disabled' : ''}}"
      bindtap="onSubmit"
      hover-class="submit-btn--hover"
    >
      {{isSubmitting ? '派发中...' : '立即派发'}}
    </view>
  </view>

  <view class="loading-mask" wx:if="{{isLoading}}">
    <view class="loading-box">
      <view class="loading-spinner"></view>
      <text class="loading-text">加载中...</text>
    </view>
  </view>

  <!-- 模板选择底部弹层 -->
  <block wx:if="{{showTemplateSheet}}">
    <view class="sheet-mask" bindtap="closeTemplateSheet"></view>
    <view class="sheet-panel">
      <view class="sheet-hd">
        <text class="sheet-title">选择订单模板</text>
        <text class="sheet-close" bindtap="closeTemplateSheet">×</text>
      </view>
      <view class="sheet-search">
        <input
          class="sheet-search-input"
          placeholder="搜索模板ID/介绍..."
          value="{{templateKeyword}}"
          bindinput="onTemplateKeywordInput"
          bindconfirm="onTemplateSearch"
        />
        <text class="sheet-search-btn" bindtap="onTemplateSearch">搜索</text>
      </view>
      <scroll-view class="sheet-list" scroll-y bindscrolltolower="onTemplateScrollLower">
        <block wx:for="{{templateList}}" wx:key="mobanId">
          <view class="sheet-item" data-item="{{item}}" bindtap="onSelectTemplate">
            <view class="sheet-item-intro">{{item.jieshao || '无介绍'}}</view>
            <view class="sheet-item-row">
              <chenghao-tag wx:if="{{item.labelName}}" mingcheng="{{item.labelName}}" texiaoJson="{{''}}"/>
              <text class="sheet-item-price">¥{{item.jiage || '0.00'}}</text>
            </view>
          </view>
        </block>
        <view class="sheet-empty" wx:if="{{!templateLoading && templateList.length === 0}}">暂无模板</view>
        <view class="sheet-empty" wx:if="{{templateLoading}}">加载中...</view>
      </scroll-view>
    </view>
  </block>

  <global-notification id="global-notification" />
  <popup-notice id="popupNotice" />
</view>
