<template>
  <div>
    <div class="tab-header webtop">
      <!-- 标题 -->
      <div>{{title}}收货单</div>
      <!-- start 添加修改按钮 -->
      <div>
        <el-button type="primary" size="small" :disabled="submitdisabled" @click="saveOrUpdate">保存</el-button>
        <el-button type="primary" size="small" :disabled="submitdisabled" @click="submit">确认</el-button>
        <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
      </div>
      <!-- end 添加修改按钮 -->
      <!-- end 详情按钮 -->
    </div>
    <div class="listconadd">
      <el-form ref="form_obj" :model="formobj" class="formaddcopy02">
        <div class="title">
          <div>基础信息</div>
        </div>
        <el-row>

          <el-col :span="12">
            <div class="span-sty">单据编号</div>
            <el-form-item><span class="addinputInfo">{{ formobj.billNo }}</span></el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty">制单人姓名</div>
            <el-form-item> <el-input v-model="formobj.createByName" placeholder="" class="addinputw addinputInfo"
                clearable /></el-form-item>
          </el-col>

        </el-row>
        <el-row>

          <el-col :span="12">
            <div class="span-sty">外部单号</div>
            <el-form-item><span class="addinputInfo">{{ formobj.sourceBillNo }}</span></el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty">单据日期</div>
            <el-form-item> <el-date-picker v-model="formobj.createTime" type="date" class="addinputInfo"
                value-format="yyyy-MM-dd" placeholder="选择日期">
              </el-date-picker></el-form-item>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="12">
            <div class="span-sty">业务类型</div>
            <el-form-item><el-select v-model="formobj.busTypeValue" filterable clearable placeholder="请选择"
                class="addinputInfo" @change="busTypeSelect">
                <el-option v-for="item in busTypeList" :key="item.sid" :label="item.name" :value="item.sid">
                </el-option>
              </el-select></el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty">供应商</div>
            <el-form-item> <el-select v-model="formobj.supplierName" filterable clearable placeholder="请选择"
                class="addinputInfo" @change="supplierNameSelect">
                <el-option v-for="item in supplierList" :key="item.sid" :label="item.name" :value="item.sid">
                </el-option>
              </el-select></el-form-item>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="12">
            <div class="span-sty">到货日期</div>
            <el-form-item><el-date-picker v-model="formobj.deliveryDate" type="date" class="addinputInfo"
                value-format="yyyy-MM-dd" placeholder="选择日期">
              </el-date-picker></el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty">单据状态</div>
            <el-form-item> <span class="addinputInfo">{{formobj.billState}}</span></el-form-item>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="24">
            <div class="span-sty">备注</div>
            <el-form-item><el-input v-model="formobj.remarks" placeholder="" class="addinputw addinputInfo"
                type="textarea" :rows="4" clearable /></el-form-item>
          </el-col>

        </el-row>

        <div class="title titleOne">
          <div>商品列表</div>
          <el-button type="primary" size="mini" class="btntopblueline" @click="batchAddAll()">批次收货</el-button>
        </div>
        <el-table :key="tableKey" v-loading="listLoading" :data="formobj.list" :index="index" border
          style="width: 100%;" ref="dataTable">
          <el-table-column fixed width="60" label="序号" type="index" :index="index + 1" align="center" />
          <el-table-column align="center" width="180">
            <template slot="header" slot-scope="scope">
              <i v-if="!isUpdata" class="add-btn-icon el-icon-plus" style="color: red;font-size:20px"
                @click="commodityAdd(scope.row)"></i>
              <span v-else>操作</span>
            </template>
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="doGoods(scope.row)">删除</el-button>
              <el-button type="primary" size="mini" @click="doAddBatch(scope.row)">批次+</el-button>
              <!-- <i v-if="!isUpdata" class="el-icon-delete" @click="commodityDelete(scope.$index)"></i> -->
            </template>
          </el-table-column>

          <el-table-column v-if="isUpdata" label="商品名称" prop="goodsSkuTitle" align="center" width="200" />

          <el-table-column label="商品名称" align="center" min-width="200" v-if="!isUpdata">
            <template slot-scope="scope" v-if="!isUpdata">
              <el-popover placement="right" width="900" trigger="click" v-if="!isUpdata">
                <div>
                  <el-table :data="commodityData" v-loading="commodityLoading" highlight-current-row
                    @current-change="commodityCurrentChange($event, scope.row)">
                    <el-table-column prop="goodsSpuName" label="商品名称" align="center" />
                    <el-table-column prop="goodsSkuCode" label="商品编码" align="center" />
                    <el-table-column prop="goodsSkuOwnSpec" label="型号" align="center" />
                    <el-table-column prop="unit" label="单位" align="center" />
                    <el-table-column prop="warehouseName" label="仓库" align="center" />
                    <el-table-column prop="warehouseRackName" label="库位" align="center" />
                  </el-table>
                  <el-pagination :page.sync="commodityQuery.current" :page-size="commodityQuery.size"
                    layout="total, pager" :total="commodityQuery.total" />
                </div>
                <el-input slot="reference" v-model="scope.row.goodsSpuName"
                  @input="commodityInput(scope.row.goodsSpuName)" clearable placeholder="商品名称" />
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column label="商品编码" prop="goodsSkuCode" align="center" width="150" />
          <el-table-column label="规格" prop="goodsSkuOwnSpec" align="center" width="150" />
          <el-table-column label="单位" prop="unit" align="center" width="120" />
          <el-table-column label="仓库" align="center" width="180">
            <template slot-scope="scope">
              <el-select v-model="scope.row.warehouseName" placeholder="请选择" clearable
                @change="selectWarehouseName(scope.row,$event)">
                <el-option v-for="(item,i) in warehouseList" :key="i" :label="item.warehouseName" :value="item.sid">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="库位" align="center" width="180">
            <template slot-scope="scope">
              <el-select v-model="scope.row.warehouseRackName" :disabled="scope.row.warehouseName==''" clearable
                @focus="getWarehouseAreaList(scope.row.warehouseSid)" placeholder="请选择"
                @change="selectWarehouseAreaCode">
                <el-option v-for="(item,i) in warehouseRackList" :key="i" :label="item.areaCode" :value="item.sid">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="预约数量" prop="orderCount" align="center" width="120" v-if="isUpdata" />
          <el-table-column label="实收数量" align="center" width="120">
            <template slot-scope="scope">
              <el-input ref="focusAssumptionInput" @input="commodityComputeYHAndXSJE(scope.row,$event)"
                v-model="scope.row.actualInCount" clearable placeholder=""
                oninput="value=value.replace(/^(0+)|[^\d]+/g,'')" />
            </template>
          </el-table-column>
          <el-table-column label="拒收数量" align="center" width="120">
            <template slot-scope="scope">
              <el-input ref="focusAssumptionInput" v-model="scope.row.rejectCount" clearable placeholder=""
                @input="commodityComputeYHAndXSJE2(scope.row,$event)"
                oninput="value=value.replace(/^(0+)|[^\d]+/g,'')" />
            </template>
          </el-table-column>
          <el-table-column label="拒收原因" align="center" width="180">
            <template slot-scope="scope">
              <el-input ref="focusAssumptionInput" v-model="scope.row.rejectReason" clearable placeholder="" />
            </template>
          </el-table-column>
          <el-table-column label="是否质检" align="center" width="180">
            <template slot-scope="scope">
              <el-radio-group v-model="scope.row.isQuality" size="small">
                <el-radio :label="0">需要</el-radio>
                <el-radio :label="1">不需要</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column label="质检状态" align="center" width="180">
            <template slot-scope="scope">
              <el-radio-group v-model="scope.row.qualityState" size="small">
                <el-radio :label="0">合格</el-radio>
                <el-radio :label="1">不合格</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column label="载具说明" align="center" width="180">
            <template slot-scope="scope">
              <el-input ref="focusAssumptionInput" v-model="scope.row.packageRemark" clearable placeholder="" />
            </template>
          </el-table-column>
          <el-table-column label="入库价" align="center" width="150">
            <template slot-scope="scope">
              <el-input ref="focusAssumptionInput" @input="commodityComputeYHAndXSJE3(scope.row,$event)"
                v-model="scope.row.cost" clearable placeholder=""
                oninput="value=value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')" />
            </template>
          </el-table-column>
          <el-table-column label="税额" align="center" width="150">
            <template slot-scope="scope">
              <el-input ref="focusAssumptionInput" @input="commodityComputeYHAndXSJE4(scope.row,$event)"
                v-model="scope.row.taxAmount" clearable placeholder=""
                oninput="value=value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')" />
            </template>
          </el-table-column>
          <el-table-column label="含税单价" prop="taxPrice" @input="commodityComputeYHAndXSJE5(scope.row,$event)"
            align="center" width="150" />
          <el-table-column label="入库金额" prop="amount" align="center" width="150" />
        </el-table>


        <div class="title"
          style="display: flex;align-items: center;justify-content: space-between;height:40px;margin-top: 10px;">
          <div>商品-批次</div>
        </div>
        <el-table v-loading="listLoading" :data="formobj.pcList" border style="width: 100%;"
          :row-style="{height: '40px'}">
          <el-table-column fixed width="60" label="序号" type="index" :index="indexMethod" align="center" />
          <el-table-column fixed label="操作" wid align="center" width="120">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="doGoodsBatch(scope.row)">删除</el-button>
            </template>
          </el-table-column>
          <el-table-column label="商品列表序号" prop="xh" align="center" width="120" />
          <el-table-column label="商品名称" prop="goodsSkuTitle" align="center" width="200" />
          <el-table-column label="商品编码" prop="goodsSkuCode" align="center" width="150" />
          <el-table-column label="规格" prop="goodsSkuOwnSpec" align="center" width="150" />
          <el-table-column label="单位" prop="unit" align="center" width="120" />
          <el-table-column label="仓库" prop="unit" align="center" width="150" />
          <el-table-column label="库位" prop="unit" align="center" width="150" />
          <el-table-column label="批次号" prop="batchNumber" align="center" width="300" />
          <el-table-column label="生产日期" align="center" width="180">
            <template slot-scope="scope">
              <el-date-picker v-model="scope.row.manufactureDate" type="date" style="width:100%"
                value-format="yyyy-MM-dd" placeholder="选择日期" @change="manufactureDateChange(scope.row,$event)" />
            </template>
          </el-table-column>
          <el-table-column label="有效期" prop="expirationDate" align="center" width="180" />
          <el-table-column label="数量" align="center" width="120">
            <template slot-scope="scope">
              <el-input ref="focusAssumptionInput" v-model="scope.row.batchCount" clearable placeholder=""
                oninput="value=value.replace(/^(0+)|[^\d]+/g,'')" />
            </template>
          </el-table-column>
        </el-table>

      </el-form>

    </div>


  </div>
</template>

<script>
  import req from '@/api/receivingGoods/receivingGoods.js'
  import req2 from '@/api/warehouse/allocation/allocation.js'
  export default {
    components: {},
    data() {
      return {
        listLoading: false,
        submitdisabled: false,
        formobj: {
          "sid": "",
          "billNo": "",
          "sourceBillSid": "",
          "sourceBillNo": "",
          "createBySid": "",
          "createByName": "",
          "createTime": "",
          "busTypeKey": "",
          "busTypeValue": "",
          "supplierSid": "",
          "supplierName": "",
          "deliveryDate": "",
          "billState": "新建",
          "remarks": "",
          "useOrgSid": "",
          "createOrgSid": "",
          "list": [],
          "pcList": []
        },
        hideUploadBtn: false,
        busTypeList: [{
            name: "业务类型1",
            sid: "1"
          },
          {
            name: "业务类型2",
            sid: "2"
          }
        ],
        supplierList: [],
        warehouseList: [],
        warehouseRackList: [],
        // commodity商品
        commodityKey: 1,
        commodityLoading: false,
        commodityQuery: {
          current: 1,
          size: 2,
          total: 0,
          params: {
            name: '',
            inOrg: "",
            outOrg: ""
          }
        },
        commodityData: [],
        isUpdata: false
      }
    },
    created() {},
    methods: {

      commodityInput(value) {
        this.commodityQuery.params.name = value
        this.commodityLoading = true
        req.getGoodsListPage(this.commodityQuery).then((response) => {
          if (response.success) {
            this.commodityLoading = false
            this.commodityData = response.data.records
            this.commodityQuery.total = response.data.total
          } else {
            this.serviceLoading = false
            this.commodityData = []
            this.commodityQuery.total = 0
          }
        })
      },
      commodityDelete(index) {
        this.formobj.list.splice(index, 1)
      },
      commodityCurrentChange(value, row) {
        console.log("commodityCurrentChange》》》》", value)
        console.log("commodityCurrentChange》》》》", row)
        row.goodsSkuSid = value.goodsSkuSid
        row.goodsSkuTitle = value.goodsSpuName
        row.goodsSpuName = value.goodsSpuName
        row.goodsSkuCode = value.goodsSkuCode
        row.goodsSkuOwnSpec = value.goodsSkuOwnSpec
        row.unit = value.unit
        row.warehouseSid = value.warehouseSid
        row.warehouseName = value.warehouseName
        row.warehouseRackSid = value.warehouseRackSid
        row.warehouseRackName = value.warehouseRackName
        row.actualInCount = 0
        row.rejectCount = 0
        row.rejectReason = ''
        row.isQuality = 0
        row.qualityState = 0
        row.packageRemark = ''
        row.cost = value.cost
        row.taxAmount = value.taxAmount
        row.taxPrice = value.taxPrice
        row.amount = value.amount
        row.shelfLife = value.shelfLife
        document.body.click()
      },

      // 在头部标题上添加“新增”图标
      commodityHeader(h, {
        column
      }) {
        return h(
          'div',
          [
            h('span', column.label),
            h('i', {
              class: 'add-btn-icon el-icon-plus',
              style: 'color: red;font-size:20px',
              on: {
                click: this.commodityAdd // 点击执行函数
              }
            })
          ]
        )
      },
      commodityAdd() {
        this.formobj.list.push({
          "goodsSkuSid": "",
          "goodsSkuTitle": "",
          "goodsSkuCode": "",
          "goodsSkuOwnSpec": "",
          "unit": "",
          "warehouseSid": "",
          "warehouseName": "",
          "warehouseRackSid": "",
          "warehouseRackName": "",
          "actualInCount": 0,
          "rejectCount": 0,
          "rejectReason": "",
          "isQuality": 0,
          "qualityState": 0,
          "packageRemark": "",
          "state": 0,
          "xh": "",
          "orderCount": 0,
          "cost": 0,
          "taxAmount": 0,
          "taxPrice": 0,
          "amount": 0,
          'shelfLife': 0
        })
      },


      doGoodsDel(sid) {
        console.log("doGoodsDel》》》》", sid)
        this.$confirm("是否确定删除此商品？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const index = this.formobj.list.findIndex((item) => item === row)
          console.log("index》》》》", index)
          this.formobj.list.splice(index, 1)

          for (var i = this.formobj.pcList.length - 1; i >= 0; i--) {
            if (this.formobj.pcList[i].xh === (index + 1)) {
              this.formobj.pcList.splice(i, 1);
            }
          }

        })
      },

      indexMethod(index) {
        return index + 1
      },
      saveOrUpdate() {
        console.log('>>>>>>>>>saveOrUpdate', this.formobj)


        // if (this.formobj.createByName == '') {
        //   this.$message({
        //     showClose: true,
        //     type: 'error',
        //     message: '制单人姓名不能为空'
        //   })

        //   return
        // }

        // if (this.formobj.createTime == '') {
        //   this.$message({
        //     showClose: true,
        //     type: 'error',
        //     message: '单据日期不能为空'
        //   })

        //   return
        // }


        // if (this.formobj.busTypeKey == '' || this.formobj.busTypeValue == '') {
        //   this.$message({
        //     showClose: true,
        //     type: 'error',
        //     message: '业务类型不能为空'
        //   })

        //   return
        // }

        // if (this.formobj.supplierSid == '' || this.formobj.supplierName == '') {
        //   this.$message({
        //     showClose: true,
        //     type: 'error',
        //     message: '供应商不能为空'
        //   })

        //   return
        // }

        // if (this.formobj.deliveryDate == '') {
        //   this.$message({
        //     showClose: true,
        //     type: 'error',
        //     message: '到货日期不能为空'
        //   })

        //   return
        // }


        // for (var i = 0; i < this.formobj.pcList.length; i++) {
        //   var item = this.formobj.pcList[i]

        //   if (item.manufactureDate == '') {
        //     this.$message({
        //       showClose: true,
        //       type: 'error',
        //       message: '生产日期不能为空'
        //     })

        //     return
        //   }

        //   if (Number(item.batchCount) == 0) {
        //     this.$message({
        //       showClose: true,
        //       type: 'error',
        //       message: '商品批次数量不能为0'
        //     })

        //     return
        //   }

        // }


        // for (var i = 0; i < this.formobj.list.length; i++) {
        //   var index = i
        //   var num = 0
        //   const choose = this.formobj.pcList.filter((item) => Number(item.xh) == (index + 1))
        //   for (var j = 0; j < choose.length; j++) {

        //     num += Number(choose[j].batchCount)

        //   }

        //   console.log('>>>>>>>>>saveOrUpdate', num)

        //   if (num > Number(this.formobj.list[i].actualInCount)) {
        //     this.$message({
        //       showClose: true,
        //       type: 'error',
        //       message: '商品批次数量不能大于商品实收数量'
        //     })

        //     return
        //   }


        // }


        this.$refs['form_obj'].validate((valid) => {
          if (valid) {
            this.submitdisabled = true
            req.save(this.formobj).then((res) => {
              if (res.success) {
                this.$message({
                  showClose: true,
                  type: 'success',
                  message: '保存成功'
                })
                this.handleReturn('true')
              } else {
                this.submitdisabled = false
              }
            }).catch(() => {
              this.submitdisabled = false
            })
          }
        })
      },
      submit() {

        if (this.formobj.createByName == '') {
          this.$message({
            showClose: true,
            type: 'error',
            message: '制单人姓名不能为空'
          })

          return
        }

        if (this.formobj.createTime == '') {
          this.$message({
            showClose: true,
            type: 'error',
            message: '单据日期不能为空'
          })

          return
        }


        if (this.formobj.busTypeKey == '' || this.formobj.busTypeValue == '') {
          this.$message({
            showClose: true,
            type: 'error',
            message: '业务类型不能为空'
          })

          return
        }

        if (this.formobj.supplierSid == '' || this.formobj.supplierName == '') {
          this.$message({
            showClose: true,
            type: 'error',
            message: '供应商不能为空'
          })

          return
        }

        if (this.formobj.deliveryDate == '') {
          this.$message({
            showClose: true,
            type: 'error',
            message: '到货日期不能为空'
          })

          return
        }

        if (this.formobj.list.length == 0) {
          this.$message({
            showClose: true,
            type: 'error',
            message: '请添加商品'
          })

          return
        }

        for (var i = 0; i < this.formobj.list.length; i++) {
          var item = this.formobj.list[i]
          if (item.goodsSkuSid == '') {
            this.$message({
              showClose: true,
              type: 'error',
              message: '请添加商品'
            })

            return
          }

          if (item.actualInCount == 0) {
            this.$message({
              showClose: true,
              type: 'error',
              message: '请添加商品实收数量'
            })

            return
          }

          if (this.isUpdata) {
            if (item.actualInCount + item.rejectCount > item.orderCount) {
              this.$message({
                showClose: true,
                type: 'error',
                message: '商品实收数量或拒收数量错误'
              })

              return
            }
          }

        }


        for (var i = 0; i < this.formobj.pcList.length; i++) {
          var item = this.formobj.pcList[i]

          if (item.manufactureDate == '') {
            this.$message({
              showClose: true,
              type: 'error',
              message: '生产日期不能为空'
            })

            return
          }

          if (Number(item.batchCount) == 0) {
            this.$message({
              showClose: true,
              type: 'error',
              message: '商品批次数量不能为0'
            })

            return
          }

        }


        for (var i = 0; i < this.formobj.list.length; i++) {
          var index = i
          var num = 0
          const choose = this.formobj.pcList.filter((item) => Number(item.xh) == (index + 1))
          for (var j = 0; j < choose.length; j++) {

            num += Number(choose[j].batchCount)

          }

          console.log('>>>>>>>>>saveOrUpdate', num)

          if (num > Number(this.formobj.list[i].actualInCount)) {
            this.$message({
              showClose: true,
              type: 'error',
              message: '商品批次数量不能大于商品实收数量'
            })

            return
          }


        }

        this.$refs['form_obj'].validate((valid) => {
          if (valid) {
            this.submitdisabled = true
            req.submit(this.formobj).then((res) => {
              if (res.success) {
                this.$message({
                  showClose: true,
                  type: 'success',
                  message: '保存成功'
                })
                this.handleReturn('true')
              } else {
                this.submitdisabled = false
              }
            }).catch(() => {
              this.submitdisabled = false
            })
          }
        })

      },
      handleReturn(isreload) {
        if (isreload === 'true') this.$emit('reloadlist')
        this.formobj = {
          "sid": "",
          "billNo": "",
          "sourceBillSid": "",
          "sourceBillNo": "",
          "createBySid": "",
          "createByName": "",
          "createTime": "",
          "busTypeKey": "",
          "busTypeValue": "",
          "supplierSid": "",
          "supplierName": "",
          "deliveryDate": "",
          "billState": "新建",
          "remarks": "",
          "useOrgSid": "",
          "createOrgSid": "",
          "list": [],
          "pcList": []
        }
        this.submitdisabled = false
        this.isUpdata = false
        this.$emit('doback')
      },

      showAdd() {
        this.isUpdata = false
        console.log("showAdd", this.isUpdata);
        this.getsupplierLust()
      },
      showEdit(row) {
        this.isUpdata = true
        this.getsupplierLust()
        console.log("showEdit", this.isUpdata);
        var params = {
          sid: row.sid
        }

        req.init(params)
          .then(resp => {
            if (resp.success) {
              this.formobj = resp.data
            }
          })
          .catch(e => {
            this.formobj = {}
          })
      },
      busTypeSelect(val) {
        const choose = this.busTypeList.filter((item) => item.sid == val)
        console.log('>>>>>>>>>busTypeSelect', choose)
        this.formobj.busTypeKey = choose[0].sid
        this.formobj.busTypeValue = choose[0].name

      },
      supplierNameSelect(val) {

        console.log("supplierNameSelect", val);
        const choose = this.supplierList.filter((item) => item.sid == val)
        console.log('>>>>>>>>>supplierNameSelect', choose)
        this.formobj.supplierName = choose[0].supplierName
        this.formobj.supplierSid = choose[0].sid

      },
      getsupplierLust() {
        var params = {
          createOrgSid: ""
        }
        req.choiceSupplier(params).then((res) => {
          if (res.success) {
            this.supplierList = res.data

            console.log("aaaaaa", this.supplierList);

          }
        })
      },
      getWarehouseList() {
        req2.getWarehouses().then((res) => {
          if (res.success) {
            this.warehouseList = res.data

            console.log("aaaaaa", this.warehouseList);

          }
        })
      },
      getWarehouseAreaList(sid) {
        var query = {
          ckSid: sid
        }
        req2.getWarehouseareas(query).then((res) => {
          if (res.success) {
            this.warehouseRackList = res.data

            console.log("aaaaaa", this.warehouseRackList);

          }
        })
      },
      selectWarehouseName(row, val) {
        console.log("selectWarehouseName", row);
        console.log("selectWarehouseName", val);
        const choose = this.warehouseList.filter((item) => item.sid == val)
        console.log('>>>>>>>>>selectWarehouseName', choose)
        row.warehouseName = choose[0].warehouseName
        row.warehouseSid = choose[0].sid

      },
      selectWarehouseAreaCode(val) {
        console.log("selectWarehouseAreaCode", val);

        const choose = this.warehouseRackList.filter((item) => item.sid == val)
        console.log('>>>>>>>>>selectWarehouseAreaCode', choose)
        row.warehouseRackName = choose[0].areaCode
        row.warehouseRackSid = choose[0].sid

      },

      batchAddAll() {

        for (var i = 0; i < this.formobj.list.length; i++) {
          var item = this.formobj.list[i]

          var info = {
            xh: i + 1,
            goodsSkuSid: item.goodsSkuSid,
            goodsSkuTitle: item.goodsSkuTitle,
            goodsSkuCode: item.goodsSkuCode,
            goodsSkuOwnSpec: item.goodsSkuOwnSpec,
            unit: item.unit,
            warehouseSid: item.warehouseSid,
            warehouseName: item.warehouseName,
            warehouseRackSid: item.warehouseRackSid,
            warehouseRackName: item.warehouseRackName,
            shelfLife: item.shelfLife,
            orderCount: item.orderCount,
            batchNumber: '',
            manufactureDate: '',
            batchCount: 0,
          }

          this.formobj.pcList.push(info)

        }

      },
      doGoods(row) {
        console.log("doGoodsDel》》》》", row)

        this.$confirm("是否确定删除此商品？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const index = this.formobj.list.findIndex((item) => item === row)
          console.log("index》》》》", index)
          this.formobj.list.splice(index, 1)

          for (var i = this.formobj.pcList.length - 1; i >= 0; i--) {
            if (this.formobj.pcList[i].xh === (index + 1)) {
              this.formobj.pcList.splice(i, 1);
            }
          }

        })
      },

      doGoodsBatch(row) {
        console.log("doGoodsDel》》》》", row)

        this.$confirm("是否确定删除此商品批次？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const index = this.formobj.pcList.findIndex((item) => item === row)
          console.log("index》》》》", index)
          this.formobj.pcList.splice(index, 1)

        })

      },

      manufactureDateChange(row, val) {

        console.log("manufactureDateChange》》》》", val)
        console.log("manufactureDateChange》》》》", row)

        row.manufactureDate = val
        row.expirationDate = this.addDate(val, row.shelfLife)

        let reg = new RegExp('-', 'g') //g代表全部

        row.batchNumber = this.formobj.deliveryDate.replace(reg, '') + " - " + row.expirationDate.replace(reg, '')



        this.$forceUpdate(); // 强制更新
        console.log("manufactureDateChange》》》》", row)

      },

      addDate(date, days) {
        var dates = new Date(date)
        dates.setDate(dates.getDate() + days)
        var year = dates.getFullYear()
        var month = dates.getMonth() + 1
        var day = dates.getDate()
        if (month < 9) {
          month = "0" + month
        }
        if (day < 9) {
          day = "0" + day
        }
        var time = year + '-' + month + '-' + day
        return time
      },

      doAddBatch(row) {
        const index = (this.formobj.list.findIndex((item) => item === row)) + 1
        console.log("doAddBatch》》》》", index)
        console.log("doAddBatch》》》》", row)

        var info = {
          xh: index,
          goodsSkuSid: row.goodsSkuSid,
          goodsSkuTitle: row.goodsSkuTitle,
          goodsSkuCode: row.goodsSkuCode,
          goodsSkuOwnSpec: row.goodsSkuOwnSpec,
          unit: row.unit,
          warehouseSid: row.warehouseSid,
          warehouseName: row.warehouseName,
          warehouseRackSid: row.warehouseRackSid,
          warehouseRackName: row.warehouseRackName,
          shelfLife: row.shelfLife,
          orderCount: row.orderCount,
          batchNumber: '',
          manufactureDate: '',
          batchCount: 0,
        }

        console.log("aaaaaaaaaaa", info);

        this.formobj.pcList.push(info)

      },
      commodityComputeYHAndXSJE(row, val) {
        console.log("aaa", row);
        console.log("aaa", val);

        if (this.isUpdata) {
          if (Number(row.actualInCount) > Number(row.orderCount)) {
            row.actualInCount = row.orderCount

          }

        }

        row.amount = (Number(row.actualInCount) * Number(row.taxPrice)).toFixed(2)
      },

      commodityComputeYHAndXSJE2(row, val) {
        console.log("aaa", row);
        console.log("aaa", val);
        if (this.isUpdata) {
          if ((Number(row.rejectCount) + Number(row.actualInCount)) > Number(row.orderCount)) {
            row.rejectCount = Number(row.orderCount) - Number(row.actualInCount)
          }
        }
      },

      commodityComputeYHAndXSJE3(row, val) {
        console.log("aaa", row);
        console.log("aaa", val);

        row.taxPrice = (Number(row.cost) * Number(row.taxAmount)).toFixed(2)
        row.amount = (Number(row.actualInCount) * Number(row.taxPrice)).toFixed(2)
      },

      commodityComputeYHAndXSJE4(row, val) {
        console.log("aaa", row);
        console.log("aaa", val);

        row.taxPrice = (Number(row.cost) * Number(row.taxAmount)).toFixed(2)
        row.amount = (Number(row.actualInCount) * Number(row.taxPrice)).toFixed(2)
      },
    }
  }
</script>
<style scoped>
  .span-sty {
    width: 130px !important;
  }

  .addinputInfo {
    margin-left: 120px !important;
  }

  .formaddcopy02 .el-row .el-col /deep/ .el-form-item .addinputw {
    margin-left: 120px !important;
    width: calc(100% - 115px);
  }

  .titleOne {
    padding: 7px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
</style>
