<template>
  <view class="page-product-receipt">
    <view class="header" :style="{ backgroundColor: `rgba(250, 53, 52, ${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" label-width="180rpx">
      <!-- 单号 -->
      <view class="single">
        <view class="single-left">
          <view>rfid:</view>
          <u-search placeholder="请扫描" :focus="shouciFocus" v-model="orderNo" :show-action="false"></u-search>
          <uni-icons type="scan" size="35" @click="scanCodeOne" style="color: #0b9eff; margin: auto; padding: 22rpx"></uni-icons>
        </view>
        <view class="single-right">
          <u-button type="primary" @click="query">查询</u-button>
        </view>
      </view>
      <!-- <u-form-item label="物料编码">
        <u-input :disabled="true" v-model="model.orderNoItemList.sku" placeholder="" style="overflow: hidden" />
      </u-form-item> -->
      <!-- <u-form-item label="托盘码：">
        <u-search placeholder="请扫描托盘码" v-model="location" :show-action="false"></u-search>
      </u-form-item>
      <u-form-item>
        <choose-one @switchfunction="switchChangeFun" :switchType="'text'" :defaultColor="'#4A72F9'" :highColor="'#FFFFFF'" :defaultValue="locationStatus" :switchList="switchListText"></choose-one>
      </u-form-item> -->
      <div v-show="isshow">
        <!-- <div v-if="oldstationNos.length">
          <u-form-item label="设备：">
            <jPicker sureColor="#ff0000" :moren="moren1" @bindpicker="selectProductCode" showKey="label" valKey="value" :val="productCodeList.value" :options="oldstationNos" />
          </u-form-item>
        </div> -->

        <div>
          <u-form-item label="设备类型：">
            <jPicker sureColor="#ff0000" :moren="moren2" @bindpicker="selectProductCodeType" showKey="label" valKey="value" :val="productCodeTypeList.value" :options="DictTypeList" />
          </u-form-item>
          <u-form-item label="设备：">
            <jPicker sureColor="#ff0000" :moren="moren1" @bindpicker="selectProductCode" showKey="label" valKey="value" :val="productCodeList.value" :options="DictList" />
          </u-form-item>
        </div>
      </div>
    </u-form>
    <view class="bottom-bar">
      <u-row class="button-bar">
        <!-- 确定 -->
        <u-col :span="6">
          <u-button @click="onsubmit" type="primary">确定</u-button>
        </u-col>
        <!-- 返回 -->
        <u-col :span="6">
          <u-button type="error" @click="uni.navigateBack({})">返回</u-button>
        </u-col>
      </u-row>
    </view>
    <u-toast ref="uToast" />
  </view>
</template>
<script lang="ts">
import { Component } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import model from './model';
import chooseOne from '@/components/choose-one/choose-one.vue';
import jPicker from '@/components/J-Picker/jPicker.vue';
import { session } from '@/store/modules/session';
//import store from '@/store';
@Component({
  components: {
    chooseOne,
    jPicker,
  },
})
export default class PalletChange extends BasePage {
  model = model;
  moren1 = '选择设备';
  moren2 = '选择设备类型';
  shouciFocus = true;
  isshow = false;
  zaiciFocus = false;
  DictList: any = [];
  oldstationNos: any = [];
  DictTypeList: any = [];
  switchListText = [
    {
      title: '置为正常',
      value: 1,
    },
    {
      title: '人工处理',
      value: 0,
    },
  ];
  productCodeList: any = {};
  productCodeTypeList: any = {};
  // remove: any = {};
  async onReady() {
    await this.model.getAllEquipmentsType();
    this.DictTypeList = model.DictTypeList;
    await this.model.getAllEquipments();
    this.DictList = model.DictList;
    //this.remove = this.model.WlList[0];
  }
  // selectItem(e: any) {
  //   this.remove = e.pickerName;
  // }
  orderNo: any = '';
  location: any = '';
  locationStatus: any = -1;
  async query() {
    if (this.orderNo == '' || this.orderNo.length == 0) {
      (this.$refs.uToast as any).show({
        title: '请输入RFID',
        type: 'default',
      });
      return;
    }
    this.isshow = false;
    this.$nextTick(() => {
      this.isshow = true;
    });
    await this.model.requestDestinationStation(this.orderNo);
    // const stationNos = model.orderNoItemList.stationNos;
    // for (let i = 0; i < stationNos.length; i++) {
    //   for (let j = 0; j < this.DictList.length; j++) {
    //     if (stationNos[i].stationNo === this.DictList[j].equipmentCode) {
    //       stationNos[i].equipmentName = this.DictList[j].equipmentName;
    //       break;
    //     }
    //   }
    // }
    // this.oldstationNos = stationNos.map((item) => ({
    //   label: item.equipmentName,
    //   value: item.stationNo,
    //   ...item,
    // }));
    // console.log('111', stationNos);
    // if (this.oldstationNos.some((item) => !item.label || item.label == undefined)) {
    //   this.oldstationNo = [];
    // }
    // console.log('fffff',this.oldstationNos)
  }
  generateGUID() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
      var r = (Math.random() * 16) | 0,
        v = c === 'x' ? r : (r & 0x3) | 0x8;
      return v.toString(16);
    });
  }
  async onsubmit() {
    if (this.orderNo == '' || this.orderNo.length == 0) {
      this.customToast('请输入nficl');
      return;
    }
    // var currentDate = new Date();

    // // 获取年份、月份、日期、小时、分钟和秒
    // var year = currentDate.getFullYear();
    // var month = ('0' + (currentDate.getMonth() + 1)).slice(-2);
    // var day = ('0' + currentDate.getDate()).slice(-2);
    // var hours = ('0' + currentDate.getHours()).slice(-2);
    // var minutes = ('0' + currentDate.getMinutes()).slice(-2);
    // var seconds = ('0' + currentDate.getSeconds()).slice(-2);

    // 格式化为 "YYYY-MM-DD HH:mm:ss" 结构
    //var formattedDate = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    let params = {
      rfidNo: this.orderNo,
      factoryCode: session.FactoryCode,
      equipmentCode: this.productCodeList.value,
      // reqCode: this.generateGUID(),
      // reqTime: formattedDate,
      // location: this.location,
      // locationStatus: this.locationStatus,
      // productionState: this.productCodeList.value,
    };
    await this.model.palletInforUpdate(params);
    if (model.SubmitCode == 200) {
      this.uni.showToast({ title: '成功' });
      this.Clear();
    }
  }
  Clear() {
    this.orderNo = '';
    this.location = '';
    this.locationStatus = -1;
    this.productCodeList = {};
    this.productCodeTypeList = {};
    this.shouciFocus = false;
    this.isshow = false;
    this.$nextTick(() => {
      this.shouciFocus = true;
    });
  }
  switchChangeFun(e) {
    //console.log(e);
    this.locationStatus = e.swithcSelectItem.value;
  }
  async selectProductCode(e: any) {
    this.productCodeList = e.pickerName;
  }
  async selectProductCodeType(e: any) {
    this.productCodeTypeList = e.pickerName;
    let params = {
      factoryCode: session.FactoryCode,
      equipmentTypeCode: this.productCodeTypeList.value,
    };
    await this.model.getAllEquipmentsle(params);
    this.DictList = model.seleDictList;
  }
  scanCodeOne() {
    uni.scanCode({
      scanType: ['barCode'],
      success: (res) => {
        this.orderNo = res.result;
      },
      fail(result) {
        this.customToast(result);
      },
    });
  }
}
</script>
<style lang="scss" scoped>
.page-product-receipt {
  background: #f2f2f2 linear-gradient(0deg, #f2f2f2 0%, #f8262c 51%, #d9001b 100%) no-repeat;
  background-size: 100% 600rpx;
  padding: 118rpx 30rpx 162rpx;
  min-height: 100%;

  .header {
    position: fixed;
    top: 0rpx;
    left: 0;
    right: 0;
    z-index: 99;
    display: flex;
    height: 120rpx;
    line-height: 88rpx;
    color: #fff;
    font-size: 34rpx;
    font-weight: 500;
    text-align: center;
    padding: 45rpx 0rpx 0rpx;
    .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;

      .Transfer {
        width: 280rpx;
        height: 64rpx;
        background: rgb(242, 242, 242);
        border-radius: 110rpx;
      }
    }

    .single {
      width: 100%;
      height: 100rpx;
      display: flex;

      .single-left {
        width: 80%;
        height: 100%;
        display: flex;

        view {
          // width: 142rpx;
          height: 100%;
          line-height: 100rpx;
        }
      }

      .single-right {
        button {
          margin-top: 15rpx;
          width: 140rpx;
          height: 70rpx;
          background-color: #fa3534;
        }
      }
    }
  }
  .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;
  }
  ::v-deep .yjy-switch-container .yjy-switch-item {
    width: 100%;
  }
  ::v-deep .yjy-switch-container {
    width: 50%;
  }
}
</style>
