<template>
  <view class="list-page">
    <!--  页面头  -->
    <page-head title="成品留样" />

    <u-form class="form" ref="form" label-width="180rpx" style="margin-top: 10px">
      <u-form-item label="首检日期">
        <u-input @click="showCalendar = true" placeholder="请选择日期" v-model="checkTime" :clearable="false" />
        <u-icon name="close-circle-fill" @click="clear" color="rgb(96, 98, 102)" size="28"></u-icon>
      </u-form-item>
    </u-form>

    <scroll-view id="list" scroll-y="true" :style="{ height: listHeight + 'px' }" :lower-threshold="50">
      <!--  列表  -->
      <u-form class="list">
        <view v-if="list.length > 0">
          <view class="list-item" v-for="(item, index) in list" :key="index" >
            <lj-list-row label="物料名称:" :value="item.materialName" />
            <lj-list-row label="批次号:" :value="item.incomeBatchNo" />
            <lj-list-row label="留样时间:" :value="formatDate(item.sampleTime, '未留样')" />

            <view v-if="!item.sampleTime" class="righttitle">
              <view @click.stop="handelOption(item)" class="boder-icon-rigth"> 留样</view>
            </view>
          </view>
        </view>
        <view v-else> 暂无数据 </view>
      </u-form>
    </scroll-view>

<!--    <view class="scroll">-->
<!--      <view v-for="(item, index) in list" :key="index">-->
<!--        <u-form style="margin-top: 10rpx" class="form2">-->
<!--          <view>-->
<!--            <lj-list-row label="物料名称:" :value="item.materialName" />-->
<!--            <lj-list-row label="来料批次号:" :value="item.incomeBatchNo" />-->
<!--            <lj-list-row label="留样时间:" :value="formatDate(item.sampleTime, '未留样')" />-->

<!--            <view v-if="!item.sampleTime" class="righttitle">-->
<!--              <view @click.stop="handelOption(item)" class="boder-icon-rigth"> 留样</view>-->
<!--            </view>-->
<!--          </view>-->
<!--        </u-form>-->
<!--      </view>-->
<!--    </view>-->

    <u-calendar v-model="showCalendar" :mode="mode" @change="changeTime"></u-calendar>
  </view>
</template>
<script lang="ts">
import { Component } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import model from './model';
import moment from 'moment';
import PageHead from '@/components/lanju/page-head/index.vue';
import LjListRow from '@/components/lanju/lj-list-row/index.vue';
import {getWmsRawOrderInListToPda} from "@/pages/wms/Raw/TemporarilyCollected/model";

@Component({
  components: {
    LjListRow,
    PageHead,
  },
})
export default class ProductSample extends BasePage {
  listHeight = 500;
  model = model;
  checkTime: any = moment().format('YYYY-MM-DD');
  showCalendar = false;
  mode = 'date';
  queryParams = {
    queryDate: undefined,
  };
  list: any = [];
  userinfo: any = uni.getStorageSync('userinfo');
  clear() {
    this.checkTime = null;
  }

  async changeTime(e) {
    console.log(e.result);
    this.checkTime = e.result;
    await this.getList();
  }

  onLoad() {
    this.getList();
  }

  async handelOption(item) {
    uni.showModal({
      title: '提示',
      content: '是否选择留样',
      confirmText: '确定',
      cancelText: '取消',
      success: async (res) => {
        //点击确定
        if (res.confirm) {
          await this.model.updateQcCheckSampleTask({
            id: item.id,
            sampleTime: new Date(),
            sampleNum: '1盒',
            sampleAddress: '成品留样室',
            sampleUserCode: this.userinfo.userName,
            sampleUserName: this.userinfo.nickName,
          });
          if (this.model.confirmCode === 200) {
            await this.getList();
          }
        }
      },
    });
  }

  async getList() {
    let time = this.checkTime;
    if (!time) {
      time = moment().format('YYYY-MM-DD');
    }
    this.queryParams.queryDate = time;
    this.queryParams.pageNum = 1
    this.queryParams.pageSize = 9999
    await this.model.selectQcCheckSampleTaskList(this.queryParams);
    this.list = this.model.list;
  }

  //时间转换
  formatDate(time: any, msg: string) {
    if (!time) {
      return msg;
    }
    return moment(time).format('YYYY-MM-DD HH:mm:ss');
  }

  onReady() {
    //等待页面加载完成
    this.$nextTick(() => {
      let buttonTop = 0;
      //获取底部按钮信息
      const query = uni.createSelectorQuery().in(this);
      const screenHeight = uni.getSystemInfoSync().screenHeight;
      //获取列表信息
      query
        .select('#list')
        .boundingClientRect((data) => {
          //获取列表到顶部距离
          const listTop = data.top;
          //
          this.listHeight = screenHeight - listTop - 10;
        })
        .exec();
    });
  }

}
</script>
<style lang="scss" scoped>

.list-page {
  background: #f2f2f2 linear-gradient(0deg, #f2f2f2 0%, #f8262c 51%, #d9001b 100%) no-repeat;
  background-size: 100% 600rpx;
  padding: 118rpx 30rpx 0;
  min-height: 100%;
}

.form {
  background-color: #fff;
  padding: 0 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;
  }

  .row {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    flex: 1;
  }
}



.list {
  background-color: #fff;
  margin-top: 20rpx;
  padding: 20rpx 20rpx 25rpx;
  border-radius: 10rpx;
  box-shadow: 0 0 20rpx 0 rgba(128, 128, 128, 0.2);
  color: #8d8989;

  .list-item {
    padding: 20rpx;
  }

  .righttitle {
    display: flex;
    justify-content: flex-end;

    .boder-icon-rigth {
      font-size: 30rpx;
      border-radius: 5px;
      border: 1rpx solid #fa3534;
      text-align: center;
      background: #fa3534;
      color: #ffffff;
      margin-top: 10px;
      margin-left: 10px;
    }
  }

  /* 奇数行背景色 */
  .list-item:nth-child(odd) {
    background-color: #ffffff;
  }

  /* 偶数行背景色 */
  .list-item:nth-child(even) {
    background-color: #f5f5f5;
  }
}

::v-deep .list-item {
  width: 100% !important;
}
</style>
