<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>
    <!-- <view class="single-left">
      <view>设备名称:</view>
      <u-search placeholder="请输入" @search="search()" :focus="shouciFocus" v-model="orderNo" :show-action="false"></u-search>
    </view> -->
    <view style="margin: 20px">
      <wyb-table ref="table" :headers="headers" :contents="tableData" enable-check="single" width="auto" first-col-bg-color="#ffffff" checker-color="#000000" @onCheck="changeContent" show-left-and-right-border />
    </view>
    <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-modal v-model="isshow" class="modal" :show-cancel-button="true" title="" :content="content" @cancel="cancel" @confirm="confirm()">
      <!-- <div class="form">
        <div class="formlable">申领数量</div>
        <u-input style="" v-model="number1" placeholder="" type="number" />
      </div> -->
    </u-modal>
    <u-toast ref="uToast" />
  </view>
</template>
<script lang="ts">
import { Component } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import jPicker from '@/components/J-Picker/jPicker.vue';
import model from '../equipment/Repairbx/model';
//import { session } from '@/store/modules/session';
// import wybTable from '@/components/wyb-table/wyb-table.vue';
@Component({
  components: {
    jPicker,
  },
})
export default class ProductionQtyInsplist extends BasePage {
  model = model;
  rowdata: any = {};
  content: any = '是否选择设备';
  headers = [
    {
      label: '序号',
      key: 'index',
      width: 100,
    },
    {
      label: '设备名称',
      key: 'equipmentName',
      width: 320,
    },
    {
      label: '设备编码',
      key: 'equipmentCode',
      width: 320,
    },
    {
      label: '位置',
      key: 'equipmentLocation',
    },
    {
      label: '工作中心',
      key: 'workshopName',
    },
    // {
    //   label: '产品',
    //   key: 'productName',
    //   width: 220,
    // },
    // {
    //   label: '工单',
    //   key: 'workorderCode',
    //   width: 220,
    // },
    // {
    //   label: '不良描述',
    //   key: 'badMeg',
    // },
  ];
  tableData: any = [];
  orderNo: any = '';
  shouciFocus = true;
  // 详细
  detailsinfo: any = {};
  detailsinfolist: any = {};
  detailsinfocontent: any = {};
  // 模态框
  isshow = false;
  inputmodal = false;
  isvalue = false;
  ischecked = false;
  radiomodal = false;
  number1: any = '';
  // remove: any = {};
  // async onReady() {
  //   await this.model.queryLocation();
  //   this.remove = this.model.WlList[0];
  // }
  // selectItem(e: any) {
  //   this.remove = e.pickerName;
  // }
  onShow() {
    // this.query();
    console.log(2, this.model.rowdata);
  }
  async confirm() {
    var bool = null;
    if (this.model.rowdata.length > 0) {
      bool = this.model.rowdata.some((item) => item.equipmentCode == this.rowdata.equipmentCode);
      console.log(bool);
      if (!bool) {
        this.rowdata.spareQuantity = this.number1;
        await this.model.rowdatanull();
        // console.log(this.model.rowdata)
        this.model.rowdata.push(this.rowdata);
        // uni.navigateTo({
        //   url: `/pages/equipment/Repair/repairing?listitem=` + encodeURIComponent(JSON.stringify(this.detailsinfo)),
        // });
        uni.navigateBack({});
      }
      if (bool) {
        (this.$refs.uToast as any).show({
          title: '请勿重复选择',
          type: 'default',
        });
        // _this.customToast('请勿重复申领');
      }
    } else {
      this.rowdata.spareQuantity = this.number1;
      this.model.rowdata.push(this.rowdata);
      // uni.navigateTo({
      //   url: `/pages/equipment/Repair/repairing?listitem=` + encodeURIComponent(JSON.stringify(this.detailsinfo)),
      // });
      uni.navigateBack({});
    }
    console.log(this.model.rowdata, this.page, this.rowdata);
  }
  cancel() {
    this.isshow = false;
  }
  goback() {
    uni.redirectTo({
      url: `/pages/equipment/Repair/repairing?listitem=` + encodeURIComponent(JSON.stringify(this.detailsinfo)),
    });
  }
  async onLoad() {
    let query = {
      pageNum: 1,
      pageSize: 10000,
    };
    await this.model.queryhandChecklist(query);
    this.tableData = this.model.equipmentlist;
    this.tableData.map((item, index) => {
      item.index = index + 1;
    });
  }
  changeContent(e) {
    //console.log('eee', e.data);
    this.rowdata = e.data[0]?.lineData;
    // uni.$emit('changeContent',e);
  }
  gozhijian() {
    this.uni.navigateTo({
      url: this.page.mes.ProductionQtyInsp,
    });
  }
  onSubmit() {
    //debugger
    //console.log('xssss',this.rowdata);

    if (JSON.stringify(this.rowdata) === '{}' || this.rowdata === undefined) {
      this.customToast('请选择至少一个备件');
      return;
    }
    this.isshow = true;

    // this.uni.navigateTo({
    //   url: this.page.mes.ProductionQtyInspDetail,
    // });
  }
  // async search() {
  //   let query = {
  //     pageNum: 1,
  //     pageSize: 10000,
  //   };
  //   await this.model.queryhandChecklist(query);
  //   this.tableData = this.model.equipmentlist;
  //   this.tableData.map((item, index) => {
  //     item.index = index + 1;
  //   });
  // }
  histroyItem: any = {};
  barcode: any = '';
}
</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-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;
  }
  .single-left {
    width: 90%;
    height: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-left: 20px;
    margin-right: 20px;
    view {
      width: 142rpx;
      height: 100%;
      line-height: 100rpx;
      font-size: 15px;
      // font-weight: bold;
      color: black;
    }
  }

  .photoList {
    display: flex;
    padding-top: 12rpx;

    .chooseBtn {
      width: 202rpx;
      height: 202rpx;
      background: #fafafa;
      border-radius: 12rpx;
      border: 2rpx dashed #e2e2e2;
      display: flex;
      justify-content: center;
      align-items: center;

      .inner {
        text-align: center;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
      }

      .desc {
        font-size: 28rpx;
        font-weight: 400;
        color: #24252a;
        line-height: 40rpx;
      }

      .img {
        width: 50rpx;
        height: 50rpx;
        margin-bottom: 6rpx;
      }
    }

    .photoBox {
      width: 202rpx;
      height: 202rpx;
      background: #fafafa;
      border-radius: 12rpx;
      position: relative;

      .closeBtn {
        position: absolute;
        top: -12rpx;
        right: -12rpx;
        z-index: 2;
        width: 36rpx;
        height: 36rpx;

        .img {
          width: 36rpx;
          height: 36rpx;
        }
      }

      .img {
        width: 202rpx;
        height: 202rpx;
        border-radius: 12rpx;
      }
    }

    .itemBox {
      flex: 0 0 202rpx;
      margin-right: 20rpx;
      padding: 9px 0px;
      &:last-child {
        margin-right: 0;
      }
    }

    // /deep/ .remarksBox textarea {
    //   font-size: 24rpx;
    // }
  }
}
// .wyb-table-scroll-view {
//   width: auto !important;
// }
.form {
  margin-top: 10px;
  margin-bottom: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-around;
}
::v-deep .form .uni-input-input {
  margin-left: 10px;
  width: 93%;
  border: 1px solid;
  padding: 10px 5px;
  box-sizing: border-box;
  outline: none;
  height: 35px;
  font-weight: 500;
}
</style>
