<!--pages/create-order/index.wxml-->
<view class="sg-container">
  <view class="sg-tabs sg-flex sg-align-center sg-space-around">
    <block wx:for="{{tabs}}" wx:key="index">
      <view class="sg-tab sg-pad {{index == tabIndex ? 'sg-seleted' : 'sg-gray-color'}}" bindtap="switchTab"
        data-index="{{index}}">{{item}}</view>
    </block>
  </view>
  <view class="sg-order-box" wx:if="{{tabIndex == 0}}">
    <view class="sg-form">
      <view class="sg-form-item sg-pad sg-top-border">
        <view class="sg-label">项目名称</view>
        <input value="{{project ? project.name : ''}}" class="sg-input" disabled="true"></input>
      </view>
      <view class="sg-form-item sg-pad sg-top-border">
        <view class="sg-label">需求工点</view>
        <picker bindchange="onChange" value="{{pointIndex}}" range="{{work_points}}" range-key="name"
          data-name="pointIndex" class="sg-input">
          <view class="picker sg-gray-color">
            {{pointIndex >= 0 ? work_points[pointIndex].name : '选择所需的工点'}}
          </view>
        </picker>
      </view>
      <view class="sg-form-item sg-pad sg-top-border">
        <view class="sg-label">租赁设备</view>
        <input value="{{device_total + '台'}}" class="sg-input" disabled="{{true}}"></input>
      </view>
      <view class="sg-form-item sg-pad sg-top-border">
        <view class="sg-label">租赁总金额</view>
        <input value="{{'￥' + device_money}}" class="sg-input" disabled="{{true}}"></input>
      </view>
      <view class="sg-form-item sg-pad sg-top-border">
        <view class="sg-label">备注</view>
        <input value="{{remark}}" class="sg-input" bindinput="onChange" data-name="remark" placeholder="订单备注填写"></input>
      </view>
    </view>
  </view>
  <van-calendar show="{{ showDate }}" bind:close="switchShowDate" bind:confirm="confirmDate" data-show="{{false}}"
    type="range" class="sg-calendar" default-date="{{default_dates}}" allow-same-day="{{true}}"/>
  <view class="sg-device-box" wx:if="{{tabIndex == 1}}">
    <view class="sg-device-list sg-top-border">
      <block wx:if="{{devices.length <= 0}}">
        <view class="sg-center sg-pad">暂无设备</view>
      </block>
      <block wx:else>
        <!-- <view class="sg-item sg-flex sg-align-center sg-bottom-border" wx:for="{{devices}}" wx:key="index"
          bindtap="selectDevice" data-index="{{index}}">
          <view class=" sg-flex-grow sg-pad sg-flex-column">
            <view class="sg-left-top sg-flex sg-justify-center sg-space-between">
              <view class="sg-name">{{item.type_name}}-{{item.name}}-{{item.spec}}</view>
              <view class="sg-left-right sg-quantity-price sg-red-color" style="color:red">
                ￥<text>{{item.price*item.quantity}}</text>
              </view>
            </view>
            <view class="sg-left-bottom sg-gray-color sg-font-xs">
              租赁方式：{{item.rent}}
            </view>
            <view class="sg-left-bottom sg-red-color sg-font-xs" style="color:red">
              租赁单价：￥{{item.price}}
            </view>
            <view class="sg-left-bottom sg-gray-color sg-font-xs">
              租赁数量：{{item.quantity}}
            </view>
            <view class="sg-left-bottom sg-gray-color sg-font-xs">{{item.start_date}}至{{item.end_date}}</view>
          </view>
          <view class="sg-right sg-pad sg-flex sg-align-center sg-icon" bindtap="selectDevice">
            <van-icon name="passed" wx:if="{{selectIndex == index}}" class="sg-index-color" />
            <van-icon name="circle" wx:else />
          </view>
          <view class="sg-right sg-red-bg sg-pad sg-flex sg-align-center" bindtap="deleteDevice" data-index="{{index}}">删除</view>
        </view> -->
        <view class="sg-item sg-pad sg-margin" wx:for="{{devices}}" wx:key="index" bindtap="selectDevice"
          data-index="{{index}}">
         <view class="sg-flex sg-align-center" style=" justify-content: space-between;">
          <view class="sg-title sg-bold">{{index+1}}. {{item.type_name}}-{{item.name}}-{{item.spec}}
          </view>
          <view class="sg-right sg-pad sg-flex sg-align-center sg-icon" bindtap="selectDevice">
            <van-icon name="passed" wx:if="{{selectIndex == index}}" class="sg-index-color" />
            <van-icon name="circle" wx:else />
          </view>
         </view>
          <view class="sg-content sg-gray-color sg-font-small">
            <view class="sg-margin-tb-sm sg-flex sg-align-center sg-space-between">
              <view>租赁单价：￥{{item.price}}</view>
              <view>租赁计数：{{item.quantity}}</view>
            </view>
            <view class="sg-margin-tb-sm">租赁方式：{{item.rent_type ? item.rent_type.name : item.rent}}</view>
            <view class="sg-margin-tb-sm">租赁时间：<text
                class="sg-rent-date sg-border" style=" border-radius: 25rpx;padding-left:15rpx;padding-right:15rpx;">{{item.start_date ? (item.start_date + '至' + item.end_date) : ''}}</text>
            </view>
          </view>
          <view class="sg-footer sg-flex sg-align-center sg-space-between sg-margin-top-sm">
            <view class="sg-font-lg sg-bold">总金额：￥{{item.price * item.quantity}}</view>
            <!-- <view class="sg-btn sg-index-bg sg-pad-sm sg-white" hidden="{{!changePrice}}" bindtap="switchShowPrice"
              data-item="{{item}}" data-show="{{true}}">修改价格</view> -->
          </view>
        </view>
      </block>
    </view>
  </view>
  <van-dialog show="{{ showAdd }}" use-slot title="{{dialog_type == 'create' ? '添加设备' : '修改设备'}}" show-cancel-button
    bind:confirm="addDevice" bind:cancel="closeshow"  z-index="1" data-show="{{false}}" confirm-button-color="#5693FC">
    <view class="sg-add-device-box sg-pad sg-font-small">
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">设备类型</view>
        <picker bindchange="onChange" value="{{typeIndex}}" range="{{device_types}}" range-key="name"
          data-name="typeIndex" class="sg-input">
          <view class="picker sg-gray-color">
            {{typeIndex >= 0 ? device_types[typeIndex].name : '选择设备类型'}}
          </view>
        </picker>
      </view>
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">设备名称</view>
        <block wx:if="{{customName}}">
          <input value="{{customNameVal}}" class="sg-input" bindinput="onChange" data-name="customNameVal"
            placeholder="请输入设备名称"></input>
        </block>
        <block wx:else>
          <picker bindchange="onChange" value="{{nameIndex}}" range="{{device_types[typeIndex].names}}" range-key="name"
            data-name="nameIndex" class="sg-input">
            <view class="picker sg-gray-color">
              {{nameIndex >= 0 ? device_types[typeIndex].names[nameIndex].name : '选择设备名称'}}
            </view>
          </picker>
        </block>
        <view class="">
          <van-checkbox value="{{ customName }}" bind:change="onChange" data-name="customName">自填</van-checkbox>
        </view>
      </view>
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">规格型号</view>
        <block wx:if="{{customSpec}}">
          <input value="{{customSpecVal}}" class="sg-input" bindinput="onChange" data-name="customSpecVal"
            placeholder="请输入规格型号"></input>
        </block>
        <block wx:else>
          <picker bindchange="onChange" value="{{specIndex}}" range="{{device_types[typeIndex].names[nameIndex].specs}}"
            range-key="name" data-name="specIndex" class="sg-input">
            <view class="picker sg-gray-color">
              {{specIndex >= 0 ? device_types[typeIndex].names[nameIndex].specs[specIndex].name : '选择规格型号'}}
            </view>
          </picker>
        </block>
        <view class="">
          <van-checkbox value="{{ customSpec }}" bind:change="onChange" data-name="customSpec">自填</van-checkbox>
        </view>
      </view>
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">租赁方式</view>
        <block wx:if="{{customRent}}">
          <input value="{{customRentVal}}" class="sg-input" bindinput="onChange" data-name="customRentVal"
            placeholder="请输入租赁方式"></input>
        </block>
        <block wx:else>
          <picker bindchange="onChange" value="{{rentIndex}}" range="{{rent_types}}" range-key="name"
            data-name="rentIndex" class="sg-input">
            <view class="picker sg-gray-color">
              {{rentIndex >= 0 ? rent_types[rentIndex].name : '选择租赁方式'}}
            </view>
          </picker>
        </block>
        <view class="">
          <van-checkbox value="{{ customRent }}" bind:change="onChange" data-name="customRent">自填</van-checkbox>
        </view>
      </view>
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">租赁时间</view>
        <input value="{{ start_date ? start_date + '至' + end_date : '' }}" placeholder="请选择租赁时间" class="sg-input"
          disabled="true" bindtap="switchShowDate" data-show="{{true}}"></input>
      </view>
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">租赁计数</view>
        <input value="{{device_quantity}}" class="sg-input" bindinput="onChange" data-name="device_quantity"
          placeholder="请输入租赁计数" type="number"></input>
      </view>
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">租赁单价</view>
        <input value="{{device_price}}" class="sg-input" bindinput="onChange" data-name="device_price"
          placeholder="请输入设备单价" type="digit"></input>
      </view>
    </view>
  </van-dialog>
  <block wx:if="{{tabIndex == 1}}">
    <view class="sg-submit-box sg-pad sg-fix-bottom sg-flex sg-align-center sg-center" wx:if="{{selectIndex == -1}}"
      bindtap="switchShowAdd" data-show="true">
      <van-icon name="plus" /><text>立即添加</text>
    </view>
    <view class="sg-submit-box sg-fix-bottom sg-flex sg-align-center sg-center" wx:else>
      <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white" bindtap="editDevice">编辑</view>
      <view class="sg-action sg-pad sg-white sg-red-bg" bindtap="deleteDevice">删除</view>
    </view>
  </block>
  <view class="sg-submit-box sg-fix-bottom sg-flex sg-align-center sg-center" wx:if="{{tabIndex == 0}}">
    <view class="sg-action sg-draft sg-pad sg-border-right" bindtap="submit" data-type='draft'>暂存</view>
    <view class="sg-action sg-pad sg-index-bg sg-white" bindtap="submit" data-type='save'>提交</view>
  </view>
</view>