<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()"
          ><img
            width="6"
            height="10"
            style="vertical-align: bottom; margin-right: 3px"
            src="../../../public/img/lujing.png"
            alt=""
          />返回</el-button
        >
      </el-col>
    </el-row>
    <ws-form ref="deptBudgetList" :v-model="deptBudgetList">
      <div class="center">
        <h2 style="padding-left: 20px">
          <img
            style="position: relative; top: 2px"
            width="19"
            height="19"
            src="../../../public/img/cangku.png"
            alt=""
          />
          {{ this.$route.query.warehouseName }}
          <span class="position" v-show="this.$route.query.warehouseType == 1">
            {{ this.$route.query.binNumber }}仓位
          </span>
          <span v-show="this.$route.query.warehouseType == 2">(临)</span>
        </h2>
        <el-table :data="improved.records">
          <el-table-column type="index" label="序号">
            <template scope="scope">
              <span v-if="scope.$index < 9">0{{ scope.$index + 1 }}</span>
              <span v-else>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="goodsName" label="货名"> </el-table-column>
          <el-table-column
            prop="grossWeight"
            label="毛重（吨）"
          ></el-table-column>
          <el-table-column prop="tare" label="皮重（吨）"> </el-table-column>
          <el-table-column
            prop="netWeight"
            label="净重（吨）"
          ></el-table-column>
          <el-table-column prop="grade" label="品级">
            <template slot-scope="scope">
              <span v-if="scope.row.grade == '一等品'" class="top-grade">{{
                scope.row.grade
              }}</span>
              <span v-if="scope.row.grade == '二等品'" class="second-class">{{
                scope.row.grade
              }}</span>
              <span v-if="scope.row.grade == '三等品'" class="third-class">{{
                scope.row.grade
              }}</span>
              <span v-if="scope.row.grade == '等外'" class="substandard">{{
                scope.row.grade
              }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="inOutDate" label="出入库日期">
          </el-table-column>
          <el-table-column prop="inOutType" label="类型"> </el-table-column>
          <el-table-column prop="contractNo" label="合同编号">
          </el-table-column>
          <el-table-column prop="carNo" label="车牌号"> </el-table-column>
          <el-table-column prop="agent" label="经办人"> </el-table-column>
          <el-table-column prop="backOffice" label="内勤"> </el-table-column>
          <el-table-column prop="updateDate" label="保存时间">
          </el-table-column>
          <el-table-column prop="address" label="操作" width="200">
            <template slot-scope="scope">
              <div class="record" @click="edits(scope.row)">编辑</div>
              <div class="adjustment" @click="handleDelete(scope.row)">
                删除
              </div>
            </template>
          </el-table-column>
        </el-table>
<div style='text-align:center;'>
   <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="deptBudgetTotal"
    >
    </el-pagination>
</div>
       
      </div>
    </ws-form>
  </div>
</template>
<script>
import {
  complete,
  delInOut,
  completeList,
  // deletewarehouse,
  // warehouseName,
  // addstorageputList,
} from '@/model/warehouse/index'
// import { downloadFile } from '@/utils/batchDown'
import Pagination from '@/components/Pagination'
import WsUpload from '@/components/WsUpload'
import { dayjs } 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,
      deletewarehouse: [],
      improved: [],
      row: [],
      deptBudgetList1: [],
      // 提交类型
      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: [],
      // inOutDate:null,
      pickerBeginDateBefore: {
        disabledDate: (time) => {
          return time.getTime() > Date.now()
        },
      },
      accessoryTFs: false,
    }
  },
  activated() {
    //cg.viewBudget
    //cg.viewSpareMoney
    // this.getVesselData();
    this.deptBudgetList1.warehouseName = this.$route.query.warehouseName
    this.binNumber = this.$route.params.binNumber
    this.deptBudgetList.warehouseType = this.$route.query.warehouseType
    this.createType=this.$route.query.createType,
    //接参
    this.getList(
      this.$route.query.baseId,
      this.$route.query.positionId,
      this.$route.query.warehouseType
    )
    this.showType = this.isShow
  },
  methods: {
    //返回按钮
    returnWarehouse() {
      this.$router.go(-1)
    },
    //编辑
    edits(row) {
      if (row.inOutFlag == 2) {
        this.$store.dispatch('app/setdeptBudgetList', row)
        this.$router.push({
          path: 'warehouseManagementPerfectput',
          query: {
            id: row.id,
            agent: row.agent,
            baseId: row.baseId,
            binNumber: row.binNumber,
            carNo: row.carNo,
            compId: row.compId,
            contractNo: row.contractNo,
            goodsName: row.goodsName,
            goodsNameKey: row.goodsNameKey,
            grade: row.grade,
            grossWeight: row.grossWeight,
            inOutDate: row.inOutDate,
            inOutFlag: row.inOutFlag,
            inOutType: row.inOutType,
            inOutTypeKey: row.inOutTypeKey,
            netWeight: row.netWeight,
            positionId: row.positionId,
            statusFlag: row.statusFlag,
            tare: row.tare,
            warehouseName: row.warehouseName,
            warehouseInOutDetail: row.warehouseInOutDetail,
            warehouseType: this.deptBudgetList.warehouseType,
            createType: this.createType,
            temporaryOutType : row.temporaryOutType,
            cost:row.cost,
            freight:row.freight,
            type:row.type,
            buckleWeightRatio:row.buckleWeightRatio,
            tidalGrainWater:row.tidalGrainWater,
            solidGrainWater:row.solidGrainWater,
            pureWeight:row.pureWeight,
            deductionAmount:row.deductionAmount,
            deductionWeight:row.deductionWeight
          },
        })
      } else if (row.inOutFlag == 1) {
        this.$store.dispatch('app/setdeptBudgetList', row)
        // this.$store.commit('deptBudgetList',row)
        this.$router.push({
          path: 'warehouseManagementPerfectDelivery',
          query: {
            id: row.id,
            agent: row.agent,
            baseId: row.baseId,
            binNumber: row.binNumber,
            carNo: row.carNo,
            compId: row.compId,
            contractNo: row.contractNo,
            goodsName: row.goodsName,
            goodsNameKey: row.goodsNameKey,
            grade: row.grade,
            grossWeight: row.grossWeight,
            inOutDate: row.inOutDate,
            inOutFlag: row.inOutFlag,
            inOutType: row.inOutType,
            inOutTypeKey: row.inOutTypeKey,
            netWeight: row.netWeight,
            positionId: row.positionId,
            statusFlag: row.statusFlag,
            tare: row.tare,
            warehouseName: row.warehouseName,
            warehouseInOutDetail: row.warehouseInOutDetail,
            warehouseType: this.deptBudgetList.warehouseType,
            temporaryOutType : this.temporaryOutType,
            cost:row.cost,
            freight:row.freight,
            type:row.type,
            buckleWeightRatio:row.buckleWeightRatio,
            tidalGrainWater:row.tidalGrainWater,
            solidGrainWater:row.solidGrainWater,
            pureWeight:row.pureWeight,
            deductionAmount:row.deductionAmount,
            deductionWeight:row.deductionWeight
          },
        })
      }
    },
    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(id, id1, id2) {
      if (id2 == 1) {
        complete({
          // compId: sessionStorage.getItem('ws-pf_compId'),
          baseId: id,
          positionId: id1,
          pageSize: this.pageSize,
          currentPage: this.currentPage,
          // inOutDate:this.inOutDate
        })
          .toPromise()
          .then((response) => {
            this.deptBudgetTotal=response.total
            this.improved = response
          })
      } else if (id2 == 2) {
        completeList({
          baseId: id,
          positionId: id1,
          pageSize: this.pageSize,
          currentPage: this.currentPage,
        })
          .toPromise()
          .then((response) => {
            this.improved = response
          })
      }
    },
    handleExamine(row) {
      this.$router.push({
        name: 'salesContractExamine',
        query: { id: row.id },
      })
    },
    //删除
    handleDelete(row) {
      this.$confirm(`删除后不可恢复，确认删除？`, {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'warning',
      })
        .then(() => {
          delInOut({ id: row.id })
            .toPromise()
            .then((response) => {
              this.$notify.success({
                title: '成功',
                message: '删除成功',
              })
              this.getList(
                row.baseId,
                row.positionId,
                this.$route.query.warehouseType
              )
            })
            .catch((response) => {})
        })
        .catch(() => {
          return false
        })
    },
  },
  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()
  },
  // deletecontract(){},
  //删除
  approve() {},
  listQuery() {},
  total() {},
  clearfiltQuery() {},
  selectCrtDuty() {},
}
</script>
<style lang="scss" scoped>
.center {
  position: relative;
  top: 50px;
  width: 90%;
  height: 500px;
  margin: 0 auto;
}
.container .bg-left {
  margin-left: 40px;
}
.container .bg-bottom {
  position: absolute;
  float: right;
  top: 15px;
  right: 20px;
}
.vertical-text-left {
  width: 62px;
  text-align: right;
}
/deep/.el-form-item {
  width: 33%;
}
.el-row {
  background: #f6f7fc;
  // box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.5);
  border-radius: 4px 4px 1px 1px;
}
.container .bg-bottom {
  width: 74px;
  height: 32px;
  background: #5473e8;
  border-radius: 4px;
}
.bg-bottom {
  margin-top: 5px 0px;
}
.el-table .el-table__header tr {
  width: 1091px;
  height: 50px;
  background: #f6f7fc;
  border: 1px solid #e8ecf6;
  text-align: center;
}
.el-table .cell {
  text-align: center;
  width: 29px;
  height: 20px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #5878e8;
  line-height: 20px;
}
.default .winseaview-main .el-table th > .cell {
  color: #8890b1;
}
.record,
.adjustment {
  display: inline-block;
  color: #5878e8;
  padding: 0 4px !important;
  position: relative;
}
/deep/.el-table td,
.el-table th {
  text-align: center;
}
/deep/.el-table .el-table__header th {
  border-bottom-width: 0px;
  text-align: center;
}
.top-grade {
  background: linear-gradient(90deg, #5678e9, #7993f6);
  color: #fff;
  padding: 3px;
  border-radius: 2px;
}
.second-class {
  background: linear-gradient(90deg, #50cdd9, #82e2ea);
  color: #fff;
  padding: 3px;
  border-radius: 2px;
}
.third-class {
  background: linear-gradient(90deg, #ffa735, #ffbf70);
  color: #fff;
  padding: 3px;
  border-radius: 2px;
}
.substandard {
  background: linear-gradient(90deg, #b2b4bb, #ced0d5);
  color: #fff;
  padding: 3px;
  border-radius: 2px;
}
// .container .bg-left{
// width: 663px;
// height: 28px;
// font-size: 18px;
// font-family: PingFangSC-Medium, PingFang SC;
// font-weight: 500;
// color: #262626;
// line-height: 28px;
// text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.5);
// }
.a {
  width: 19px;
  height: 19px;
  background: #afb5cb;
  margin-left: 10px;
}
.container .bg-left {
  width: 140px;
  height: 29px;
  font-size: 21px;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  color: #323233;
  line-height: 29px;
}
.position {
  width: 52px;
  height: 20px;
  background: #afb5cb;
  border-radius: 2px;
  font-size: 12px;
  font-family: PingFangSC-Medium, PingFang SC;
  color: #ffffff;
  line-height: 20px;
}
</style>
