<template>
  <view class="page-raw-returning">
    <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" ref="form" :model="form" :error-type="['toast']" label-width="135rpx">
      <u-form-item label="月台">
        <u-input v-model="form.tlName" type="select" @click="returningTypeSelect = true" />
        <u-select
          :confirm-text="this.$t('message.product_Confirm')"
          :cancel-text="this.$t('message.product_Cancel')"
          v-model="returningTypeSelect"
          :list="model.returningTypeList"
          @confirm="
            (v) => {
              form.tlType = v[0].value;
              form.tlName = v[0].label;
            }
          "
        ></u-select>
      </u-form-item>
      <u-row gutter="0">
        <u-col :span="10">
          <u-form-item label="预装编号" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
        <u-col :span="2" text-align="right">
          <u-button size="mini">提单</u-button>
        </u-col>
      </u-row>
      <u-row gutter="0">
        <u-col :span="10">
          <u-form-item label="集装箱" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
      </u-row>
      <u-row gutter="0">
        <u-col :span="10">
          <u-form-item label="铅封号" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
        <u-col :span="2" text-align="right">
          <u-button size="mini">铅封</u-button>
        </u-col>
      </u-row>
      <u-row gutter="0">
        <u-col :span="4">
          <u-form-item label="单据总数" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
        <u-col :span="4">
          <u-form-item label="已分配" prop="amount" label-width="95rpx" label-align="right">
            <u-input v-model="form.amount" />
          </u-form-item>
        </u-col>
        <u-col :span="4">
          <u-form-item label="已扫描" prop="amount" label-width="95rpx" label-align="right">
            <u-input v-model="form.amount" />
          </u-form-item>
        </u-col>
      </u-row>
      <u-row gutter="0">
        <u-col :span="10">
          <u-form-item label="物料" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
        <u-col :span="2" text-align="right">
          <u-button size="mini">选择</u-button>
        </u-col>
      </u-row>
      <u-row gutter="0">
        <u-col :span="10">
          <u-form-item label="物料描述" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
        <u-col :span="2" text-align="right">
          <u-button size="mini">库存</u-button>
        </u-col>
      </u-row>
      <u-row gutter="0">
        <u-col :span="6">
          <u-form-item label="总数/已扫" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
        <u-col :span="4">
          <u-form-item label="托盘" prop="sapFactoryCode" label-width="70rpx" label-align="right">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
        <u-col :span="2" text-align="right">
          <u-button size="mini">确认</u-button>
        </u-col>
      </u-row>
      <u-row gutter="0">
        <u-col :span="10">
          <u-form-item label="保证书" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
      </u-row>
      <u-row gutter="0">
        <u-col :span="10">
          <u-form-item label="条码" prop="sapFactoryCode">
            <u-input v-model="form.sapFactoryCode" />
          </u-form-item>
        </u-col>
        <u-col :span="2" text-align="right">
          <u-button size="mini">封箱</u-button>
        </u-col>
      </u-row>
    </u-form>
    <view class="bottom-bar">
      <u-row class="button-bar">
        <u-col :span="3">
          <u-button type="warning">拣货明细</u-button>
        </u-col>
        <u-col :span="3">
          <u-button type="error">清空</u-button>
        </u-col>
        <u-col :span="3">
          <u-button type="primary" @click="onSubmit">封箱</u-button>
        </u-col>
        <u-col :span="3">
          <u-button type="success">重提</u-button>
        </u-col>
      </u-row>
    </view>
  </view>
</template>

<script lang="ts">
import { Component, Ref } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import { VForm, VFormRules } from 'vue/types/form';
import { auth } from '@/store/modules/auth';
import model from './model';

@Component
export default class foreignDom extends BasePage {
  /**
   * 表单引用
   */
  @Ref('form') readonly $form!: VForm;

  /**
   * 页面Module
   */
  model = model;

  /**
   * 表单数据
   */
  form = {
    sapFactoryCode: null,
    operator: '',
    amount: null,
    rfPwd: null,
    tlType: null, // 退料类型code
    tlName: null, // 退料类型name
  };
  /**
   * 工位退料人名称
   */
  operatorName = '';
  /**
   * 退料类型选择
   */
  returningTypeSelect = false;

  /**
   * 表单验证规则
   */
  rules: VFormRules<any> = {
    operator: [{ required: true, message: '退料人不能为空！' }],
    sapFactoryCode: [{ required: true, message: '工厂代码不能为空！' }],
    amount: [{ required: true, message: '数量不能为空！' }],
  };

  get guest(): boolean {
    return true;
  }

  // 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
  async onReady() {
    this.$form.setRules(this.rules);
    // this.model.queryReturningTypeList();
    // this.form.sapFactoryCode = await this.model.queryDefaultFactoryCode();
  }

  /**
   * 上传
   */
  onSubmit() {
    this.$form.validate(async (valid: boolean) => {
      if (!valid) return;
      await this.model.tluSubmit(this.form);
      this.$form.resetFields();
      this.operatorName = '';
    });
  }

  /**
   * 操作人输入回车
   */
  async onOperatorConfirm(loginName: string) {
    try {
      const { userName } = await auth.getUserInfo({ loginName });
      this.form.operator = loginName;
      this.operatorName = userName;
    } catch {
      this.form.operator = '';
      this.operatorName = '';
    }
  }
}
</script>

<style lang="scss" scoped>
.page-raw-returning {
  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 {
      padding: 30rpx 0;
      line-height: 35rpx;
    }
  }

  .bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 99;
    background: #ffffff;
    box-shadow: 0 1rpx 20rpx 0 rgba(128, 128, 128, 0.2);
    padding: 20rpx;
  }

  .button-bar {
  }
}
</style>
