<!--质检信息-->
<template>
  <div class="container">
    <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: 80%; margin: 0 auto">
          <div class="title">基本信息</div>
          <ws-info-table>
            <ws-form-item label="仓库" span="1" prop="warehouseName">
              <ws-input v-model="warehouseName" placeholder="请输入仓库" maxlength="100" disabled size="small" />
            </ws-form-item>
            <ws-form-item label="编号" span="1" prop="qualityNo">
              <ws-input v-model="inspect.qualityNo" placeholder="请输入编号" maxlength="100" disabled size="small" />
            </ws-form-item>
            <ws-form-item label="仓位号" span="1" prop="binNumber">
              <ws-select v-model="inspect.binNumber" placeholder="请输入仓位号" class="typeselect" :disabled="disabled">
                <ws-option v-for="item in getbinNumberList" :key="item.value" :label="item.value" :value="item.value" />
              </ws-select>
            </ws-form-item>

            <ws-form-item label="囤位号" span="1" prop="storageTagNo">
              <ws-input v-model="inspect.storageTagNo" placeholder="请输入囤位号" maxlength="15" size="small"
                :disabled="disabled3" />
            </ws-form-item>
            <ws-form-item label="购粮性质" span="1" prop="natureOfGrainPurchase">
              <ws-input v-model="inspect.natureOfGrainPurchase" placeholder="请输入购粮性质" maxlength="10" size="small"
                :disabled="disabled" />
            </ws-form-item>
            <ws-form-item label="货名" span="1" prop="goodsName">
              <ws-select v-model="inspect.goodsName" placeholder="" class="typeselect" :disabled="disabledName" @change="waterContentChange">
                <ws-option v-for="item in goodNameList" :key="item.goodsName" :label="item.goodsName"
                  :value="item.goodsName" />
              </ws-select>
            </ws-form-item>
            <ws-form-item label="客户" span="1" prop="customerName">
              <el-select v-model="inspect.customerName" clearable filterable placeholder="请选择" class="typeselect"
                @change="customerChange" :disabled="disabled1">
                <el-option v-for="item in customerList" :key="item.valueKey" :label="item.value" :value="item.value" />
              </el-select>
            </ws-form-item>
            <ws-form-item label="车牌号" span="1" prop="carNumber">
              <!-- <el-select v-model="inspect.carNumber" clearable  @blur="selectBlur" filterable  placeholder="请选择" class="typeselect" @change="shipperNameChange"
                :disabled="disabled1"> -->
                
                <el-select v-model="inspect.carNumber" clearable filterable allow-create default-first-option placeholder="请选择" class="typeselect" @change="shipperNameChange"
                :disabled="disabled1">
                <el-option v-for="(item,index) in carNumberList" :key="index" :label="item.carNo" :value="index" />
              </el-select>
              <!-- <ws-input @change='carnochange' v-model="inspect.carNumber" placeholder="请输入车牌号" maxlength="10" size="small"
                :disabled="disabled" /> -->
            </ws-form-item>
            <ws-form-item label="箱号-1" span="1" prop="boxNo">
              <ws-input :disabled="disabled" v-model="inspect.boxNo" placeholder="请输入箱号" maxlength="20" size="small" />
            </ws-form-item>
            <ws-form-item label="箱号-2" span="1" prop="boxNoOther">
              <ws-input :disabled="disabled" v-model="inspect.boxNoOther" placeholder="请输入箱号" maxlength="20"
                size="small" />
            </ws-form-item>
            <ws-form-item label="封号-1" span="1" prop="titleNo">
              <ws-input :disabled="disabled" v-model="inspect.titleNo" placeholder="请输入封号" maxlength="20"
                size="small" />
            </ws-form-item>
            <ws-form-item label="封号-2" span="1" prop="titleNoOther">
              <ws-input :disabled="disabled" v-model="inspect.titleNoOther" placeholder="请输入封号" maxlength="20"
                size="small" />
            </ws-form-item>
            
            <ws-form-item v-if="inspect.paramType != '1'" label="扣重比" span="1" prop="buckleWeightRatio">
              <ws-input type="number" @mousewheel.native.prevent v-model="inspect.buckleWeightRatio"
                placeholder="请输入扣重比" maxlength="100" size="small" :disabled="disabled" />
            </ws-form-item>
            <ws-form-item v-else label="扣杂" span="1" prop="buckleWeightRatio">
              <ws-input type="number" style="padding-right:30px" @mousewheel.native.prevent
                v-model="inspect.buckleMiscellaneous" @input="waterContentChange" placeholder="请输入扣杂" maxlength="100"
                size="small" :disabled="disabled" />
              <ws-input v-if='types==4' type="number" @mousewheel.native.prevent v-model="inspect.reBuckleMiscellaneous"
                placeholder="请输入扣杂" maxlength="100" size="small" />
              <ws-input v-else type="number" @mousewheel.native.prevent v-model="inspect.reBuckleMiscellaneous"
                placeholder="未复检" maxlength="100" size="small" disabled />
            </ws-form-item>
            <ws-form-item label="类型" span="1" prop="type">
              <ws-select v-model="inspect.type" disabled @change="typeChange">
                <ws-option v-for="item in typeList" :key="item" :label="item" :value="item" />
              </ws-select>
            </ws-form-item>
            <ws-form-item label="净重单价（元/公斤）" span="1" prop="tidalGrainPrice" v-if="inspect.type == '潮粮'">
              <ws-input type="number" @mousewheel.native.prevent v-model="inspect.tidalGrainPrice" placeholder="请输入净重单价"
                maxlength="10" size="small"  />
            </ws-form-item>
            <ws-form-item label="干粮单价（元/公斤）" span="2" prop="dryGrainPrice" v-if="inspect.type == '干粮'">
              <ws-input type="number" @mousewheel.native.prevent v-model="inspect.dryGrainPrice" placeholder="请输入干粮单价"
                maxlength="10" size="small"  />
            </ws-form-item>
              <ws-form-item label="复检备注" span="2" prop="reMemo" v-if="information == '编辑复检' || statusShow == '已复检'">
                <ws-input type="textarea" v-model="inspect.reMemo" placeholder="请输入复检备注" maxlength="300" v-if="statusShow != '已复检'" />
                <ws-input type="textarea" v-model="inspect.reMemo" placeholder="请输入复检备注" maxlength="300" v-else disabled />
              </ws-form-item>
               <ws-form-item label="车型" span="2" prop="dryGrainPrice" v-if="types==4&&warehouseName=='鲅鱼圈金信库'||types==2&&warehouseName=='鲅鱼圈金信库'">
                <el-select v-model="inspect.carModel" clearable filterable placeholder="请选择" class="typeselect"
                 :disabled="disabled3">
                <el-option v-for="item in cartypeList" :key="item.constValue" :label="item.constValue" :value="item.constValue" />
              </el-select>
            </ws-form-item>
          </ws-info-table>

          <div class="title">质检数据&nbsp;&nbsp;&nbsp;&nbsp; </div>
          <!-- <div class="title">质检数据&nbsp;&nbsp;&nbsp;&nbsp; <el-checkbox v-if='types==1||types==3' v-model="checked">补录</el-checkbox></div> -->
          <ws-info-table>
            <ws-form-item label="等级" span="1" prop="grade">
              <ws-select v-model="inspect.grade" placeholder="请输入等级" class="typeselect" :disabled="disabled"
                @change="waterContentChange">
                <ws-option v-for="item in gradeList" :key="item.constKey" :label="item.constValue"
                  :value="item.constValue" />
              </ws-select>
            </ws-form-item>
            <ws-form-item label="杂质（%）" span="1" prop="impurity">
              <ws-input type="number" @mousewheel.native.prevent v-model="inspect.impurity" placeholder="请输入杂质占比"
                maxlength="100" size="small" :disabled="disabled" />
            </ws-form-item>
            <ws-form-item label="水分（%）" span="1" prop="waterContent">

              <ws-input type="number" @mousewheel.native.prevent style="padding-right:30px"
                v-model="inspect.waterContent" placeholder="请输入水分占比" maxlength="100" size="small"
                @change="waterContentChange('water')" :disabled="disabled" />
              <ws-input v-if='types==4' type="number" @mousewheel.native.prevent v-model="inspect.reWaterContent"
                placeholder="请输入水分占比" maxlength="100" size="small" />
              <ws-input v-else type="number" @mousewheel.native.prevent v-model="inspect.reWaterContent"
                placeholder="未复检" maxlength="100" size="small" disabled />
            </ws-form-item>
            <ws-form-item label="霉变粒（%）" span="1" prop="mildewGrain">
              <ws-input type="number" @mousewheel.native.prevent v-model="inspect.mildewGrain" placeholder="请输入霉变粒占比"
                maxlength="100" size="small" :disabled="disabled" />
            </ws-form-item>
            <ws-form-item label="容重(克/升)" span="1" prop="bulkDensity">
              <ws-input type="number" @mousewheel.native.prevent v-model="inspect.bulkDensity" placeholder="请输入容重"
                maxlength="100" size="small" :disabled="disabled" />
            </ws-form-item>
            <ws-form-item label="热损伤（%）" span="1" prop="jiaorenli">
              <ws-input type="number" @mousewheel.native.prevent v-model="inspect.jiaorenli" placeholder="请输入热损伤占比"
                maxlength="100" size="small" :disabled="disabled" />
            </ws-form-item>
            <ws-form-item label="不完善粒（%）" span="1" prop="imperfectGrain">
              <ws-input type="number" @mousewheel.native.prevent v-model="inspect.imperfectGrain"
                placeholder="请输入不完善粒占比" maxlength="100" size="small" :disabled="disabled" />
            </ws-form-item>
          </ws-info-table>
          <div class="but">
            <el-button @click="cancel" v-if="types != 2" type="primary">取消</el-button>
               <el-button @click="checkOk" v-if="types == 4" type="primary">确认初检信息</el-button>
            <el-button @click="print" v-if="types ==3 || types ==1" type="primary">保存</el-button>
            <el-button @click="print" v-if="types == 5 || types==4" type="primary">确认并打印</el-button>
            <el-button @click="cancel" v-if="types == 2" type="primary">关闭</el-button>
          </div>
        </div>
      </ws-form>
    </div>
    <el-dialog width="70%" class="table-content" center :visible.sync="isShowPrint" title="粮食质检单" @opened='opendBtn' @close="closeDialog"
      :close-on-click-modal="false">
      <inspectInfoPrint :printData="inspect" ref="saveImg"></inspectInfoPrint>
      <div style="text-align:center">
        <el-button type="primary" @click="closePrint">关闭</el-button>
        <el-button type="primary" @click="printSmall">打印小票</el-button>
        <el-button type="primary" @click="printBig">打印单据</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {
    inspectAdd,
    getbinNumber,
    getcustomer,
    getinspectLook,
    getinspectLookUnitPrice,
    getinspectLookGoods,
    getinspectEdit,
    getamount,
    getCount,
    getDryGrainPrice,
    getshippinginfo,
    postCheck,
    getQRcode,
    getcartype
  } from '@/model/houseSelfCollect/index'
  import {
    packList
  } from '@/model/contarct/index'
  import inspectInfoPrint from './component/inspectInfoPrint.vue'
  import html2canvas from 'html2canvas'
  import axios from 'axios'
  export default {
    components: {
      inspectInfoPrint,
    },
    watch: {},
    data() {
      return {
        isShowPrint: false,
        customerList1: [],
        // warehouseList: {},
        inspect: {
          tidalGrainPrice: 0,
          buckleWeightRatio: 0,
          natureOfGrainPurchase: '贸易粮',
          buckleMiscellaneous: 0,
          paramType: 1,
          type: '潮粮'
        },
        carNumberList: [],
        disabled: false,
        disabled1: false,
        checked:false,
        disabled2: false,
        disabled3:false,
        disabledName: false,
        types: '1',
        information: '添加初检',
        goodNameList: [],
        gradeList: [],
        customerList: [],
        getbinNumberList: [],
        cartypeList:[],
        cangid: '', //仓库id
        warehouseName: '',
        unitPrice: 0,
        count: 0,
        cangNo: '',
        typeList: ['干粮', '潮粮'],
        purchasePriceList: [],
        id: '',
        imgUrl: '',
        printData: {},
        num: 0,
        tipFlag: true,
        allowEdit: 0,
        statusShow :''
      }
    },
    activated() {
      this.types = this.$route.query.type
      this.allowEdit = this.$route.query.allowEdit
      if (this.allowEdit == 0) {
        this.disabled2 = true
      } else if (this.allowEdit == 1) {
        this.disabled2 = false
      }
      if (!this.types) {
        this.types = 1
        this.information = '添加初检'
        this.disabled = false
        this.inspect = {
          tidalGrainPrice: 0,
          buckleWeightRatio: 0,
          natureOfGrainPurchase: '贸易粮',
          type: '潮粮'
        }
      }
      this.cangid = this.$route.query.cangid
      this.warehouseName = this.$route.query.warehouseName
      this.cangNo = this.$route.query.warehouseNo
      this.count = Number(this.$route.query.count) + 1
      this.statusShow = this.$route.query.status
      // this.purchasePriceList = this.$route.query.purchasePriceList
      this.id = this.$route.query.id
      if (this.types == 2) {
        this.disabled = true
        this.disabled1 = true
        this.disabled2 = true
        this.disabledName = true
        this.disabled3=true
        this.information = '查看质检'
      } else if (this.types == 3) {
        this.disabled = false
        this.disabled1 = true
        this.disabledName = true
        this.information = '编辑初检'
      } else if (this.types == 4) {
        this.disabled = true
        this.disabled1 = true
        this.disabledName = true
        this.information = '编辑复检'
      } else if (this.types == 5) {
        this.disabled = false
        this.disabled1 = true
        this.disabledName = false
        this.information = '确认质检'
      } else {
        this.disabled1 = false
        this.disabled = false
        this.disabledName = false
      }
      this.calculation()
      this.getList(this.id)
    },
    methods: {
      //确认初检信息
      checkOk(){
        this.$confirm('确定初检信息后，初检员不需要再次确认质检信息，是否确认提交', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            })
            .then(() => {
              postCheck(this.inspect)
                .toPromise()
                .then((response) => {
                   postCheck({id:this.id,flag:2})
                    .toPromise()
                    .then((response) => {
                      if(response == 'OK'){
                      this.$message.success('提交成功')
                        this.$router.push({path: 'inspectionManagement' })
                        }else{
                          this.$message.error('提交失败')
                        }
                    })
                }).catch(() => {
              return false
            })
        })

      },
      printSmall() {
        window.open('../../../static/inspection.html?type=1&dataList=' + JSON.stringify(this.inspect))
      },
      printBig() {
        window.open('../../../static/inspection.html?type=2&dataList=' + JSON.stringify(this.inspect))
      },
      getdate() {
        var date = new Date()
        var year = date.getFullYear() //获取完整的年份(4位)
        var mouth = date.getMonth() + 1 //获取当前月份(0-11,0代表1月)
        var datetime = date.getDate() //获取当前日(1-31)
        if (mouth < 10) {
          mouth = '0' + mouth
        }
        if (datetime < 10) {
          datetime = '0' + datetime
        }
        return String(year) + String(mouth) + String(datetime)
      },
      calculation() {
        let number = '000' + this.count
        number = number.substring(number.length - 4, number.length)
        this.inspect.qualityNo = 'SGRK' + this.getdate() + this.cangNo + number //SGRK+8位时间+3位仓库编号+4位序列号
      },
      selectBlur(e) {
                if (e.target.value) {  
                 // 不在表单的时候不需要判断，也不需要isname字段
                    this.inspect.carNumber = e.target.value;
                    // this.isName = true;   
                } else {
                    // this.isName = false;
                }
            },
      opendBtn(){
           html2canvas(this.$refs.saveImg.$el).then(canvas => {
          let dataURL = canvas.toDataURL('image/png');
          this.imgUrl = dataURL;
          if (this.imgUrl !== '') {
            let b = this.dataURLtoFile(this.imgUrl, 'printImg')
            let formdata = new FormData();
            formdata.append('file', b);
            axios({
              method: 'post',
              url: this.global.uploadPath,
              data: formdata
            }).then((response) => {
              //编辑接口
              this.inspect.pictureAddress = response.data.url
              console.log(this.types)
              if (this.types == 3) {
                this.inspect.flag = 0
              } else if (this.types == 4) {
                this.inspect.flag = 1
              }
              getinspectEdit(this.inspect)
                .toPromise()
                .then((response) => {
                  this.types = ''
                  // this.inspect = [] 
              
                })
            })
          }
        })
      },
      
      closeDialog() {
        html2canvas(this.$refs.saveImg.$el).then(canvas => {
          let dataURL = canvas.toDataURL('image/png');
          this.imgUrl = dataURL;
          if (this.imgUrl !== '') {
            let b = this.dataURLtoFile(this.imgUrl, 'printImg')
            let formdata = new FormData();
            formdata.append('file', b);
            axios({
              method: 'post',
              url: this.global.uploadPath,
              data: formdata
            }).then((response) => {
              //编辑接口
              this.inspect.pictureAddress = response.data.url
              console.log(this.types)
              if (this.types == 3) {
                this.inspect.flag = 0
              } else if (this.types == 4) {
                this.inspect.flag = 1
              }
              getinspectEdit(this.inspect)
                .toPromise()
                .then((response) => {
                  this.types = ''
                  // this.inspect = [] 
                  this.isShowPrint = false
                  this.$router.push({
                    path: 'inspectionManagement'
                  })
                })
            })
            this.dialogTableVisible = true;
          }
        })

      },
      typeChange() {
        if (this.inspect.type == '干粮' && this.inspect.goodsName) {
          getDryGrainPrice({
              warehouseId: this.cangid,
              goodsName: this.inspect.goodsName
            })
            .toPromise()
            .then((response) => {
              this.$set(this.inspect, 'dryGrainPrice', response)
            })
        }
      },
      closePrint() {
        // this.inspect = [] 
        this.isShowPrint = false
      },
      submit() {
        this.inspect.warehouseName = this.warehouseName
        this.inspect.compId = localStorage.getItem('ws-pf_compId')
        if (this.types == 1) {
          this.inspect.qualityInspector = localStorage.getItem('ws-pf_staffName')
          this.$confirm('确定保存质检信息？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            })
            .then(() => {
              if (!this.inspect.tidalGrainPrice || this.inspect.tidalGrainPrice == 'NaN') {
                this.inspect.tidalGrainPrice = 0
              }
              inspectAdd(this.inspect)
                .toPromise()
                .then((response) => {
                  this.checked=false
                  this.$message.success('保存成功')
                  getinspectLook({
                      id: response
                    })
                    .toPromise()
                    .then((response) => {
                    //  let printString = localStorage.getItem('ws-pf_compId') + "," + row.qualityNo + "," + this.cangid 
                    //       getQRcode({printString}).toPromise()
                    //             .then((res) => {
                            this.isShowPrint = true
                            this.printData = response
                            // this.printData.qrCodeUrl = res
                            // })
                      this.inspect = response
                      if (response.compName == '黑龙江秋收有限公司') {
               				 this.inspect.compName = '黑龙江中天昊元贸易有限公司'
              					}
                    })
                  this.isShowPrint = true
                  //打印
                  // this.$router.go(-1)
                })
            })
            .catch(() => {
              return false
            })
        } else if (this.types == 3) {
          this.inspect.qualityInspector = localStorage.getItem('ws-pf_staffName')
          this.inspect.flag = 0
          this.$confirm('确定保存初检信息？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            })
            .then(() => {
              // return
              getinspectEdit(this.inspect)
                .toPromise()
                .then((response) => {
                  this.$message.success('修改成功')
                  this.checked=false
                  this.$router.push({
                    path: 'inspectionManagement'
                  })
                })
            })
            .catch(() => {
              return false
            })
        } else if (this.types == 4) {
          this.inspect.flag = 1
          this.inspect.reInspector = localStorage.getItem('ws-pf_roleName') + localStorage.getItem('ws-pf_staffName')
          this.$confirm('确定保存复检信息？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            })
            .then(() => {
              // return
              getinspectEdit(this.inspect)
                .toPromise()
                .then((response) => {
                  this.$message.success('修改成功')
                  
                  // this.$router.push({
                  //   path: 'inspectionManagement'
                  // })
                   getinspectLook({
                      id: this.inspect.id
                    })
                    .toPromise()
                    .then((response) => {
                      this.inspect = response
                      if (response.compName == '黑龙江秋收有限公司') {
               				 this.inspect.compName = '黑龙江中天昊元贸易有限公司'
              					}
                    })
                  this.isShowPrint = true
                })
            })
            .catch(() => {
              return false
            })
        } else if (this.types == 5) {
          this.inspect.flag = 2
          // this.inspect.reInspector=localStorage.getItem('ws-pf_roleName') + localStorage.getItem('ws-pf_staffName')
          this.$confirm('确定保存质检信息？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            })
            .then(() => {
              getinspectEdit(this.inspect)
                .toPromise()
                .then((response) => {
                  this.$message.success('修改成功')
                  getinspectLook({
                      id: this.inspect.id
                    })
                    .toPromise()
                    .then((response) => {
                      this.inspect = response
                      if (response.compName == '黑龙江秋收有限公司') {
               				 this.inspect.compName = '黑龙江中天昊元贸易有限公司'
              					}
                    })
                  this.isShowPrint = true
                })
            })
            .catch(() => {
              return false
            })
        }
      },
      print() {
        if (!this.inspect.qualityNo) {
          this.$message({
            message: '编号不能为空',
            type: 'warning',
          })
          return
        }
        if (!this.inspect.binNumber) {
          this.$message({
            message: '仓位不能为空',
            type: 'warning',
          })
          return
        }
        if (!this.inspect.customerName) {
          this.$message({
            message: '客户不能为空',
            type: 'warning',
          })
          return
        }
        // if (!this.inspect.storageTagNo) {
        //   this.$message({
        //     message: '囤位号不能为空',
        //     type: 'warning',
        //   })
        //   return
        // }
        if(this.inspect.storageTagNo){
            if (this.inspect.storageTagNo.length > 10) {
            this.$message({
              message: '囤位号不超过10个字符',
              type: 'warning',
            })
            return
          }
        }
        if (!this.inspect.carNumber) {
          this.$message({
            message: '车牌号不能为空',
            type: 'warning',
          })
          return
        }
        if (this.inspect.carNumber.length > 7 || this.inspect.carNumber.length != 7) {
          this.$message({
            message: '车牌号输入错误',
            type: 'warning',
          })
          return
        }
        if (this.inspect.boxNo && this.inspect.boxNo.length > 20) {
          this.$message({
            message: '箱号-1输入错误',
            type: 'warning',
          })
          return
        }
        if (this.inspect.boxNoOther && this.inspect.boxNoOther.length > 20) {
          this.$message({
            message: '箱号-2输入错误',
            type: 'warning',
          })
          return
        }
        if (this.inspect.titleNo && this.inspect.titleNo.length > 20) {
          this.$message({
            message: '封号-1输入错误',
            type: 'warning',
          })
          return
        }
        if (this.inspect.titleNoOther && this.inspect.titleNoOther.length > 20) {
          this.$message({
            message: '封号-2输入错误',
            type: 'warning',
          })
          return
        }
        if (!this.inspect.goodsName) {
          this.$message({
            message: '货名不能为空',
            type: 'warning',
          })
          return
        }
        if (this.inspect.paramType == '2') {
          if (
            this.inspect.buckleWeightRatio < 0 ||
            this.inspect.buckleWeightRatio > 2
          ) {
            this.$message({
              message: '扣重比输入错误',
              type: 'warning',
            })
            return
          }
          if (
            String(this.inspect.buckleWeightRatio).indexOf('.') != -1 &&
            String(this.inspect.buckleWeightRatio).length -
            (String(this.inspect.buckleWeightRatio).indexOf('.') + 1) >
            2
          ) {
            this.$message({
              message: '扣重比输入错误',
              type: 'warning',
            })
            return
          }
        }
        if (!this.inspect.type) {
          this.$message({
            message: '类型不能为空',
            type: 'warning',
          })
          return
        }
        if (!this.inspect.natureOfGrainPurchase) {
          this.$message({
            message: '购粮性质不能为空',
            type: 'warning',
          })
          return
        }
        if (this.inspect.type == '干粮') {
          if (!this.inspect.dryGrainPrice) {
            this.$message({
              message: '干粮价格不能为空',
              type: 'warning'
            })
            return
          }
          if (this.inspect.dryGrainPrice <= 0 || this.inspect.dryGrainPrice > 1000) {
            this.$message({
              message: '干粮价格输入错误',
              type: 'warning'
            })
            return
          }
          if (
            String(this.inspect.dryGrainPrice).indexOf('.') != -1 &&
            String(this.inspect.dryGrainPrice).length - (String(this.inspect.dryGrainPrice).indexOf('.') + 1) > 4) {
            this.$message({
              message: '干粮价格输入错误',
              type: 'warning',
            })
            return
          }
        } else {
          if (!this.inspect.tidalGrainPrice) {
            this.$message({
              message: '净重单价不能为空',
              type: 'warning'
            })
            return
          }
          if (this.inspect.tidalGrainPrice <= 0 || this.inspect.tidalGrainPrice > 1000) {
            this.$message({
              message: '净重单价输入错误',
              type: 'warning'
            })
            return
          }
        }
        if(!this.checked){
          if (!this.inspect.grade) {
            this.$message({
              message: '等级不能为空',
              type: 'warning',
            })
            return
          }
          if (!this.inspect.impurity) {
            this.$message({
              message: '杂质不能为空',
              type: 'warning',
            })
            return
          }
          if (String(this.inspect.impurity).indexOf('.') != -1 && String(this.inspect.impurity).length - (String(this
              .inspect.impurity).indexOf('.') + 1) > 1) {
            this.$message({
              message: '杂质输入错误',
              type: 'warning',
            })
            return
          }

          if (this.inspect.impurity < 0 || this.inspect.impurity > 40) {
            this.$message({
              message: '杂质输入错误',
              type: 'warning',
            })
            return
          }
          if( this.information != '编辑复检'){
          if (!this.inspect.waterContent) {
            this.$message({
              message: '水分不能为空',
              type: 'warning',
            })
            return
          }
          if (this.inspect.waterContent < 0 || this.inspect.waterContent > 50) {
            this.$message({
              message: '水分输入错误',
              type: 'warning',
            })
            return
          }
          if (String(this.inspect.waterContent).indexOf('.') != -1 && String(this.inspect.waterContent).length - (String(
              this.inspect.waterContent).indexOf('.') + 1) > 1) {
            this.$message({
              message: '水分输入错误',
              type: 'warning',
            })
            return
          }
          }
          
          if (!this.inspect.mildewGrain) {
            this.$message({
              message: '霉变粒不能为空',
              type: 'warning',
            })
            return
          }
          if (this.inspect.mildewGrain < 0 || this.inspect.mildewGrain > 40) {
            this.$message({
              message: '霉变粒输入错误',
              type: 'warning',
            })
            return
          }
          if (String(this.inspect.mildewGrain).indexOf('.') != -1 && String(this.inspect.mildewGrain).length - (String(
              this.inspect.mildewGrain).indexOf('.') + 1) > 1) {
            this.$message({
              message: '霉变粒输入错误',
              type: 'warning',
            })
            return
          }
          if (!this.inspect.bulkDensity) {
            this.$message({
              message: '容重不能为空',
              type: 'warning',
            })
            return
          }
          if (this.inspect.bulkDensity < 500 || this.inspect.bulkDensity > 1000) {
            this.$message({
              message: '容重输入错误',
              type: 'warning',
            })
            return
          }
          if (String(this.inspect.bulkDensity).indexOf('.') != -1 && String(this.inspect.bulkDensity).length - (String(
              this.inspect.bulkDensity).indexOf('.') + 1) > 0) {
            this.$message({
              message: '容重需输入整数',
              type: 'warning',
            })
            return
          }
          if (!this.inspect.jiaorenli) {
            this.$message({
              message: '热损伤不能为空',
              type: 'warning',
            })
            return
          }
          if (this.inspect.jiaorenli < 0 || this.inspect.jiaorenli > 40) {
            this.$message({
              message: '热损伤输入错误',
              type: 'warning',
            })
            return
          }
          if (String(this.inspect.jiaorenli).indexOf('.') != -1 && String(this.inspect.jiaorenli).length - (String(this
              .inspect.jiaorenli).indexOf('.') + 1) > 1) {
            this.$message({
              message: '热损伤输入错误',
              type: 'warning',
            })
            return
          }
          if (!this.inspect.imperfectGrain) {
            this.$message({
              message: '不完善粒不能为空',
              type: 'warning',
            })
            return
          }
          if (this.inspect.imperfectGrain < 0 || this.inspect.imperfectGrain > 40) {
            this.$message({
              message: '不完善粒输入错误',
              type: 'warning',
            })
            return
          }
          if (String(this.inspect.imperfectGrain).indexOf('.') != -1 && String(this.inspect.imperfectGrain).length - (
              String(this.inspect.imperfectGrain).indexOf('.') + 1) > 1) {
            this.$message({
              message: '不完善粒输入错误',
              type: 'warning',
            })
            return
          }
        }
        
        getamount({
            compId: localStorage.getItem('ws-pf_compId'),
            customerNumberCard: this.inspect.customerNumberCard,
            goodsName: this.inspect.goodsName,
          })
          .toPromise()
          .then((response) => {
            for (let i = 0; i < this.purchasePriceList.length; i++) {
              if (
                this.inspect.goodsName == this.purchasePriceList[i].goodsName
              ) {
                let count = (this.purchasePriceList[i].saleLimit - response / 1000).toFixed(2)
                if (count <= 0) {
                  count = 0
                  this.$alert(
                    '该客户累计销售' +
                    this.inspect.goodsName +
                    (response / 1000).toFixed(2) +
                    '吨，还可售粮' +
                    count +
                    '吨',
                    '提示', {
                      confirmButtonText: '确定',
                      callback: (action) => {
                        this.$message({
                          type: 'info',
                          message: `累计售粮已超出上限`,
                        })
                      },
                    }
                  )
                } else {
                  this.submit();
                }
              }
            }
          })
      },
      cancel() {
        this.types = ''
        // this.inspect = [] 
        this.$router.push({
          path: 'inspectionManagement'
        })

      },
      shipperNameChange(e) {
        this.$set(this.inspect, 'customerName', this.carNumberList[e].shipperName)
        this.$set(this.inspect, 'carNumber', this.carNumberList[e].carNo)
        this.$set(this.inspect, 'customerPhone', this.carNumberList[e].shipperPhone)
        for (let i = 0; i < this.customerList1.length; i++) {
          if (this.customerList1[i].customerName == this.inspect.customerName) {
            this.inspect.customerNumberCard = this.customerList1[i].customerNumberCard
          }
        }
        if (this.inspect.goodsName && this.inspect.customerName) {
          // //查看当前用户对应货名有未结算状态的送货
          // let count = 0
          // getCount({
          //     compId: localStorage.getItem('ws-pf_compId'),
          //     customerName: this.inspect.customerName,
          //     goodsName: this.inspect.goodsName,
          //     customerNumberCard: this.inspect.customerNumberCard
          //   }).toPromise()
          //   .then((response) => {
          //     count = response
          //   })
          //  客户下拉校验
          // getamount({
          //   compId: localStorage.getItem('ws-pf_compId'),
          //   customerName: this.inspect.customerName,
          //   goodsName: this.inspect.goodsName,
          //   customerNumberCard:this.inspect.customerNumberCard
          // })
          //   .toPromise()
          //   .then((response) => {
          //     for (let i = 0; i < this.purchasePriceList.length; i++) {
          //       if (this.inspect.goodsName == this.purchasePriceList[i].goodsName) {
          //         if ((this.purchasePriceList[i].saleLimit - response/1000 < 50 || count > 0)&&this.tipFlag) {
          //           this.tipFlag = false
          //           this.$message('当前客户已累计销售我司' +this.inspect.goodsName + (response/1000).toFixed(2) +'吨，最高可售' +this.purchasePriceList[i].saleLimit +'吨。');
          //         }
          //       }
          //     }
          //   })
        }
      },
      customerChange(e) {
        let customers = e.split('(')
        this.inspect.customerName = customers[0]
        for (let i = 0; i < this.customerList1.length; i++) {
          // console.log(this.customerList1[i].customerName, this.customerList1[i])
          if (this.customerList1[i].customerName == this.inspect.customerName) {
            // console.log(this.customerList1[i])
            this.inspect.customerNumberCard = this.customerList1[i].customerNumberCard
          }
        }
        this.inspect.customerPhone = customers[1].split(')')[0]
        if (this.inspect.goodsName && this.inspect.customerName) {
          // //查看当前用户对应货名有未结算状态的送货
          // let count = 0
          // getCount({
          //     compId: localStorage.getItem('ws-pf_compId'),
          //     customerName: this.inspect.customerName,
          //     goodsName: this.inspect.goodsName,
          //     customerNumberCard: this.inspect.customerNumberCard
          //   }).toPromise()
          //   .then((response) => {
          //     count = response
          //   })
          //   //  客户下拉校验
          // getamount({
          //   compId: localStorage.getItem('ws-pf_compId'),
          //   customerName: this.inspect.customerName,
          //   goodsName: this.inspect.goodsName,
          //   customerNumberCard:this.inspect.customerNumberCard
          // })
          //   .toPromise()
          //   .then((response) => {
          //     for (let i = 0; i < this.purchasePriceList.length; i++) {
          //       if (this.inspect.goodsName == this.purchasePriceList[i].goodsName) {
          //         if ((this.purchasePriceList[i].saleLimit - response/1000 < 50 || count > 0)&&this.tipFlag) {
          //           this.tipFlag = false
          //           this.$message('当前客户已累计销售我司' +this.inspect.goodsName + (response/1000).toFixed(2) +'吨，最高可售' +this.purchasePriceList[i].saleLimit +'吨。');
          //         }
          //       }
          //     }
          //   })
        }
      },

      waterContentChange(type) {
        if (this.inspect.goodsName && type != 'water') {
          if (this.inspect.goodsName.indexOf('潮粮') != -1) {
            this.inspect.type = '潮粮'
          } else {
            this.inspect.type = '干粮'
          }
          if (!this.inspect.dryGrainPrice || this.inspect.dryGrainPrice == 0) {
            getDryGrainPrice({
                warehouseId: this.cangid,
                goodsName: this.inspect.goodsName
              })
              .toPromise()
              .then((response) => {
                this.$set(this.inspect, 'dryGrainPrice', response)
              })
          }
        //客户
        getcustomer({
            warehouseId: this.cangid,
            goodsName:this.inspect.goodsName
          })
          .toPromise()
          .then((response) => {
            this.customerList1 = response
            this.customerList = []
            let customer = response
            for (let i = 0; i < response.length; i++) {
              if (response[i].supplier) {
                customer = response[i].customerName + '(' + response[i].customerPhone + ')' + '-' + response[i]
                  .supplier
              } else {
                customer = response[i].customerName + '(' + response[i].customerPhone + ')'
              }
              this.customerList.push({
                valueKey: i,
                value: customer,
              })
            }
          })
          for (var i = 0; i < this.purchasePriceList.length; i++) {
            if (this.purchasePriceList[i].goodsName == this.inspect.goodsName) {
              this.$set(this.inspect, 'buckleWeightRatio', this.purchasePriceList[i].deductWeight)
              this.$set(this.inspect, 'paramType', this.purchasePriceList[i].paramType)

            }
          }
        }
        //潮粮单价改变事件
        if (
          this.inspect.goodsName &&
          this.inspect.waterContent &&
          this.inspect.grade
        ) {
          getinspectLookUnitPrice({
              warehouseId: this.cangid,
              goodsName: this.inspect.goodsName,
              waterContent: this.inspect.waterContent,
              grade: this.inspect.grade,
            })
            .toPromise()
            .then((response) => {
              if (this.inspect.paramType == '1') {
                this.inspect.tidalGrainPrice = parseFloat(parseFloat(response) - parseFloat(this.inspect
                  .buckleMiscellaneous) / 100 * parseFloat(this.inspect.dryGrainPrice)).toFixed(4)
              } else {
                if (this.inspect.type == '干粮') {
                  if (response == 0) {
                    getDryGrainPrice({
                        warehouseId: this.cangid,
                        goodsName: this.inspect.goodsName
                      })
                      .toPromise()
                      .then((response) => {
                        this.$set(this.inspect, 'dryGrainPrice', response)
                      })
                  } else {
                    this.inspect.dryGrainPrice = response
                  }
                } else {
                  this.inspect.tidalGrainPrice = response
                }
              }
            })
        }
        if (this.inspect.goodsName && this.inspect.customerName) {
          // //查看当前用户对应货名有未结算状态的送货
          // let count = 0
          // if (
          //   this.inspect.goodsName &&
          //   this.inspect.customerName
          // ) {
          //   getCount({
          //       compId: localStorage.getItem('ws-pf_compId'),
          //       customerName: this.inspect.customerName,
          //       goodsName: this.inspect.goodsName,
          //       customerNumberCard: this.inspect.customerNumberCard
          //     }).toPromise()
          //     .then((response) => {
          //       count = response
          //     })
          //   // //  货名下拉校验
          //   // getamount({
          //   //   compId: localStorage.getItem('ws-pf_compId'),
          //   //   customerName: this.inspect.customerName,
          //   //   goodsName: this.inspect.goodsName,
          //   //   customerNumberCard:this.inspect.customerNumberCard
          //   // })
          //   //   .toPromise()
          //   //   .then((response) => {
          //   //     for (let i = 0; i < this.purchasePriceList.length; i++) {
          //   //       if (this.inspect.goodsName == this.purchasePriceList[i].goodsName) {
          //   //         if ((this.purchasePriceList[i].saleLimit - response/1000 < 50 || count > 0 )&&this.tipFlag) {
          //   //           this.tipFlag = false
          //   //           this.$message('当前客户已累计销售我司' +this.inspect.goodsName + (response/1000).toFixed(2) +'吨，最高可售' +this.purchasePriceList[i].saleLimit +'吨。');
          //   //         }
          //   //       }
          //   //     }
          //   //   })
          // }
        }
      },

      getList(ids) {
        // 车型
        getcartype({constId:'QUA1'}).toPromise()
          .then((response) => {
            this.cartypeList=response
          })
        // 货名
        getinspectLookGoods({
            warehouseId: this.cangid
          })
          .toPromise()
          .then((response) => {
            this.goodNameList = []
            this.goodNameList = response
            this.purchasePriceList = response
          })
        // 品级
        packList({
            constId: 'CON3'
          })
          .toPromise()
          .then((response) => {
            this.gradeList = response
          })
        getshippinginfo({
            compId: localStorage.getItem('ws-pf_compId'),
            warehouseName: this.warehouseName
          }).toPromise()
          .then((response) => {
            this.carNumberList = response
          })
        // 仓位
        getbinNumber({
            id: this.cangid
          })
          .toPromise()
          .then((response) => {
            this.getbinNumberList = []
            for (let i = 0; i < response.warehousePositionInfoList.length; i++) {
              this.getbinNumberList.push({
                value: response.warehousePositionInfoList[i].binNumber,
              })
            }
          })
        if (this.types != 1) {
          //查看
          getinspectLook({
              id: ids
            })
            .toPromise()
            .then((response) => {
              this.inspect = response
            })
        }
      },
    },
  }
</script>
<style lang="scss" scoped>
  /deep/.el-dialog__header {
    text-align: center !important;
    padding: 10px 0 !important;
    height: auto !important;
  }

  /deep/.el-dialog__title {
    font-size: 24px !important;
  }

  .center {
    background: #f6f7fc;
  }

  .ws-info-table {
    border: none;
  }

  .ws-info-table .el-form-item {
    width: 50%;
    border: none;
  }

  /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;
    // overflow: auto!important;
    height: 55px;
  }

  /deep/.el-textarea__inner {
    width: 100%;
  }

  .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;
  }
</style>