<template>
  <div class="center">
    <el-row>
      <el-col :span="12">
        <h2 class="bg-left titleup">{{ information }}检斤信息</h2>
      </el-col>
      <el-col :span="12" class="bg-right">
        <el-button class="bg-bottom" type="primary" size="small" @click="cancel"
          ><img
            width="6"
            height="10"
            style="vertical-align: bottom; margin-right: 3px"
            src="../../../public/img/lujing.png"
            alt=""
          />返回</el-button
        >
      </el-col>
    </el-row>
    <div class="substance">
      <ws-form>
        <div style="width: 50%; margin: 0 auto">
          <div class="title">基本信息</div>
          <ws-info-table>
            <ws-form-item label="编号" span="1" prop="number">
              <ws-input
                v-model="weighingList.number"
                placeholder="请输入编号"
                maxlength="100"
                disabled
                size="small"
              />
            </ws-form-item>
            <ws-form-item label="仓位号" span="1" prop="binNumber">
              <ws-input
                v-model="weighingList.binNumber"
                placeholder="请输入仓位号"
                maxlength="100"
                disabled
                size="small"
              />
            </ws-form-item>
            <ws-form-item label="客户" span="1" prop="customer">
              <ws-input
                v-model="weighingList.customer"
                placeholder="请输入客户"
                maxlength="100"
                disabled
                size="small"
              />
            </ws-form-item>
            <ws-form-item label="囤位号" span="1" prop="storageNumber">
              <ws-input
                v-model="weighingList.storageNumber"
                placeholder="请输入囤位号"
                maxlength="100"
                size="small"
                disabled
              />
            </ws-form-item>
            <ws-form-item label="车牌号" span="1" prop="carNumber">
              <ws-input
                v-model="weighingList.carNumber"
                placeholder="请输入车牌号"
                maxlength="100"
                size="small"
                disabled
              />
            </ws-form-item>
            <ws-form-item label="货名" span="1" prop="goodsName">
              <ws-input
                v-model="weighingList.goodsName"
                placeholder="请输入货名"
                maxlength="100"
                size="small"
                disabled
              />
            </ws-form-item>
            <!-- <div class="formitem"> -->
            <ws-form-item
              label="毛重（公斤）"
              span="1"
              prop="grossWeight"
            >
              <ws-input
                v-model="weighingList.grossWeight"
                placeholder="请输入毛重"
                maxlength="100"
                size="small"
                disabled
              />
            </ws-form-item>
            <el-button type="primary" :class="tpyeNo != 2?'':'css1'" @click="chongxin">重新获取</el-button>
            <ws-form-item
              label="皮重（公斤）"
              span="1"
              prop="tare"
              v-if="this.tpyeNo == 2"
            >
              <ws-input
                v-model="weighingList.tare"
                placeholder="请输入皮重"
                maxlength="100"
                size="small"
                :disabled="disabled"
              />
            </ws-form-item>

            <el-button type="primary"  v-if="this.tpyeNo == 2">重新获取</el-button>
            <div class="formItem">
              <ws-form-item
                label="扣杂（公斤）"
                span="1"
                prop="buckleWeightRatio"
                 v-if="this.tpyeNo == 2"
              >
                <ws-input
                  v-model="weighingList.buckleMiscellaneous"
                  placeholder="请输入扣杂"
                  maxlength="100"
                  size="small"
                  :disabled="disabled"
                />
              </ws-form-item>

              <ws-form-item
                label="净重（公斤）"
                span="1"
                prop="netWeight"
                 v-if="this.tpyeNo == 2"
              >
                <ws-input
                  v-model="weighingList.netWeight"
                  placeholder="请输入净重"
                  maxlength="100"
                  size="small"
                  disabled
                />
              </ws-form-item>
            </div>
          </ws-info-table>
          <div class="but">
            <el-button @click="cancel" type="primary"
              >取消</el-button
            >
            <el-button @click="print" v-if="this.tpyeNo == 1" type="primary"
              >保存</el-button
            >
            <el-button @click="print" v-if="this.tpyeNo == 2" type="primary"
              >保存并打印</el-button
            >
          </div>
        </div>
      </ws-form>
    </div>
  </div>
</template>
<script>
import { tare,grossWeight } from '@/model/houseSelfCollect/index'
export default {
  data() {
    return {
      inspect: {},
      types: 1,
      information: '',
      weighingList: {},
      tpyeNo: '',
      disabled:false,
      relationId:"",
    }
  },
  activated() {
    this.tpyeNo = this.$route.query.tpyeNo
    this.weighingList.number = this.$route.query.number
    this.weighingList.binNumber = this.$route.query.binNumber
    this.weighingList.customer = this.$route.query.customer
    this.weighingList.storageNumber = this.$route.query.storageNumber
    this.weighingList.carNumber = this.$route.query.carNumber
    this.weighingList.goodsName = this.$route.query.goodsName
    this.weighingList.id = this.$route.query.id
    // this.weighingList.grossWeight = this.$route.query.grossWeight
    // this.weighingList.tare = this.$route.query.tare
    // this.weighingList.netWeight = this.$route.query.netWeight
    this.relationId = this.$route.query.relationId
    if(this.tpyeNo == 1){
      this.information = "毛重"
    }else if(this.tpyeNo == 2){
      this.information = "皮重"
    }
  },
  methods: {
    submit() {
      //皮重保存
      this.$confirm('确定保存检斤信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {})
        .catch(() => {
          return false
        })
    },
    chongxin(){
      if(this.tpyeNo == 2){
        return
      }
console.log("dfsgfgdgdsgszdf")
    },
     cancel() {
      this.$router.push({ path: 'weighingManagement' })
    },
    print(){
      this.$confirm('确定保存检斤信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          if(this.tpyeNo == 1){
            this.weighingList.relationId = this.relationId
            grossWeight(this.weighingList)
            .toPromise()
            .then((response) => {
              this.$notify.success({
                title: '成功',
                message: '保存成功',
              })
              this.$router.go(-1) 
            })
            .catch((response) => {
              // EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
            })
           }else if(this.tpyeNo == 2){
              tare(this.weighingList)
            .toPromise()
            .then((response) => {
              this.$notify.success({
                title: '成功',
                message: '保存成功',
              })
              this.$router.go(-1)
            })
            .catch((response) => {
              // EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
            })
           }
        })
        .catch(() => {
          return false
        })
    },
    commit() {
      //毛重保存
      this.$confirm('确定保存检斤信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {})
        .catch(() => {
          return false
        })
    },
  },
}
</script>
<style lang="scss" scoped>
.center {
  background: #f6f7fc;
}
.ws-info-table {
  border: none;
}
.ws-info-table .el-form-item {
  width: 50%;
  border: none;
}
.formItem {
  width: 100%;
  display: inline;
}
//  .ws-info-table .widthChange {
//    width: 51%;
// }
/deep/.ws-info-table .el-form-item .el-form-item__label {
  width: 30%;
  text-align: center;
  background: #ffffff;
  font-size: 14px;
  color: #8890b1;
}
/deep/.ws-info-table .el-form-item .el-form-item__content {
  border: none;
}
.title {
  font-size: 16px;
  font-weight: 600;
  margin: 10px;
}
.titleup {
  position: relative;
}
.title::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 15px;
  background: #8890b1;
  margin-right: 5px;
}

.substance {
  background: #ffffff;
  width: 100%;
  border-radius: 4px;
  margin: 0 auto;
  padding-top: 20px;
}
/deep/.el-table .el-table__header .cell,
.el-table .el-table__body .cell {
  text-align: center;
}
/deep/.el-table--enable-row-transition .el-table__body td {
  text-align: center;
}
.bg-left {
  padding-left: 30px;
}
.bg-right {
  padding-right: 10px;
  text-align: right;
}
.bg-bottom {
  margin: 15px 0px;
}
.titleup {
  position: relative;
}
.titleup::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 30px;
  background: #5473e8;
  position: absolute;
  left: 0;
}
.but {
  text-align: center;
  margin: 20px auto;
}
.css1{
  opacity: 0;
}
</style> 