<wxs module="m1">
  var displayPrice = function (item) {
    var numberFormat = require("/utils/numberFormat.wxs");
    // 如果有促销显示标准售价,如果正常品显示标价
    // if (item.promotionType == 0) {
    //优先显示促销价
    if (item.pricePromotion) {
      return '¥' + numberFormat.toThousandCents(item.pricePromotion)
    } else {
      return '¥' + numberFormat.toThousandCents(item.priceStandard)
    }

    // } else {
    //   return '¥' + numberFormat.toThousandCents(item.pricePromotion)
    // }
    // return ''
  }
  module.exports.displayPrice = displayPrice
</wxs>
<wxs src='/utils/numberFormat.wxs' module="numberFormat"></wxs>
<loading wx:if="{{loading}}" loadingName="加载中" backgroundColor="#f2f2f2;" opacity="0.8"></loading>
<van-tabs type="card" custom-class="tags-class" tab-active-class="{{active==0?'van-tab-active-left':'van-tab-active-right'}}" animated="{{true}}" swipeable="{{true}}" active="{{ active }}" dot bind:change="changeTag">
  <van-tab title="商品列表"></van-tab>
  <van-tab title="已选商品" info="{{choosedGoodsList.length==0?'':choosedGoodsList.length}}"></van-tab>
</van-tabs>

<view class="main-good-class" style="height:{{windowHeight+'px'}}">
  <scroll-view scroll-y='{{true}}' bindscrolltolower='scrollToLower' lower-threshold='100' wx:if="{{active == 0}}" class="goods-class" style="height:calc({{windowHeight+'px'}} - 295rpx);overflow: scroll;">
    <van-cell-group style="display: flex;justify-content: flex-end;width: calc({{windowWidth+'px'}} - 20rpx);" custom-class="width-70">

      <!-- 商品列表 -->
      <view wx:for="{{goodsList}}" data-item="{{item}}" wx:key="index" class="main-class" catchtap="openAddItemInfo">
        <!-- 上半部分 -->
        <view class="main-foot" style="position: relative;border-radius:  15rpx;">

          <view class="table-content" bind:tap="toDetail" data-item="{{item}}">
            <view class="table-content-row">
              <view class="order-and-status" style="align-items: center;">
                <view catchtap="toCustomer" data-item="{{item}}" style="width:100%;display:flex;padding-left: 14rpx;font-size: 30rpx;align-items: center;">
                  <dk-text bind:tap="toCustomer" data-item="{{item}}" fontSize="15px" value="{{item.skuName}}"></dk-text>
                </view>
              </view>
            </view>
            <view style="display: flex; width: 100%;text-align: right; ">
              <view style="flex:1;width: 80%;">
                <!-- 商品编码 -->
                <view class="table-content-row">
                  <view style="display: flex;">
                    <view class="table-content-row-font">
                      <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="商品编码"></dk-text>
                    </view>
                    <view class="table-content-class">
                      {{item.skuCode}}
                    </view>
                  </view>
                </view>

                <!-- 库区 -->
                <view class="table-content-row">
                  <view style="display: flex;">
                    <view class="table-content-row-font">
                      <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="库  区"></dk-text>
                    </view>
                    <view class="table-content-class">
                      {{item.whName}}
                    </view>
                  </view>
                </view>
                <!-- 色号 -->
                <view class="table-content-row">
                  <view style="display: flex;">
                    <view class="table-content-row-font">
                      <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="非 标 号"></dk-text>
                    </view>
                    <view class="table-content-class">
                      {{item.nonStdCode}}
                    </view>
                  </view>
                </view>
                <!-- 库存量 -->
                <view style="display:flex;width:100%;" class="table-content-row">
                  <view style="display:flex;width:50%;text-align: center;">
                    <view style="width: 50%;">
                      <dk-text fontSize="16px" color="#95A8CB" fontWeight="normal" value="库存量"></dk-text>
                    </view>
                    <view style="width: 50%;color: #CAA977">
                      {{item.ivtQty}}
                    </view>
                  </view>
                  <view style="display:flex;width:50%;text-align: center;">
                    <view style="width: 50%;">
                      <dk-text fontSize="16px" color="#95A8CB" fontWeight="normal" value="可售量"></dk-text>
                    </view>
                    <view style="width: 50%;color: #CAA977 ;">
                      {{item.usableQty}}
                    </view>
                  </view>
                </view>


              </view>
              <!-- 加号 -->
              <view class="van-icon-class" style="margin-top:4%;margin-right:4%;">
                <van-icon size="25px" name="add" style="color:#1B365D" />
              </view>
            </view>
          </view>
        </view>
      </view>



      <view wx:if="{{goodsList.length!=0}}" style="height:180rpx;"></view>
      <van-cell wx:if="{{goodsList.length==0}}" border="{{ false }}">
        <view style="width:100%;">
          <van-empty description="暂无商品" />
        </view>
      </van-cell>
    </van-cell-group>
  </scroll-view>
  <!--已选列表-->
  <view wx:if="{{active == 1}}" class="goods-selected-class">
    <view class="goods-class" style="height:calc({{windowHeight+'px'}} - 295rpx);overflow: scroll;"></view>
    <van-cell-group style="display: flex;justify-content: flex-end;width: calc({{windowWidth+'px'}} - 20rpx);" custom-class="width-80">
      <van-cell wx:if="{{choosedGoodsList.length==0}}" border="{{ false }}">
        <van-empty description="暂无商品" />
      </van-cell>
      <van-cell custom-class="goods-cell-class" wx:for="{{choosedGoodsList}}" wx:key="index" data-index="{{index}}" border="{{ false }}">
        <van-swipe-cell right-width="{{ 65 }}" data-index="{{index}}" async-close bind:close="delChoosedGoodsItem">
          <view class="main-class">
            <!-- 上半部分 -->
            <view class="main-foot" style="position: relative;border-radius:  15rpx;">

              <view class="table-content" bind:tap="toDetail" data-item="{{item}}">
                <view class="table-content-row">
                  <view class="order-and-status" style="align-items: center;">
                    <view catchtap="toCustomer" data-item="{{item}}" style="width:100%;display:flex;padding-left: 14rpx;font-size: 30rpx;align-items: center;">
                      <dk-text bind:tap="toCustomer" data-item="{{item}}" fontSize="15px" value="{{item.skuName}}"></dk-text>
                    </view>
                  </view>
                </view>
                <view style="display: flex; width: 100%;text-align: right; ">
                  <view style="flex:1;width: 80%;">
                    <!-- 商品编码 -->
                    <view class="table-content-row">
                      <view style="display: flex;">
                        <view class="table-content-row-font">
                          <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="商品编码"></dk-text>
                        </view>
                        <view class="table-content-class">
                          {{item.skuCode}}
                        </view>
                      </view>
                    </view>

                    <!-- 库区 -->
                    <view class="table-content-row">
                      <view style="display: flex;">
                        <view class="table-content-row-font">
                          <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="库  区"></dk-text>
                        </view>
                        <view class="table-content-class">
                          {{item.whName}}
                        </view>
                      </view>
                    </view>
                    <!-- 色号 -->
                    <view class="table-content-row">
                      <view style="display: flex;">
                        <view class="table-content-row-font">
                          <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="非 标 号"></dk-text>
                        </view>
                        <view class="table-content-class">
                          {{item.nonStdCode}}
                        </view>
                      </view>
                    </view>
                    <!-- 出库数量 -->
                    <view class="table-content-row">
                      <view style="display: flex;">
                        <view class="table-content-row-font" style="  display: flex; justify-content: center; align-items: center;">
                          <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="出库数量"></dk-text>
                        </view>
                        <view class="table-content-class">
                          <van-stepper value="{{item.itemQuantity}}" integer="{{true}}" data-index="{{index}}" min="0" max="999999999" bind:change="changeAllreadyChooseQuantity" />
                          <!-- 加号 -->
                          <!-- <view class="van-icon-class" style="margin-top:4%;margin-right:4%;">
                        <van-icon size="25px" name="add" style="color:#1B365D" />
                      </view> -->
                        </view>
                      </view>
                    </view>


                  </view>

                </view>
              </view>
            </view>
          </view>
          <view slot="right">删除</view>
        </van-swipe-cell>
      </van-cell>
    </van-cell-group>
    <view style="height:180rpx;"></view>
  </view>
</view>




<van-search wx:if="{{active == 0}}" bind:search="doSearch" custom-class="search-class" bind:change="onSearchText" model:value="{{ searchText }}" placeholder="商品名称/商品型号" use-right-icon-slot="{{true}}" placeholder-style="color:#95A8CB">
</van-search>
<view wx:if="{{active == 0}}" class="scan-class">
  <image class="scan-image" fit="fill" src="/static/image/Group.png"></image>
</view>
<view wx:if="{{active == 0}}" class="screen-class" >
  <van-dropdown-menu active-color="#1B365D" style=" width: calc(100% ) !important; ">
    <!-- 库区 -->
    <van-dropdown-item id="statusItemWareHouse" title="{{ form.whName ? form.whName:'仓库' }}" bind:open="dropdowncommit">
    </van-dropdown-item>
    <!-- 可售量排序 -->
    <van-dropdown-item title="{{ orderBy.text }}" value="{{value}}" options="{{ orderBy }}" bind:change="onSwitchChange"  >
    </van-dropdown-item>
  </van-dropdown-menu>
</view>


<van-sidebar activeKey="{{sideKey}}" bindchange="changeSidebar" custom-class="{{active == 0 ? 'left-class' : 'right-class'}}">
  <view wx:if="{{active != 1}}" style="z-index: 1; position: fixed; top: 25%;height:calc({{windowHeight+'px'}} - {{active == 1 ? '270rpx' :'400rpx' }});overflow: scroll;">
    <van-sidebar-item wx:key="index" custom-class="{{sideKey - 1 == index? 'sidebar-item-before': (sideKey + 1 == index?'sidebar-item-next':'sidebar-item')}}" title="{{item.name}}" data-id="{{item.id}}" wx:for="{{typeList}}" />
  </view>
</van-sidebar>

<!--  确定 -->
<view class="bottom-class">
  <van-button custom-class="save-button-class" disabled="{{loadingButtonFlag}}" loading="{{loadingButtonFlag}}" bind:click="submit" type="default">确定
  </van-button>
</view>
<!--选择框-->
<van-popup custom-class="dk-popup" show="{{ showAdd }}" round="{{true}}" position="bottom" bind:close="closeAddItemInfo">
  <view style="  position:relative; top:280rpx;background-color: transparent; height: 44rpx;"></view>

  <view class="special-topic">
    <view class="special-topic-content">
      <van-image radius="15rpx" custom-class="goods-pop-image" fit="fill" src="{{ currentChoosedItem.iconThumPath }}">
      </van-image>
      <!--  -->
    </view>
    <view class="special-topic-title">
      <dk-title id="titleTagPop" titleTag="{{currentChoosedItem.titleTag}}" title="{{currentChoosedItem.skuModel}}"></dk-title>
      <view style="padding-top: 10rpx;white-space: nowrap;">
        <dk-text fontWeight="" value="{{currentChoosedItem.skuName}}"> </dk-text>
      </view>

      <!--sku编码-->
      <view style="padding-top:3px !important;display:flex;font-size: 14px;color: #1B365D;justify-content: flex-end; margin-right: 14vw;margin-top: 5vw;">
        <view style="margin: 2vw;">库存量：{{currentChoosedItem.ivtQty}}</view>
        <view style="margin: 2vw;">可售量：{{currentChoosedItem.usableQty}}</view>
      </view>

    </view>
  </view>
  <view class="pop-content-class">
    <van-cell-group>
      <view style="height:calc({{windowHeight+'px'}} - 676rpx);overflow-y: scroll;overflow-x: hidden;">
        <!-- 正常品 -->
        <view>

          <!-- 就一个商品 -->
          <view wx:if="{{currentChoosedItem.specsList.length == 0}}" style="display: flex;justify-content: space-between;">
            <view style="width: 30%;">
            </view>
            <!--显示已选商品编码-->
            <view style="align-items: center; padding-top: 12rpx;">
              <dk-text fontSize="10px" fontWeight="" value="编码：{{currentChoosedItem.skuCode}}"> </dk-text>
            </view>
          </view>

          <view wx:for="{{currentChoosedItem.specsList}}" wx:key="index" wx:for-item="itemspecs">
            <view style="display: flex;justify-content: space-between;">
              <view style="width: 30%;">
                <dk-text fontSize="13px" value="{{itemspecs.specsName}}"></dk-text>
              </view>
              <!--显示已选商品编码-->
              <view style="align-items: center; padding-top: 12rpx;" wx:if="{{currentChoosedItem.skuCode && index == 0}}">
                <dk-text fontSize="10px" fontWeight="" value="编码：{{currentChoosedItem.skuCode}}"> </dk-text>
              </view>
            </view>
            <view class="tags">
              <view class="tag-bom-item" wx:key="indext" wx:for="{{itemspecs.specsValues}}" wx:for-index="indext" wx:for-item="itemt">
                <van-button size="small" custom-class="button-selected-class">
                  <view style="display: flex;  justify-content: center;  align-items: center; height: 100%;"> {{ itemt }} </view>
                </van-button>

              </view>
            </view>
          </view>
        </view>


        <van-cell border="{{ false }}" title="数量" title-class="red-label">
          <van-stepper value="{{currentChoosedItem.itemQuantity}}" integer="{{true}}" data-index="{{index}}" min="0" max="999999999" bind:change="changeAllreadyChooseQuantityPop" />
        </van-cell>


        <van-field disabled label-class="nomal-label" label="库区" value="{{currentChoosedItem.whName}}" input-align="right" border="{{ false }}" />

        <van-field disabled label-class="nomal-label" label="色号" value="{{currentChoosedItem.nonStdCode}}" input-align="right" border="{{ false }}" />


        <view style="height: 100rpx;"></view>
      </view>
      <van-cell value-class="button-pop-cell-class">
        <van-button disabled="{{skuloading}}" custom-class="button-pop-class" type="info" size="small" bind:click="chooseSkuInfo">确定
        </van-button>
      </van-cell>
    </van-cell-group>
  </view>
</van-popup>

<!-- 仓库 -->
<dk-single-dropdown-item show="{{whFlag}}" content="{{form.whName}}" id='warehouse-orther' typeName='warehouse-orther' bind:muticommit='mutiSearch' bind:muticlose='muticlose'>
</dk-single-dropdown-item>