<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        :size="sizeType"
        v-model="search.orderCode"
        placeholder="订单单号"
        style="width: 200px;"
        class="filter-item"/>
      <el-input :size="sizeType" v-model="search.userName" placeholder="修图人" style="width: 200px;" class="filter-item"/>
      <el-select :size="sizeType" v-model="search.dispatchState">
        <el-option
          v-for="item in stateOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"></el-option>
      </el-select>
      <el-date-picker
        :size="sizeType"
        v-model="searchTime"
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd HH:mm:ss"
        :default-time="['00:00:00', '23:59:59']">
      </el-date-picker>
      <el-button :size="sizeType" class="filter-item" type="primary" icon="el-icon-search" @click="searchData">
        搜索
      </el-button>
      <el-button size="mini" class="filter-item" type="primary" @click="designerBtn">
        人员排序
      </el-button>
      <el-switch
        size="mini"
        class="filter-item"
        v-model="workKind"
        style="margin-right: 1em"
        inactive-color="#13ce66"
        active-text="手工分配"
        inactive-text="自动分配"
        :active-value="1"
        :inactive-value="0"
        @change="changeKind"
      >
      </el-switch>
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="getList"/>
        </el-tooltip>
      </div>
    </div>
    <el-table
      size="mini"
      :data="tableData"
      v-loading="listLoading"
      max-height="320px"
      row-key="id"
      border
      style="margin-top: 10px"
      ref="orderTable"
      :row-style="customRowStyle"
      default-expand-all>
      <el-table-column
        label="序号"
        fixed
        align="center"
        width="50"
        type="index">
        <template slot-scope="scope">
          <span>{{ (listData.page - 1) * listData.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>

      <el-table-column
        fixed
        label="操作"
        align="center"
        width="295">
        <template slot-scope="{row}">
          <el-button
            v-if="row.workStatus == 0"
            @click="handleDispatch(row)"
            type="primary"
            :size="sizeType">
            分配
          </el-button>
          <el-button
            v-if="row.workStatus == 0"
            @click="backDispatch(row)"
            type="danger"
            :size="sizeType">
            退回
          </el-button>
          <el-button
            v-if="row.workStatus == 10"
            @click="completeProof(row)"
            type="primary"
            :size="sizeType">
            校稿完成
          </el-button>
          <el-button
            v-if="row.workStatus == 10"
            @click="backProof(row)"
            type="danger"
            :size="sizeType">
            校稿退回
          </el-button>
          <el-button size="mini" v-if="row.workStatus == 10 || row.workStatus == 100" @click="downloadPDF(row)">下载pdf文件</el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="printOrder.orderCode"
        label="订单编号"
        width="130">
        <template slot-scope="{row}">
          <a href="javascript:;" style="color: #20a0ff" @click="getOrderStep(row)">{{ row.printOrder.orderCode }}
            <span v-if="row.printOrder.businessKind==3"
                  style="display: inline-block;color: red">(补{{ row.printOrder.rePrintIndex }})</span>
            <el-image v-if="row.printOrder.firstOrderFlag == 1" :src="new_badge"></el-image></a>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="printOrder.orderName"
        label="印品名称"
        width="110">
        <template slot-scope="{row}">
          <a href="javascript:;" style="color: #20a0ff" @click="openDetail(row.printOrder)">{{
              row.printOrder.orderName
            }}</a>
        </template>
      </el-table-column>
      <el-table-column
        prop="printOrder.productSize"
        label="成品尺寸"
        width="150">
      </el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="printOrder.clientName"
        label="客户名称"
        width="100">
      </el-table-column>
      <el-table-column
        prop="printOrder.saleWorkTeamName"
        label="所属业务组"></el-table-column>
      <el-table-column
        label="状态">
        <template slot-scope="{row}">
          <el-tag size="mini" v-if="row.workStatus == 0">未分配</el-tag>
          <el-tag size="mini" v-else-if="row.workStatus == 1">已分配</el-tag>
          <el-tag size="mini" v-else-if="row.workStatus == 102">已退回</el-tag>
          <el-tag size="mini" v-else-if="row.workStatus == 10">待校稿</el-tag>
          <el-tag size="mini" v-else-if="row.workStatus == 100">已完成</el-tag>
          <el-tag size="mini" v-else-if="row.workStatus == 103">直接完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="userName"
        label="修图人"></el-table-column>
      <el-table-column
        prop="processCount"
        label="处理次数"></el-table-column>
      <el-table-column
        prop="pCount"
        width="65"
        label="订单P数"></el-table-column>
      <el-table-column
        prop="printOrder.partCount"
        width="65"
        label="部件数量"></el-table-column>
      <el-table-column
        prop="processMemo"
        width="100"
        show-overflow-tooltip
        label="退回原因"></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="printOrder.productName"
        label="产品类型"></el-table-column>
      <el-table-column
        prop="printOrder.orderMoneyTotal"
        width="65"
        label="订单金额"></el-table-column>
      <el-table-column label="文件描述" show-overflow-tooltip>
        <template slot-scope="{row}">
          <el-link :href="row.printOrder.originFileLink" target="_blank" style="color: #20a0ff">
            {{ row.printOrder.fileDescription }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column
        width="125"
        label="分配时间">
        <template slot-scope="{row}">
          <span v-if="row.dispatchTime"> {{ row.dispatchTime | getTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="printOrder.orderMemo"
        label="生产备注"></el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="printOrder.allProcessStr"
        label="订单后工"></el-table-column>
    </el-table>
    <pagination
      v-show="listData.total>0"
      :total="listData.total"
      :page.sync="listData.page"
      :limit.sync="listData.pageSize"
      @pagination="getList"/>
    <div class="sortTable-con" style="margin-top: 20px">
      <div
        size="mini"
        v-for="(item,index) in tableDataDesigner"
        :key="item.id"
        class="item-badge">
        <div v-if="item.workInState==1" style="position: relative;">
          <el-button-group style="width: 160px">
            <el-button style="padding-bottom: 8px" size="mini" :plain="checkId!=item.id" @click="handleClick(index,item.id)" type="success">
              <span style="display: block;width: 80px" class="ellipsis">{{ item.userName }}{{ item.workInCount }}</span>
            </el-button>
            <el-button size="mini" @click="handleClickBtn(index,item.id)" :plain="checkId!=item.id" type="success"><i class="el-icon-arrow-down"></i>
            </el-button>
          </el-button-group>
          <el-button @click="relaxBtn(index,item.id)" type="danger" plain style="position: absolute;left: 75px;top: 28px;z-index: 999;cursor: pointer" size="mini" v-show="checkIdBtn==item.id">停止接单</el-button>
        </div>
        <div v-if="item.workInState==2" style="position: relative;">
          <el-button-group style="width: 160px">
            <el-button style="padding-bottom: 8px" size="mini" :plain="checkId!=item.id" @click="handleClick(index,item.id)" type="danger">
              <span style="display: block;width: 80px" class="ellipsis">{{ item.userName }}{{ item.workInCount }}</span>
            </el-button>
            <el-button size="mini" @click="handleClickBtn(index,item.id)" :plain="checkId!=item.id" type="danger"><i class="el-icon-arrow-down"></i>
            </el-button>
          </el-button-group>
          <el-button @click="busyBtn(index,item.id)" type="success" plain style="position: absolute;left: 75px;top: 28px;z-index: 999;cursor: pointer" size="mini" v-show="checkIdBtn==item.id">开始接单</el-button>
        </div>
      </div>
    </div>
    <div v-if="printOrderList.length>0" style="margin-top: 15px">
      <el-table
        size="mini"
        :data="printOrderList"
        v-loading="listLoadingOrder"
        max-height="320px"
        row-key="id"
        border
        style="margin-top: 10px"
        ref="orderTable"
        default-expand-all>
        <el-table-column
          label="序号"
          fixed
          align="center"
          width="50"
          type="index">
          <template slot-scope="scope">
            <span>{{ (listDataOrder.page - 1) * listDataOrder.pageSize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="printOrder.orderCode"
          label="订单编号"
          width="100">
          <template slot-scope="{row}">
            <a href="javascript:;" style="color: #20a0ff" @click="getOrderStep(row)">{{ row.printOrder.orderCode }}</a>
          </template>
        </el-table-column>
        <el-table-column
          prop="printOrder.orderName"
          label="印品名称"
          width="110"
          show-overflow-tooltip>
          <template slot-scope="{row}">
            <a href="javascript:;" style="color: #20a0ff" @click="openDetail(row.printOrder)">{{
                row.printOrder.orderName
              }}</a>
          </template>
        </el-table-column>
        <el-table-column
          prop="printOrder.productSize"
          label="成品尺寸"
          width="150">
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="printOrder.clientName"
          label="客户名称"
          width="100">
        </el-table-column>
        <el-table-column
          prop="printOrder.saleWorkTeamName"
          label="所属业务组"></el-table-column>
        <el-table-column
          label="状态">
          <template slot-scope="{row}">
            <el-tag size="mini" v-if="row.workStatus == 0">未分配</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 1">已分配</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 102">已退回</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 10">待校稿</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 100">已完成</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 103">直接完成</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="userName"
          label="修图人"></el-table-column>
        <el-table-column
          prop="processCount"
          label="处理次数"></el-table-column>
        <el-table-column
          prop="pCount"
          width="65"
          label="订单P数"></el-table-column>
        <el-table-column
          prop="printOrder.partCount"
          width="65"
          label="部件数量"></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="printOrder.productName"
          label="产品类型"></el-table-column>
        <el-table-column
          prop="printOrder.orderMoneyTotal"
          width="65"
          label="订单金额"></el-table-column>
        <el-table-column label="文件描述" show-overflow-tooltip>
          <template slot-scope="{row}">
            <el-link :href="row.printOrder.originFileLink" target="_blank" style="color: #20a0ff">
              {{ row.printOrder.fileDescription }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column
          width="125"
          label="分配时间">
          <template slot-scope="{row}">
            <span v-if="row.dispatchTime"> {{ row.dispatchTime | getTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="printOrder.orderMemo"
          label="生产备注"></el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="printOrder.allProcessStr"
          label="订单后工"></el-table-column>
      </el-table>
      <pagination
        v-show="listDataOrder.total>0"
        :total="listDataOrder.total"
        :page.sync="listDataOrder.page"
        :limit.sync="listDataOrder.pageSize"
        @pagination="getPrintOrderList"/>
    </div>

    <el-dialog title="分配订单" :close-on-click-modal="false" :visible.sync="distributeDialog" width="800px">
      <el-table
        :data="checkInUserList"
        border
        v-loading="userListLoading">
        <el-table-column label="操作">
          <template slot-scope="{row}">
            <el-button size="mini" type="primary" @click="chooseUser(row)">选择</el-button>
          </template>
        </el-table-column>
        <el-table-column label="用户名" prop="userName"></el-table-column>
        <el-table-column label="上班时间" prop="checkInTime">
          <template slot-scope="{row}">
            <span v-if="row.checkInTime">{{ row.checkInTime | getTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="工作状态" prop="checkInTime">
          <template slot-scope="{row}">
            <el-tag v-if="row.workInState == 1" type="success">可接单</el-tag>
            <el-tag v-else-if="row.workInState == 2" type="danger">忙碌</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="P数" prop="workInCount">
        </el-table-column>
      </el-table>
      <pagination
        v-show="userListData.total>0"
        :total="userListData.total"
        :page.sync="userListData.page"
        :limit.sync="userListData.pageSize"
        @pagination="getCheckInUser"/>
    </el-dialog>
    <el-dialog title="退回" :close-on-click-modal="false" :visible.sync="backDialog" width="500px">
      <el-form label-width="80px" label-position="right">
        <el-form-item label="退回备注">
          <el-input type="textarea" v-model="backInfo.returnMemo"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="backDialog = false">取 消</el-button>
        <el-button type="primary" @click="checkBack">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="校稿退回" :close-on-click-modal="false" :visible.sync="proofBackDialog" width="500px">
      <el-form label-width="80px" label-position="right">
        <el-form-item label="退回备注">
          <el-input type="textarea" v-model="proofBackInfo.returnMemo"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="proofBackDialog = false">取 消</el-button>
        <el-button type="primary" @click="backProofSure">确 定</el-button>
      </div>
    </el-dialog>
    <order-step ref="orderStep"></order-step>
    <el-dialog title="订单详情" :close-on-click-modal="false" class="orderDetailDialog" :visible.sync="detailVisible" top="10px" width="1200px">
      <order-detail ref="orderDetail"></order-detail>
    </el-dialog>
    <el-dialog top="20" :before-close="handleClose" title="人员排序" :visible.sync="dangerDialog" width="500px">
      <draggable  class="board-column-content" :list="tableDataDesignerCopy" group="people" @start="drag=true" @end="drag=false">
        <div class="board-item" v-for="(element,index) in tableDataDesignerCopy" :key="element.id"><span @click="handleSortFirst(element,index)" style="margin-right: 5px;color: #409EFF">置顶</span>{{index+1}}  {{element.userName}}({{element.workInCount}})</div>
      </draggable>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="sortDesignerBtn">确 定</el-button>
      </div>
    </el-dialog>
    <cancledialog @tableRefresh="tableRefresh" ref="confirmDialog" :noDoubleClick="true"></cancledialog>
  </div>
</template>

<script>
import {
  getPrintOrderList,
  getAllCheckInUser,
  manualDispatchOrder,
  returnOrder,
  getImageDesignerStateList,
  relaxedOtherCheck,
  busyOtherCheck,
  sortImageDesignerList,
  configDispatchWorkKind,
  getDispatchWorkKind,
  proofBackOrder,
  imageDispatchFormToken
} from '@/api/specialEdition/dispatchOrder'
import OrderStep from '@/components/orderStep/orderStep'
import OrderDetail from "@/components/orderDetail/orderDetail";
import draggable from 'vuedraggable'
import Cancledialog from "@/components/Dialog/Cancledialog";
import new_badge from '@/assets/new_badge.gif'

export default {
  name: 'DispatchOrder',
  components: {Cancledialog, OrderDetail, OrderStep,draggable},
  data() {
    return {
      dispatchFormToken:"",
      intervalId:null,
      dangerDialog:false,
      new_badge: new_badge,
      checkIdBtn:"",
      printOrderList: [],
      checkId: "",
      tableDataDesignerCopy: [],
      tableDataDesigner: [],
      sizeType: 'mini',
      search: {
        orderCode: '',
        userName: '',
        dispatchState: 0,
        dispatchBeginTime: '',
        dispatchEndTime: ''
      },
      searchTime:[],
      tableData: [],
      listLoadingOrder: false,
      listLoading: false,
      listData: {
        total: 0,
        page: 1,
        pageSize: 20
      },
      listDataOrder: {
        total: 0,
        page: 1,
        pageSize: 30
      },
      stateOptions: [
        {
          label: '未分配',
          value: 0
        },
        {
          label: '已分配',
          value: 1
        },
        {
          label: '待校稿',
          value: 10
        },
        {
          label: '已完成',
          value: 100
        },
        {
          label: '已退回',
          value: 102
        }
      ],
      chooseInfo: {
        id: '',
        idOrder: '',
        pCount: '',
        orderCode: ''
      },
      distributeDialog: false,
      checkInUserList: [],
      userListLoading: false,
      userListData: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      backDialog: false,
      backInfo: {
        idItem: '',
        returnMemo: ''
      },

      drawer: false,
      stepList: [],
      timeString: '',
      detailVisible: false,
      workKind:0,

      proofBackDialog:false,
      proofBackInfo:{
        idItem:'',
        returnMemo:'',
      },
    }
  },
  created(){
    this.getImageDesignerStateList();
    this.dataRefreh();
  },
  destroyed(){
    // 在页面销毁后，清除计时器
    this.clear();
  },
  mounted() {
    this.getList();

    // this.timer = setInterval(() => {
    //   setTimeout(this.getImageDesignerStateList, 0)
    // }, 5000)
    this.getWorkKind();
  },
  methods: {
    handleClose(){
      const _that = this;
      _that.dataRefreh();
      _that.dangerDialog = false;
    },
    dataRefreh() {
      // 计时器正在进行中，退出函数
      const _that = this;
      if (_that.intervalId != null) {
        return;
      }
      // 计时器为空，操作
      _that.intervalId = setInterval(() => {
        // console.log("刷新" + _that.$route.path);
        if(_that.$route.path=="/idp/dispatchOrder"){
        _that.getImageDesignerStateList(); //加载数据函数
        }
      }, 5000);
    },
    // 停止定时器
    clear() {
      clearInterval(this.intervalId); //清除计时器
      this.intervalId = null; //设置为null
    },
    sortDesignerBtn(){
      const _that = this;
      var tasks = [];
      for (let i = 0; i < _that.tableDataDesignerCopy.length; i++) {
        var dataItem = _that.tableDataDesignerCopy[i];
        var info = {
          id:"",
          value:""
        }
        info.id = dataItem.id;
        info.value = i+1;
        tasks.push(info)
      }
      // console.log(tasks);
      var data = {
        tasks:JSON.stringify(tasks),
      }
      sortImageDesignerList(data).then(response => {
        _that.$message.success("成功");
        _that.getImageDesignerStateList();
        _that.dataRefreh();
        _that.dangerDialog = false;
      }).catch(err => {
        _that.$message.error(err);
        _that.dangerDialog = false;
      })
    },
    handleSortFirst(row, index) {
      const _that = this;
      _that.tableDataDesignerCopy.splice(index, 1);
      _that.tableDataDesignerCopy.splice(0, 0, row);
    },
    designerBtn(){
      const _that = this;
      _that.clear();
      _that.dangerDialog = true;
    },
    relaxBtn(index, id){
      const _that = this;
      _that.checkIdBtn = "";
      var data = {
        idUser:id
      }
      busyOtherCheck(data).then(response => {
        _that.$message.success("开始接单成功");
        _that.getImageDesignerStateList();
      }).catch(err => {
        _that.$message.error(err);
      })
    },
    busyBtn(index, id){
      const _that = this;
      _that.checkIdBtn = "";
      var data = {
        idUser:id
      }
      relaxedOtherCheck(data).then(response => {
        _that.$message.success("停止接单成功");
        _that.getImageDesignerStateList();
      }).catch(err => {
        _that.$message.error(err);
      })
    },
    handleClick(index, id) {
      const _that = this;
      _that.checkId = id;
      _that.checkIdBtn = "";
      _that.getPrintOrderList();
    },
    handleClickBtn(index, id) {
      const _that = this;
      _that.checkIdBtn = id;
    },
    getPrintOrderList() {
      const _that = this;
      _that.listLoadingOrder = true;
      var params = {
        dispatchState: 1,
        idImageUser: _that.checkId
      }
      var page = {
        pageIndex: _that.listDataOrder.page,
        pageSize: _that.listDataOrder.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      getPrintOrderList(data).then(response => {
        _that.listLoadingOrder = false;
        const data = response.data
        // //  组合表单数据
        _that.listDataOrder.total = response.total
        _that.printOrderList = data;
        _that.listLoadingOrder = false;
      }).catch(err => {
        _that.$message.error(err);
      })
    },
    getImageDesignerStateList() {
      const _that = this;
      var data = {}
      getImageDesignerStateList(data).then(response => {
        const data = response.data
        // //  组合表单数据
        _that.tableDataDesigner = data;
        _that.tableDataDesignerCopy = JSON.parse(JSON.stringify(_that.tableDataDesigner));
        // _that.listData2.total = response.total
      }).catch(err => {
        _that.$message.error(err);
      })
    },
    getList() {
      var _that = this;
      _that.listLoading = true;
      if (_that.searchTime == null || _that.searchTime < 0) {
        _that.search.dispatchBeginTime = ''
        _that.search.dispatchEndTime = ''
      } else {
        _that.search.dispatchBeginTime = _that.searchTime[0]
        _that.search.dispatchEndTime = _that.searchTime[1]
      }
      var params = _that.search
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      if (_that.listData.pageSize == 10) {
        _that.sizeType = 'medium'
      } else {
        _that.sizeType = 'mini'
      }
      // console.log(data);
      getPrintOrderList(data).then(response => {
        // console.log(response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data
        _that.listData.total = response.total
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },

    customRowStyle({row, rowIndex}) {
      if (row.processMemo != '' && row.processMemo != null) {
        return {
          background: '#e5b6b6'
        }
      }
    },

    getWorkKind() {
      const _that = this;
      getDispatchWorkKind().then(res =>{
        console.log(res);
        _that.workKind = res.data
        console.log(_that.workKind);
      })
    },
    changeKind() {
      const _that = this
      var data = {
        'workKind': _that.workKind
      }
      configDispatchWorkKind(data).then(res => {
        console.log(res);
      })
    },

    // 搜索
    searchData() {
      this.listData.page = 1
      this.getList()
    },

    // 刷新
    tableRefresh() {
      this.getList()
    },

    // 获取脚印
    getOrderStep(row) {
      const _that = this
      _that.$refs.orderStep.idOrder = row.printOrder.id
      _that.$refs.orderStep.getOrderStep()
    },
    // 订单详情
    openDetail(row) {
      var _that = this
      _that.detailVisible = true
      _that.$nextTick(() => {
        _that.$refs.orderDetail.idOrder = row.id
        _that.$refs.orderDetail.getInfo()
      })
    },
    // 分配
    handleDispatch(row) {
      const _that = this
      _that.distributeDialog = true
      _that.chooseInfo.idOrder = row.idOrder
      _that.chooseInfo.pCount = row.pCount
      _that.chooseInfo.id = row.id
      _that.chooseInfo.orderCode = row.printOrder.orderCode;
      var data = {}
      imageDispatchFormToken(data).then(res => {
        console.log(res)
        _that.dispatchFormToken = res.data;
        // _that.tableRefresh()
      }).catch(err => {
        _that.$message.error(err)
      })
      _that.getCheckInUser()
    },
    getCheckInUser() {
      const _that = this
      var page = {
        pageIndex: _that.userListData.page,
        pageSize: _that.userListData.pageSize
      }
      var data = {
        // 'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      getAllCheckInUser(data).then(res => {
        console.log(res)
        _that.userListLoading = false
        _that.checkInUserList = res.data
        // _that.tableRefresh()
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    chooseUser(row) {
      const _that = this;
      _that.distributeDialog = false
      var data = {
        // 'idOrder': _that.chooseInfo.idOrder,
        // 'pCount': _that.chooseInfo.pCount,
        // 'orderCode': _that.chooseInfo.orderCode,
        'idItem': _that.chooseInfo.id,
        'idDispatchUser': row.id,
        'token':_that.dispatchFormToken
      }
      // console.log(data);
      // return
      manualDispatchOrder(data).then(res => {
        // console.log(res)
        if (res.httpCode == 200) {
          _that.$message({
            message: '分配成功',
            type: 'success'
          })
          _that.tableRefresh()
        } else {
          _that.$message.error(res.msg)
        }
      }).catch(err => {
        _that.$message.error(err)
      })
    },

    // 退回
    backDispatch(row) {
      const _that = this
      _that.backDialog = true
      _that.backInfo.idItem = row.id
      _that.backInfo.returnMemo = ''
    },
    checkBack() {
      var _that = this
      // var data = {
      //   backInfo: _that.backInfo
      // }
      returnOrder(_that.backInfo).then(response => {
        console.log(response)
        if (response.httpCode == 200) {
          _that.backDialog = false
          _that.$message({
            message: '退回成功',
            type: 'success'
          })
          _that.tableRefresh()
        }
      }).catch(err => {
        _that.$message.error(err)
      })
    },

    // 校稿完成
    completeProof(row) {
      const _that = this
      var data = {
        idItem: row.id
      }
      var url = '/idp/proofCompleteOrder'
      _that.$refs.confirmDialog.updataClick(data, url)
    },
    // 退回校稿
    backProof(row) {
      const _that = this
      _that.proofBackDialog = true
      _that.proofBackInfo.idItem = row.id
      _that.proofBackInfo.returnMemo = ''
    },
    backProofSure() {
      var _that = this
      // var data = {
      //   backInfo: _that.backInfo
      // }
      proofBackOrder(_that.proofBackInfo).then(response => {
        console.log(response)
        if (response.httpCode == 200) {
          _that.proofBackDialog = false
          _that.$message({
            message: '退回成功',
            type: 'success'
          })
          _that.tableRefresh()
        }
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    downloadPDF(row){
      const _that = this;
      var userAgent = navigator.userAgent
      if (userAgent.indexOf('DnyERPBrowser') > 0) {
        dyERP.sendOrderPDFFile(row.idOrder.toString(), row.printOrder.orderCode)
      } else {
        // alert('请使用开发商提供的ERP客户端')
        _that.$message({
          message: '请使用开发商提供的ERP客户端',
          type: 'warning'
        })
      }
    }
  },

  beforeDestroy() {
    clearInterval(this.timer);
    this.timer = null;
  }
  }
</script>

<style scoped>
.board-column-content {
  padding-top: 10px;
  height: 600px;
  overflow-y: auto;
  border: 10px solid transparent;
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
  align-items: center;
  background-color: #EBEEF5;
}
.board-item {
  cursor: pointer;
  width: 100%;
  height: 34px;
  margin: 5px 0;
  background-color: #f6f6f6;
  text-align: left;
  line-height: 24px;
  padding: 5px 10px;
  box-sizing: border-box;
  box-shadow: 0px 1px 3px 0 rgba(0, 0, 0, 0.2);
}

.item-badge {
  display: inline-block;
  margin-right: 10px;
  margin-bottom: 10px;
}
</style>
