<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>
<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-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">

      <!-- 商品列表 -->
      <van-cell wx:for="{{goodsList}}" wx:key="index" border="{{ false }}" data-item="{{item}}" bind:click="openAddItemInfo" custom-class="goods-cell-class">
        <view class="goods-item-class">
          <view>
            <van-image radius="15rpx" custom-class="goods-item-image" fit="fill" src="{{item.iconThumPath }}" />
          </view>
          <view style="margin-left: 26rpx;width: 100%;">
            <!-- 标题 -->
            <view style="display: flex;">
              <dk-title titleTag="{{item.titleTag}}" title="{{item.title}}"></dk-title>
            </view>
            <!-- 描述 -->
            <view style="display: flex; ">
              <dk-text value="{{item.desc}}"></dk-text>
            </view>
            <view style="display: flex;">
              <!-- 标准价/标价-->
              <view style="width: 85%;">
                <dk-cell height="46rpx" spaceWidth="1rpx" left="0" fontSize="13" contentColor="#CAA977" fontWeight="bold" title="标准售价:" content="{{item.pricePromotion?item.pricePromotion:(item.priceStandard?item.priceStandard:0)}}"></dk-cell>
              </view>
              <!-- 加号 -->
              <view class="van-icon-class">
                <van-icon size="25px" name="add" style="color:#1B365D" />
              </view>
            </view>
          </view>
        </view>
      </van-cell>
      <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="goods-item-class">
            <view>
              <van-image radius="15rpx" custom-class="goods-item-image" fit="fill" src="{{item.iconThumPath }}" />
            </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="{{item.titleTag}}" title="{{item.title}}"></dk-title>
                </view>
                <!-- 描述 -->
                <view style="display: flex; ">
                  <dk-text value="{{item.desc}}"></dk-text>
                </view>
                <view style="display: flex;">
                  <!-- 标准价/标价-->
                  <view style="width: 85%;">
                    <dk-cell height="46rpx" spaceWidth="1rpx" left="0" fontSize="13" contentColor="#CAA977" fontWeight="bold" title="售价:" content="{{item.priceSale?item.priceSale:0}}"></dk-cell>
                  </view>
                  <view style="text-align: right;width: 5%;">
                    <van-icon name="arrow" style="font-size:3.5vw;" />
                  </view>
                </view>
              </view>

              <view style="display:flex">
                <view style="padding-top: 5rpx;">
                  <dk-text value="数量："></dk-text>
                </view>
                <van-stepper value="{{item.itemQuantity}}" 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: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>

<van-sidebar activeKey="{{sideKey}}" bindchange="changeSidebar" custom-class="{{active == 0 ? 'left-class' : 'right-class'}}">
  <view wx:if="{{active != 1}}" style="height:calc({{windowHeight+'px'}} - {{active == 1 ? '270rpx' :'370rpx' }});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>

<!-- 合计保存相关组件 -->
<dk-save-bottom flagTypeName="order-choose-goods" selectTotallength="{{sumQuantity}}" selectlength="{{categoryQuantity}}" totallength="{{numberFormat.toThousandCents(sumGoodsAmount)}}" bind:submit="submit" />

<!--选择框-->
<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.title}}"></dk-title>
      <view style="padding-top: 10rpx;white-space: nowrap;">
        <dk-text fontWeight="" value="{{currentChoosedItem.desc}}"> </dk-text>
      </view>
      <view style="display: flex;padding-top: 5rpx;">
        <view wx:if="{{currentChoosedItem.promotionType != 0 }}" class="price-pop-class" style="display: flex;width: 100%;">
          <view style="width: 100%;" wx:if="{{ currentChoosedItem.promotionType == 2 || currentChoosedItem.skuName}}">
            <dk-cell height="46rpx" spaceWidth="1rpx" left="0" fontSize="14" contentColor="#CAA977" fontWeight="bold" title="标准售价:" content="{{currentChoosedItem.pricePromotion}}" tailColor="#95A8CB" tailLine="{{true}}" tailFontWeight="400" tail="{{currentChoosedItem.priceStandard?'¥' + numberFormat.toThousandCents(currentChoosedItem.priceStandard):''}}"></dk-cell>
          </view>
          <!-- <view style="width: 50%;" wx:if="{{currentChoosedItem.priceStandard}}">
            <dk-cell height="46rpx" spaceWidth="0rpx" left="0" fontSize="12" contentColor="#1B365D" fontWeight="nomal" title="标价:" content="{{currentChoosedItem.priceStandard}}"></dk-cell>
          </view> -->
        </view>
        <view wx:else class="price-pop-class">
          <dk-cell height="46rpx" spaceWidth="0rpx" left="0" fontSize="14" contentColor="#CAA977" fontWeight="bold" title="标价：" content="{{currentChoosedItem.priceStandard}}"></dk-cell>
        </view>

        <!-- 可换件 -->
        <view style="text-align: right; width: 14%;" wx:if="{{currentChoosedItem.replaceableSku}}">
          <dk-van-tag color="red" roundFlag="{{true}}" size="medium" value="可换件"></dk-van-tag>
        </view>
      </view>
      <!--sku编码-->
      <view class="selected-sku-text" wx:if="{{(currentChoosedItem.skuSpecsList && currentChoosedItem.skuSpecsList.length > 0 && (currentChoosedItem.skuName || currentChoosedItem.skuCode))  || (skuSpecsData.length  == 1 &&( currentChoosedItem.promotionType == 0 ||  currentChoosedItem.promotionType == 1)) }}" style="padding-top: 3rpx;">
        <dk-text fontWeight="" fontSize="10px" value="已选：{{ currentChoosedItem.skuName ? currentChoosedItem.skuName : ''}}"> </dk-text>
        <dk-text fontWeight="" fontSize="10px" value="编码：{{ currentChoosedItem.skuCode ? currentChoosedItem.skuCode : ''}}"> </dk-text>
      </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 wx:if="{{ show1}}">

          <!-- 就一个商品 -->
          <view wx:if="{{currentChoosedItem.skuSpecsList.length == 0  && skuSpecsData.length  == 1 && (currentChoosedItem.promotionType == 0 || currentChoosedItem.promotionType == 1)}}" 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 ? currentChoosedItem.skuCode : ''}}"> </dk-text>
            </view>
          </view>

          <view wx:for="{{currentChoosedItem.skuSpecsList}}" wx:key="index" date-item="{{item}}">
            <view style="display: flex;justify-content: space-between;">
              <view style="width: 30%;">
                <dk-text fontSize="13px" value="{{item.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 ? currentChoosedItem.skuCode : ''}}"> </dk-text>
              </view>
            </view>
            <view class="tags">
              <view class="tag-bom-item" wx:key="indext" wx:for="{{item.specsList}}" wx:for-index="indext" wx:for-item="itemt">
                <!-- <view wx:if="{{itemt.disabled}}" style="z-index: 1000; position:absolute;margin-top: -25rpx;margin-left: 75rpx;">
                  <dk-van-tag color="#98979C" fontSize="8px" height="20rpx" size="small" value="无货"></dk-van-tag>
                </view> -->
                <!-- <van-button disabled="{{itemt.disabled}}" size="small" catchtap="changeSkuSpecs" data-pindex="{{index}}" custom-class="{{itemt.default?'button-selected-class':'button-class'}}" data-itemt="{{itemt}}" data-indext="{{indext}}">{{ itemt.key }}
                </van-button> -->
                <van-button disabled="{{itemt.disabled}}" size="small" bind:click="changeSkuSpecs" data-pindex="{{index}}" custom-class="{{itemt.default?'button-selected-class':'button-class'}}" data-itemt="{{itemt}}" data-indext="{{indext}}"><text wx:if="{{itemt.disabled}}" style="color:black;text-decoration:line-through"><text style="color:#95A8CB;">{{ itemt.key }}</text></text><text wx:if="{{!itemt.disabled}}">{{ itemt.key }}</text></van-button>

              </view>
            </view>
          </view>
        </view>
        <!-- 组合促销 -->
        <view wx:if="{{show4}}">
          <view wx:for="{{currentChoosedItem.combinedData.combinedType}}" wx:key="index">
            <view style="width: 30%;">
              <dk-text fontSize="13px" value="{{item.specsName}}"></dk-text>
            </view>
            <view class="tags">
              <view wx:key="indext" wx:for="{{currentChoosedItem.combinedData.combinedItem}}" wx:for-index="indext" wx:for-item="itemt">
                <van-button wx:if="{{item.typeId == itemt.combinedTypeId}}" size="small" catchtap="changeCombinedItem" custom-class="{{itemt.infotype=='info'?'button-selected-class':'button-class'}}" data-pindex="{{index}}" data-itemt="{{itemt}}">
                  <view class="tag-text">{{ itemt.skuModel?itemt.skuModel:'' }}</view>
                  <view class="tag-text">{{ itemt.skuName }}</view>
                </van-button>
              </view>
            </view>
            <!-- <van-divider /> -->
          </view>
          <view>
          </view>
        </view>

        <!-- 促销单品选择 -->
        <view wx:if="{{show5}}">
          <view>
            <view class="tags">
              <view style="margin-left: 5px;margin-bottom: 12px;" wx:key="indext" wx:for="{{PricePromotionData}}" wx:for-index="indext" wx:for-item="itemt">
                <van-button size="small" catchtap="clickDP" custom-class="button-class" data-pindex="{{index}}" data-itemt="{{itemt}}" data-indext="{{indext}}" plain type="{{itemt.infotype}}">
                  <text style="display:flex;">{{ itemt.skuName }}</text>
                  <text style="display:flex;">{{ itemt.skuCode }}</text>
                </van-button>
              </view>
            </view>
            <van-divider />
          </view>
          <view>
          </view>
        </view>


        <!-- 非标商品选择 -->
        <view wx:if="{{show6 && (skuData.length > 0)}}">

          <view wx:key="index">
            <view style="width: 30%;">
              <dk-text fontSize="13px" value="商品"></dk-text>
            </view>
            <view class="tags">
              <view wx:key="indext" wx:for="{{skuData}}" wx:for-index="indext" wx:for-item="itemt">
                <van-button disabled="{{itemt.disabled}}" size="small" bind:click="nonGlassSpuItemsTap" custom-class="{{itemt.infotype=='info'?'button-selected-class':'button-class'}}" data-indext="{{indext}}" data-itemt="{{itemt}}">
                  <view wx:if="{{itemt.disabled}}" style="color:black;text-decoration:line-through">
                    <view class="tag-text" style="color:#95A8CB;">{{ itemt.skuModel}} </view>
                    <view class="tag-text" style="color:#95A8CB;">{{ itemt.skuName }}</view>
                  </view>
                  <view wx:else>
                    <view class="tag-text">{{ itemt.skuModel}} </view>
                    <view class="tag-text">{{ itemt.skuName }}</view>
                  </view>
                </van-button>
              </view>
            </view>

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

        <!-- 非标参数选择 -->
        <view wx:if="{{ show7}}">
          <view wx:for="{{currentChoosedItem.nonStandardList}}" wx:key="index" date-item="{{item}}">
            <view style="width: 30%;">
              <dk-text wx:if="{{item.isScope == 0}}" fontSize="13px" value="{{item.fieldName}}"></dk-text>
            </view>
            <view class="tags" wx:if="{{item.isScope == 0}}">
              <view class="tag-bom-item" wx:key="indext" wx:for="{{item.options}}" wx:for-index="indext" wx:for-item="itemt">
                <van-button size="small" catchtap="nonStandardTap" data-pindex="{{index}}" custom-class="{{itemt.infotype=='info'?'button-selected-class':'button-class'}}" data-itemt="{{itemt}}" data-indext="{{indext}}">{{ itemt.name }}
                </van-button>
              </view>
            </view>



            <!-- 输入范围 -->
            <view wx:if="{{item.isScope == 1}}" style="display: flex; padding-bottom: 20rpx; padding-top: 10rpx;">
              <view style="width: 50%;">
                <dk-text fontSize="13px" value="{{item.fieldName}}"></dk-text>
              </view>
              <view style="width: 50%; text-align: right;font-size: 13px; ">
                <input type="text" placeholder-class="placeholder-class" placeholder="{{'请输入'+item.fieldName}}" data-pindex="{{index}}" data-item="{{item}}" value="{{item.optionName}}" bindblur="bindBlurIsScopeOne" bindinput="bindInputIsScopeOne"></input>
              </view>

            </view>
          </view>
          <view wx:if="{{currentChoosedItem.flgNonStandardType == 1}}">
            <view style="display: flex; padding-bottom: 20rpx; padding-top: 10rpx;">
              <view style="width: 50%;">
                <dk-text fontSize="13px" value="面积公式"></dk-text>
              </view>
              <view style="width: 50%; text-align: right;font-size: 13px; ">
                <input type="text" placeholder-class="placeholder-class" data-pindex="{{index}}" disabled="{{true}}" data-item="{{item}}" value="{{currentChoosedItem.specialFormulaName}}" bindblur="bindBlurIsScopeOne" bindinput="bindInputIsScopeOne"></input>
              </view>

            </view>


            <van-cell border="{{ false }}" title-width="410rpx" title-class="{{!currentChoosedItem.flgGift ? 'red-label' : ''}}" disabled="{{currentChoosedItem.flgGift}}">
              <view slot="title">
                面积
              </view>
              <view Cell Slot="value">
                <!-- <input type="text" placeholder-class="placeholder-class" placeholder="请输入面积"   value="{{currentChoosedItem.nonStandardArea ? currentChoosedItem.nonStandardArea : ''}}" bindblur="bindBlurNonStantardArea" bindinput="bindInputNonStantardArea"></input> -->
                <dk-number-input sign="" formatThousandth="{{false}}" digits="{{6}}" center="right" data-key="nonStandardArea" inputValue="{{currentChoosedItem.nonStandardArea?currentChoosedItem.nonStandardArea:0}}" bind:triggerBindValue="bindBlurNonStantardArea">
                </dk-number-input>
              </view>
            </van-cell>

          </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-cell border="{{ false }}" title-width="410rpx" title-class="{{!currentChoosedItem.flgGift ? 'red-label' : ''}}" disabled="{{currentChoosedItem.flgGift}}">
          <view slot="title">
            销售价格
          </view>
          <view Cell Slot="value">
            <dk-number-input center="right" data-key="priceSale" inputValue="{{currentChoosedItem.priceSale}}" bind:triggerBindValue="changeSalesPriceField"></dk-number-input>
          </view>
        </van-cell>

        <!--销售金额-->
        <van-cell border="{{ false }}" title-width="410rpx" title-class="{{!currentChoosedItem.flgGift ? 'red-label' : ''}}" disabled="{{currentChoosedItem.flgGift}}">
          <view slot="title">
            销售金额
          </view>
          <view Cell Slot="value">
            <dk-number-input center="right" data-key="itemAmount" inputValue="{{currentChoosedItem.itemAmount}}" bind:triggerBindValue="changeItemAmountField"></dk-number-input>
          </view>
        </van-cell>

        <!--正常品显示-->
        <van-cell wx:if="{{currentChoosedItem.promotionType==0}}" border="{{ false }}" title-width="410rpx" disabled="{{currentChoosedItem.flgGift}}">
          <view slot="title" style="color:#95A8CB">
            标价折扣
          </view>
          <dk-number-input center="right" signSize="20" percentSignFlag="{{true}}" data-key="discountStandard" inputValue="{{(currentChoosedItem.discountStandard  || currentChoosedItem.discountStandard ==0)?(currentChoosedItem.discountStandard):'' }}" bind:triggerBindValue="changeDiscountField"></dk-number-input>
          <!-- <dk-text color="#1B365D" fontSize="13px" fontWeight="nomal" value="{{(currentChoosedItem.discountStandard  || currentChoosedItem.discountStandard ==0)?(currentChoosedItem.discountStandard+ '%'):'' }}"></dk-text> -->
        </van-cell>

        <!--促销品显示-->
        <van-cell wx:if="{{currentChoosedItem.promotionType !=0 }}" border="{{ false }}" title-width="410rpx" disabled="{{currentChoosedItem.flgGift}}">
          <view slot="title" style="color:#95A8CB">
            标准售价折扣
          </view>

          <!--只显示-->
          <dk-number-input center="right" signSize="20" percentSignFlag="{{true}}" data-key="discountPromotion" inputValue="{{(currentChoosedItem.discountPromotion  || currentChoosedItem.discountPromotion ==0)?(currentChoosedItem.discountPromotion):'' }}" bind:triggerBindValue="changeDiscountField"></dk-number-input>
          <!-- <dk-text color="#1B365D" fontSize="13px" fontWeight="nomal" value="{{currentChoosedItem.discountPromotion?(currentChoosedItem.discountPromotion+ '%'):'' }}"></dk-text> -->
        </van-cell>

        <van-field label-class="nomal-label" label="使用位置" type="usedLocation" bind:click-icon="clicIconkUseLocation" bind:blur="blurUseLocation" bind:change="changeUseLocation" data-item="currentChoosedItem" data-key="usedLocation" value="{{currentChoosedItem.usedLocation}}" input-align="right" placeholder="请输入使用位置" border="{{ false }}" />

        <van-cell wx:if="{{currentChoosedItem.cpFlgGift}}" style="color:#95A8CB" title="赠品标识" border="{{ false }}" value-class="value-class">
          <van-checkbox shape="round" value="{{ currentChoosedItem.flgGift}}" data-index="{{index}}" data-key="flgGift" bind:change="changeAllReadyCheckBox" />
        </van-cell>

        <van-cell wx:if="{{currentChoosedItem.flgAllowSpecsUndefine}}" style="color:#95A8CB" title="坑距待定" border="{{ false }}" value-class="value-class">
          <van-checkbox shape="round" value="{{ currentChoosedItem.flgSpecsUndefine}}" data-index="{{index}}" data-key="flgSpecsUndefine" bind:change="changeFlgAllowSpecsUndefine" />
        </van-cell>



        <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>