//采购入库报表
<template>
  <div class="container">
    <el-scrollbar style="height:100%">
      <el-scrollbar style="width:130%">
        <el-row>
          <el-col :span="12">
            <h2 class="bg-left title"></h2>
          </el-col>
          <el-col :span="12" class="bg-right">
            <el-button class="bg-bottom" type="primary" size="small" @click="revert()">
              <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> -->
        <div>
          <ws-button type="primary" @click="handleAdd()">待审核</ws-button>
          <ws-button type="primary" @click="handleAdd()">待结算</ws-button>
          <ws-button type="primary" @click="handleAdd()">已结算</ws-button>
          <ws-button type="primary" @click="handleAdd()">全部</ws-button>
          <ws-button type="primary" @click="handleAdd()">通过</ws-button>
          <ws-button type="primary" @click="handleAdd()">驳回</ws-button>
          <ws-button type="primary" @click="dialogFormVisible1=true">付款</ws-button>
          <el-dialog
            width="25%"
            title="付款"
            :visible.sync="dialogFormVisible1"
            :append-to-body="true"
          >
            <el-form :model="form">
              <el-form-item label="未付金额（元）" :label-width="formLabelWidth">
                <!-- <el-input v-model="form.region" autocomplete="off" class="deal"></el-input> -->
              </el-form-item>
              <el-form-item label="补充金额" :label-width="formLabelWidth">
                <el-input
                  v-model="form.region"
                  autocomplete="off"
                  placeholder="请输入补充金额"
                  class="deal"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="付款日期"
                prop="submissionDate"
                :label-width="formLabelWidth"
                class="deal"
              >
                <ws-date-picker
                  v-model="deptBudgetList.submissionDate"
                  type="date"
                  placeholder="请选择付款日期"
                  value-format="yyyy-MM-dd"
                  class="deal"
                />
              </el-form-item>
              <el-form-item label="上传付款截图" :label-width="formLabelWidth">
                <el-upload
                  action="https://www.zthymaoyi.com/upload/admin"
                  list-type="picture-card"
                  :on-preview="handlePictureCardPreview"
                  :on-remove="handleRemove"
                  class="photo2"
                >
                  <i class="el-icon-plus"></i>
                </el-upload>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible1 = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible1= false">提 交</el-button>
            </div>
          </el-dialog>
          <!-- 开发票 -->
          <ws-button type="primary" @click="dialogFormVisible2=true">开发票</ws-button>
          <el-dialog
            width="30%"
            title="批量开发票"
            :visible.sync="dialogFormVisible2"
            :append-to-body="true"
          >
            <el-form :model="form">
              <el-form-item label="发票类型" :label-width="formLabelWidth">
                <el-select v-model="form.name" autocomplete="off" class="deal"></el-select>
              </el-form-item>
              <el-form-item label="发票金额（元）" :label-width="formLabelWidth">
                <el-input v-model="form.region" autocomplete="off" class="deal"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible2 = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible2 = false">提 交</el-button>
            </div>
          </el-dialog>
          <!-- 开发票 -->
          <el-dialog
            width="30%"
            title="开发票"
            :visible.sync="dialogFormVisible2"
            :append-to-body="true"
          >
            <el-form :model="form">
              <el-form-item label="发票类型" :label-width="formLabelWidth">
                <el-select v-model="form.name" autocomplete="off" class="deal"></el-select>
              </el-form-item>
              <el-form-item label="可开发票金额（元）" :label-width="formLabelWidth">
                <!-- <el-input v-model="form.region" autocomplete="off" class="deal"></el-input> -->
              </el-form-item>
              <el-form-item label="实际发票金额（元）" :label-width="formLabelWidth">
                <el-input v-model="form.region" autocomplete="off" class="deal"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible2 = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible2 = false">提 交</el-button>
            </div>
          </el-dialog>
          <ws-button type="primary" @click="dialogFormVisible5=true">修改</ws-button>
          <el-dialog
            width="30%"
            title="修改"
            :visible.sync="dialogFormVisible5"
            :append-to-body="true"
          >
            <el-form :model="form">
              <el-form-item label="单价" :label-width="formLabelWidth">
                <el-input v-model="form.name" autocomplete="off" class="deal"></el-input>
              </el-form-item>
              <el-form-item label="基差" :label-width="formLabelWidth">
                <el-input v-model="form.region" autocomplete="off" class="deal"></el-input>
              </el-form-item>
              <el-form-item label="卸车费" :label-width="formLabelWidth">
                <el-input v-model="form.region" autocomplete="off" class="deal"></el-input>
              </el-form-item>
              <el-form-item label="发票费" :label-width="formLabelWidth">
                <el-input v-model="form.region" autocomplete="off" class="deal"></el-input>
              </el-form-item>
              <el-form-item label="扣款" :label-width="formLabelWidth">
                <el-input v-model="form.region" autocomplete="off" class="deal"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible5 = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible5 = false">提 交</el-button>
            </div>
          </el-dialog>
          <ws-button type="primary" @click="dialogFormVisible11 = true">补货结转</ws-button>
          <el-dialog
            width="30%"
            title="补货结转"
            :visible.sync="dialogFormVisible11"
            :append-to-body="true"
          >
            <el-form :model="form">
              <el-button @click="dialogFormVisible5 = false">本合同</el-button>
              <el-button @click="dialogFormVisible5 = false">其他合同</el-button>
              <el-form-item label="合同编号" :label-width="formLabelWidth">
                <el-select v-model="form.name" autocomplete="off" class="deal"></el-select>
              </el-form-item>
              <el-form-item label="结转重量" :label-width="formLabelWidth">
                <el-input v-model="form.name" autocomplete="off" class="deal" placeholder="请输入结转重量"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible11 = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible11= false">确认</el-button>
            </div>
          </el-dialog>
          <ws-button type="primary" @click="handleAdd()">审核</ws-button>
          <ws-select
            v-model="searchKeyWord"
            placeholder="可按照合同编号和任务编号进行查找"
            clearable
            maxlength="500"
            type="input"
            class="findValue"
          ></ws-select>
        </div>

        <span>合同重量:吨</span>
        <span>成交量:吨</span>
        <span>已平仓:吨</span>
        <span>入库量:吨</span>
        <el-table
          class="wenzi"
          :data="warehouseList.records"
          style="width: 100%; margin-top: 20px"
          height="780"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column type="index" label="序号" width="50"></el-table-column>
          <el-table-column class="table_td" prop="contractNo" label="合同编号"></el-table-column>
          <el-table-column class="table_td" prop="procurementPlan" label="货名"></el-table-column>
          <el-table-column class="table_td" prop="customer" label="仓位号"></el-table-column>
          <el-table-column class="table_td" prop="unitPrice" label="车牌号"></el-table-column>
          <el-table-column class="table_td" prop="basis" label="入库日期"></el-table-column>
          <el-table-column class="table_td" prop="freezingDeposit" label="蛋白(%)>="></el-table-column>
          <el-table-column class="table_td" prop="defaultDeposit" label="水分(%)>="></el-table-column>
          <el-table-column class="table_td" prop="unloadingCharge" label="单价(元/吨)"></el-table-column>
          <el-table-column class="table_td" prop="invoiceFee" label="基差(元/吨)"></el-table-column>
          <el-table-column class="table_td" prop="send" label="卸车费(元/吨)"></el-table-column>
          <el-table-column class="table_td" prop="stockInQuantity" label="发票费(元/吨)"></el-table-column>
          <el-table-column class="table_td" prop="openPosition" label="扣款(元/吨)"></el-table-column>
          <el-table-column class="table_td" prop="closedPosition" label="结算单价(元/吨)"></el-table-column>
          <el-table-column class="table_td" prop=" cumulativeTurnover" label="净重(吨)"></el-table-column>
          <el-table-column class="table_td" label="应付金额(元)" prop="type"></el-table-column>
          <el-table-column class="table_td" label="已付金额(元)"></el-table-column>
          <el-table-column class="table_td" label="未付金额(元)" prop="type"></el-table-column>
          <el-table-column class="table_td" label="付款日期"></el-table-column>
          <el-table-column class="table_td" label="结转"></el-table-column>
          <el-table-column class="table_td" label="客户确认"></el-table-column>
          <el-table-column class="table_td" label="客户"></el-table-column>
          <el-table-column class="table_td" label="库点"></el-table-column>
          <el-table-column class="table_td" label="发票类型"></el-table-column>
          <el-table-column class="table_td" label="已开发票(元)"></el-table-column>
          <el-table-column prop="status" label="状态"></el-table-column>
        </el-table>

        <!-- 页数 -->
        <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>
      </el-scrollbar>
    </el-scrollbar>
  </div>

  <!-- </div> -->
</template>
<script>
import {
  detailsList,
  chengList,
  closePositionList
} from '@/model/purchasingManagement/index'
import { downloadFile } from '@/utils/batchDown'
import Pagination from '@/components/Pagination'
import WsUpload from '@/components/WsUpload'
import { dayjs, fmoney, EventBus } from 'base-core-lib'
export default {
  name: 'viewSpareMoney',
  components: {
    WsUpload,
    Pagination
  },
  watch: {
    vesselId(val) {
      this.getList()
    },
    isShow(val) {
      this.showType = val
    }
  },

  data() {
    return {
      checked: true,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      dialogFormVisible4: false,
      dialogFormVisible5: false,
      dialogFormVisible6: false,
      dialogFormVisible7: false,
      dialogFormVisible8: false,
      dialogFormVisible11: false,
      dialogVisible: false,

      form: {
        transactionPrice: '',
        transactionsNumber: '',
        basis: '',
        submissionDate: ''
        // delivery: false,
        // type: [],
        // resource: '',
        // desc: ''
      },
      formLabelWidth: '120px',

      barWidth: 0,
      barHeight: 0,
      retioX: 1,
      ratioY: 1,
      isTaped: false,
      isHover: false,
      isShow: !this.autohide,
      //弹出框
      dialogViewSpareMoney: false,
      dialogApproveFormVisible: false,
      // 船舶类型
      monetaryKey: null,
      // 表格显示数据
      tableDate: [],

      // 是否显示
      showType: true,
      // 年
      year: '',
      pickerOptions: {},
      value2: '',
      deptBudgetTotal: 0,
      currentPage: 1,
      tranTypeKey: 1,
      pageSize: 10,
      searchType: 1,
      searchTypeText: '未完成',
      searchKeyWord: '',
      contractType: 2,
      enter: {
        closePositionList: []
      },
      // taskTypeList:[
      //   {value:'待审核',type:1},
      //   {value:'已完成',type:2},
      //   {value:'已通过',type:3},
      //   {value:'已成交',type:4},
      // ],

      // 提交类型
      submitType: true,
      size: 10,
      spanArr: [],
      contractNo: '',
      inOutTaskNo: '',
      compId: sessionStorage.getItem('ws-pf_compId'),
      deptCircularPage: {},
      warehouseList: [],
      deptBudgetList: {},
      pcFlag: 1,
      historyList: [],
      pickerBeginDateBefore: {
        disabledDate: time => {
          return time.getTime() > Date.now()
        }
      },
      accessoryTFs: false
    }
  },
  activated() {
    // this.loaddata()
    this.getList()
    this.showType = this.isShow
  },
  methods: {
    //成交
    submit() {
      if (!this.warehouseList.transactionPrice) {
        this.$message({
          message: '成交价不能为空',
          type: 'warning'
        })
        return
      }
      this.$confirm(`确定提交成交信息`, {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'warning'
      }).then(() => {
        console.log(23456678790)
        // chengList({
        //    id: this.id,
        //    compId: sessionStorage.getItem('ws-pf_compId'),
        //    transactionPrice: this.transactionPrice,
        //    transactionsNumber: this.transactionsNumber,
        //    basis: this.basis,
        // })
        chengList(this.warehouseList)
          .toPromise()
          .then(response => {
            this.$message.success('添加成功')

            // this.$router.go(-1)
          })
          .catch(() => {
            console.log(1111111111)
            return false
          })
      })
    },
    getList() {
      console.log(123456)
      detailsList({
        compId: sessionStorage.getItem('ws-pf_compId'),
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        pcFlag: this.pcFlag,
        searchType: this.searchType,
        searchKeyWord: this.searchKeyWord
      })
        .toPromise()
        .then(response => {
          this.warehouseList = response
        })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleRemove(file) {
      console.log(file)
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    handleDownload(file) {
      console.log(file)
    },

    // statusquery(state) {
    //   this.searchType = state
    //   this.getList()
    // },
    // delivery(item) {
    //   this.$router.push({
    //     path: 'warehouseManagementDelivery',
    //     query: {
    //       baseId: item.warehouseId,
    //       positionId: item.binNumberId,
    //       warehouseName: item.warehouseName,
    //       binNumber: item.binNumber,
    //       capacity: item.capacity
    //     }
    //   })
    // },
    getSpanArr(data) {
      let that = this

      //页面展示的数据，不一定是全部的数据，所以每次都清空之前存储的 保证遍历的数据是最新的数据。以免造成数据渲染混乱

      that.spanArr = []

      that.pos = 0

      // //遍历数据

      data.forEach((item, index) => {
        //判断是否是第一项

        if (index === 0) {
          this.spanArr.push(1)
          this.pos = 0
        } else {
          //不是第一项时，就根据标识去存储
          if (data[index].warehouseNumViewList.length > 1) {
            查找到符合条件的数据时每次要把之前存储的数据 + 1
            this.spanArr[this.pos] = data[index].warehouseNumViewList.length
            this.spanArr.push(0)
          } else {
            // 没有符合的数据时，要记住当前的index
            this.spanArr.push(1)
            this.pos = index
          }
        }
      })
    },
    //查看
    handleLook(row) {
      this.$router.push({
        path: 'warehouseManagementPutOutLook',
        query: {
          relevanceId: row.relevanceId
        }
      })
    },
    //返回
    revert() {
      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()
    },
    editClick(row) {
      var status = ''
      if (row.status == '待审核' || row.status == '已完成') {
        status = '执行中'
      } else if (row.status == '执行中') {
        status = '已完成'
      }
      //cancelButtonClass: "btn-custom-cancel"
      this.$confirm(`是否将状态改为${status}`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          alsostate({ id: row.id })
            .toPromise()
            .then(response => {
              this.$notify.success({
                title: '成功',
                message: '状态修改成功'
              })
              this.getList()
            })
            .catch(response => {
              // EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
            })
        })
        .catch(() => {
          return false
        })
    },
    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) {
      billoperatehis({ id: row.id })
        .toPromise()
        .then(response => {
          this.historyList = response
        })
    },
    //查找
    find() {
      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'
      })
    },
    total() {}
  }
}
</script>
<style lang="scss" scoped>
.connert {
  width: 90%;
  margin: 0 auto;
}
.vertical-text-left {
  width: 62px;
  text-align: right;
}
//分页
.el-pagination {
  padding: 10px 15px;
  margin-bottom: 0;
  text-align: center;
}
/deep/.el-pager li.active {
  color: #5878e8;
  cursor: default;
}
/deep/.el-pager li:hover {
  color: #5878e8;
  cursor: default;
}
.el-button--primary {
  background-color: #5878e8;
  border-color: #5878e8;
}
.el-button--default {
  color: #8890b1;
  border-color: #e8eaf1;
}
/deep/.base_header_layout .grid-content.right .find.el-button--primary {
  width: 30px;
  margin-left: 0;
  border-top-left-radius: 0px;
  border-bottom-left-radius: 0px;
}
/deep/.findValue .el-input__inner {
  border-top-right-radius: 0px;
  border-bottom-right-radius: 0px;
  width: 385px;
}
.completed.el-button--default {
  border-color: #5878e8;
  background-color: #f6f7fc;
  color: #5878e8;
}
.putstorage.el-button--default,
.deliverystorage.el-button--default {
  border-color: #8890b1;
  background-color: #fff;
  color: #8890b1;
}
/deep/.el-table td,
/deep/.el-table th.is-leaf {
  border-right: 1px solid #e9ecf7;
  text-align: center;
}
/deep/.el-table tr td:first-child,
/deep/.el-table tr th.is-leaf:first-child {
  border-left: 1px solid #e9ecf7;
}
.record,
.adjustment {
  display: inline-block;
  color: #5878e8;
  padding: 0 4px !important;
  position: relative;
}
.record:after {
  position: absolute;
  content: '';
  display: block;
  top: 5px;
  right: -2px;
  width: 1px;
  height: 12px;
  background: #e9ecf7;
}
// .el-row{
//     height: 150px;
// }
.base_header_layout .grid-content {
  margin-top: 80px;
}
.el-input--small .el-input__inner {
  margin-left: 20px;
}
.el-range-editor--small.el-input__inner {
  height: 32px;
  margin-left: -20%;
}
//执行样式
.executory,
.inExecution,
.done {
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
  position: relative;
  top: -1px;
  font-size: 14px;
}
.executory {
  background: #ff9f24;
}
.inExecution {
  background: #5878e8;
}
.done {
  background: #50cad4;
}
.record,
.adjustment {
  display: inline-block;
  color: #5878e8;
  padding: 0 4px !important;
  position: relative;
  font-size: 14px;
}
.container {
  overflow: scroll;
  height: 93vh;
}
.button-container {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  width: 100%;
  height: 50px;
  padding: 0 10px;
  & > div {
    margin-left: 10px;
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    & > span {
      line-height: 50px;
    }
  }

  /deep/.auditFlow-box {
    position: unset;
    margin-left: 10px;
    &/deep/.auditFlow-icon {
      width: auto;
      padding-right: 30px;
    }
    &/deep/.auditFlow-main {
      position: absolute;
    }
  }
}
.bg-left {
  padding-left: 30px;
}
.title {
  position: relative;
}
.title::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 30px;
  background: #5473e8;
  position: absolute;
  left: 0;
}
.el-button--primary {
  background-color: #5878e8;
  border-color: #5878e8;
  // margin-left: 85%;
  margin-top: 20px;
}
//导航条样式
.el-col-12 {
  width: 50%;
  height: 60px;
  background: #f6f7fc;
  border-radius: 4px 4px 1px 1px;
}
.el-input--small .el-input__inner {
  height: 32px;
  line-height: 32px;
  width: 385px;
  margin-top: 10px;
}
.bg-bottom {
  margin-left: 85%;
}
.but {
  margin-left: 30%;
  /* margin-top: -32px; */
  overflow: auto;
  /* float: left; */
  /* margin-left: 1px; */
  margin-left: -10px;
}
.el-input--small {
  font-size: 13px;
  width: 390px;
  margin-left: 74%;
}
/deep/.el-table .el-table__header .cell,
.el-table .el-table__body .cell {
  text-align: center;
}
.el-scrollbar__wrap {
  overflow-y: hidden;
}
/deep/.deal {
  margin-left: 0%;
  width: 64%;
}
.photo {
  padding: 0% 34%;
}
.photo1 {
  padding: 0 10%;
}
.photo2 {
  padding: 0 12%;
}
/deep/.el-form-item--small .el-form-item__label,
.el-form-item--small .el-form-item__content {
  text-align: center;
}
hr {
  width: 91%;
}
/deep/.deaal {
  width: 66%;
  margin-left: 9%;
}
.el-date-editor.el-input,
.el-date-editor.el-input__inner,
.el-input-number--small {
  width: 123% !important;
}
// .danjia{
//   width: 9px;
//   height: 9px;
//   margin-left: 40px;
// }
</style>
