<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="back" />
      </view>
      <view class="title">{{ $t('message.screen') }}</view>
      <view class="right"></view>
    </view>
    <!-- 开始时间 -->
    <view style="display: flex">
      <u-field style="background: white; border-radius: 10rpx" v-model="startMobile" :placeholder="$t('message.starttime')" :label="$t('message.start')"> </u-field>
      <u-picker :confirm-text="$t('message.product_Confirm')" :cancel-text="$t('message.product_Cancel')" v-model="startShow" :params="startParams" mode="time" @confirm="startConfirm"></u-picker>
      <u-button @click="startShow = true" type="primary">{{ $t('message.workArea_Selelct') }}</u-button>
    </view>
    <!-- 结束时间 -->
    <view style="display: flex; margin-top: 20rpx">
      <u-field style="background: white; border-radius: 10rpx" v-model="endMobile" :placeholder="$t('message.endtime')" :label="$t('message.end')"> </u-field>
      <u-picker :confirm-text="$t('message.product_Confirm')" :cancel-text="$t('message.product_Cancel')" v-model="endShow" :params="endParams" mode="time" @confirm="endConfirm"></u-picker>
      <u-button @click="endShow = true" type="primary">{{ $t('message.workArea_Selelct') }}</u-button>
    </view>
    <!-- 表格 -->
    <view class="table-wrapper" style="margin-top: 10rpx">
      <wyb-table class="table" ref="table" width="100%" enable-check="single" checkType="single" show-left-and-right-border :headers="headers" :contents="OddList" :show-vert-border="false" @onCheck="onCheck"></wyb-table>
    </view>
    <view class="bottom-bar">
      <u-row class="button-bar">
        <u-col :span="6">
          <u-button type="primary" @click="onSubmit">{{ $t('message.Query') }}</u-button>
        </u-col>
        <u-col :span="6">
          <u-button type="error" @click="back">{{ $t('message.workArea_Confirm') }}</u-button>
        </u-col>
      </u-row>
    </view>
  </view>
</template>

<script lang="ts">
import { Component } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import model from './model';
import { headers } from './config';
@Component({
  components: {},
})
export default class returningDom extends BasePage {
  model = model;
  startShow = false;
  endShow = false;
  startMobile = '';
  endMobile = '';
  materialList = [];
  OddList: any = [];
  data: any = {
    label: '',
    value: '',
    amount: 0,
    sendSpot: '',
  };

  startParams = {
    year: true,
    month: true,
    day: true,
    hour: false,
    minute: false,
    second: false,
  };
  endParams = {
    year: true,
    month: true,
    day: true,
    hour: false,
    minute: false,
    second: false,
  };
  headers = headers;
  startConfirm(startParams: any) {
    this.startMobile = startParams.year + '-' + startParams.month + '-' + startParams.day;
  }
  endConfirm(endParams: any) {
    this.endMobile = endParams.year + '-' + endParams.month + '-' + endParams.day;
  }
  onCheck(e: any) {
    console.log('eeeee', e.data[0].lineData);
    this.data = e.data[0].lineData;
  }
  back() {
    if (this.data.label == '' || this.data.label == null) {
      this.redirectTo(this.page.raw.handover.returning.index);
    } else {
      sessionStorage.setItem('data', JSON.stringify(this.data));
      this.redirectTo(this.page.raw.handover.returning.index);
    }
  }
  getNowFormatDate() {
    var date = new Date();
    var seperator1 = '-';
    var year = date.getFullYear();
    var month: any = date.getMonth() + 1;
    var strDate: any = date.getDate();
    if (month >= 1 && month <= 9) {
      month = '0' + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = '0' + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
  }
  async onReady() {
    this.startMobile = this.getNowFormatDate();
    this.endMobile = this.getNowFormatDate();
    await this.onSubmit();
  }
  async onSubmit() {
    if (this.startMobile == '' || this.endMobile == '') {
      this.customToast(this.$t('message.time') as string);
      return;
    }
    let time = {
      requireDateMin: this.startMobile,
      requireDateMax: this.endMobile,
    };
    await this.model.queryTimeInInfo(time);
    this.OddList = model.materielList;
  }
}
</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;
    }
  }

  .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;
  }
}
</style>
