<template>
    <view class="page">
      <StickyNavBar>
        <NavBar :title="$t('品号信息查询')"></NavBar>
      </StickyNavBar>
      <u-form ref="daohuoForm" :modelValue="daohuoForm" class="login-form">
        <u-form-item prop="mb001" class="under">
          <input
            v-model="daohuoForm.mb001"
            type="text"
            @confirm="inputCC"
            :placeholder="$t('品号')"
          >
          </input>
        </u-form-item>
        <u-form-item style="width:100%;">
          <button
            :loading="loading"
            size="medium"
            type="primary"
            style="width:95%;margin-top: 50rpx"
            @click="submit()"
          >
            <span>{{$t('确定')}}</span>
          </button>
        </u-form-item>
      </u-form>
    </view>
  </template>
  
  <script>
import i18n from '../../lang/index'

  import StickyNavBar from "@/components/StickyNavBar/index.vue";
  import ContentLoadingMore from "@/components/ContentLoadingMore/index.vue";
  export default {
    components: {
      StickyNavBar,
      ContentLoadingMore,
    },
    data() {
      return {
        number: 0,
        totalNum: 0,
        show: true,
        wxparams: "",
        loading: false,
        daohuoForm: {
					mb001: ""
				}
      }
    },
    created() {
    },
    methods: {
      inputCC(e){
        if(e && e.detail.value) {
          if(e.detail.value.includes("-")){
            const arr = e.detail.value.split("-")
            if (arr.length === 1) {
              this.daohuoForm.mb001 = arr[0]
              this.submit()
            }
          } else {
            this.submit()
          }
        }
      },
      submit(){
        if(!this.daohuoForm.mb001) return this.$u.toast(i18n.t('请输入品号'));
        this.loading = true;
        this.$u.api.getforinvmbinfo({
          mb001: this.daohuoForm.mb001
        })
        .then(res => {
        this.loading = false;
          if (res.success) {
            if (res.data) {
              uni.navigateTo({
                url: '/pages/invmbinfo/Info?info=' + encodeURIComponent(JSON.stringify(res.data))
              });
            } else {
              this.$u.toast(i18n.t('品号不存在'));
            }
          } else {
          this.$u.toast(res.errorMessage);
        }
        });
      }
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .btn {
    padding: 20rpx;
    background: #fff;
    .topSearch {
      margin-bottom: 20rpx;
    }
  }
  .bottomBtn {
    position: sticky;
    padding: 20rpx;
    display: flex;
    justify-content: space-between;
    background: #fff;
    bottom: 0rpx;
    margin-top: 20rpx;
    .u-btn {
      width: 300rpx;
    }
  }
  .blue {
    color: #3f9dcc;
  }
  .total {
    background: #fff;
    color: #000;
    padding: 0rpx 40rpx;
    display: flex;
    justify-content: space-between;
    font-size: 32rpx;
    .line {
      margin: 0px 10rpx;
    }
  }
  .cardbox {
    min-height: calc(100vh - 540rpx);
    padding: 0rpx 20rpx;
    margin-top: 20rpx;
  }
  .cardContent {
    border-radius: 8px;
    background: #fff;
    margin-bottom: 20rpx;
  }
  /deep/ .u-sticky {
    top: 0 !important;
    background: #fff;
  }
  page {
    position: relative;
    width: 100%;  height: 100%;
  }
  .login-form {
    position: absolute;
    border-radius: 6px;
    background: #ffffff;
    width: 80%;
    left: 50%;
    margin-top: 70rpx;
    transform: translateX(-50%);
    padding: 25px 25px 5px 25px;
  }
  </style>
  