<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>
    <div class="center">
      <h2>鲅鱼圈一号库  102仓位</h2>
      <ws-form ref="deptBudgetList" :model="deptBudgetList">
        <!-- 货名 -->
        <ws-form-item label="货名" span="1"  class="readonly">
          <ws-select
           
            placeholder=""
            class="typeselect"
            @change="selectpackingMethod"
          >
            <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="shippingType">
          <ws-input
            v-model="deptBudgetList.shippingType"
            placeholder="当期累计入库量（吨）"
            maxlength="20"
            size="small"
          />
        </ws-form-item>

        <!--当期累计出库量（吨）-->
        <ws-form-item
          label="当期累计出库量（吨）"
          span="1"
          prop="buyer"
          class="readonly"
        >
          <ws-input
            v-model="deptBudgetList.buyer"
            placeholder="当期累计出库量（吨）"
            maxlength="100"
            size="small"
          />
        </ws-form-item>

        <!--应余库存（吨）-->
        <ws-form-item label="应余库存（吨）" span="1" prop="settlementMethod">
          <ws-input
            v-model="deptBudgetList.settlementMethod"
            placeholder="应余库存（吨）"
            maxlength="120"
            size="small"
          />
        </ws-form-item>

        <!--实际库存（吨）-->
        <ws-form-item
          label="实际库存（吨）"
          span="1"
          prop="seller"
          class="readonly"
        >
          <ws-input
            v-model="deptBudgetList.seller"
            placeholder="实际库存（吨）"
            maxlength="100"
            size="small"
          />
        </ws-form-item>

        <!--损耗量（吨）-->
        <ws-form-item label="损耗量（吨）" span="1" prop="sourceGoods">
          <ws-input
            v-model="deptBudgetList.sourceGoods"
            placeholder="损耗量（吨）"
            maxlength="20"
            size="small"
          />
        </ws-form-item>

        <!--库损比例-->
        <ws-form-item label="库损比例" span="1" prop="contractNo">
          <ws-input
            v-model.number="deptBudgetList.buyerPhone"
            placeholder="库损比例"
            maxlength="100"
            size="small"
          />
        </ws-form-item>
        <p>注：提交成功后，当期实际库存将作为下一期的初始库存。</p>
      </ws-form>

      <div style="text-align: right; padding: 10px">
        <el-button
          class="bg-bottom-up"
          type="primary"
          size="small"
          @click="submit()"
          >提交</el-button
        >
      </div>
    </div>
  </div>
</template>
<script>
import {
  getList,
  export1,
  billoperatehis,
} from '@/model/contarct/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,
      // 提交类型
      submitType: true,
      selectpackingMethod: {},
      size: 10,
      compId: sessionStorage.getItem('ws-pf_compId'),
      deptCircularPage: {},
      packtypeList: {},
      date: {
        year: dayjs().format('YYYY'),
        month: dayjs().format('MM'),
      },
      contractList: [],
      deptBudgetList: {},
      historyList: [],

      pickerBeginDateBefore: {
        disabledDate: (time) => {
          return time.getTime() > Date.now()
        },
      },
      accessoryTFs: false,
    }
  },
  activated() {
    //cg.viewBudget
    //cg.viewSpareMoney
    // this.getVesselData();
    this.getList()
    this.showType = this.isShow
  },
  methods: {
    //返回按钮
    returnWarehouse() {
      this.$router.push({ path: 'warehouseManagementList' })
    },
    //提交按钮
    submit(){
      this.$router.push({ path: 'warehouseManagementList' })
    },
    dateFormat(fmt, date) {
      let ret
      const opt = {
        'Y+': date.getFullYear().toString(), // 年
        'm+': (date.getMonth() + 1).toString(), // 月
        'd+': date.getDate().toString(), // 日
        'H+': date.getHours().toString(), // 时
        // "M+": date.getMinutes().toString(),         // 分
        // "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
      }
      for (let k in opt) {
        ret = new RegExp('(' + k + ')').exec(fmt)
        if (ret) {
          fmt = fmt.replace(
            ret[1],
            ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')
          )
        }
      }
      return fmt
    },
    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() {
      getList({
        compId: sessionStorage.getItem('ws-pf_compId'),
        contractType: this.contractType,
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        searchType: this.searchType,
        searchKeyWord: this.searchKeyWord,
        startDate: this.startDate,
        endDate: this.endDate,
        contrPage: this.contrPage,
      })
        .toPromise()
        .then((response) => {
          for (var i = 0; i < response.records.length; i++) {
            if (response.records[i].addressUrl != null) {
              response.records[i].addressUrlArray = response.records[
                i
              ].addressUrl.split(',')
            } else {
              response.records[i].addressUrlArray = []
            }
          }
          this.deptCircularPage.currentPage = response.current
          this.deptCircularPage.pageSize = response.size
          this.deptBudgetTotal = response.total
          this.contractList = 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
        })
    },
    find() {
      this.startDate = this.dateFormat('YYYY-mm-dd', this.value2[0])
      this.endDate = this.dateFormat('YYYY-mm-dd', this.value2[1])
      this.currentPage = 1
      this.getList()
    },
    async exportlist() {
      const { data } = await export1(
        {
          compId: sessionStorage.getItem('ws-pf_compId'),
          contractType: this.contractType,
          currentPage: this.currentPage,
          pageSize: this.pageSize,
          searchType: this.searchType,
          searchKeyWord: this.searchKeyWord,
          startDate: this.startDate,
          endDate: this.endDate,
        },
        {},
        { responseType: 'blob' }
      ).toPromise()
      downloadFile({
        res: data,
        fileName: `${
          this.date.year + (this.date.month ? `-${this.date.month}` : '')
        }_采购合同`,
        type: 'xls',
      })
    },
    // deletecontract(){},
    //删除
    approve() {},
    listQuery() {},
    total() {},
    clearfiltQuery() {},
    selectCrtDuty() {},
  },
}
</script>
<style lang="scss" scoped>
.center {
  position: relative;
  margin-top: 100px;
  top: 100px;
  width: 40%;
  height: 700px;
  margin: 0 auto; 
}
/deep/.el-form-item__label {
    width: 160px;
}
/deep/.el-input--small{
  width: 70%;
}
.container .bg-bottom {
  position: absolute;
  float: right;
  top: 15px;
  right: 20px;
}
</style>
