<wxs module="m1">
  var displayPrice = function (item) {
    var numberFormat = require("/utils/numberFormat.wxs");

    if (item.pricePromotion) {
      return '¥' + numberFormat.toThousandCents(item.pricePromotion)
    } else {
      return '¥' + numberFormat.toThousandCents(item.priceStandard)
    }
  }
  module.exports.displayPrice = displayPrice
</wxs>

<wxs src='/utils/numberFormat.wxs' module="numberFormat"></wxs>
<wxs src='/utils/wxmlUtil.wxs' module="wxmlUtil"></wxs>
<loading wx:if="{{loading}}" loadingName="加载中" backgroundColor="#f2f2f2;" opacity="0.8"></loading>

<van-dialog id="van-dialog" />
<van-sticky offset-top="{{ 0 }}">
  <van-nav-bar title="选择商品" left-text="" border="{{false}}" left-arrow="{{true}}" bind:click-left="onClickLeft" />

  <view style="display: flex;">
    <view style="width: 85%;">
      <!-- 查询条件 --> 
      <dk-dropdown-menu model:value="{{searchForm}}" menuList="{{searchContent}}"  bind:search="searchData" searchTextPlaceholder="{{wxmlUtil.setSearchPlaceholder($t,['skuName','skuModel'])}}">
      </dk-dropdown-menu>
    </view>
    <view bind:tap="toAddGoods"  class="scan-class" style="width: 15%;display: flex;align-items: center;">
    <image class="scan-image" fit="fill" src="{{imageUrl+'/goods_add_icon.png'}}"></image>
  </view>
  </view>




  <view style="display: flex;margin-left: 24rpx;margin-right: 24rpx;margin-top: 10rpx;">
    <view bind:tap="selectedProduct" data-active="{{0}}" class="{{ active == 0 ?'selected-product selected-product-color-01' : 'selected-product selected-product-color-02'}}">
      商品列表

    </view>
    <view bind:tap="selectedProduct" data-active="{{1}}" class="{{ active == 0 ? 'selected-product selected-product-color-02' : 'selected-product selected-product-color-01'}}" style="position: relative;">
      <view>已选商品</view>
      <view wx:if="{{choosedGoodsList.length > 0}}" style="position: absolute;top:16rpx;right: 40rpx;">
        <view class="icon">{{choosedGoodsList.length}}</view>
      </view>
    </view>
  </view>
</van-sticky>




<view style="height:100%;background: #F8F9FD ;" class="{{(active == 0 && controlFlags.choosewhFlag)?'addtop':''}}">
  <!-- 商品编码的列表 走sku-->
  <scroll-view scroll-y='{{true}}' bindscrolltolower='scrollToLower' lower-threshold='100' wx:if="{{active == 0 &&( billType == 'pur'|| billType == 'purInto' || billType == 'sale'  || billType == 'saleOut' ||  billType ==  'saleOutReturn')}}" 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="cell-width">
      <view wx:for="{{tableData}}" wx:key="index" border="{{ false }}" class="goods-cell-class" data-item="{{item}}" bind:tap="openAddItemInfo">
        <view class="goods-item-class">

          <view>

            <van-image radius="15rpx" custom-class="goods-item-image" fit="fill" src="{{item.imagesUrl}}" />
          </view>
          <view style="margin-left: 26rpx;width: 100%; ">
            <!-- 标题 -->
            <view>

              <dk-title titleTag="{{}}" title="{{item.skuModel}}"></dk-title>
            </view>
            <!-- 描述 -->
            <view style="display: flex;padding-top: 10rpx;">
              <dk-text fontSize="24rpx" value="{{item.skuName}}" data-item="{{item}}" bind:tap="openAddItemInfo"></dk-text>
            </view>
            <view style="display: flex;align-items: flex-end;margin-top:20rpx;">
              <!-- 标准价/标价-->
              <view style="width: 85%;">


                <view wx:if="{{billType == 'pur'||billType == 'purInto'}}">
                  <!-- <view style="color: #002340A6;font-size:22rpx;font-weight: 500;">采购价</view> -->
                  <dk-cell height="46rpx" spaceWidth="1rpx" left="0" fontSize="14" contentColor="#FF7B1A" fontWeight="700" title="" content="{{item.pricePurchase?item.pricePurchase:0}}"></dk-cell>
                </view>
                <view wx:else style="margin-top: 30rpx;">
                  <!-- <view style="color: #002340A6;font-size:22rpx;font-weight: 500;margin-top: 18rpx;">标价</view> -->
                  <dk-cell height="46rpx" spaceWidth="1rpx" left="0" fontSize="14" contentColor="#FF7B1A" fontWeight="700" title="" content="{{item.priceStandard?item.priceStandard:0}}"></dk-cell>
                </view>


              </view>
              <!-- 加号 -->
              <view class="van-icon-class">
                <van-icon data-item="{{item}}" bind:tap="openAddItemInfo" size="25px" name="add-square" style="color:#3E69F6;border-radius: 8px !important;" />
              </view>
            </view>
          </view>
        </view>
      </view>




    </van-cell-group>

    <view wx:if="{{tableData.length!=0}}" style="height:180rpx;"></view>

    <view wx:if="{{tableData.length==0}}" style="width:100%;">
      <van-empty description="暂无商品" border="{{ false }}" />
    </view>
  </scroll-view>

  <!--出库商品 列表 走库存-->
  <view wx:if="{{active == 0 && (billType == 'out' ||  billType =='purReturn' ||  billType =='inventory')}}" style="height:calc({{windowHeight+'px'}} - 295rpx);overflow: scroll;">
    <scroll-view scroll-y='{{true}}' bindscrolltolower='scrollToLower' lower-threshold='100'>
      <view wx:for="{{tableData}}" wx:key="index" catch:tap="openAddItemInfo" data-item="{{item}}" class="main-class" style="width: 75%;margin-left: 166rpx;">
        <view class="main-foot" style="border-radius:15rpx;">
          <view>
            <view class="table-content-row">
              <view style="display:flex;width:100%;">
                <view data-item="{{item}}" style="display:flex;font-size: 15px;">
                  <dk-text style="font-size:30rpx;" fontWeight="nomal" value="{{item.skuModel}}"></dk-text>
                </view>
              </view>
            </view>

            <!-- 商品名称 -->
            <view class="table-row">
              <view class="table-content-row">
                <view style="display: flex;">
                  <view class="table-content-row-font">
                    <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="商品名称" copyValue="{{item.skuName}}"></dk-text>
                  </view>
                  <view class="table-content-class">
                    {{item.skuName?item.skuName:''}}
                  </view>
                </view>
              </view>
            </view>

            <!-- 库区 -->
            <view class="table-content-row">
              <view style="display: flex;">
                <view class="table-content-row-font">
                  <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="库区" copyValue="{{item.whName}}"></dk-text>
                </view>
                <view class="table-content-class">
                  {{item.whName?item.whName:''}}
                </view>
              </view>
            </view>

            <!-- 库区色号 -->
            <view class="table-content-row">
              <view style="display: flex; justify-content:space-between;">


                <view style="display: flex;">
                  <view class="table-content-row-font">
                    <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="色号" copyValue="{{item.nonStdCode}}"></dk-text>
                  </view>
                  <view class="table-content-class">
                    {{item.nonStdCode?item.nonStdCode:''}}
                  </view>
                </view>

                <!-- 加号 -->
                <view class="van-icon-class">
                  <van-icon size="25px" name="add" style="color:#1B365D" />
                </view>
              </view>
            </view>
            <!-- 分割线 -->
            <dk-divider marginTop="20rpx" marginBottom="0rpx"></dk-divider>
            <!-- 下半部分 -->
            <view class="table-content-row">
              <view style="display: flex;justify-content:space-between">
                <view style="display: flex;">
                  <view class="table-content-row-font">
                    <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="库存量"></dk-text>
                  </view>
                  <view style="font-size: 13px;color: #CAA977;">
                    {{item.invQty}}
                  </view>
                </view>

                <view style="display: flex;">
                  <view class="table-content-row-font">
                    <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="可售量"></dk-text>
                  </view>
                  <view style="font-size: 13px;color: #CAA977;">
                    {{item.usableQty }}
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
      <view style="height:200rpx"></view>
    </scroll-view>

  </view>
</view>

<!--已选列表-->
<view wx:if="{{active == 1&& (billType != 'out')}}" 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="goods-item-class">
          <view>
            <van-image radius="15rpx" custom-class="goods-item-image" fit="fill" src="{{item.imagesUrl }}" />
          </view>
          <view style="margin-left: 26rpx;width: 100%;">
            <view data-item="{{item}}" data-index="{{index}}" bind:tap="openChoosedItemInfo">
              <!-- 标题 -->
              <view style="display: flex;">
                <dk-title titleTag="{{ }}" title="{{item.skuModel}}"></dk-title>
              </view>
              <!-- 描述 -->
              <view style="display: flex; ">
                <dk-text value="{{item.skuName}}"></dk-text>
              </view>
              <view style="display: flex;margin-top:20rpx;" wx:if="{{billType == 'pur'||billType == 'purInto'}}">
                <!-- 标准价/标价-->
                <view style="width: 85%;">
                  <dk-cell height="46rpx" spaceWidth="1rpx" left="0" fontSize="13" contentColor="#CAA977" fontWeight="bold" title=" " content="{{item.sumPrice?item.sumPrice:0}}"></dk-cell>
                </view>
                <view style="text-align: right;width: 5%;">
                  <!-- <van-icon name="arrow" style="font-size:3.5vw;" /> -->
                </view>
              </view>
              <view style="display: flex;" wx:if="{{billType == 'sale'}}">
                <view class="table-content-row-font">
                  <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="库区" copyValue="{{item.whName}}"></dk-text>
                </view>
                <view class="table-content-class">
                  {{item.whName?item.whName:''}}
                </view>
              </view>
              <view style="display: flex;" wx:if="{{billType == 'sale'}}">
                <view class="table-content-row-font">
                  <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="色号号" copyValue="{{item.nonStdCode}}"></dk-text>
                </view>
                <view class="table-content-class">
                  {{item.nonStdCode?item.nonStdCode:''}}
                </view>
              </view>

            </view>

            <view style="display:flex">
              <!-- <view style="padding-top: 5rpx;">
                  <dk-text value="数量："></dk-text>
              
                </view> -->
              <van-stepper value="{{item.itemQty}}" data-index="{{index}}" min="0" integer="{{true}}" max="999999999" bind:change="changeAllreadyChooseQuantity" />
            </view>
          </view>
        </view>
        <view slot="right">删除</view>
      </van-swipe-cell>
    </van-cell>

  </van-cell-group>
  <view style="height:220rpx;"></view>
</view>


<!--已选列表 库存盘点-->
<view wx:if="{{active == 1 && (billType == 'out')}}" style="height:calc({{windowHeight+'px'}} - 295rpx);overflow: scroll;">
  <scroll-view scroll-y='{{true}}' bindscrolltolower='scrollToLower' lower-threshold='100'>
    <view wx:for="{{choosedGoodsList}}" wx:key="index" catch:tap="openAddItemInfo" data-item="{{item}}" class="main-class">
      <van-swipe-cell right-width="{{ 65 }}" data-index="{{index}}" async-close bind:close="delChoosedGoodsItem">
        <view class="main-foot" style="border-radius:15rpx;">
          <view>
            <view class="table-content-row">
              <view style="display:flex;width:100%;">
                <view data-item="{{item}}" style="display:flex;font-size: 15px;">
                  <dk-text style="font-size:30rpx;" fontWeight="nomal" value="{{item.skuName}}"></dk-text>
                </view>
              </view>
            </view>
            <!-- 商品名称 -->
            <view class="table-row">
              <view class="table-content-row">
                <view style="display: flex;">
                  <view class="table-content-row-font">
                    <dk-text fontSize="14px" color="#95A8CB" fontWeight="nomal" value="商品编码" copyValue="{{item.skuCode}}"></dk-text>
                  </view>
                  <view class="table-content-class">
                    {{item.skuCode?item.skuCode:''}}
                  </view>
                </view>
              </view>
            </view>
            <!-- 库存盘点显示的 -->
            <view wx:if="{{controlFlags&&controlFlags.sourcePage =='inventory-check'}}">
              <!-- 库存量  可售量 -->
              <view class="table-content-row">
                <view style="display: flex;">
                  <view style="display: flex;flex: 1;">
                    <view class="table-content-row-font">
                      <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="库存量"></dk-text>
                    </view>
                    <view class="table-content-class">
                      {{item.invQty?item.invQty:''}}
                    </view>
                  </view>
                  <view style="display: flex;flex: 1;">
                    <view class="table-content-row-font">
                      <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="可售量"></dk-text>
                    </view>
                    <view class="table-content-class">
                      {{item.usableQty?item.usableQty:''}}
                    </view>
                  </view>
                </view>
              </view>
              <!--数量step-->
              <view class="table-content-row">
                <view style="display: flex;">
                  <view class="table-content-row-font" style="display: flex;  align-items: center;">
                    <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="盘点数量"></dk-text>
                  </view>
                  <view class="table-content-class">
                    <van-stepper value="{{item.itemQty}}" integer="{{true}}" data-index="{{index}}" data-item="{{item}}" data-key="{{item.code}}" bind:change="changeStep" />
                  </view>
                </view>
              </view>
              <!-- 盈亏数量 -->
              <view class="table-content-row">
                <view style="display: flex;">
                  <view class="table-content-row-font">
                    <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="盈亏数量"></dk-text>
                  </view>
                  <view class="table-content-class">
                    {{item.balanceQty}}
                  </view>
                </view>
              </view>
              <!-- 盈亏原因 -->
              <view class="table-content-row">
                <view style="display: flex;">
                  <view class="table-content-row-font">
                    <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="盈亏原因"></dk-text>
                  </view>
                  <view class="table-content-class">
                    {{item.lossReasonName?item.lossReasonName:''}}
                  </view>
                </view>
              </view>
            </view>
            <!-- 库区 -->
            <view class="table-content-row">
              <view style="display: flex;">
                <view class="table-content-row-font">
                  <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="库区" copyValue="{{item.whName}}"></dk-text>
                </view>
                <view class="table-content-class">
                  {{item.whName?item.whName:''}}
                </view>
              </view>
            </view>
            <!-- 库区色号 -->
            <view class="table-content-row">
              <view style="display: flex; justify-content:space-between;">
                <view style="display: flex;">
                  <view class="table-content-row-font">
                    <dk-text layoutFlag="{{true}}" fontSize="14px" color="#95A8CB" fontWeight="nomal" value="色号" copyValue="{{item.nonStdCode}}"></dk-text>
                  </view>
                  <view class="table-content-class">
                    {{item.nonStdCode?item.nonStdCode:''}}
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
        <view slot="right">删除</view>
      </van-swipe-cell>
    </view>
    <view style="height:200rpx"></view>
  </scroll-view>
</view>






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


<!--  采购入库 采购订单 其它入库  --> 
<dk-popup wx:if="{{ billType != 'sale' && billType != 'saleOut' && billType !== 'inventory'  }}" stepperDecimal ="decimalPlaces" type="sale" descCol="skuName" titleTagCol="" titleCol="skuModel" iconCol="imagesUrl"  subCol="calculationFormula"  value="{{dataItem}}" show="{{showPop}}" routeObjName="{{routeObjName}}" priceTitle="" priceCol="sumPrice"  contentObj="{{popContent}}"bind:changeStep="changeStep" bind:changeField= "changeField" bind:blurNumberField="blurNumberField" bind:openPackageBox="openPackageBox" bind:commit="editItems"> 
</dk-popup>

<!-- 库存 -->
<dk-popup wx:if="{{ billType == 'inventory' }}" type="sale" descCol="skuName"stepperDecimal ="decimalPlaces"  subCol="calculationFormula" titleTagCol="" titleCol="skuModel" iconCol="imagesUrl" value="{{dataItem}}" show="{{showPop}}" routeObjName="{{routeObjName}}" priceTitle="" priceCol="sumPrice" contentObj="{{popContent}}" bind:commit="editItems" bind:openPackageBox="openPackageBox"bind:changeStep="changeStep" bind:blurNumberField="blurNumberField" bind:changeField= "changeField" >
</dk-popup>


<!-- 销售开单 -->
<dk-popup wx:if="{{ billType == 'sale' }}" type="sale" titleTagCol="" subCol="calculationFormula" descCol="skuName" stepperDecimal ="decimalPlaces" titleCol="skuModel"  priceCol="sumPrice"  iconCol="imagesUrl"   value="{{dataItem}}" show="{{showPop}}" routeObjName="{{routeObjName}}" bind:changeStep="changeStep" bind:openPackageBox="openPackageBox" contentObj="{{popContent}}" bind:commit="editItems" bind:blurNumberField="blurNumberField"  bind:changeField= "changeField">
</dk-popup>
<!-- 销售出库 -->
<dk-popup wx:if="{{ billType == 'saleOut'}}" type="sale" titleTagCol="" subCol="calculationFormula" descCol="skuName" stepperDecimal ="decimalPlaces" titleCol="skuModel"  priceCol="sumPrice"  iconCol="imagesUrl"   value="{{dataItem}}" show="{{showPop}}" routeObjName="{{routeObjName}}" contentObj="{{popContent}}" bind:changeStep="changeStep"  bind:commit="editItems" popupTopObj="{{popupTopObj}}" bind:openPackageBox="openPackageBox" bind:blurNumberField="blurNumberField" bind:changeField= "changeField">
</dk-popup>

<!-- 箱片 -->
<dk-popup   type="basic"  title="修改包装数量"    titleCol="skuModel"  iconCol="imagesUrl"   value="{{dataItem}}" show="{{showPopBox}}" routeObjName="{{routeObjName}}"   contentObj="{{popContentBox}}" bind:changeStep="changeStep" bind:commit="editItemsBox" stepperDecimal ="decimalPlaces" ></dk-popup>

<dk-save-button cssType="sale" model:value="{{btnFormData}}" btnAutoWidthFlag="{{false}}" btnRightFlag="{{true}}" buttonList="{{buttonList}}" contentList="{{contentList}}" bind:open="submit"></dk-save-button>

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