<template>
  <div class="app-container" style="height: auto;position: relative">

    <div class="filter-container">
      <div v-if="workingOn" style="display: inline-block;margin-right: 5px"><span style="font-weight: bold;font-size: 16px;color: #F56C6C"> {{ name }}</span>({{ loginName }})</div>
      <div v-if="workingOn" style="display: inline-block;margin-right: 5px">当前上班机台:<span style="font-weight: bold;font-size: 16px;color: #F56C6C"> {{ printMachineName }}</span></div>
      <div v-if="!workingOn" style="display: inline-block;margin-right: 5px"><span style="font-weight: bold;font-size: 16px;color: #F56C6C"> {{ name }}</span>({{ loginName }}):当前未上班</div>
      <el-button size="mini" class="filter-item" type="primary" @click="setDiadog">
        上班
      </el-button>
      <el-input size="mini" v-model="search.keyWord" 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" type="danger" @click="searchPrintBillList">
        查询施工单
      </el-button>
      <el-button size="mini" class="filter-item" type="primary" @click="handleMachine">
        查看机台任务
      </el-button>
<!--      <el-button size="mini"  class="filter-item" type="primary" @click="setDiadog">-->
<!--        印刷机台设置-->
<!--      </el-button>-->
      <el-button class="filter-item" size="mini" type="warning" icon="el-icon-s-operation" @click="diyColumn">
        自定义列
      </el-button>
    </div>
    <div class="rowHoverNone elTble">
      <el-table
        max-height="640"
        size="mini"
        :data="tableData"
        v-loading="listLoading"
        @row-contextmenu="rowContextmenu"
        :row-class-name="tableRowClassName"
        @row-click="handleClickTableRow"
        ref="multipleTable"
        tooltip-effect="light"
        row-key="id"
        border
        default-expand-all>
        <el-table-column
          label="#"
          fixed
          align="center"
          type="index"
          :index="indexMethod">
        </el-table-column>
        <el-table-column label="操作" fixed align="center" width="200px" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button v-if="scope.row.workProcess.feedBackContent==0" :disabled="scope.row.pauseStatus==1"
                       @click="handleBackRecordStart(scope.row,scope.$index)" type="success" size="mini">
              反馈完成
            </el-button>
            <el-button v-if="scope.row.workProcess.feedBackContent==1 && scope.row.taskStatus==0"
                       :disabled="scope.row.pauseStatus==1" @click="handleBackRecordStart(scope.row,scope.$index)"
                       type="primary" size="mini">
              反馈开始
            </el-button>
            <el-button v-if="scope.row.workProcess.feedBackContent==1 && scope.row.taskStatus>0"
                       :disabled="scope.row.pauseStatus==1" @click="handleBackRecord(scope.row,scope.$index)"
                       type="success" size="mini">
              反馈完成
            </el-button>
            <el-button v-if="scope.row.workProcess.feedBackContent==2 && scope.row.taskStatus==0"
                       :disabled="scope.row.pauseStatus==1" @click="handleBackRecordStart(scope.row,scope.$index)"
                       type="primary" size="mini">
              反馈开始
            </el-button>
            <el-button v-if="scope.row.workProcess.feedBackContent==2 && scope.row.taskStatus>0"
                       :disabled="scope.row.pauseStatus==1" @click="handleBackRecord(scope.row,scope.$index)"
                       type="success" size="mini">
              反馈完成
            </el-button>
            <el-button plain @click="twicePaperBtn(scope.row,scope.$index)" type="warning" size="mini">
              二次领纸
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          fixed
          label="施工单号"
          width="160px"
        >
          <template slot-scope="{row}">
            <el-tooltip :content="getCodeName(row)" placement="top-start" effect="light">
              <a @click="getOrderStep(row.printBill.id)" style="color: #409EFF" href="javascript:;" class="ellipsis">
                {{ row.printBill.billCode }}-{{ row.printBreed.breedName }}</a>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          fixed
          label="印品名称"
          width="110px"
          show-overflow-tooltip
        >
          <template slot-scope="{row}">
            <a href="javascript:;" style="color: #20a0ff" @click="handleDetail(row.printBill.id)" class="ellipsis">
              {{ row.printBill.billName }}</a>
            <el-image v-if="row.printBill.importantBill == 1" :src="new_badge"></el-image>
          </template>
        </el-table-column>
        <template v-for="column in columnTable">
          <el-table-column  v-if="column.columnTitle == 'taskStatus'" label="生产状态" align="center" :width="column.columnWidth" class-name="small-padding fixed-width">
            <template slot-scope="{row}">
              <div v-if="row.pauseStatus==0">
                <el-tag size="mini" type="info" v-if="row.taskStatus==0">未开始</el-tag>
                <!--            <el-tag type="warning" type="info" v-if="row.taskStatus==0 && row.pauseStatus==1">暂停</el-tag>-->
                <el-tag size="mini" type="success" v-if="row.taskStatus==1">生产中</el-tag>
                <el-tag size="mini" type="danger" v-if="row.taskStatus==2">终止</el-tag>
                <el-tag size="mini" type="" v-if="row.taskStatus==5">完成</el-tag>
                <el-tag size="mini" type="su" v-if="row.taskStatus==10">已完成</el-tag>
              </div>
              <div v-if="row.pauseStatus==1">
                <el-tag size="mini" type="warning">暂停</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="施工单消息"
            v-else-if="column.columnTitle == 'breedMsg'"
            :width="column.columnWidth"
            show-overflow-tooltip
          >
            <template slot-scope="{row}">
              <template v-if="row.breedMsg">
                <el-button size="mini" circle icon="el-icon-plus" @click="openMessage(row)"></el-button>
                <span
                  style="color: #20a0ff;cursor: pointer"
                  @click="openMessage(row)"> {{ row.breedMsg }}</span>
              </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
            label="拼版要求"
            show-overflow-tooltip
            v-else-if="column.columnTitle == 'assembleBreedRequire'"
            :width="column.columnWidth"
          >
            <template slot-scope="{row}">
                      <span>
                        {{ row.printBill.assembleBreedRequire }}
                      </span>
            </template>
          </el-table-column>
          <el-table-column
            label="印刷要求"
            v-else-if="column.columnTitle == 'orderPrintRequire'"
            :width="column.columnWidth"
            show-overflow-tooltip
          >
            <template slot-scope="{row}">
            <span>
              {{ row.printBill.orderPrintRequire }}
            </span>
            </template>
          </el-table-column>
          <el-table-column
            label="印刷机台"
            show-overflow-tooltip
            v-if="column.columnTitle == 'machineName'"
            :width="column.columnWidth"
          >
            <template slot-scope="{row}">
              {{ row.machineName }}
            </template>
          </el-table-column>
          <el-table-column
            label="多机台"
            show-overflow-tooltip
            v-if="column.columnTitle == 'otherBreedStatus'"
            :width="column.columnWidth"
          >
            <template slot-scope="{row}">
              {{ row.otherBreedStatus }}
            </template>
          </el-table-column>

          <el-table-column
            label="客户名称"
            v-else-if="column.columnTitle == 'clientName'"
            :width="column.columnWidth"
            show-overflow-tooltip
          >
            <template slot-scope="{row}">
              <span> {{ row.printBill.clientName }}</span>
            </template>
          </el-table-column>

          <el-table-column
            label="产品类型"
            show-overflow-tooltip
            v-else-if="column.columnTitle == 'productName'"
            :width="column.columnWidth"
          >
            <template slot-scope="{row}">
              <span> {{ row.printBill.productName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="用纸"
            show-overflow-tooltip
            v-else-if="column.columnTitle == 'actualPaperName'"
            :width="column.columnWidth"
          >
            <template slot-scope="{row}">
              <span> {{ row.printBreed.actualPaperName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'wholePaperCount'"
            :width="column.columnWidth"
            label="大纸张数">
            <template slot-scope="{row}">
              {{ row.printBreed.wholePaperCount }}
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'cutName'"
            :width="column.columnWidth"
            label="开数">
            <template slot-scope="{row}">
              {{ row.printBreed.cutName }}
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'cutSize'"
            :width="column.columnWidth"
            label="开纸尺寸">
            <template slot-scope="{row}">
              {{ row.printBreed.cutSize }}
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'assembleStatus'"
            :width="column.columnWidth"
            label="拼版状态">
            <template slot-scope="{row}">
              <el-tag size="mini" type="info" v-if="row.assembleStatus=='未开始'">{{ row.assembleStatus }}</el-tag>
              <el-tag size="mini" type="warning" v-if="row.assembleStatus=='生产中'">{{ row.assembleStatus }}</el-tag>
              <el-tag size="mini" type="success" v-if="row.assembleStatus=='完成'">{{ row.assembleStatus }}</el-tag>

            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'assembleMan'"
            :width="column.columnWidth"
            label="拼版人">
            <template slot-scope="{row}">
            <span v-if="row.assembleStatus!='未开始'">
              {{ row.assembleMan }}
            </span>

            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'cutPaperStatus'"
            :width="column.columnWidth"
            label="白料状态">
            <template slot-scope="{row}">
              <el-tag size="mini" type="info" v-if="row.cutPaperStatus=='未开始'">{{ row.cutPaperStatus }}</el-tag>
              <el-tag size="mini" type="warning" v-if="row.cutPaperStatus=='生产中'">{{ row.cutPaperStatus }}</el-tag>
              <el-tag size="mini" type="success" v-if="row.cutPaperStatus=='完成'">{{ row.cutPaperStatus }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'cutPaperMan'"
            :width="column.columnWidth"
            label="白料人">
            <template slot-scope="{row}">
            <span v-if="row.cutPaperStatus!='未开始'">
              {{ row.cutPaperMan }}
            </span>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'madeBreedStatus'"
            :width="column.columnWidth"
            label="制版状态">
            <template slot-scope="{row}">
              <el-tag size="mini" type="info" v-if="row.madeBreedStatus=='未开始'">{{ row.madeBreedStatus }}</el-tag>
              <el-tag size="mini" type="warning" v-if="row.madeBreedStatus=='生产中'">{{ row.madeBreedStatus }}</el-tag>
              <el-tag size="mini" type="success" v-if="row.madeBreedStatus=='完成'">{{ row.madeBreedStatus }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'madeBreedMan'"
            :width="column.columnWidth"
            label="制版人">
            <template slot-scope="{row}">
            <span v-if="row.madeBreedStatus!='未开始'">
              {{ row.madeBreedMan }}
            </span>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'printStatus'"
            :width="column.columnWidth"
            label="印刷状态">
            <template slot-scope="{row}">
              <el-tag size="mini" type="info" v-if="row.printStatus=='未开始'">{{ row.printStatus }}</el-tag>
              <el-tag size="mini" type="warning" v-if="row.printStatus=='生产中'">{{ row.printStatus }}</el-tag>
              <el-tag size="mini" type="success" v-if="row.printStatus=='完成'">{{ row.printStatus }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'printMan'"
            :width="column.columnWidth"
            label="印刷人">
            <template slot-scope="{row}">
            <span v-if="row.printStatus!='未开始'">
              {{ row.printMan }}
            </span>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'deliveryDate'"
            :width="column.columnWidth"
            label="交货时间"
          >
            <template slot-scope="{row}">
              {{ row.printBill.deliveryDate  | getTime }}
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'paperStatusInfo'"
            :width="column.columnWidth"
            show-overflow-tooltip
            label="纸张状态">
            <template slot-scope="{row}">
              <span v-for="(item, index) in row.paperStatusInfo.split('/')" :key="index">
                <span v-if="item.indexOf('未')!=-1">{{item}}&nbsp;&nbsp;</span>
                <span style="color: #67C23A" v-if="item.indexOf('已')!=-1">{{item}}&nbsp;&nbsp;</span>
              </span>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'breedFlipType'"
            :width="column.columnWidth"
            label="版式">
            <template slot-scope="{row}">
              <span v-if="row.printBreed.breedFlipType==1">正反</span>
              <span v-if="row.printBreed.breedFlipType==2">滚翻</span>
              <span v-if="row.printBreed.breedFlipType==3">自翻</span>
              <span v-if="row.printBreed.breedFlipType==4">单面</span>
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'breedSets'"
            :width="column.columnWidth"
            label="版套数">
            <template slot-scope="{row}">
              {{ row.printBreed.breedSets }}
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'printCount'"
            :width="column.columnWidth"
            label="印量">
            <template slot-scope="{row}">
              {{ row.printBreed.printCount }}
            </template>
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'lastOperateManName'"
            :width="column.columnWidth"
            prop="lastOperateManName"
            label="最后操作人名字">
          </el-table-column>

          <el-table-column
            v-else-if="column.columnTitle == 'billMemo'"
            :width="column.columnWidth"
            show-overflow-tooltip
            prop="billMemo"
            label="备注">
          </el-table-column>
          <el-table-column
            v-else-if="column.columnTitle == 'createTime'"
            :width="column.columnWidth"
            label="创建时间"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.createTime">{{ scope.row.createTime | getTime }}</span>
            </template>
          </el-table-column>
        </template>
      </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="printbilTitle" :visible.sync="printbilVisible" width="500px">
      <el-form :model="printForm" label-width="50px" :rules="rulesPrint" ref="ruleForm" label-position="right">
        <el-form-item prop="taskMemo" label="备注">
          <el-input type="textarea" v-model="printForm.taskMemo"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="printbilVisible = false">取 消</el-button>
        <el-button :disabled="disabledBtn" type="primary" @click="printBtn">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="dialogTitle" :close-on-click-modal="false" :visible.sync="dialogVisible" width="500px">
      <el-form :model="ruleForm" label-width="130px" :rules="rules" ref="ruleForm" label-position="right">
        <el-form-item prop="isComplete" label="是否反馈完成">
          <el-checkbox v-model="ruleForm.isComplete">任务已完成</el-checkbox>
        </el-form-item>
        <el-form-item v-show="feedBackContentVisible" prop="feedbackCount"  label="反馈数量">
          <el-input oninput = "value=value.replace(/[^0-9]/gi,'')" type="number" v-model.trim="ruleForm.feedbackCount"></el-input>
        </el-form-item>
        <el-form-item prop="memo" label="反馈备注">
          <el-input type="textarea" v-model="ruleForm.memo"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button :disabled="btnClick" type="primary" @click="backRecordBtn">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="选择机台" :visible.sync="dialogMachineInfo" width="850px">
      <div style="width: 250px;margin-top: -15px;margin-bottom: 8px">
        <el-input size="mini" placeholder="关键字" v-model="searchVal" class="input-with-select">
          <el-button @click="handleSearch" slot="append" type="success" icon="el-icon-search">搜索</el-button>
        </el-input>
      </div>
      <el-table
        :data="tableData2"
        v-loading="listLoading"
        style="width: 100%;margin-bottom: 20px;"
        max-height="400px"
        size="mini"
        row-key="id"
        border
        default-expand-all>
        <el-table-column label="操作" align="center" width="130" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <el-button @click="handleCheck(row)" type="primary" size="mini">
              选择
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="machineName"
          label="机台名称">
        </el-table-column>
        <el-table-column
          label="对应机型"
          prop="machineSize"
        >
        </el-table-column>
        <el-table-column
          label="ps版规格"
          prop="psSize"
        >
        </el-table-column>
        <el-table-column align="center" label="状态" class-name="status-col" width="100">
          <template slot-scope="{row}">
            <el-tag v-if="row.voidFlag==0" type="success">
              启用
            </el-tag>
            <el-tag v-else="row.voidFlag==1" type="danger">
              禁用
            </el-tag>
          </template>
        </el-table-column>

      </el-table>
    </el-dialog>
    <!--    <servicedialog @tableRefresh="tableRefresh" ref="menuDialog" :dialogStatus="dialogStatus" :menuId="menuId" :titleDialog="titleDialog" :dialogVisible="dialogVisible"/>-->
    <cancledialog @tableRefresh="tableRefresh" ref="confirmDialog"></cancledialog>
    <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>
    <right-menu :btnShow="btnShow" :btnList="btnList" v-if="menuVisible" @foo="foo" ref="rightmenu"
                @handleOne="handleOne" @handleTwo="handleTwo"></right-menu>
    <column-edit @saveColum="saveColum" ref="columnEdit"></column-edit>
    <div v-show="machinefListVisible" style="width: 100%;position: fixed;left: 0px;height: 510px;z-index: 1024;background: #fff;bottom:0px;border-top: 1px solid #ddd;overflow-y: auto">
      <machinef-list @closeDrawer="closeDrawer" @searchList="searchList" ref="machinefList"></machinef-list>
    </div>
    <el-dialog title="二次领纸" :visible.sync="twicePaperVisible" width="500px">

      <el-form size="mini" label-width="120px" label-position="right">
        <el-form-item label="施工单号:">
          <span>{{ twiceName}}</span>
        </el-form-item>
        <el-form-item label="实际用纸:">
          <span>{{ twicePaperName}}</span>
        </el-form-item>
        <el-form-item prop="requestMemo" label="领用数量(张):">
          <el-input type="Number" v-model="paperForm.requestQty"></el-input>
        </el-form-item>
        <el-form-item prop="requestMemo" label="领用原因:">
          <el-input type="textarea" v-model="paperForm.requestMemo"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="twicePaperVisible = false">取 消</el-button>
        <el-button :disabled="twicePrintBtnDisable" type="primary" @click="twicePrintBtn">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getInfo,
  getPageInfo,
  taskFeedbackPause,
  feedbackTask,
  taskFeedbackStart,
  ifPermission,
  getMachineInfoList, getPageTableColumn, savePageTableColumn,
  requestPaperOutTwice,
  getMachineOnWork,
  machineOnWork
} from '@/api/feedBack/feedBack.js'
import new_badge from '@/assets/new_badge.gif'
import { getMachineInfoByID } from '@/api/baseInfo/machineInfo.js'
import Cancledialog from '@/components/Dialog/Cancledialog.vue';
import { mapGetters } from 'vuex';
import OrderMessage from './orderMessage/orderMessage'
import rightMenu from '@/components/rightMenu/index.vue'
import PrintbillDetail from "@/components/printbillDetail/printbillDetail";
import machinefList from "@/components/machinefList/machinefList";
import printStep from "@/components/printbillDetail/printStep";
import columnEdit from "@/components/columnEdit/list.vue";
import {addPaperInfo} from "@/api/baseInfo/paper/paperInfo";

const defaultItems = [
  {
    columnName: '生产状态', id: 1, columnTitle: 'taskStatus', columnWidth: '110'
  },
  {
    columnName: '施工单消息', id: 2, columnTitle: 'breedMsg', columnWidth: '180'
  },
  {
    columnName: '出版备注', id: 3, columnTitle: 'assembleBreedRequire', columnWidth: '110'
  },
  {
    columnName: '印刷要求', id: 4, columnTitle: 'orderPrintRequire', columnWidth: '110'
  },
  {
    columnName: '印刷机台', id: 5, columnTitle: 'machineName', columnWidth: '110'
  },
  {
    columnName: '多机台', id: 6, columnTitle: 'otherBreedStatus', columnWidth: '110'
  },
  {
    columnName: '客户名称', id: 7, columnTitle: 'clientName', columnWidth: '130'
  },
  {
    columnName: '产品类型', id: 8, columnTitle: 'productName', columnWidth: '120'
  },
  {
    columnName: '用纸', id: 9, columnTitle: 'actualPaperName', columnWidth: '150'
  },
  {
    columnName: '大纸张数', id: 10, columnTitle: 'wholePaperCount', columnWidth: '130'
  },
  {
    columnName: '开数', id: 11, columnTitle: 'cutName', columnWidth: '100'
  },
  {
    columnName: '开纸尺寸', id: 12, columnTitle: 'cutSize', columnWidth: '120'
  },
  {
    columnName: '拼版状态', id: 13, columnTitle: 'assembleStatus', columnWidth: '100'
  },
  {
    columnName: '拼版人', id: 14, columnTitle: 'assembleMan', columnWidth: '120'
  },
  {
    columnName: '白料状态', id: 15, columnTitle: 'cutPaperStatus', columnWidth: '100'
  },
  {
    columnName: '白料人', id: 16, columnTitle: 'cutPaperMan', columnWidth: '90'
  },
  {
    columnName: '制版状态', id: 17, columnTitle: 'madeBreedStatus', columnWidth: '100'
  }, {
    columnName: '制版人', id: 18, columnTitle: 'madeBreedMan', columnWidth: '90'
  },
  {
    columnName: '印刷状态', id: 19, columnTitle: 'printStatus', columnWidth: '120'
  },
  {
    columnName: '印刷人', id: 20, columnTitle: 'printMan', columnWidth: '90'
  },
  {
    columnName: '交货时间', id: 21, columnTitle: 'deliveryDate', columnWidth: '120'
  },
  {
    columnName: '纸张状态', id: 22, columnTitle: 'paperStatusInfo', columnWidth: '220'
  },
  {
    columnName: '版式', id: 23, columnTitle: 'breedFlipType', columnWidth: '50'
  },
  {
    columnName: '版套数', id: 24, columnTitle: 'breedSets', columnWidth: '50'
  },
  {
    columnName: '印量', id: 25, columnTitle: 'printCount', columnWidth: '70'
  },
  {
    columnName: '最后操作人名字', id: 26, columnTitle: 'lastOperateManName', columnWidth: '100'
  },
  {
    columnName: '备注', id: 27, columnTitle: 'billMemo', columnWidth: '150'
  },
  {
    columnName: '创建时间', id: 28, columnTitle: 'createTime', columnWidth: '130'
  }
]

export default {
  name: 'printingList',
  computed: {
    ...mapGetters([
      'name',
      'loginName'
    ])
  },
  components: {
    Cancledialog,
    rightMenu,
    OrderMessage,
    PrintbillDetail,
    printStep,
    machinefList,
    columnEdit
  },
  data() {
    return {
      disabledBtn:"",
      new_badge: new_badge,
      searchVal:"",
      workingOn:false,
      twicePrintBtnDisable:false,
      twiceName:"",
      twicePaperName:"",
      paperForm:{
        requestMemo:"",
        requestQty:""
      },
      twicePaperVisible:false,
      defaultItemCopyData:[],
      columnTable: [],
      machineId:"",
      clickCheckId:"",
      machinefListVisible:false,
      copyTableData:[],
      heightTable:"auto",
      printMachineName:"",
      rowIndex:999,
      rowData:{},
      activities: [],
      avtiveStep: true,
      activitiesArray: [],
      memoDrawer: false,
      workProcessShow:false,
      menuVisible:false,
      btnShow:false,
      row:{},
      btnList:[
        {name: '暂停'},
        {name: '反馈'}
      ],
      dialogMachineInfo:false,
      permission:false,
      btnClick:false,
      printbilVisible:false,
      printbilTitle:"",
      feedBackContentVisible:false,
      activeIndex:99,
      activeName: '2',
      machineInfList: [],
      multipleSelection: [],
      multipleSelection2:[],
      dialogStatus: 1,//1增加，2修改
      dialogTitle: '',
      dialogVisible: false,
      search: {
        keyWord: ''
      },
      printForm:{},
      ruleForm: {},
      rules: {
        feedbackCount: [
          { type: 'number', message: '必须为数字值'}
        ]
      },
      rulesPrint: {
        taskMemo: [
          {required: true, message: '请填写备注信息', trigger: 'blur'}
        ]
      },
      listData: {
        total: 0,
        page: 1,
        pageSize: 30
      },
      listData2: {
        total: 0,
        page: 1,
        pageSize: 15
      },
      confirmdialog: false,
      listLoading: false,
      tableData: [],
      tableData2:[],
      menuId: ''
    }
  },
  mounted() {
    this.listData.page=1;
    this.tableData = [];
    // console.log(dyERP.getPrintMachineId());
    this.getMachineOnWork();
    this.getColum();
    this.getIfPermission();

  },
  methods: {
    handleSearch(){
      const _that = this;
      _that.listData.page=1;
      _that.getMachList();
    },
    getMachineOnWork(){
      const _that = this;
      var data = {}
      getMachineOnWork(data).then(res => {
        // console.log("getMachineOnWork",res.data);
        // console.log(res.httpCode);
        if (res.httpCode == 200) {
          // console.log(res.data == "" || res.data == null);
          if(res.data=="" || res.data==null){
            _that.workingOn  = false;
          }else {
            _that.workingOn  = true;
            _that.printMachineName = res.data.machineName;
            _that.machineId = res.data.id;
            _that.getTableInfo();
          }
        } else {

        }
      }).catch(err => {
      })

    },
    searchPrintBillList(){
      const _that = this;
      if (!_that.search.keyWord) {
        _that.$message("施工单号不能为空");
        return
      }
      _that.$router.push({path:'/printbill/listSearch',query:{printbillCode:_that.search.keyWord}})
    },
    twicePaperBtn(row,index){
      const _that = this;
      _that.rowData = row;
      _that.twicePaperVisible = true;
      _that.paperForm.requestQty = row.printBreed.wholePaperCount;
      _that.paperForm.requestMemo = "";
      _that.twiceName = row.printBill.billCode+"-"+row.printBreed.breedName;
      _that.twicePaperName = row.printBreed.actualPaperName
    },
    twicePrintBtn(){
      const _that = this;
      if (!_that.paperForm.requestQty) {
        _that.$message.error('领用数量不能为空')
        return
      }
      if (!_that.paperForm.requestMemo) {
        _that.$message.error('领用原因不能为空')
        return
      }
      _that.twicePrintBtnDisable = true;
      var data = {
        'idBreed': _that.rowData.idPrintBreed,
        'requestQty': _that.paperForm.requestQty,
        'requestMemo': _that.paperForm.requestMemo
      }
      requestPaperOutTwice(data).then(res => {
        // console.log(res);
        _that.twicePrintBtnDisable = false;
        if (res.httpCode == 200) {
          _that.twicePaperVisible = false
          _that.$message({
            message: '成功',
            type: 'success'
          })
        } else {
          _that.twicePaperVisible = false;
          _that.twicePrintBtnDisable = false;
        }
      }).catch(err => {
      })
    },
    getColum() {
      const _that = this;
      var Infos = {};
      _that.defaultItemCopyData = JSON.parse(JSON.stringify(defaultItems));
      getPageTableColumn(Infos, "印刷反馈").then(response => {
        _that.$refs.columnEdit.tableItem = response.data;
        if (response.data.length <= 0) {
          _that.columnTable = defaultItems;
          _that.$refs.columnEdit.defaultItem = defaultItems;
        } else {
          _that.columnTable = response.data;
          for (let i = 0; i < response.data.length; i++) {
            var datai = response.data[i];
            for (let j = 0; j < _that.defaultItemCopyData.length; j++) {
              var dataj = _that.defaultItemCopyData[j];
              if(datai.columnTitle == dataj.columnTitle){
                _that.defaultItemCopyData.splice(j,1);
              }
            }
          }
          _that.$refs.columnEdit.defaultItem = _that.defaultItemCopyData
        }
      }).catch(err => {
        _that.$message.error(err);
      })
    },
    saveColum(data, pageName) {
      // console.log("1123", data);
      const _that = this;
      for (let i = 0; i < data.length; i++) {
        var item = data[i];
        _that.$set(item, 'pageName', "印刷反馈");
        _that.$set(item, 'columnIndex', i);
      }

      var Infos = JSON.stringify(data);
      savePageTableColumn(Infos, "印刷反馈").then(response => {
        _that.$message("保存成功");
        _that.$refs.columnEdit.columnVisible = false;
        _that.listData.page = 1;
        _that.search.idMachineInfo = "";
        _that.search.keyWord = "";
        _that.tableData = [];
        _that.machinefListVisible = false;
        _that.getTableInfo();
        _that.getColum();

      }).catch(err => {
        _that.$message.error(err);
      })
    },
    diyColumn() {
      const _that = this;
      _that.$refs.columnEdit.columnVisible = true;
      _that.$refs.columnEdit.form.pageName = "印刷反馈";
      _that.getColum();
    },
    tableRowClassName({row, rowIndex}) {
      var _that = this;
      if (row.id == _that.clickCheckId ) {
        return 'primary-row';
      }
      if(row.madeBreedStatusInt==10 && row.cutPaperStatusInt==10){
        return 'complete-text';
      }
    },
    handleClickTableRow(row, event, column) {
      const _that = this;
      _that.clickCheckId = row.id;
    },
    handleTwo(){
      const _that = this;
    },
    handleOne(row){
      const _that = this;
      _that.rowData = row;
      if(row.pauseStatus==1){
        _that.printbilTitle = "确定启动？";
        _that.printForm={
          id: row.id,
          taskStatus: row.taskStatus,
          taskMemo: ""
        }
      }else if(row.pauseStatus==0){
        _that.printbilTitle = "确定暂停？";
        _that.printForm={
          id: row.id,
          taskStatus: row.taskStatus,
          taskMemo: ""
        }
      }

      _that.disabledBtn = false;
      _that.printbilVisible = true;
    },
    openMessage(row) {
      var _that = this
      _that.memoDrawer = true;
      _that.rowData = row;
      _that.$nextTick(function() {
        // console.log(_that.$refs.orderMemo);
        _that.$refs.orderMessage.idOrder = row.id;
        _that.$refs.orderMessage.idPrint = row.idPrintBreed;
        _that.$refs.orderMessage.idPrintBill = row.idPrintBill;
        _that.$refs.orderMessage.sMessage = "";
        _that.$refs.orderMessage.getList()
      })
    },
    handleAddBreed(breedMsg){
      this.memoDrawer = false;
      this.rowData.breedMsg =breedMsg;
    },
    searchList(id){
      const _that = this;
    },
    handleMachine(){
      const _that = this;
      _that.machinefListVisible = true;
      _that.$refs.machinefList.getMachine(_that.$refs.machinefList.activeName,_that.$refs.machinefList.activeIndex);
    },
    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();
    },
    handleBackRecordStart(row,rowIndex){
      const _that = this;
      _that.rowData = row;
      _that.rowIndex  = rowIndex;
      _that.dialogTitle = "版任务反馈";
      _that.ruleForm={
        idTask: row.id,
        taskStatus: row.taskStatus,
        isComplete: true,
        feedbackCount:'',
        memo: "",
      }
      this.$confirm('反馈开始？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var Infos = {
          "item": JSON.stringify(_that.ruleForm),
        }
        feedbackTask(Infos).then(response => {
          // console.log("feedbackTask", response);
          _that.$message("反馈成功");

          if(row.workProcess.feedBackContent==0){
            _that.tableData.splice(_that.rowIndex,1);
            _that.listData.page=1;
          }else {
            _that.rowData.taskStatus = 1;
          }
        }).catch(err => {
          // _that.$message.error(err);
        })
      }).catch(() => {
      });
    },
    handleCheck(row){
      const _that = this;
      _that.printMachineName = "";

      // alert(row.id)
      // console.log(dyERP);
      // dyERP.setPrintMachineId(row.id.toString())
      // alert(dyERP.getPrintMachineId())
      var Infos = {
        "idMachine": row.id,
      }
      machineOnWork(Infos).then(response => {
        // console.log("machineOnWork", response);
        _that.machineId = row.id;
        _that.printMachineName = row.machineName;
        _that.dialogMachineInfo =false;
        _that.listData.page=1;
        _that.getMachineOnWork();
        _that.tableData = [];
        _that.getTableInfo();
      }).catch(err => {
        // _that.$message.error(err);
      })


      // alert(dyERP.setPrintMachineId(row.id.toString()))
    },
    setDiadog(){
      const _that = this;
      _that.listData.page=1;
      _that.searchVal = "";
      _that.getMachList();
      _that.dialogMachineInfo = true;
    },
    getIfPermission(){
      const _that = this;
      var Infos = {
        "permission": "printbill.feedback.machineconfig",
      }
      ifPermission(Infos).then(response => {
        // console.log("ifPermission", response);
        if(response.data==1){
          _that.permission = true;
        }else {
          _that.permission = false;
        }

      }).catch(err => {
        // _that.$message.error(err);
      })
    },
    printBtn(){
      const _that = this;
      // console.log(_that.printForm);
      if(!_that.printForm.taskMemo && _that.rowData.pauseStatus==0){
        _that.$message.warning("备注信息不能为空");
        return
      }
      _that.printbilVisible =false;
      _that.disabledBtn = true;
      if(_that.rowData.pauseStatus==0){
        var Infos = {
          "task": JSON.stringify(_that.printForm),
        }
        taskFeedbackPause(Infos).then(response => {
          // console.log("taskFeedbackPause", response);
          _that.$message("暂停成功");
          _that.printbilVisible =false
          _that.rowData.pauseStatus = 1;
          _that.rowData.breedMsg =response.data.breedMsg;


        }).catch(err => {
          _that.$message.error(err);
          _that.printbilVisible =false;
          _that.btnClick = false;
        })
      }else if(_that.rowData.pauseStatus==1){
        var Infos = {
          "task": JSON.stringify(_that.printForm),
        }
        taskFeedbackStart(Infos).then(response => {
          // console.log("taskFeedbackPause", response);
          _that.$message("启动成功");
          _that.printbilVisible =false
          _that.rowData.pauseStatus = 0;
          _that.rowData.breedMsg =response.data.breedMsg;
        }).catch(err => {
          // _that.$message.error(err);
          _that.printbilVisible =false;
          _that.btnClick = false;
        })
      }
    },
    backRecordBtn(){
      const _that = this;
      // console.log(_that.ruleForm);
      // if(!_that.ruleForm.memo){
      //   _that.$message.warning("备注信息不能为空");
      //   return
      // }
      if(_that.ruleForm.feedbackCount<=0 && _that.feedBackContentVisible){
        _that.$message.warning("反馈数量不能小于0");
        return
      }
      var Infos = {
        "item": JSON.stringify(_that.ruleForm),
      }
      feedbackTask(Infos).then(response => {
        // console.log("feedbackTask", response);

        _that.$message("成功");
        _that.dialogVisible = false;
        _that.btnClick = false;
        _that.listData.page=1;
        _that.tableData = [];
        _that.getTableInfo();


      }).catch(err => {
        // _that.$message.error(err);
        _that.dialogVisible = false;
        _that.btnClick = false;
      })
    },
    //版任务数量反馈
    handleBackRecord(row){
      const _that = this;
      _that.dialogTitle = "版任务反馈";
      _that.dialogVisible = true;
      // console.log(row.workProcess.feedBackContent);
      if(row.workProcess.feedBackContent==0){

      }else if(row.workProcess.feedBackContent==1){
        _that.workProcessShow = false;
        _that.feedBackContentVisible = false;
        _that.ruleForm={
          idTask: row.id,
          taskStatus: row.taskStatus,
          isComplete: true,
          feedbackCount:'',
          memo: "",
        }
      }else if(row.workProcess.feedBackContent==2){
        _that.workProcessShow = true;
        _that.feedBackContentVisible = true;
        _that.ruleForm={
          idTask: row.id,
          taskStatus: row.taskStatus,
          isComplete: true,
          feedbackCount: '',
          memo: "",
        }
      }
    },
    //任务暂停
    handlePause(id,pauseStatus){
      const _that = this;
      if(pauseStatus==1){
        _that.printbilTitle = "确定启动？";
        _that.printForm={
          id: id,
          pauseStatus: 0,
          taskMemo: ""
        }
      }else if(pauseStatus==0){
        _that.printbilTitle = "确定暂停？";
        _that.printForm={
          id: id,
          pauseStatus: 1,
          taskMemo: ""
        }
      }
      _that.printbilVisible = true;
    },
    getMachList(){
      const _that = this
      _that.listLoading = true;
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var params= {
        "keyWord":_that.searchVal
      };
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }

      getMachineInfoList(data).then(response => {
        // console.log('getMachineInfoList', response)
        const data = response.data
        // //  组合表单数据
        _that.tableData2 = data
        // console.log(_that.tableData)
        _that.listData2.total = response.total
        _that.listLoading = false
      }).catch(err => {
        _that.listLoading = false;
        _that.$message.error(err)
      })
    },
    //获取列表
    getTableInfo() {
      const _that = this
      _that.listLoading = true;
      var idMachineInfo1 = _that.machineId;

      var data = {
        idMachineInfo: idMachineInfo1
      }


      getMachineInfoByID(data).then(res => {
        // console.log(res.data.machineName);
        _that.printMachineName = res.data.machineName;
      }).catch(err => {
      })
      // console.log(dyERP);
      // alert(idMachineInfo)
      if(idMachineInfo1=="" || undefined || null){
        // idMachineInfo=0
      }
      // console.log(idMachineInfo1);

      // console.log(datas);
      // var Infos = {
      //   "params": JSON.stringify(datas),
      // }
      var url = window.location.href.split(":id");
      var idProcess =url[1];
      var params = {
        idProcess:idProcess,
        idMachineInfo:idMachineInfo1,
        keyWord:_that.search.keyWord
      };
      var page = {
        pageIndex:_that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var dataInfo = {
        "params": JSON.stringify(params),
        "page": JSON.stringify(page),
      }
      getPageInfo(dataInfo).then(response => {
        _that.listData.total = response.total;
        if(response.data.length>0){
          _that.tableData = response.data
          _that.copyTableData = JSON.parse(JSON.stringify(_that.tableData));
        }
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err);
        _that.listLoading = false
      })
    },

    //刷新表格
    tableRefresh() {
      //刷新变革
      this.listData.page=1;
      this.tableData = [];
      this.machinefListVisible = false;
      this.getTableInfo()
    },
    closeDrawer(){
      this.machinefListVisible = false;
    },
    //搜索
    searchData() {
      this.listData.page = 1;
      this.search.idMachineInfo = "";
      this.machinefListVisible = false;
      this.getTableInfo()
    },
    $tableScrollMove(refName, index) {
      if (!refName || !this.$refs[refName]) return//不存在表格的ref vm 则返回
      let vmEl = this.$refs[refName].$el
      if (!vmEl) return
      //计算滚动条的位置
      const targetTop = vmEl.querySelectorAll('.elTble .el-table__body tr')[index].getBoundingClientRect().top
      const containerTop = vmEl.querySelector('.elTble .el-table__body').getBoundingClientRect().top
      const scrollParent = vmEl.querySelector('.elTble .el-table__body-wrapper')
      scrollParent.scrollTop = targetTop - containerTop;
    },
    //序号
    indexMethod(index) {
      return index+1;
    },
    getCodeName(row){
      return row.printBill.billCode+"-"+row.printBreed.breedName
    },
    getPaper(row){
      return row.printBreed.cutSize+"-"+row.printBreed.paperName;
    },
    rowContextmenu(row, column, event) {
      const _that = this;
      _that.row = row;
      _that.clickCheckId = row.id;
      if(row.pauseStatus==1){
        _that.btnList[0].name="启动";
        _that.btnShow = true;
      }
      if(row.pauseStatus==0){
        _that.btnList[0].name="暂停";
        _that.btnShow = false;
      }
      _that.menuVisible = false;
      _that.menuVisible = true;

      // _that.$refs.multipleTable.toggleRowSelection(row);
      // 阻止右键默认行为
      event.preventDefault()
      _that.$nextTick(() => {
        _that.$refs.rightmenu.init(row, column, event);
      })
    },
    foo() {// 取消鼠标监听事件 菜单栏
      this.menuVisible = false;
      document.removeEventListener('click', this.foo)
    }
  }
}
</script>
<style>
.hsp {
  background: yellow !important;
}
</style>

<style lang="scss" scoped>
::v-deep .el-table__fixed {

  bottom: 15px !important;

}
::v-deep .elTble .el-table .primary-row {
  background: #8cc5ff!important;
  color: #fff!important;
}
::v-deep .elTble .el-table .complete-text a {
  color: #67C23A!important;
}
::v-deep .elTble .el-table .complete-text .cell {
  color: #67C23A!important;
}
aside{
  background: #eef1f6;
  padding: 18px 24px;
  margin-bottom: 20px;
  border-radius: 2px;
  display: block;
  line-height: 32px;
  font-size: 16px;
  font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;
  color: #2c3e50;
  -webkit-font-smoothing: antialiased;
}
.filter-container {
  margin-bottom: 15px;
}
.text-task {
  font-size: 14px;
  text-align: center;
  color: #7c7c7c;
  margin-left: 15px;
}
</style>

