<!--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" bindtap="switchShow" data-name="showDevice">
        <view class="sg-label">维修设备</view>
        <view class="sg-input sg-gray-color">{{deviceIndex >= 0 ? inner_devices[deviceIndex].device_name.name : '选择需要维修的设备'}}</view>
      </view>
      <view class="sg-form-item sg-pad sg-top-border">
        <view class="sg-label">维修总金额</view>
        <input value="{{money}}" class="sg-input" disabled="true" bindinput="onChange" data-name="money" placeholder="请填写维修总金额"></input>
      </view>
      <view class="sg-form-item sg-pad sg-top-border">
        <view class="sg-label">维修原因</view>
        <input value="{{reason}}" class="sg-input" bindinput="onChange" data-name="reason"
          placeholder="请填写维修原因"></input>
      </view>
      <view class="sg-form-item sg-pad sg-top-border">
        <view class="sg-label">维修天数</view>
        <input value="{{day}}" class="sg-input" bindinput="onChange" type="digit" data-name="day" placeholder="请填写维修天数"></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-popup show="{{ showDevice }}" bind:close="switchShow" data-name="showDevice" custom-style="width: 90%;">
    <view class="sg-pad">
      <view class="sg-font-lg sg-bold sg-text-center">已调用设备</view>
      <view class="sg-list sg-height-limit">
        <view class="sg-item sg-pad-tb-sm sg-flex sg-align-center sg-space-between sg-bottom-border sg-font-small" wx:for="{{inner_devices}}" wx:key="index" bindtap="switchChecked" data-name="inner_devices" data-index="{{index}}">
          <view>
            <view class="sg-bold">{{item.device_name ? item.device_name.name : ''}}-{{item.spec_name ? item.spec_name : ''}}</view>
            <view class="sg-font-xs">固定资产编号：{{item.number}}</view>
          </view>
          <van-icon name="checked" class="sg-icon sg-index-color" wx:if="{{item.checked}}"/>
          <van-icon name="circle" wx:else class="sg-icon"/>
        </view>
      </view>
      <view class="sg-btns sg-flex sg-align-center sg-space-between sg-white-bg sg-pad-top">
        <van-button type="danger" color="#737477" class="sg-popup-btn" block bind:click="switchShow" round data-name="showDevice">取消</van-button>
        <van-button type="info" class="sg-popup-btn" block bind:click="switchShow" round data-name="showDevice">确认</van-button>
      </view>
    </view>
  </van-popup>
  <van-calendar show="{{ showDate }}" bind:close="switchShowDate" bind:confirm="confirmDate" data-show="{{false}}"
    type="range" class="sg-calendar" default-date="{{default_dates}}" />
  <view class="sg-device-box" wx:if="{{tabIndex == 1}}">
    <view class="sg-device-list sg-top-border">
      <block wx:if="{{parts.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="{{parts}}" 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-align-center" style="justify-content: space-between">
              <view>
                <view class="sg-name">
                  设备维修部位：{{item.name}}
                </view>
                <view class="sg-name">
                  需要更换配件：{{item.change}}
                </view>
              </view>
              <view class="sg-left-right sg-quantity-price sg-gray-color">
                ￥<text>{{item.price}}</text>
              </view>
            </view>
          </view>
          <view class="sg-right  sg-pad sg-flex sg-align-center" style="background-color: #737477;color:#fff" bindtap="delete" data-index="{{index}}">删除
          </view>
        </view>
      </block>
    </view>
  </view>
  <van-dialog show="{{ showAdd }}" use-slot title="{{dialog_type == 'create' ? '维修配件添加' : '修改设备'}}" show-cancel-button
    bind:confirm="add" z-index="1" confirm-button-color="#5693FC" bind:cancel="cancel">
    <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>
        <input value="{{part_name}}" class="sg-input" bindinput="onChange" data-name="part_name"
          placeholder="请输入设备维修部位"></input>
      </view>
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">需要更换配件</view>
        <input value="{{part_change}}" class="sg-input" bindinput="onChange" data-name="part_change"
          placeholder="请输入更换的配件"></input>
      </view>
      <view class="sg-form-item sg-pad-tb sg-top-border">
        <view class="sg-label">更换配件价格</view>
        <input value="{{part_price}}" type="digit"  class="sg-input" bindinput="onChange" data-name="part_price"
          placeholder="请输入更换配件价格(元)"></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" bindtap="switchShowAdd"
      data-show="true">
      <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}}">
    <view class="sg-action sg-pad sg-index-bg sg-white" bindtap="submit" data-type='save'>提交</view>
  </view>
</view>