<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input size="mini" v-model="search.paperName" placeholder="纸张类型" style="width: 200px;" class="filter-item" />
      <el-input size="mini" v-model="search.actualPaperName" placeholder="实际发纸" style="width: 200px;" class="filter-item" />
      <el-input size="mini" v-model="search.billCode" placeholder="施工单号" style="width: 200px;" class="filter-item" />
      <el-button size="mini" class="filter-item" type="primary" icon="el-icon-search" @click="searchData">
        搜索
      </el-button>
      <el-button
        size="mini"
        class="filter-item"
        style="margin-left: 10px;"
        type="primary"
        icon="el-icon-refresh"
        @click="refreshBtn">
        刷新
      </el-button>
    </div>
    <div class="hline-table-con">
      <el-table
        max-height="700"
        class="tb-edit"
        :data="tableData"
        tooltip-effect="light"
        v-loading="tableLoading"
        :cell-style="columnStyle"
        :row-class-name="tableRowClassName"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        border
        :default-sort="{prop: 'paperName'}"
        size="mini"
      >
        <el-table-column
          label="#"
          fixed
          align="center"
          type="index"
          :index="indexMethod">
        </el-table-column>
        <el-table-column label="操作" fixed  align="left" width="250" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" v-if="scope.row.preOutLockState!=1" @click="lockPreOutPrint(scope.row.id,scope.row,scope.$index)" type="primary">
              锁
            </el-button>
            <el-button v-if="scope.row.preOutLockState==1" @click="unlockPreOutPrint(scope.row.id,scope.row,scope.$index)" type="warning" size="mini">
              解
            </el-button>
            <el-button :ref="`completeBtn-${scope.row.id}`" v-if="!remainingNum" @click="completePreOut(scope.row,scope.$index)" type="success" size="mini">
              完成
            </el-button>
            <el-button :disabled="scope.row.selfProvidedPaper==1" @click="preOutPurchase(scope.row,scope.$index)" type="primary" size="mini">
              请购
            </el-button>
            <el-button @click="forceCompletePre(scope.row,scope.$index)" type="danger" size="mini">
              不处理
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          fixed
          show-overflow-tooltip
          width="280px"
          label="实际发纸"
        >
          <template slot-scope="scope">
            <!--            <el-button v-if="scope.row.preOutLockState==1"  @click="checkPaper(scope.$index,scope.row)" size="mini">选择纸张-->
            <!--            </el-button>-->
            <el-button  v-if="scope.row.preOutLockState==1" size="mini" type="warning" @click="defaultStock(scope.row)" class="iconfont" title="默认纸张">&#xe62d;</el-button>
            <el-popover
              :ref="`popover-${scope.$index}`"
              v-if="scope.row.preOutLockState==1"
              placement="bottom"
              trigger="manual"
              width="740"
              >
              <div style="padding: 20px">
                <el-button
                  size="mini"
                  class="filter-item"
                  style="margin-left: 10px;float: right"
                  type="primary"
                  @click="handleCreateAdd">
                  增加纸张档案
                </el-button>
                <div style="clear: both"></div>
                <el-form size="mini">
                  <el-row :gutter="10">
<!--                    <el-col :span="24">-->
<!--                      <el-form-item label="用纸数量">-->
<!--                        <el-input v-model="form.preOutStockLockQty" autocomplete="off"></el-input>-->
<!--                      </el-form-item>-->
<!--                    </el-col>-->
                    <el-col :span="8">
                      <el-form-item label="克重">
                        <el-input @keyup.enter.native="checkPaperBtn" v-model="form.mtSuttle" autocomplete="off" type="number"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="关键字">
                        <el-input @keyup.enter.native="checkPaperBtn" v-model="form.keyWord" autocomplete="off"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="类型">
<!--                        <el-input  v-if="!ckeckPaperId" v-model="form.paperName" autocomplete="off"></el-input>-->
                        <el-select v-model="form.idPaperType" clearable filterable placeholder="请选择" style="width: 200px">
                          <el-option
                            v-for="item in typeOptions"
                            :key="item.id"
                            :label="item.paperTypeName"
                            :value="item.id">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="备注:">
                        <span>{{formBillMemo}}</span>
                      </el-form-item>
                    </el-col>

                  </el-row>
                </el-form>
                <el-button style="float: right;margin-left: 10px;" size="mini" @click="closePopover(scope.row,scope.$index)">关闭</el-button>
<!--                <el-button style="float: right" size="mini" @click="resetBtn">重置</el-button>-->
                <el-button  style="float: right;" size="mini" type="primary" @click="checkPaperBtn">搜索</el-button>
                <el-checkbox style="float: right;" size="mini" v-model="queryInStockBtn" label="查询在库" border></el-checkbox>

                <div style="clear: both"></div>
                <div style="line-height: 24px;width: 100%;margin-top: 20px;">
<!--                  <div v-for="(item,index) in paperData" :key="index" class="itemRoom">-->
<!--                    <span>{{item.paperInfo.paperName}}</span>-->
<!--                    <div v-for="(datas,indexs) in item.usageEntityList" :key="indexs">-->
<!--                      <div style="margin-left: 30px"><span @click="roomPaperBtn(item,indexs,scope.$index)" style="color: #409EFF;margin-right: 10px;cursor: pointer">点击选择</span>{{item.paperInfo.paperName}}</div>-->
<!--                    </div>-->
<!--                  </div>-->
                  <el-table
                    :height="heightTable"
                    :data="paperData"
                    size="mini"
                    tooltip-effect="light"
                    v-loading="listLoading"
                    infinite-scroll-disabled="disabled"
                    v-el-table-infinite-scroll="load"
                    v-if="paperData.length>0">
                    <el-table-column show-overflow-tooltip  width="210px" label="纸张名称" prop="paperInfo.paperName">
                    </el-table-column>
                    <el-table-column label="当前库存" prop="usageEntity.stockNum">
                      <template slot-scope="{row}">
                        {{ (row.usageEntity.stockNum*0.002).toFixed(3)}}
                      </template>
                    </el-table-column>
                    <el-table-column label="已锁定库存" prop="usageEntity.lockedNum">
                      <template slot-scope="{row}">
                        {{ (row.usageEntity.lockedNum*0.002).toFixed(3)}}
                      </template>
                    </el-table-column>
                    <el-table-column label="当前锁定库存" prop="usageEntity.currentLockNum">
                      <template slot-scope="{row}">
                        {{ (row.usageEntity.currentLockNum*0.002).toFixed(3)}}
                      </template>
                    </el-table-column>
                    <el-table-column label="剩余库存" prop="usageEntity.remainingNum">
                      <template slot-scope="{row}">
                        <span style="color: #409EFF" v-if="row.usageEntity.remainingNum>0">{{ (row.usageEntity.remainingNum*0.002).toFixed(3)}}</span>
                        <span v-if="row.usageEntity.remainingNum<0">{{ (row.usageEntity.remainingNum*0.002).toFixed(3)}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作">
                      <template slot-scope="{row}">
                        <el-button size="mini" @click="paperBtn(row,scope.$index)">选择</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
              <el-button @click="checkPaper(scope.$index,scope.row)" size="mini" slot="reference" icon="el-icon-search" title="选择纸张"></el-button>
            </el-popover>
            {{ scope.row.actualPaperName }}
          </template>
        </el-table-column>
        <el-table-column
          fixed
          label="施工单号"
          show-overflow-tooltip
          width="150px"
        >
          <template slot-scope="{row}">
            <span @click="getOrderStep(row.idPrintBill)" style="color: #409EFF;cursor: pointer" class="ellipsis"> {{row.printBillCode}}-{{row.breedName}}</span>
            <el-image v-if="row.importantBill == 1" :src="new_badge"></el-image>
          </template>
        </el-table-column>
        <el-table-column
          label="施工单名称"
          fixed
          width="90px"
          show-overflow-tooltip
        >
          <template slot-scope="{row}">
            <a  href="javascript:;" style="color: #20a0ff" @click="handleDetail(row.idPrintBill)" class="ellipsis"> {{ row.printBillName }}</a>
          </template>
        </el-table-column>
        <el-table-column
          label="施工单消息"
          fixed
          width="120px"
        >
          <template slot-scope="{row}">
            <template v-if="row.breedMsg">
              <el-button size="mini" circle icon="el-icon-plus" @click="openMessage(row)"></el-button>
              <el-tooltip :content="row.breedMsg" placement="top-start" effect="light">
                <a href="javascript:;" style="color: #20a0ff;width: 80px;display: inline-block;vertical-align:middle" @click="openMessage(row)" class="ellipsis"> {{ row.breedMsg }}</a>
              </el-tooltip>
            </template>
            <template v-else>
              <el-button size="mini" circle icon="el-icon-plus" @click="openMessage(row)"></el-button>
            </template>
          </template>
        </el-table-column>
        <el-table-column
          width="100"
          show-overflow-tooltip
          label="客户名称"
        >
          <template slot-scope="{row}">
            <el-tooltip :content="row.clientName" placement="top-start" effect="light">
              <span class="ellipsis"> {{ row.clientName }}</span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          label="印刷机台"
        >
          <template slot-scope="{row}">
            {{ row.machineTypeName }}
          </template>
        </el-table-column>
        <el-table-column
          width="140px"
          show-overflow-tooltip
          sortable
          :sort-by="['paperName']"
          label="纸张类型"
        >
          <template slot-scope="{row}">
            {{ row.paperName }}
          </template>
        </el-table-column>
        <el-table-column
          width="40"
          label="自带"
        >
          <template slot-scope="{row}">
            <span v-if="row.selfProvidedPaper==1">自带</span>
          </template>
        </el-table-column>
        <el-table-column
          label="用纸要求"
          align="center"
        >
          <template slot-scope="{row}">
            <span v-if="row.paperRequireFlag==1"><i style="color: #E6A23C;font-size: 16px" class="el-icon-success"></i></span>
          </template>
        </el-table-column>
        <el-table-column
          label="发纸张数"
          width="120px"
        >
          <template slot-scope="scope">
            <el-input
              v-if="scope.row.preOutLockState==1"
              v-show="scope.row.id==indexRowId"
              size="mini"
              style="display: inline-block;width: 70px"
              v-model.trim="scope.row.originWholePaperCount"
              placeholder=""
              @input="handleBlur(scope.row.id, scope.row.originWholePaperCount,scope.row)"></el-input>
            <span v-show="indexRowId!=scope.row.id">{{ scope.row.originWholePaperCount }}</span>
            <span v-show="indexRowId!=scope.row.id" @click="handleEdit(scope.row.id)" style="color: #409EFF;cursor: pointer" v-if="scope.row.preOutLockState==1" size="mini" round>&nbsp;&nbsp;修改</span>
<!--            <span v-show="scope.row.id==indexRowId" @click="handleComplete(scope.row.id,scope.row.wholePaperCount,scope.row)" style="color: #409EFF;cursor: pointer" v-if="scope.row.preOutLockState==1" size="mini" round>&nbsp;&nbsp;确定</span>-->
          </template>
        </el-table-column>

        <el-table-column
          label="发纸令数"
        >
          <template slot-scope="scope">
            <span>{{ (scope.row.originWholePaperCount/500).toFixed(3) }}</span>
          </template>
        </el-table-column>


        <el-table-column
          label="大纸尺寸"
        >
          <template slot-scope="{row}">
            {{ row.wholePaperSize }}
          </template>
        </el-table-column>
        <el-table-column
          label="下单日期"
          width="120px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.createTime">{{scope.row.createTime | getTime}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="交货日期"
          width="120px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.createTime">{{scope.row.deliveryDate | getTime}}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="纸张开数"
        >
          <template slot-scope="{row}">
            {{ row.cutName }}
          </template>
        </el-table-column>
        <el-table-column
          label="开纸尺寸"
        >
          <template slot-scope="{row}">
            {{row.cutSize}}
          </template>
        </el-table-column>



        <el-table-column
          label="施工单备注"
        >
          <template slot-scope="{row}">
            <el-tooltip content="" placement="top-start" effect="light">
              <span class="ellipsis"></span>
            </el-tooltip>
          </template>
        </el-table-column>

      </el-table>
      <pagination v-show="listData.total>0" :total="listData.total" :page.sync="listData.page" :limit.sync="listData.pageSize" @pagination="getTableInfo" />
    </div>
<!--    <el-dialog title="选择纸张" :visible.sync="dialogVisible" width="800px">-->
<!--      <el-table-->
<!--        :data="tableDataPaper"-->
<!--        v-loading="listLoading"-->
<!--        style="width: 100%;margin-bottom: 20px;"-->
<!--        row-key="id"-->
<!--        border>-->
<!--        <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button @click="choosePaperClick(scope.row)" type="primary" size="mini">-->
<!--              选择-->
<!--            </el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--          prop="paperName"-->
<!--          width="130px"-->
<!--          label="档案名称">-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--          prop="paperTypeName"-->
<!--          label="纸张类型">-->
<!--        </el-table-column>-->

<!--        <el-table-column-->
<!--          prop="mtSuttle"-->
<!--          label="克重">-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--          prop="priceType"-->
<!--          label="计价方式">-->
<!--          <template slot-scope="{row}">-->
<!--        <span v-if="row.priceType==0" type="success">-->
<!--          吨价-->
<!--        </span>-->
<!--            <span v-else-if="row.priceType==1" type="danger">-->
<!--          平方单价-->
<!--        </span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--          prop="priceType"-->
<!--          label="单价">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ scope.row.paperPrice }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->

<!--      </el-table>-->
<!--      <pagination-->
<!--v-show="listData2.total>0"-->
<!--:total="listData2.total"-->
<!--:page.sync="listData2.page"-->
<!--                  :limit.sync="listData2.pageSize"-->
<!--@pagination="getPaperInfo"/>-->
<!--    </el-dialog>-->
<!--    <el-dialog title="填写搜索条件" :visible.sync="dialogFormVisible" width="450px">-->

<!--    </el-dialog>-->
<!--    <el-dialog title="选择" :visible.sync="dialogPaperVisible" width="450px">-->

<!--    </el-dialog>-->
    <el-drawer
      title="施工单消息"
      :reverse="true"
      :visible.sync="memoDrawer"
      size="600px">
      <order-message @handleAddBreed="handleAddBreed" ref="orderMessage"></order-message>
    </el-drawer>
    <printbill-detail ref="printbillDetail"></printbill-detail>
    <print-step ref="printStep"></print-step>
    <el-dialog title="增加纸张档案" :close-on-click-modal="false" :visible.sync="dialogVisiblePaper" width="1300px">
      <el-form size="mini" label-width="130px" label-position="right">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="规格">
              <el-input v-model="formPaper.mtRule"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="纸张类型">
              <el-button @click="openChoose">{{basePaperName?basePaperName:'请选择'}}</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="品牌">
              <el-input v-model="formPaper.mtModel"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="采购单位">
              <el-input v-model="formPaper.byUnit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="库存单位">
              <el-input v-model="formPaper.mtUnit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="使用单位">
              <el-input v-model="formPaper.seUnit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="条形码">
              <el-input v-model="formPaper.barCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="备注">
              <el-input type="textarea" :rows="2" v-model="formPaper.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisiblePaper = false">取 消</el-button>
        <el-button :disabled="disabledBtn" type="primary" @click="addBtnPaper()">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" title="选择纸张类型" :visible.sync="paperInfoVisible" width="800px">
      <BasePaperInfo ref="choosePaper" :is-choose="true" @choosePaper='choosePaper'></BasePaperInfo>
    </el-dialog>
  </div>
</template>

<script>
import {
  getInfo,
  lockPreOutPrintBreed,
  unlockPreOutPrintBreed,
  completePreOutStockV2,
  preOutPurchaseRequestV2,
  searchPaperStock,
  defaultMaterialStock, forceCompletePreOutStockV2
} from '@/api/printbill/preOut/preOut.js'
import { getPaperTypeList } from '@/api/baseInfo/paper/paperType.js'
import {addPaperInfo } from '@/api/baseInfo/paper/paperInfo.js'
import { mapGetters } from 'vuex'
// import {lockWorkParts} from "@/api/printbill/editionList";
import { getPaperInfoList } from '@/api/baseInfo/paper/basePaperInfo'
import OrderMessage from '@/views/feedBack/orderMessage/orderMessage'
import printStep from "@/components/printbillDetail/printStep";
import PrintbillDetail from "@/components/printbillDetail/printbillDetail";
import elTableInfiniteScroll from "el-table-infinite-scroll";
import BasePaperInfo from '@/views/baseInfo/paper/basePaperInfo'
import new_badge from '@/assets/new_badge.gif'
export default {
  name: 'preOut',
  computed: {
    ...mapGetters([
      'name',
      'loginName',
      'userId'
    ]),
    noMore () {
      return this.paperData.length >= this.searchPageFlipper.total;
    },
    disabled () {
      return this.paperLoading || this.noMore
    }
  },
  directives: {
    'el-table-infinite-scroll': elTableInfiniteScroll
  },
  components: {
    PrintbillDetail,
    OrderMessage,
    printStep,
    BasePaperInfo
  },
  data() {
    return {
      disabledBtn:false,
      tableLoading:false,
      new_badge: new_badge,
      getId:"",
      formBillMemo:"",
      checkRowData:{},
      paperInfoVisible:false,
      dialogVisiblePaper:false,
      basePaperName:"",
      paperLoading:false,
      heightTable:"auto",
      indexRowId:999,
      currentId:999,
      memoDrawer:false,
      rowData:{},
      visiblePopover:false,
      typeOptions: [],
      remainingNum: false,
      dialogPaperVisible: false,
      paperData: [],
      row: {},
      dialogFormVisible: false,
      form: {},
      queryInStock:1,
      queryInStockBtn:true,
      dialogVisible: true,
      tableDataPaper: [],
      scopeIndex: 9998,
      listLoading: false,
      tableData: [],
      search: {
        preOutStockState: 0,
        paperName: "",
        actualPaperName: "",
        billCode: "",
      },
      ckeckPaperId: false,
      listData: {
        total: 0,
        page: 1,
        pageSize: 50
      },
      listData2: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      searchPageFlipper:{
        total: 0,
        page: 1,
        pageSize: 50
      },
      formPaper:{
        idPaperType: '',
        idPaperBaseInfo: '',
        mtRule: '',
        mtSuttle: '',
        paperCode: '',
        mtModel: '',
        byUnit: '吨',
        mtUnit: '令',
        seUnit: '张',
        barCode: '',
        remark: ''
      }
    }
  },
  mounted() {
    this.getTableInfo()
    this.getPaperInfo()
    this.getPaperTypeInfo()
  },
  methods: {
    openChoose() {
      var _that = this
      _that.paperInfoVisible = true
    },
    choosePaper(row) {
      console.log(row)
      var _that = this
      _that.paperInfoVisible = false
      _that.formPaper.mtSuttle = row.mtSuttle
      _that.formPaper.idPaperBaseInfo = row.id
      _that.formPaper.idPaperType = row.idPaperType
      _that.basePaperName = row.paperName
    },
    load() {
      //滑到底部时进行加载
      this.paperLoading = true;
      setTimeout(() => {
        this.searchPageFlipper.page++; //页数+1
        this.getPaperData(); //调用接口，此时页数+1，查询下一页数据
      }, 1000);
    },
    addBtnPaper(){
      //增加纸张档案
      const _that = this;
      if (!_that.formPaper.idPaperBaseInfo) {
        _that.$message.error('请选择纸张类型')
        return
      }
      _that.dialogVisiblePaper = false;
      _that.disabledBtn = true;
      var info = JSON.stringify(_that.formPaper)
      var data = {
        'info': info
      }

      addPaperInfo(data).then(res => {
        // console.log(res);
        if (res.httpCode == 200) {
          _that.dialogVisible = false
          _that.$message({
            message: '增加成功',
            type: 'success'
          })
          _that.paperInfoVisible = false;

        } else {
          _that.disabledBtn = false;
          _that.paperInfoVisible = false;
          _that.$message.error(res.msg)
        }
      }).catch(err => {
        _that.$message.error(err);
        _that.disabledBtn = false;
        _that.dialogVisible = true
      })

    },
    // 增加纸张档案
    handleCreateAdd() {
      const _that = this
      _that.formPaper = {
        idPaperType: 0,
        idPaperBaseInfo: '',
        mtRule:_that.form.keyWord,
        mtSuttle: '',
        mtModel: '',
        byUnit: '吨',
        mtUnit: '令',
        seUnit: '张',
        barCode: '',
        remark: ''
      }
      _that.basePaperName = ''
      // formPaper.mtRule
      _that.dialogTitle = '增加纸张档案'
      _that.dialogStatus = '1'
      _that.dialogVisiblePaper = true;
      _that.disabledBtn = false;
    },
    refreshBtn(){
      this.listData.page = 1;
      this.getTableInfo()
    },
    handleBlur(id,wholePaperCount,row){
      const _that = this;
      _that.indexRowId = id;
      row.preOutStockLockQty = wholePaperCount;
    },
    handleComplete(id,wholePaperCount,row){
      const _that = this;
      _that.indexRowId = 999;
      row.preOutStockLockQty = wholePaperCount
    },
    handleEdit(id,row){
      const _that = this;
      _that.indexRowId = id;
    },
    handleDetail(id) {
      const _that = this;
      _that.$refs.printbillDetail.idOrder = id;
      _that.$refs.printbillDetail.printVisible = true;
      _that.$refs.printbillDetail.getDetail();
    },
    getOrderStep(id) {
      const _that = this;
      _that.$refs.printStep.idOrder = id;
      _that.$refs.printStep.drawer = true;
      _that.$refs.printStep.getStep();
    },
    // 订单消息
    openMessage(row) {
      var _that = this
      _that.memoDrawer = true;
      _that.rowData = row;
      _that.$nextTick(function() {
        // console.log(_that.$refs.orderMemo);
        _that.$refs.orderMessage.idPrint = row.id;
        _that.$refs.orderMessage.idPrintBill = row.idPrintBill;
        _that.$refs.orderMessage.sMessage = "";
        _that.$refs.orderMessage.getList()
      })
    },
    handleAddBreed(breedMsg){
      this.memoDrawer = false;
      this.rowData.breedMsg =breedMsg;
    },
    resetBtn() {
      const _that = this
      _that.ckeckPaperId = true
      // _that.form.mtSuttle = ''
      // _that.form.keyWord = ''
      _that.form.paperName = ''
    },
    changeWholePaperCount(index, row) {
      const _that = this;
      _that.form.preOutStockLockQty = parseInt(row.originWholePaperCount)
    },

    // 默认纸张
    defaultStock(row) {
      //console.log(row)
      const _that = this;
      var data = {
        'breed': {
          id: row.id,
          idPaperBaseInfo: row.idPaperBaseInfo,
          wholePaperSize: row.wholePaperSize,
          idCompany: row.idCompany,
          preOutStockLockQty: parseInt(row.originWholePaperCount)
        }
      }



      // console.log(data);
      defaultMaterialStock(data).then(response => {
        // console.log('defaultMaterialStock', response)
        var data = response.data;
        if (response.httpCode == 200) {
          _that.$message.success('设置默认成功')
          row.idActualPaperInfo = data.paperInfo.id
          row.actualPaperName = data.paperInfo.paperName
          row.preOutStockLockQty = parseInt(data.usageEntity.currentLockNum);
          _that.form.preOutStockLockQty = parseInt(row.originWholePaperCount);
        }
      }).catch(err => {
        console.log(err);
        // _that.$message.error(err)
      })
    },
    roomPaperBtn(item, indexs, scopeIndex) {
      // 选择库房确定
      // console.log(item);
      // console.log(indexs);
      const _that = this
      _that.tableData[_that.scopeIndex].preOutStockLockQty = parseInt(_that.form.preOutStockLockQty)
      _that.tableData[_that.scopeIndex].preOutStockLockIdRoom = item.usageEntityList[indexs].idStockRoom
      _that.tableData[_that.scopeIndex].idActualPaperInfo = item.paperInfo.id
      _that.tableData[_that.scopeIndex].actualPaperName = item.paperInfo.paperName
      _that.tableData[_that.scopeIndex].paperName = item.paperInfo.paperName
      // console.log(item.usageEntityList[indexs].remainingNum);
      if (item.usageEntityList[indexs].remainingNum < 0) {
        _that.remainingNum = true
      } else {
        _that.remainingNum = false
      }
      // _that.$refs.popover[indexPage]
      _that.$refs['popover' + scopeIndex].showPopper = false
      // _that.dialogPaperVisible = false
    },
    checkPaperBtn() {
      // 搜索纸张档案确定
      this.searchPageFlipper.page = 1;
      this.paperData = [];
      this.getPaperData()

    },
    getPaperData(){
      const _that = this
      _that.paperLoading = true;
      _that.ckeckPaperId = true
      // if (!_that.form.mtSuttle) {
      //   _that.form.mtSuttle = ''
      // }
      // if (!_that.form.keyWord) {
      //   _that.form.keyWord = ''
      // }
      if (_that.ckeckPaperId) {
        if(_that.queryInStockBtn){
          var checKDatas = {
            idPaperType: _that.form.idPaperType,
            mtSuttle: _that.form.mtSuttle,
            keyWord: _that.form.keyWord,
            queryInStock:1
          }
        }else {
          var checKDatas = {
            idPaperType: _that.form.idPaperType,
            mtSuttle: _that.form.mtSuttle,
            keyWord: _that.form.keyWord
          }
        }

      } else {
        var checKDatas = {
          idPaperBaseInfo: _that.row.idPaperBaseInfo,
          mtSuttle: _that.form.mtSuttle,
          keyWord: _that.form.keyWord
        }
      }

      var info = {
        searchParams: checKDatas,
        searchPageFlipper: {
          pageIndex: _that.searchPageFlipper.page,
          pageSize: _that.searchPageFlipper.pageSize
        },
        dataBreed: {
          id: _that.row.id,
          idCompany: _that.row.idCompany,
          preOutStockLockQty: parseInt(_that.form.preOutStockLockQty) || 0
        }
      }
      //console.log(info)
      var data = info;
      // var data = {
      //   'params': JSON.stringify(info)
      // }
      searchPaperStock(data).then(response => {
        //console.log('response', response)
        if (response.data.length <= 0) {
          _that.$message('搜索无数据')
          return
        }
        //console.log('_that.paperData', _that.paperData)
        _that.searchPageFlipper.total = response.total;
        // console.log(_that.searchPageFlipper.total);
        if(0<response.total&&response.total<=5){
          _that.heightTable = "180px";
          _that.paperData = _that.paperData.concat(response.data);
        }else if(5<response.total&&response.total<=10) {
          _that.heightTable = "230px";
          _that.paperData = _that.paperData.concat(response.data);
        }else if(response.total>10){
          _that.heightTable = "320px";
          _that.paperData = _that.paperData.concat(response.data);
        }else {
          _that.heightTable = "auto";
        }
        _that.paperLoading = false
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    lockPreOutPrint(id,row,index) {
      const _that = this;
      _that.rowData = row;
      var breed = {
        id: id
      }
      var data = {
        'breed': JSON.stringify(breed)
      }
      lockPreOutPrintBreed(data).then(response => {
        _that.$message.success('锁定成功')
        _that.$nextTick(() => {
          _that.$set(row,'preOutLockState',1);
          _that.$set(row,'preOutLockManId',_that.$store.state.user.userId);
          // _that.$forceUpdate();//重绘

        })


      }).catch(err => {
        _that.$message.error(err)
      })
    },
    unlockPreOutPrint(id,row) {
      const _that = this;
      _that.rowData =row;

      var breed = {
        id: id
      }
      var data = {
        'breed': JSON.stringify(breed)
      }
      unlockPreOutPrintBreed(data).then(response => {
        _that.$message.success('解锁成功')
        _that.$nextTick(() => {
          _that.$set(row,'preOutLockState',0);
          // _that.$forceUpdate();//重绘
          for (const key in this.$refs) {
            if(_that.$refs[key]){
              _that.$refs[key].showPopper = false;
              _that.$refs[key].$el.style.display = "inline-block";
            }
          }
        })
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    completePreOut(row,index) {
      const _that = this;
      if(!row.actualPaperName){
        _that.$message.warning("请选择实际发纸");
        return
      }else {
        if(!row.preOutStockLockQty || row.idActualPaperInfo<=0){
          _that.$message.warning("采购数量不能为0");
          return
        }
      }
      if(row.originWholePaperCount!=row.wholePaperCountCopy){
        var htmls = "";
        htmls+="实际发纸:"+row.actualPaperName+"<br>";
        htmls+="开纸尺寸:"+row.cutSize+"<br>";
        htmls+="大纸尺寸:"+row.wholePaperSize+"<br>";
        htmls+="发纸令数:"+(row.originWholePaperCount/500).toFixed(3)+"<br>";
        _that.$alert(htmls, '确定操作？', {
          dangerouslyUseHTMLString: true
        }).then(() => {
          var breed = {
            id: row.id,
            preOutStockLockQty: parseInt(row.originWholePaperCount),
            wholePaperCount: parseInt(row.originWholePaperCount),
            preOutStockLockIdRoom: row.preOutStockLockIdRoom,
            idActualPaperInfo: row.idActualPaperInfo,
            actualPaperName: row.actualPaperName,
            currentBillVersion: row.currentBillVersion
          }
          // console.log("000",breed);
          var datas = {
            'breed': JSON.stringify(breed)
          }
          completePreOutStockV2(datas).then(response => {
            if(response.httpCode == 200){
              _that.$message.success('成功');
              _that.tableData.splice(index,1);
              for (let i = 0; i < _that.tableData.length; i++) {
                if(row.idPrintBill==_that.tableData[i].idPrintBill){
                  _that.tableData[i].currentBillVersion = response.data.currentBillVersion;
                }
              }
            }


          }).catch(err => {
            // _that.$message.error(err)
          })
        });
      }else {
        var breed = {
          id: row.id,
          preOutStockLockQty: parseInt(row.originWholePaperCount),
          wholePaperCount: parseInt(row.originWholePaperCount),
          preOutStockLockIdRoom: row.preOutStockLockIdRoom,
          idActualPaperInfo: row.idActualPaperInfo,
          actualPaperName: row.actualPaperName,
          currentBillVersion: row.currentBillVersion
        }
        // console.log("000",breed);
        var datas = {
          'breed': JSON.stringify(breed)
        }
        completePreOutStockV2(datas).then(response => {
          if(response.httpCode == 200){
            _that.$message.success('成功');
            _that.tableData.splice(index,1);
            for (let i = 0; i < _that.tableData.length; i++) {
              if(row.idPrintBill==_that.tableData[i].idPrintBill){
                _that.tableData[i].currentBillVersion = response.data.currentBillVersion;
              }
            }
          }

        }).catch(err => {
          // _that.$message.error(err)
        })
      }


    },
    preOutPurchase(row,index) {
      const _that = this;
      if(!row.actualPaperName){
        _that.$message.warning("请选择实际发纸");
        return
      }else {
        if(!row.preOutStockLockQty || row.idActualPaperInfo<=0){
          _that.$message.warning("采购数量不能为0");
          return
        }
      }
      if(row.originWholePaperCount!=row.wholePaperCountCopy){
        var htmls = "";
        htmls+="实际发纸:"+row.actualPaperName+"<br>";
        htmls+="开纸尺寸:"+row.cutSize+"<br>";
        htmls+="大纸尺寸:"+row.wholePaperSize+"<br>";
        htmls+="发纸令数:"+(row.originWholePaperCount/500).toFixed(3)+"<br>";
        _that.$alert(htmls, '确定操作？', {
          dangerouslyUseHTMLString: true
        }).then(() => {
          var breed = {
            id: row.id,
            preOutStockLockQty: parseInt(row.originWholePaperCount),//预出库用纸锁定量
            wholePaperCount: parseInt(row.originWholePaperCount),
            preOutStockLockIdRoom: row.preOutStockLockIdRoom,
            idActualPaperInfo: row.idActualPaperInfo,
            actualPaperName: row.actualPaperName,
            currentBillVersion: row.currentBillVersion
          }
          // console.log("111",breed);
          var datas = {
            'breed': JSON.stringify(breed)
          }
          preOutPurchaseRequestV2(datas).then(response => {
            if(response.httpCode == 200){
              _that.$message.success('成功');
              _that.tableData.splice(index,1);
              for (let i = 0; i < _that.tableData.length; i++) {
                if(row.idPrintBill==_that.tableData[i].idPrintBill){
                  _that.tableData[i].currentBillVersion = response.data.currentBillVersion;
                }
              }
            }
          }).catch(err => {
            // _that.$message.error(err)
          })
        });
      }else {
        var breed = {
          id: row.id,
          preOutStockLockQty: parseInt(row.originWholePaperCount),//预出库用纸锁定量
          wholePaperCount: parseInt(row.originWholePaperCount),
          preOutStockLockIdRoom: row.preOutStockLockIdRoom,
          idActualPaperInfo: row.idActualPaperInfo,
          actualPaperName: row.actualPaperName,
          currentBillVersion: row.currentBillVersion
        }
        var datas = {
          'breed': JSON.stringify(breed)
        }
        preOutPurchaseRequestV2(datas).then(response => {
          if(response.httpCode == 200){
            _that.$message.success('成功');
            _that.tableData.splice(index,1);
            for (let i = 0; i < _that.tableData.length; i++) {
              if(row.idPrintBill==_that.tableData[i].idPrintBill){
                _that.tableData[i].currentBillVersion = response.data.currentBillVersion;
              }
            }
          }
        }).catch(err => {
          // _that.$message.error(err)
        })
      }


    },
    // 选择纸张确认
    paperBtn(row, scopeIndex) {
      const _that = this;
      _that.tableData[_that.scopeIndex].idActualPaperInfo = row.paperInfo.id
      _that.tableData[_that.scopeIndex].actualPaperName = row.paperInfo.paperName
      _that.tableData[_that.scopeIndex].preOutStockLockQty = parseInt(row.usageEntity.currentLockNum)
      // console.log(_that.$refs['popover' + scopeIndex]);
      _that.$refs['popover-' + scopeIndex].showPopper = false;
      if(row.usageEntity.remainingNum<0){
        _that.$refs['completeBtn-' + _that.getId].$el.style.display = "none";
      }
      // _that.dialogPaperVisible = false
    },
    // 预出库不再处理
    forceCompletePre(row,index) {
      const _that = this;
      _that.$alert('确定不再处理?', '提示', {
        confirmButtonText: '确定'
      }).then(() => {
        var breed = {
          id: row.id
        }
        var datas = {
          'breed': JSON.stringify(breed)
        }
        forceCompletePreOutStockV2(datas).then(response => {
          if(response.httpCode == 200){
            _that.$message.success('成功');
            _that.tableData.splice(index,1);
          }
        }).catch(err => {
          // _that.$message.error(err)
        })
      });


    },
    // 获取表格数据
    getTableInfo() {
      const _that = this
      _that.tableLoading = true
      var params = _that.search
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      // console.log(data);
      getInfo(data).then(response => {
        //console.log('tableData', response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data;
        _that.listData.total = response.total;
        _that.tableLoading = false;
        for (let i = 0; i < _that.tableData.length; i++) {
          var datas = _that.tableData[i];
          _that.$set(datas, 'wholePaperCountCopy', datas.originWholePaperCount);

        }
        // console.log("121111",_that.tableData)

      }).catch(err => {
        _that.tableLoading = false;
      })
    },
    // 搜索
    searchData() {
      this.listData.page = 1
      this.getTableInfo()
    },
    // 序号
    indexMethod(index) {
      return index + 1
    },
    tableRowClassName({ row, rowIndex }) {
      var _that = this;
      // console.log("1",row.paperRequireFlag);
      // console.log("2",row.preOutLockManId);
      // console.log("3",_that.$store.state.user.userId);
      if (row.paperRequireFlag == 1 || row.selfProvidedPaper == 1) {
        return 'warning-text';
      }
      // if (row.preOutLockState == 1 && row.preOutLockManId != _that.$store.state.user.userId) {
      //   return 'danger-row'
      // } else if (row.preOutLockState == 1 && row.preOutLockManId == _that.$store.state.user.userId) {
      //   return 'warning-row'
      // }else {
      //   return ''
      // }


    },
    columnStyle({ row, column, rowIndex, columnIndex }) {
      var _that = this;
      if (columnIndex ==2 || columnIndex ==0 || columnIndex ==1) {
        if (row.preOutLockState == 1 && row.preOutLockManId != _that.$store.state.user.userId) {
          return 'background: #f8aba6 !important;'
        }else if (row.preOutLockState == 1 && row.preOutLockManId == _that.$store.state.user.userId){
          return 'background: #cde6c7 !important;'
        }

      }
    },
    unique(arr) {
      return Array.from(new Set(arr))
    },
    // closePopover(){
    //   const _that = this;
    //   _that.visiblePopover = false;
    // },
    checkPaper(index, row) {
      //console.log(row)
      const _that = this;
      _that.queryInStockBtn = true;
      _that.getId = row.id;
      // _that.form.idPaperType = row.idPaperType
      // console.log(row.idPaperType);
      // console.log(_that.form.idPaperType);
      // console.log(this.$refs);
      // _that.$refs['completeBtn-' + _that.getId].$el.style.display = "none";
      for (const key in this.$refs) {
        if(_that.$refs[key]){
          _that.$refs[key].showPopper = false;
          _that.$refs[key].$el.style.display = "inline-block";
        }
      }
      // _that.visiblePopover = true;
      _that.$refs['popover-'+index].showPopper = true;



      _that.paperData = []
      _that.form = {
        preOutStockLockQty: '',
        // mtSuttle: row.paperName.split("克")[0],
        keyWord: row.wholePaperSize,
        paperName: '',
        idPaperType:row.idPaperType
      }
      _that.formBillMemo = row.billMemo;
      _that.scopeIndex = index
      _that.row = row
      _that.form.preOutStockLockQty = parseInt(row.originWholePaperCount)
      // _that.form.paperName = row.paperName
    },
    closePopover(row,index) { //每次只显示一个Popover弹窗 使用doClose()
      // 遍历所有的refs，判断索引名中是否有 'popover-' ;如果有，都使用doClose关掉
      const _that = this;
      _that.$refs['popover-'+index].showPopper = false;

    },
    getCodeName(row) {
      return row.printBillCode + '-' + row.breedName;
    },
    getPaperInfo() {
      const _that = this;
      _that.listLoading = true;
      var params = {
        voidFlag: 0
      }
      var page = {
        pageIndex: _that.listData2.page,
        pageSize: _that.listData2.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      // console.log(data);
      getPaperInfoList(data).then(response => {
        const data = response.data
        // //  组合表单数据
        _that.tableDataPaper = data
        // console.log('基础纸张档案列表',_that.tableData)
        _that.listData2.total = response.total
        // console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },
    getPaperTypeInfo() {
      const _that = this;
      _that.listLoading = true;
      var page = {
        pageIndex: 1,
        pageSize: 500
      }
      var data = {
        'params': JSON.stringify({
          'voidFlag': 0
        }),
        "page": JSON.stringify(page)
      }
      // console.log(data);
      getPaperTypeList(data).then(response => {
        // console.log(response)
        const data = response.data;
        _that.typeOptions = data;
      }).catch(err => {
      })
    }
  }
}
</script>
<style>
.hline-table-con .el-table .cell {
}

.hline-table-con .el-table .warning-row {
  background: #cde6c7;
}

.hline-table-con .el-table .success-row {
  background: #f0f9eb;
}

.hline-table-con .el-table .danger-row {
  background: #f8aba6;
}
.hline-table-con .el-table .cell {

}
/*.hline-tabletr{pointer-events: none; }*/
.el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(0, 0, 0, 0) !important;
}
</style>

<style lang="scss" scoped>
::v-deep .el-button+.el-button{
  margin-left: 0px !important;
}
.app-container {
  background-color: #f0f2f5;
  padding: 30px;
  min-height: calc(100vh - 84px);
  ::v-deep .iconfont{
    font-size: 13px;
  }
}
.filter-container {
  margin-bottom: 15px;
}
::v-deep .warning-text span{
  color: #e8a820;
}
::v-deep .warning-text .el-button--mini span{
  color: #fff !important;
}
::v-deep .warning-text .cell{
  color: #e8a820;
}

.itemRoom{
  border-bottom: 1px solid #ddd;
}
::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: transparent;
}
</style>
