<page-plugin isAuth="{{authInfo['SF_ERP_SALE_ORDERS_VIEW']}}" loading="{{loading}}"
  is-login="{{isLogin}}" bind:handleLogin="handleLogin">
  <search-popup placeholder="输入销售单号" bind:change="searchChange" bind:ok="searchOk"
    bind:reset="searchReset" value="{{params.order_no}}" data-key="order_no">
    <view slot="content">
      <search-input label="自定义单号" value="{{params.custom_order_no}}" data-key="custom_order_no"
        bind:change="searchChange" />
      <search-input label="经销商名称" value="{{params.custom_name}}" data-key="custom_name"
        bind:change="searchChange" />
      <search-input label="经销商手机" value="{{params.custom_phone}}" data-key="custom_phone"
        bind:change="searchChange" />
      <search-input label="客户名称" value="{{params.end_user_name}}" data-key="end_user_name"
        bind:change="searchChange" />
      <search-input label="客户手机" value="{{params.end_user_phone}}" data-key="end_user_phone"
        bind:change="searchChange" />
      <search-input label="客户地址" value="{{params.end_user_address}}" data-key="end_user_address"
        bind:change="searchChange" />

      <option-cell-plugin title="订单阶段" value="{{params.order_step}}" bind:change="searchChange"
        mode="checkbox" options="{{orderStep}}" data-key="order_step" />

      <option-cell-plugin title="生产状态" value="{{params.process_state}}" bind:change="searchChange"
        mode="checkbox" options="{{saleOrderProcessStateOption}}" data-key="process_state" />

      <option-cell-plugin title="收款状态" value="{{params.payed_state || ''}}"
        bind:change="searchChange" mode="radio" options="{{payedStateOption}}"
        data-key="payed_state" />

      <date-picker-plugin title="单据开始日期" value="{{params.document_dateL}}" data-key="document_dateL"
        bind:confirm="searchChange" />
      <date-picker-plugin title="单据结束日期" value="{{params.document_dateU}}" data-key="document_dateU"
        bind:confirm="searchChange" />
      <date-picker-plugin title="创建开始日期" value="{{params.create_dateL}}" data-key="create_dateL"
        bind:confirm="searchChange" />
      <date-picker-plugin title="创建结束日期" value="{{params.create_dateU}}" data-key="create_dateU"
        bind:confirm="searchChange" />
    </view>
  </search-popup>

  <count-plugin count="{{count}}">
    <sort-plugin options="{{sort}}" bind:ok="onSort" value="{{params.order}}" slot="right" />
  </count-plugin>
  <total-bar-plugin>
    <view style="display: inline-flex;align-items: center;">
      <text>含税金额合计：</text>
      <text>￥{{amount.tot_tax_last_money}}</text>
    </view>
    <view style="display: inline-flex;align-items: center;">
      <text>优惠金额合计：</text>
      <text>￥{{amount.tot_discount_money}}</text>
    </view>
    <view style="display: inline-flex;align-items: center;">
      <text>已收金额合计：</text>
      <text>￥{{amount.tot_payed_amount}}</text>
    </view>
    <view style="display: inline-flex;align-items: center;">
      <text>未收金额合计：</text>
      <text>￥{{amount.tot_un_payed_amount}}</text>
    </view>
  </total-bar-plugin>
  <empty-plugin wx:if="{{list.length == 0}}" />
  <card-plugin wx:for="{{ list }}" wx:key="order_no">
    <view slot="header">{{ item.order_no }}</view>
    <view slot="content">
      <card-item-plugin label="自定义单号" value="{{item.custom_order_no}}" />
      <card-item-plugin label="订单类型" value="{{item.category_name}}" />
      <card-item-plugin label="订单阶段" value="{{saleOrderProcessStateObj[item.process_state]}}" />
      <card-item-plugin label="经销商名称" value="{{item.custom_name}}" />
      <card-item-plugin label="经销商手机" value="{{item.custom_phone}}" />
      <card-item-plugin label="客户名称" value="{{item.end_user_name}}" />
      <card-item-plugin label="客户手机" value="{{item.end_user_phone}}" />
      <card-item-plugin label="客户地址" value="{{item.end_user_address}}" />
      <card-item-plugin label="单据日期" value="{{item.document_date}}" />
      <card-item-plugin label="含税合计" value="{{item.tot_tax_last_money}}" />
      <card-item-plugin label="优惠金额" value="{{item.discount_money}}" />
      <card-item-plugin label="已收金额" value="{{item.payed_amount}}" />
      <card-item-plugin label="未收金额" value="{{item.un_payed_amount}}" />
      <card-item-plugin label="创建日期" value="{{item.create_date}}" />
    </view>
    <view slot="footer" class="card-plugin-footer">
      <t-button size="small" theme="primary" bind:tap="onOrderDetail" data-index="{{index}}">详情
      </t-button>
      <t-button wx:if="{{authInfo['SF_ERP_SALE_ORDERS_PAY']}}" size="small" theme="primary"
        bind:tap="onOrderPay" data-index="{{index}}">收付款</t-button>
      <t-button wx:if="{{authInfo['SF_ERP_SALE_ORDERS_DEL']}}" size="small" theme="danger"
        bind:tap="onOrderDel" data-index="{{index}}">删除</t-button>
      <t-button wx:if="{{item.file_cnt}}" size="small" bind:tap="onViewAttachment"
        data-index="{{index}}">附件({{item.file_cnt}})</t-button>
    </view>
  </card-plugin>
  <pagination-plugin curr_page="{{params.curr_page}}" page_count="{{params.page_count}}"
    total="{{count}}" bind:change="paginationChange" />
</page-plugin>