<template>
  <view class="page-kan-dan-index">
    <view class="header" :style="{ backgroundColor: `rgba(23, 83, 234, ${scrollTop / 100})` }">
      <view class="left">
        <u-icon class="icon" name="arrow-left" @click="uni.navigateBack()" />
      </view>
      <view class="title">看单交接</view>
      <view class="right"></view>
    </view>
    <u-form class="form" label-width="130rpx">
      <view class="title">查询条件</view>
      <u-form-item label="看单号：">
        <u-input v-model="hideKdOrderNo" placeholder="请输入看单号" @confirm="onKdOrderNoConfirm" />
      </u-form-item>
      <u-row class="button-bar">
        <u-col :span="4">
          <u-button @click="uni.navigateBack({ delta: 1 })"> 返回 </u-button>
        </u-col>
        <u-col :span="8">
          <u-button
            type="primary"
            @click="uni.navigateTo({ url: page.raw.handover.kanDan.details })"
          >
            继续
          </u-button>
        </u-col>
      </u-row>
    </u-form>
  </view>
</template>

<script lang="ts">
import { Component } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import { order } from './model';
import { page } from '@/utils/page';
import { session } from '@/store/modules/session';

@Component
export default class KanDanHandOver extends BasePage {
  hideKdOrderNo = '';

  async onKdOrderNoConfirm() {
    if (this.hideKdOrderNo === '') {
      uni.showToast({ icon: 'none', title: '请扫描看单号' });
      return;
    } else {
      try {
        const odr = await order.takeOrder({
          loginName: session.loginName as string,
          factoryCode: session.factoryCode as string,
          hideKdOrderNo: this.hideKdOrderNo,
        });
        order.add({ order: odr });
        uni.navigateTo({ url: page.raw.handover.kanDan.details });
      } catch (e) {
        uni.showToast({ icon: 'none', title: e.message });
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.page-kan-dan-index {
  background: #f2f2f2 linear-gradient(0deg, #f2f2f2 0%, #4a78ea 51%, #1753ea 100%) no-repeat;
  background-size: 100% 600rpx;
  padding: 118rpx 30rpx 162rpx;
  min-height: 100%;

  .header {
    position: fixed;
    top: 36rpx;
    left: 0;
    right: 0;
    z-index: 99;
    display: flex;
    height: 88rpx;
    line-height: 88rpx;
    color: #fff;
    font-size: 34rpx;
    font-weight: 500;
    text-align: center;
    .title {
      flex: 3;
    }
    .left,
    .right {
      flex: 1;
    }
    .icon {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 88rpx;
      height: 88rpx;
    }
  }

  .form {
    background-color: #fff;
    padding: 40rpx;
    border-radius: 10rpx;
    box-shadow: 0 0 20rpx 0 rgba(128, 128, 128, 0.2);

    .u-form-item {
      background-color: #f7f6fb;
      padding: 10rpx 30rpx;
      border-radius: 8rpx;
      &:after {
        border-bottom-width: 0;
      }
    }

    .title {
      margin-bottom: 40rpx;
      color: #1a1a1a;
      font-size: 30rpx;
      font-weight: 500;
    }

    .button-bar {
      margin: 40rpx -10rpx 0;
    }
  }
}
</style>
