// 入库登记
<template>
  <div class="container">
    <el-row>
      <el-col :span="20">
        <h2 class="bg-left title">入库登记</h2>
      </el-col>
      <el-col :span="4" class="bg-right">
        <el-button
          class="bg-bottom"
          type="primary"
          size="small"
          @click="returnWarehouse()"
          >返回</el-button
        >
      </el-col>
    </el-row>

    <ws-form ref="deptBudgetList" :model="deptBudgetList" :rules="rules">
      <div class="basicInformation">
        <h2>
          {{ deptBudgetList.warehouseName }}库
          {{ deptBudgetList.binNumber }}仓位
        </h2>
        <ws-info-table>
          <!-- 货名 -->
          <ws-form-item label="货名" span="1">
            <ws-select
              v-model="deptBudgetList.goodsName"
              placeholder=""
              class="typeselect"
              @change="selectgoodsName"
            >
              <ws-option
                v-for="item in goodnameList"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>
          <!--毛重（吨）-->
          <ws-form-item label="毛重（吨）" span="1" prop="grossWeight">
            <ws-input
              @input="grossWeightchange"
              v-model="deptBudgetList.grossWeight"
              placeholder="请输入毛重"
              maxlength="20"
              size="small"
            />
          </ws-form-item>

          <!--皮重（吨）-->
          <ws-form-item
            label="皮重（吨）"
            span="1"
            prop="tare"
            class="readonly"
          >
            <ws-input
              @input="tarechange"
              v-model="deptBudgetList.tare"
              placeholder="请输入皮重"
              maxlength="100"
              size="small"
            />
          </ws-form-item>

          <!--净重（吨）-->
          <ws-form-item label="净重（吨）" span="1" prop="netWeight">
            <ws-input
              v-model.number="deptBudgetList.netWeight"
              placeholder="不可编辑，自动计算"
              type="number"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
          <!-- 品级 -->
          <ws-form-item label="品级" span="1" class="readonly">
            <ws-select
              v-model="deptBudgetList.grade"
              placeholder=""
              class="typeselect"
              @change="selectpackingMethod"
            >
              <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="agent">
            <ws-input
              v-model="deptBudgetList.agent"
              placeholder="请输入出库经办人姓名"
              maxlength="100"
              size="small"
            />
          </ws-form-item>
          <!--出库日期-->
          <ws-form-item
            label="入库日期"
            span="1"
            prop="inOutDate"
            class="deliverydate"
          >
            <ws-date-picker
              v-model="deptBudgetList.inOutDate"
              type="date"
              placeholder="请选择入库日期"
              value-format="yyyy-MM-dd"
            />
          </ws-form-item>
          <!-- 入库类型 -->
          <ws-form-item label="入库类型" span="1">
            <ws-select
              v-model="deptBudgetList.inOutType"
              placeholder=""
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>

          <!--车牌号-->
          <ws-form-item label="车牌号" span="1" prop="sourceGoods">
            <ws-input
              v-model="deptBudgetList.carNo"
              placeholder="请输入车牌号"
              maxlength="20"
              size="small"
            />
          </ws-form-item>

          <!--合同编号-->
          <ws-form-item label="合同编号" span="1" prop="contractNo">
            <ws-input
              v-model="deptBudgetList.contractNo"
              placeholder="请输入合同编号"
              maxlength="100"
              size="small"
            />
          </ws-form-item>
        </ws-info-table>
      </div>
      <ws-upload
        ref="upload"
        table-name="maintain_work_order"
        oss-key="mainPlan"
        :comp-id="compId"
        :appendix-ids="appendixIdsAdd"
        :vesselId="deptBudgetList.addressUrl"
        :size-limit="size"
        @uploadSuccess="uploadSuccess"
        @onChange="onChange"
        accept=".jpg, .jpeg, .png, .pdf, .doc, .zip, .rar"
      />
      <h2>化验数据（选填）</h2>
      <ws-info-table>
        <!--自检员-->
        <ws-form-item label="质检员" span="1" prop="qualityInspector">
          <ws-input
            v-model="deptBudgetList.warehouseInOutDetail.qualityInspector"
            placeholder="请输入质检员姓名"
            maxlength="120"
            size="small"
          />
        </ws-form-item>

        <!--水分（%）<=-->
        <ws-form-item label="水分（%）<=" span="1" prop="waterContent">
          <ws-input
            v-model="deptBudgetList.warehouseInOutDetail.waterContent"
            placeholder="请输入水分占比"
            maxlength="120"
            size="small"
          />
        </ws-form-item>
        <!--杂质（%）<=-->
        <ws-form-item label="杂质（%）<=" span="1" prop="impurity">
          <ws-input
            v-model="deptBudgetList.warehouseInOutDetail.impurity"
            placeholder="请输入杂质占比"
            maxlength="120"
            size="small"
          />
        </ws-form-item>
        <!--容重（克/升）>=-->
        <ws-form-item label="容重（克/升）>=" span="1" prop="bulkDensity">
          <ws-input
            v-model="deptBudgetList.warehouseInOutDetail.bulkDensity"
            placeholder="请输入容重"
            maxlength="120"
            size="small"
          />
        </ws-form-item>
        <!--霉变粒（%）<=-->
        <ws-form-item label="霉变粒（%）<=" span="1" prop="mildewGrain">
          <ws-input
            v-model="deptBudgetList.warehouseInOutDetail.mildewGrain"
            placeholder="请输入霉变粒占比"
            maxlength="120"
            size="small"
          />
        </ws-form-item>
        <!--热损伤（%）<=-->
        <ws-form-item label="热损伤（%）<=" span="1" prop="jiaorenli">
          <ws-input
            v-model="deptBudgetList.warehouseInOutDetail.jiaorenli"
            placeholder="请输入热损伤占比"
            maxlength="120"
            size="small"
          />
        </ws-form-item>
        <!--不完整粒（%）<=-->
        <ws-form-item label="不完整粒（%）<=" span="1" prop="imperfectGrain">
          <ws-input
            v-model="deptBudgetList.warehouseInOutDetail.imperfectGrain"
            placeholder="请输入不完整粒占比"
            maxlength="120"
            size="small"
          />
        </ws-form-item>
      </ws-info-table>
      <div style="text-align: right; padding: 10px">
        <el-button
          class="bg-bottom-up"
          type="primary"
          size="small"
          @click="submit()"
          >提交</el-button
        >
      </div>
    </ws-form>
  </div>
</template>
<script>
import { pullDown, addstorageputList } from '@/model/warehouse/index'
import { downloadFile } from '@/utils/batchDown'
import Pagination from '@/components/Pagination'
import WsUpload from '@/components/WsUpload'
// import { dayjs, fmoney, EventBus } from 'base-core-lib'
import { dayjs, EventBus } from 'base-core-lib'
export default {
  name: 'viewSpareMoney',
  components: {
    WsUpload,
    Pagination,
  },
  watch: {
    // vesselId(val) {
    //   this.getList()
    // },
    isShow(val) {
      this.showType = val
    },
  },
  data() {
    return {
      //弹出框
      dialogViewSpareMoney: false,
      dialogApproveFormVisible: false,
      // 船舶类型
      monetaryKey: null,
      // 表格显示数据
      tableDate: [],
      // 是否显示
      showType: true,
      // 年
      year: '',
      deptBudgetTotal: 0,
      currentPage: 1,
      pageSize: 10,
      searchType: 1,
      searchKeyWord: '',
      contractType: 2,
      startDate: null,
      endDate: null,
      goodnameList: {},
      // 提交类型
      submitType: true,
      storageType: [],
      appendixIdsAdd: '',
      uploadSuccess: {},
      onChange: {},
      gradeList: [],
      rules: {
        netWeight: [
          {
            required: true,
            type: 'number',
            message: '请输入活动名称',
            trigger: 'blur',
          },
        ],
      },
      size: 10,
      compId: sessionStorage.getItem('ws-pf_compId'),
      deptCircularPage: {},
      packtypeList: {},
      date: {
        year: dayjs().format('YYYY'),
        month: dayjs().format('MM'),
      },
      contractList: [],
      deptBudgetList: {
        warehouseInOutDetail: {},
      },
      historyList: [],

      pickerBeginDateBefore: {
        disabledDate: (time) => {
          return time.getTime() > Date.now()
        },
      },
      accessoryTFs: false,
    }
  },
  mounted() {
    console.log(this.$route.query)
    this.deptBudgetList.baseId = this.$route.query.baseId
    this.deptBudgetList.positionId = this.$route.query.positionId
    this.deptBudgetList.warehouseName = this.$route.query.warehouseName
    this.deptBudgetList.binNumber = this.$route.query.binNumber
    this.getList()
  },
  activated() {
  //   //cg.viewBudget
  //   //cg.viewSpareMoney
  //   // this.getVesselData();
  //   console.log(2222)
  //   this.getList()
  //   console.log(1111)
  //   this.showType = this.isShow
  // this.getList(this.$route.query.baseId,)
  },
  methods: {
    //返回按钮
    returnWarehouse() {
      this.$router.push({ path: 'warehouseManagementList' })
    },
    //提交按钮
    submit() {
      this.$refs.deptBudgetList.validate((valid) => {
        if (valid) {
          this.deptBudgetList.compId = sessionStorage.getItem('ws-pf_compId')
          this.deptBudgetList.inOutFlag = 2
          addstorageputList(this.deptBudgetList)
            .toPromise()
            .then((response) => {
              this.$message.success('添加成功')
              this.$router.push({ path: 'warehouseManagementList' })
            })
        } else {
          EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
          return false
        }
      })
    },
    tarechange(e) {
      if (this.deptBudgetList.grossWeight && this.deptBudgetList.tare) {
        this.deptBudgetList.netWeight = Number(
          this.deptBudgetList.grossWeight - this.deptBudgetList.tare
        )
      }
    },
    grossWeightchange(e) {
      if (this.deptBudgetList.grossWeight && this.deptBudgetList.tare) {
        this.deptBudgetList.netWeight = Number(
          this.deptBudgetList.grossWeight - this.deptBudgetList.tare
        )
      }
    },
    selectgoodsName(e) {
      for (var i = 0; i < this.goodnameList.length; i++) {
        if (this.goodnameList[i].constValue == e) {
          this.deptBudgetList.goodsNameKey = this.goodnameList[i].constKey
        }
      }
    },
    selectpackingMethod(e) {
      for (var i = 0; i < this.packtypeList.length; i++) {
        if (this.packtypeList[i].constValue == e) {
          this.deptBudgetList.packingMethodKey = this.packtypeList[i].constKey
        }
      }
    },
    selectstorageType(e) {
      for (var i = 0; i < this.storageType.length; i++) {
        if (this.storageType[i].constValue == e) {
          this.deptBudgetList.inOutTypeKey = this.storageType[i].constKey
        }
      }
    },
    handleClose() {
      this.accessoryTFs = false
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      console.log(`当前页: ${val}`)
      this.getList()
    },
    getList() {
      // 货名
      pullDown({ constId: 'CON2' })
        .toPromise()
        .then((response) => {
          this.goodnameList = response
        })
      // 品级
      pullDown({ constId: 'CON3' })
        .toPromise()
        .then((response) => {
          this.gradeList = response
        })
      // 类型
      pullDown({ constId: 'CON5' })
        .toPromise()
        .then((response) => {
          this.storageType = response
        })
    },
    selecttaskType(e) {
      for (var i = 0; i < this.taskTypeList.length; i++) {
        if (this.taskTypeList[i].value == e) {
          this.searchType = this.taskTypeList[i].type
        }
      }
    },
    fujian(row) {
      if (
        row.receiveAttachmentPath === null ||
        row.receiveAttachmentPath === ''
      ) {
        EventBus.$emit(
          'warning',
          this.$t('system.noticeCircular.NoInformation')
        )
      } else {
        this.accessoryTFs = true
      }
      this.appendixIdss = row.receiveAttachmentPath
    },
    handleExamine(row) {
      this.$router.push({
        name: 'salesContractExamine',
        query: { id: row.id },
      })
    },

    // 关闭 dialog时 处理文件url 初始化upload组件
    handleCloe() {
      this.dialogViewSpareMoney = false
    },
    history(row) {
      console.log(row)
      billoperatehis({ id: row.id })
        .toPromise()
        .then((response) => {
          this.historyList = response
        })
    },
    // deletecontract(){},
    //删除
    approve() {},
    listQuery() {},
  },
}
</script>
<style lang="scss" scoped>
/deep/.basicInformation {
  .ws-info-table {
    border: none;
  }
  .el-form-item {
    width: 33.3333%;
    border: none;
    .el-form-item__label {
      background: transparent;
      border: none;
    }
    .el-form-item__content {
      border: none;
    }
  }
}
.title {
  position: relative;
  padding-left: 10px;
}
.title::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 30px;
  background: #5473e8;
  position: absolute;
  left: 0;
}
.el-form {
  padding: 0 10%;
}
.el-button--primary {
  background-color: #5878e8;
  border-color: #5878e8;
}
.el-col {
  background: #f6f7fc;
}
.bg-right {
  text-align: right;
  padding: 16px 20px;
}
.center {
  position: relative;
  top: 50px;
  width: 40%;
  height: 2000px;
  margin: 0 auto;
}
/deep/.el-form-item__label {
  width: 160px;
}
/deep/.el-input--small {
  width: 70%;
}
//选填
/deep/.el-form-item {
  width: 50%;
}
.container {
  overflow: scroll;
  height: 120vh;
}

/deep/.ws-info-table .el-form-item .el-form-item__label {

  text-align: center;
}
.deliverydate {
  width: 35%;
}
.center {

  margin-top: -60px;
}
</style>
