<!--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" disabled="{{!canEdit}}">
          <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="{{devices.length}}" class="sg-input" disabled="true"></input>
      </view>
      <block wx:if="{{type == 'edit'}}">
        <view class="sg-form-item sg-pad sg-top-border">
          <view class="sg-label">填单人</view>
          <view class="sg-input sg-gray-color">{{order.user ? order.user.name : ''}}</view>
        </view>
        <view class="sg-form-item sg-pad sg-top-border">
          <view class="sg-label">创建时间</view>
          <view class="sg-input sg-gray-color">{{order.created_at}}</view>
        </view>
        <view class="sg-form-item sg-pad sg-top-border">
          <view class="sg-label">订单状态</view>
          <view class="sg-input sg-gray-color sg-bold" style="color:{{order.color}}">{{order.status}}</view>
        </view>
      </block>
      <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-dialog id="van-dialog" />
  <van-popup show="{{ showBack }}" bind:close="onClose" custom-style="width: 90%">
    <view class="sg-title sg-text-center sg-bold sg-font-lg sg-pad-tb sg-border-bottom">选择归还的设备</view>
    <view class="sg-list">
      <inner-device-card  wx:for="{{devices}}" wx:key="index" item="{{item}}"  data-index="{{index}}" showStatus="{{false}}" showChecked="{{true}}" bind:checked="switchChecked" index="{{index}}"></inner-device-card>
    </view>
    <view class="sg-btns sg-flex">
      <van-button type="default" class="sg-btn" block bindtap="switchShow" data-name="showBack">取消</van-button>
      <van-button type="danger" class="sg-btn" block bindtap="submitCheck" data-type="back" data-change="{{false}}" data-name="showBack">确认</van-button>
    </view>
  </van-popup>
  <van-popup show="{{ showRent }}" bind:close="onClose" custom-style="width: 90%">
    <view class="sg-title sg-text-center sg-bold sg-font-lg sg-pad-tb sg-border-bottom">请确定续租时间</view>
    <view class="sg-list">
      <inner-device-card  wx:for="{{devices}}" wx:key="index" item="{{item}}"  data-index="{{index}}" bind:editDate="editDate" index="{{index}}" showStatus="{{false}}" editDate="{{true}}"></inner-device-card>
    </view>
    <view class="sg-btns sg-flex">
      <van-button type="default" class="sg-btn" block bindtap="switchShow" data-name="showRent" data-show="{{false}}">取消</van-button>
      <van-button type="danger" class="sg-btn" block bindtap="submit" data-type="re-rent" data-change="{{false}}" data-name="showRent">确认</van-button>
    </view>
  </van-popup>
  <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-left 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.device ? item.device.name + ' - ' : ''}}{{item.name}}</view>
            </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">
            <view class="sg-right sg-red-bg sg-white sg-pad-sm sg-font-small" bindtap="deleteDevice"
              data-index="{{index}}">删除</view>
          </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-list sg-pad">
          <inner-device-card item="{{item}}" wx:for="{{devices}}" wx:key="index" index="{{index}}" data-index="{{index}}" showStatus="{{false}}" showDelete="{{canEdit}}" bind:delete="deleteDevice" editDate="{{actionType == 'back'}}" bind:editDate="editDate"></inner-device-card>
        </view>
      </block>
    </view>
  </view>
  <van-calendar show="{{ showDate }}" bind:close="switchShow" bind:confirm="confirmDate" data-name="showDate"
    type="range" class="sg-calendar" default-date="{{default_dates}}" />
  <block wx:if="{{tabIndex == 1 &&  canEdit}}">
    <view class="sg-submit-box sg-pad sg-fix-bottom sg-flex sg-align-center sg-center" bindtap="goAdd"
      data-url="/pages/add-inner-device/index">
      <van-icon name="plus" /><text>立即添加</text>
    </view>
  </block>
  <view class="sg-submit-box sg-fix-bottom sg-flex sg-align-center sg-center" wx:if="{{tabIndex == 0}}">
    <block wx:if="{{type == 'create'}}">
      <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>
    </block>
    <block wx:if="{{actionType == 'check'}}">
      <view class="sg-action sg-draft sg-pad sg-border-right sg-red-bg" bindtap="check" data-change="2"
        data-type='reject'>驳回申请</view>
      <block wx:if="{{ role && role.project_role && role.project_role.key == 'admin' }}">
        <view class="sg-action sg-pad sg-green-bg" bindtap="check" data-change="2" data-type='pass'>通过审核</view>
        <view class="sg-action sg-pad sg-index-bg sg-white" bindtap="check" data-change="1" data-type='pass'>修订通过</view>
      </block>
      <block wx:else>
        <view class="sg-action sg-pad sg-green-bg" bindtap="check" data-change="2" data-type='checked'>通过审核</view>
      </block>
    </block>
    <block wx:if="{{actionType == 'edit'}}">
      <view class="sg-action sg-draft sg-pad sg-border-right" bindtap="submit" data-type='update'>暂存</view>
      <view class="sg-action sg-pad sg-index-bg sg-white" bindtap="check" data-type='re-submit'>提交</view>
    </block>
    <!-- <block wx:if="{{actionType == 'pass'}}">
      <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white sg-block" bindtap="check" data-change="2"
        data-type='confirm' style="width: 100%">提交确认</view>
    </block> -->
    <block wx:if="{{actionType == 're-submit'}}">
      <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white sg-block" bindtap="check"
        data-change="2" data-type='re-submit' style="width: 100%">重新提交</view>
    </block>
    <block wx:if="{{actionType == 'back'}}">
      <view class="sg-action sg-draft sg-pad sg-border-right sg-red-bg" bindtap="check" data-change="2"
        data-type='back' data-name="showBack">归还</view>
      <view class="sg-action sg-pad sg-index-bg sg-green-bg" bindtap="check" data-name="showRent" data-change="2" data-type='re-rent'>续租
      </view>
    </block>
  </view>
</view>