<wxs src='../../../utils/wxmlUtil.wxs' module="wxmlUtil"></wxs>
<view class="dk-card-outer-class">

  <!--日期-->
  <view class="dk-card-class" wx:if="{{dateCol}}">
    <van-field required is-link arrow-direction="down" value="{{ form[dateCol]}}" label="{{dateLabel}}" autosize border="{{ false }}" readonly="{{true}}" input-class="dk-cell-value-right-class" catchtap="openDatePop">
    </van-field>
  </view>
  <!--对象-->
  <view class="dk-card-class" wx:if="{{objCol}}" id="{{objCol}}">
    <!--展示对象信息-->
    <view wx:if="{{form.objInfo}}" class="dk-obj-class">
      <view style="width: 100%;">
        <view class="dk-obj-label-class">
          <view style="font-size: 17px;font-weight: bold;">{{form.objInfo[objTitle]}} </view>
          <view style="display: flex;align-items: center;"> {{form.objInfo[objSubTitle]!=null?form.objInfo[objSubTitle]:''}}</view>
        </view>
        <view class="dk-obj-amount-class" wx:if="{{amountArr && amountArr.length > 0}}">
          <view style="width: {{100/amountArr.length + '%'}};margin-top: 20rpx;" wx:for="{{amountArr}}" wx:for-item="amount" data-item="{{amount}}" wx:for-index="amountIndex">
            <view class="background-amount">
              <view style="display: flex;justify-content: center;">{{amount.title}}</view>
              <view style="display: flex;justify-content: center;margin-top: 10rpx;font-weight: bold;">
                <view class="sign-class">¥</view>
                <view class="amount-class">{{wxmlUtil.toThousandCents(form.objInfo[amount.code])}}</view>
              </view>
            </view>

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

      <view class="corner-view" bind:tap="openObjPop">
        <view class="corner-view-text">{{chooseText}}

        </view>
        <view class="corner-view-text" style="margin-top: 10rpx;">
          <van-image round width="30rpx" height="30rpx" src="/static/image/right.png" />
        </view>
      </view>
    </view>

    <!--选择对象-->
    <van-field  wx:else required is-link value="{{ form[objCol]}}" label="{{objLabel}}" autosize border="{{ false }}" readonly="{{true}}" input-class="dk-cell-value-right-class" catchtap="openObjPop">
    </van-field>

  </view>

  <!-- 单据信息 -->
  <view class="dk-card-class" wx:for="{{cardList}}" wx:for-item="card" wx:for-index="cardIndex" data-item="{{card}}">
    <view wx:if="{{card.title}}" class="item-class">
      <view class="item-title-class">{{card.title}}</view>
      <view class="item-count-class" wx:if="{{card.name == 'items'}}"> </view>
      <view class="item-count-class" wx:else=""></view>
      <view style="width:{{(card.chooseFlag && card.name=='items')?'50%':'15%'}} ;text-align: right;">
        <!-- <dk-tag wx:if="{{card.chooseFlag && form[objIdCol]}}" type="primary" padding="0 20rpx" height="40rpx" color="#9FAEE5" textColor="#FFFFFF" radius="5rpx" roundFlag="{{true}}" data-index="{{cardIndex}}" value="{{card.chooseTitle}}" catchtap="choose"></dk-tag> -->
        <view style="margin-right: 20rpx;" data-index="{{cardIndex}}" catchtap="choose" wx:if="{{card.chooseFlag && form[objIdCol]}}">
          <van-image round width="30rpx" height="30rpx" src="/static/image/right.png" />
        </view>
        <!-- <dk-tag wx:if="{{card.name=='items'}}" type="primary" style="margin-left: 10rpx;" padding="0 20rpx" height="40rpx" color="#9FAEE5" textColor="#FFFFFF" radius="5rpx" roundFlag="{{true}}" data-index="{{cardIndex}}" value="{{(card.show ||  card.show == undefined )?'收起':'展开'}}" catchtap="clickTag"></dk-tag> -->
      </view>
    </view>
    <!--明细card-->
    <view wx:if="{{card.name == 'items'}}">
      <view wx:if="{{card.show || card.show == undefined}}" wx:for="{{form[itemName]}}" data-item="{{itemt}}" wx:for-item="itemt" wx:key="indext" wx:for-index="indext">
        <van-swipe-cell right-width="{{readonly? 0:65 }}" data-index="{{indext}}" async-close bind:close="onCloseDel">
          <view wx:for="{{contentObj[card.name]}}" wx:for-item="item" data-item="{{item}}" wx:key="index">
            <!--文本框-->
            <van-field wx:if="{{item.type=='str'}}" required="{{item.required?true:false }}" data-key="{{item.code}}" data-item="{{item}}" data-index="{{indext}}" data-card="{{card.name}}" value="{{ itemt[item.code]}}" input-align="left" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" autosize clearable border="{{ false }}" readonly="{{!!item.readonly}}" input-class="dk-cell-value-class" maxlength="{{item.maxlength?item.maxlength:50}}" right-icon="{{item.rightIcon}}" bind:change="changeItemField"  bind:blur="blurField" bind:clear="clearItemField" errorMessage="{{itemt[item.code + '_errMsg']}}">
            </van-field>
            <!--选单-->
            <van-field wx:if="{{item.type=='choose' }}" required="{{item.required?true:false }}" data-name="{{item.name}}" data-key="{{item.code}}" data-item="{{item}}" data-index="{{indext}}" data-card="{{card.name}}" value="{{ itemt[item.name]}}" input-align="left" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" is-link catchtap="open" autosize border="{{ false }}" readonly="{{true}}" input-class="dk-cell-value-class" data-type='{{item.dropType}}' errorMessage="{{itemt[item.code + '_errMsg']}}">
              <van-icon wx:if="{{!readonly &&  itemt[item.name]}}" slot="icon" name="clear" color="#c8c9cc;" data-item="{{item}}" data-name="{{item.name}}" data-card="{{card.name}}" data-key="{{item.code}}" catchtap="clearChoose"></van-icon>
            </van-field>
            <!--选择框-->
            <van-field wx:if="{{item.type=='checkbox'}}" input-width="200rpx" input-class="dk-cell-value-class" label-class="nomal-label" input-align="left" value="{{ itemt[item.code] ? '  需要' : '  不需要' }}" label="{{item.title?item.title:$t[item.code]}}" autosize border="{{ false }}" readonly="{{true}}" errorMessage="{{itemt[item.code + '_errMsg']}}">
              <view slot="inputbefor" style="text-align: left;padding-left: 10rpx;" data-item="{{item}}" data-index="{{indext}}" data-card="{{card.name}}" data-value="{{itemt[item.code]}}" data-key="{{item.code}}" catchtap="onItemChange">
                <van-checkbox shape="round" value="{{itemt[itemName][item.code]}}" />
              </view>
            </van-field>
            <!--开关-->
            <van-field wx:if="{{item.type=='switch'}}" input-width="200rpx" input-class="dk-cell-value-class" label-class="nomal-label" input-align="right" label="{{item.title?item.title:$t[item.code]}}" autosize border="{{ false }}" readonly="{{true}}" errorMessage="{{itemt[item.code + 'errMsg']}}">
              <view slot="inputbefor" style="text-align: left;padding-top: 5rpx;">
                <van-switch size="20px" checked="{{ itemt[item.code]}}" bind:change="onItemChange" active-color="#1B365D" data-item="{{item}}" data-index="{{indext}}" data-card="{{card}}" data-value="{{form[item.code]}}" data-key="{{item.code}}" />
              </view>
            </van-field>
            <!--数字类-->
            <dk-number-input wx:if="{{item.type=='number'}}" sign="{{(item.sign || item.sign == '')?item.sign:'¥'}}" digits="{{(item.digits || item.digits == 0)?item.digits:2}}" fontSize="14" left="30rpx" data-key="{{item.code}}" data-item="{{item}}" data-index="{{indext}}" data-card="{{card.name}}" center="left" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" errorMessage="{{itemt[item.code + '_errMsg']}}" titleValue="{{item.title?item.title:$t[item.code]}}" inputColor="#FF7B1A" titleFontWeight="{{item.required?'normal':'normal'}}" titleColor="{{item.required?'#95A8CB':'#95A8CB'}}"inputValue="{{itemt[item.code]}}" readonly="{{!!readonly || !!item.readonly || (objIdCol && !form[objIdCol]) || (item.control && !itemt[item.control])}}"  maxFlag="{{item.maxFlag}}" max="{{item.max}}" negative="{{item.negative}}" min="{{item.min}}"   required="{{item.required?true:false }}"bind:triggerBindValue="changeItemNumberField"></dk-number-input>
            <!--备注-->
            <van-field wx:if="{{item.type=='textarea'}}" type="textarea" required="{{item.required?true:false }}" data-key="{{item.code}}" data-item="{{item}}" data-index="{{indext}}" data-card="{{card.name}}" value="{{ itemt[item.code]}}" input-align="left" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" clearable autosize border="{{ false }}" readonly="{{!!readonly || !!item.readonly|| !form[objIdCol]}}" input-class="dk-cell-value-class" maxlength="{{item.maxlength?item.maxlength:500}}" right-icon="{{item.rightIcon}}" bind:change="changeItemField" bind:blur="blurField" bind:clear="clearItemField" errorMessage="{{itemt[item.code + '_errMsg']}}">
            </van-field>
          </view>
          <van-divider wx:if="{{indext < form[itemName].length - 1}}" custom-style="margin:20rpx 20rpx" borderColor="#DCDCDC"></van-divider>
          <view wx:if="{{!readonly}}" slot="right">删除</view>
        </van-swipe-cell>
      </view>
      <view class="item-btn-title-class" bind:tap="addItem" wx:if="{{card.addFlag || card.addFlag == undefined}}">
        <view class="item-add-btn-class">
          <van-icon name="plus" color="#606EB2" size="26rpx" custom-style="font-weight:bold" />
        </view>
        {{itemBtn}}
      </view>
    </view>
    <!--非明细card-->
    <view wx:if="{{card.name != 'items'}}" wx:for="{{contentObj[card.name]}}" wx:for-item="item" data-item="{{item}}" wx:key="index">
      <!--文本框-->
      <van-field id="{{item.code}}" wx:if="{{item.type=='str'}}" required="{{item.required?true:false }}" data-key="{{item.code}}" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" value="{{ form[item.code]}}" input-align="left" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" autosize clearable border="{{ false }}" readonly="{{!!item.readonly}}" input-class="dk-cell-value-class" maxlength="{{item.maxlength?item.maxlength:50}}" right-icon="{{item.rightIcon}}" bind:change="changeField" bind:blur="blurField" bind:clear="clearField" errorMessage="{{item.errMsg}}">
        <van-icon wx:if="{{item.tip}}" slot="label-icon" name="question-o" data-item="{{item}}" catchtap="showTip" />
      </van-field>
      <!--下拉-->
      <van-field id="{{item.code}}" wx:if="{{item.type=='drop'}}" required="{{item.required?true:false }}" data-name="{{item.name}}" data-key="{{item.code}}" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" value="{{ form[item.name]}}" input-align="left" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" is-link catchtap="open" autosize border="{{ false }}" readonly="{{true}}" input-class="dk-cell-value-class" data-type='{{item.dropType}}' errorMessage="{{item.errMsg}}">
        <van-icon wx:if="{{!readonly &&  form[item.code]}}" slot="icon" name="clear" color="#c8c9cc;" data-item="{{item}}" data-name="{{item.name}}" data-key="{{item.code}}" catchtap="clearChoose"></van-icon>
      </van-field>
      <!--选单-->
      <van-field id="{{item.code}}" wx:if="{{item.type=='choose' }}" required="{{item.required?true:false }}" data-name="{{item.name}}" data-key="{{item.code}}" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" value="{{ form[item.name]}}" input-align="left" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" is-link catchtap="open" autosize border="{{ false }}" readonly="{{true}}" input-class="dk-cell-value-class" data-type='{{item.dropType}}' errorMessage="{{item.errMsg}}">
        <van-icon wx:if="{{!readonly &&  form[item.name]}}" slot="icon" name="clear" color="#c8c9cc;" data-item="{{item}}" data-name="{{item.name}}" data-card="{{card.name}}" data-key="{{item.code}}" catchtap="clearChoose"></van-icon>
      </van-field>
      <!--日期-->
      <van-field id="{{item.code}}" wx:if="{{item.type=='date' }}" required="{{item.required?true:false }}" is-link value="{{ form[item.code]}}" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" data-item="{{item}}" data-key="{{item.code}}" data-index="{{index}}" clearable data-card="{{card.name}}" errorMessage="{{item.errMsg}}" border="{{ false }}" readonly="{{true}}" input-class="dk-cell-value-class" catchtap="openDatePop">
        <van-icon wx:if="{{!readonly &&  form[item.code]}}" slot="icon" name="clear" color="#c8c9cc;" data-key="{{item.code}}" catchtap="clearDate"></van-icon>
      </van-field>
      <!--选择框-->
      <van-field id="{{item.code}}" wx:if="{{item.type=='checkbox'}}" input-width="200rpx" input-class="dk-cell-value-class" label-class="nomal-label" input-align="left" value="{{ form[item.code] ? '  需要' : '  不需要' }}" label="{{item.title?item.title:$t[item.code]}}" autosize border="{{ false }}" readonly="{{true}}" errorMessage="{{item.errMsg}}">
        <view slot="inputbefor" style="text-align: left;padding-left: 10rpx;" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" data-value="{{form[item.code]}}" data-key="{{item.code}}" catchtap="onChange">
          <van-checkbox shape="round" value="{{form[item.code]}}" />
        </view>
      </van-field>
      <!--核销-->
      <van-field id="{{item.code}}" wx:if="{{item.type=='cancel'}}" input-width="200rpx" input-class="dk-cell-nomal-class" label-class="nomal-label" input-align="left" value="{{ item.title?item.title:$t[item.code] }}{{item.bill!=null?(' (已选' + item.bill + '单，共' + item.amount + '元)'):''}}" autosize border="{{ false }}" readonly="{{true}}" errorMessage="{{item.errMsg}}">
        <view slot="inputbefor" class="cancel-class" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" data-value="{{form[item.code]}}" data-key="{{item.code}}" catchtap="onChange">
          <van-checkbox shape="round" value="{{form[item.code]}}" />
        </view>
      </van-field>
      <!--客户地址-->
      <van-field id="{{item.code}}" wx:if="{{item.type=='address'}}" input-width="200rpx" input-class="dk-cell-value-class" required="{{item.required?true:false }}" input-align="left" data-key="address" type="textarea" value="{{ wxmlUtil.addressToIndexOf(form.address.address) }}" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" autosize border="{{ false }}" right-icon="location" data-type='address' catchtap="onClickWxchartAddress" readonly="{{true}}" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" errorMessage="{{item.errMsg}}">
        <view style="display: flex;" slot="right-icon">
          <van-icon wx:if="{{!readonly &&  form.address.address}}" slot="right-icon" name="clear" color="#c8c9cc;" data-key="{{item.code}}" catchtap="clearAddress"></van-icon>
          <van-icon custom-style="padding-left:10rpx" name="location"></van-icon>
        </view>
      </van-field>
      <!--联系电话-->
      <dk-number-phone-input id="{{item.code}}" wx:if="{{item.type=='phone'}}" data-key="{{item.code}}" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" required="{{item.required?true:false }}" rightIcon="phone" model:value="{{ form[item.code]}}" bind:changeField="changePhone" bind:changeFieldblur="changePhoneblur" clearable bind:clear="clearField" errorMessage="{{item.errMsg}}" id="{{item.code}}" readonly="{{!!readonly || !!item.readonly}}" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.code)}}"></dk-number-phone-input>
      <!--数字类-->
      <dk-number-input id="{{item.code}}" wx:if="{{item.type=='number'}}" required="{{item.required?true:false }}"  sign="{{(item.sign || item.sign == '')?item.sign:'¥'}}" digits="{{(item.digits || item.digits == 0)?item.digits:2}}" fontSize="14" left="30rpx" data-key="{{item.code}}" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" center="left" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" errorMessage="{{item.errMsg}}" readonly="{{!!readonly || !!item.readonly}}" titleValue="{{item.title?item.title:$t[item.code]}}" inputColor="#FF7B1A" titleFontWeight="{{item.required?'normal':'normal'}}" titleColor="{{item.required?'#95A8CB':'#95A8CB'}}"  maxFlag="{{item.maxFlag}}" max="{{item.max}}" negative="{{item.negative}}" min="{{item.min}}"  inputValue="{{form[item.code]}}" bind:triggerBindValue="changeNumberField"></dk-number-input>
      <!--备注-->
      <van-field wx:if="{{item.type=='textarea'}}" type="textarea" required="{{item.required?true:false }}" data-key="{{item.code}}" data-item="{{item}}" data-index="{{index}}" data-card="{{card.name}}" value="{{ form[item.code]}}" input-align="left" label="{{item.title?item.title:$t[item.code]}}" placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" autosize border="{{ false }}" readonly="{{!!readonly && !!item.readonly}}" clearable input-class="dk-cell-value-class" maxlength="{{item.maxlength?item.maxlength:500}}" right-icon="{{item.rightIcon}}" bind:change="changeField" bind:blur="blurField" bind:clear="clearField" errorMessage="{{item.errMsg}}"> </van-field>
      <!--附件-->
      <view style="display:flex;width:100%;margin: 1vw; padding-top: 20rpx;" wx:if="{{item.type=='uploader'}}">
        <view style="width: 168rpx; flex:1;color: #95A8CB;font-size: 28rpx;padding-left: 27rpx;">附件</view>
        <view style="width: calc(100% - 168rpx);text-align: left;">
          <van-uploader max-count="5" disabled="{{!!item.readonly}}" accept="image" style="margin-left: 4%;border-radius: 15rpx;" preview-size="160rpx;" file-list="{{ form['annexPaths']  }}" data-readonly="{{!!item.readonly}}" bind:delete="deleteImg" bind:after-read="afterRead" multiple="true" imageFit="aspectFit" max-size="{{maxSize}}" bind:oversize="overSize" upload-text="添加照片" />
          <view style="margin-left: 27rpx;color: #C8C9CC;font-size: 12px;">
            图片最多上传5张
          </view>
        </view>
      </view>
    </view>

    <!--分割线-->
    <van-divider wx:if="{{totalObj && totalObj[card.name]}}" custom-style="margin:20rpx 20rpx" borderColor="#DCDCDC"></van-divider>

    <!--合计信息-->
    <van-grid wx:if="{{totalObj && totalObj[card.name]}}" column-num="2" border="{{ false }}" center="{{false}}">
      <van-grid-item use-slot wx:for="{{totalObj[card.name]}}" data-item="{{item}}" wx:key="index" content-class="grid-item-class">
        <dk-cell contentColor="#FF7B1A" titleColor="#002340;" title="{{item.title}}" content="{{form[item.code]?form[item.code]:0}}"></dk-cell>
      </van-grid-item>
    </van-grid>
  </view>
</view>
<!--弹出-->
<dk-single-dropdown-item show="{{show}}" typeName='{{dropType}}' bind:commit='chooseData' bind:muticlose='muticlose'></dk-single-dropdown-item>


<van-popup show="{{ showDate }}" custom-style="border-radius:30rpx 30rpx 0 0;" position="bottom" bind:close="cancelDatePop">
  <van-datetime-picker type="date" bind:confirm="chooseDate" bind:cancel="cancelDatePop" loading="{true}" value="{{dataTime}}" />
</van-popup>