<template>
  <div class="app-container">
    <div class="filter-container">

      <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="primary" @click="checkRepot">-->
      <!--        选择日报表-->
      <!--      </el-button>-->
      <!--      <el-button size="mini" class="filter-item" type="success" @click="generateBtn">-->
      <!--        批量生成日报表-->
      <!--      </el-button>-->
    </div>
    <div class="table-con">
      <el-table
        size="mini"
        :data="tableData"
        v-loading="listLoading"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        border
      >
        <el-table-column
          label="#"
          align="center"
          type="index"
          :index="indexMethod">
        </el-table-column>
        <el-table-column label="操作" align="left" width="240" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <el-button @click="handleEdit(row.id)" plain type="primary" size="mini">
              修改
            </el-button>
            <el-button @click="handleRecord(row)" plain type="warning" size="mini">
              修图记录
            </el-button>
            <el-button @click="handlePrint(row)" plain type="success" size="mini">
              打印
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="personName"
          width="90"
          label="报表人">
        </el-table-column>
        <el-table-column
          prop="totalPCount"
          width="60"
          label="总P数">
        </el-table-column>
        <el-table-column
          width="60"
          label="状态">
          <template slot-scope="{row}">
            <el-tag v-if="row.itemState<=1" size="mini" type="danger">
              待审核
            </el-tag>
            <el-tag v-else-if="row.itemState==2" size="mini" type="success">
              已审核
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="checkMan"
          width="90"
          label="审核人">
        </el-table-column>
        <el-table-column
          label="审核日期"
          width="160"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.checkTime">{{ scope.row.checkTime | getTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="itemMemos"
          width="100"
          label="备注">
        </el-table-column>
        <el-table-column
          prop="typePCount1"
          width="80"
          label="合版类P数">
        </el-table-column>
        <el-table-column
          prop="typePCount2"
          width="80"
          label="画册台历挂历周历P数">
        </el-table-column>
        <el-table-column
          prop="typePCount3"
          width="80"
          label="单页/联单/对联P数">
        </el-table-column>
        <el-table-column
          prop="typePCount4"
          width="80"
          label="模切/袋子类P数">
        </el-table-column>
        <el-table-column
          prop="typePCount5"
          width="80"
          label="数码/小批量/单色画册P数">
        </el-table-column>
        <el-table-column
          prop="typePCount6"
          width="80"
          label="盒子/专色P数">
        </el-table-column>
        <el-table-column
          prop="createMan"
          width="90"
          label="制单人">
        </el-table-column>
        <el-table-column
          label="制单日期"
          width="160"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.mainCreateTime">{{ scope.row.mainCreateTime | getTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="reportName"
          width="140"
          label="报表名称"
        >

        </el-table-column>
        <el-table-column
          label="起始日期"
          width="160"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.beginTime">{{ scope.row.beginTime | getTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="160"
          label="结束时间"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.endTime">{{ scope.row.endTime | getTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="createMan"
          width="90"
          label="创建人">
        </el-table-column>
        <el-table-column
          label="创建时间"
          width="160"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.createTime">{{ scope.row.createTime | getTime }}</span>
          </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="修改日报表" width="500px" :visible.sync="dialogEditVisible">
      <el-form>
        <el-form-item label="备注" label-width="100">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="textarea">
          </el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">

        <el-button @click="dialogEditVisible = false">取 消</el-button>
        <el-button type="primary" @click="editSubmit">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog top="10px" title="修图人修图记录明细" width="1150px" :visible.sync="dialogTableVisible">
      <el-table
        size="mini"
        max-height="700"
        :data="gridData"
        v-loading="recorLoading"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        border
      >
        <el-table-column
          label="#"
          type="index"
          :index="indexMethod">
        </el-table-column>
        <el-table-column
          prop="itemKindName"
          width="130px"
          label="P数类型">
        </el-table-column>
        <el-table-column
          label="p数"
          align="center"
          show-overflow-tooltip
          width="80"
        >
          <template slot-scope="{row}">
            <span @click.stop="handlePCount(row)"
                  style="width: 80px;display: block;cursor: pointer;color: #409eff">{{ row.pCount }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="修改次数"
          align="center"
          show-overflow-tooltip
          width="60"
        >
          <template slot-scope="{row}">
            <span style="color: #e4493c" v-if="row.editCountP>=1">{{ row.editCountP }}</span>
            <span v-else>{{ row.editCountP }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="修图人"
          show-overflow-tooltip
          width="80"
        >
          <template slot-scope="{row}">
            <span>{{ row.userName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单编号"
          show-overflow-tooltip
          width="100"
        >
          <template slot-scope="{row}">
            <span>{{ row.printOrder.orderCode }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="产品类型"
          show-overflow-tooltip
          width="120"
        >
          <template slot-scope="{row}">
            <span>{{row.printOrder.productName}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="印品名称"
          show-overflow-tooltip
          width="140"
        >
          <template slot-scope="{row}">
            <span @click="openDetail(row.printOrder)"
                  style="color: #20a0ff;cursor: pointer">{{ row.printOrder.orderName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单备注"
          show-overflow-tooltip
          width="350"
        >
          <template slot-scope="{row}">
            {{ row.printOrder.orderMemo }}
          </template>
        </el-table-column>
        <el-table-column
          label="客户名称"
          show-overflow-tooltip
          width="140"
        >
          <template slot-scope="{row}">
            {{ row.printOrder.clientName }}
          </template>
        </el-table-column>
      </el-table>
      <span style="font-size: 16px;margin-top: -10px;padding-bottom: 10px" v-if="pCount_Sum">P数合计：<span
        style="font-weight: bold;color: #409EFF">{{ pCount_Sum }}</span></span>
      <pagination v-show="listData2.total>0" :total="listData2.total" :page.sync="listData2.page"
                  :limit.sync="listData2.pageSize" @pagination="getRecordInfo"/>
    </el-dialog>
    <el-dialog
      title="订单详情"
      append-to-body
      :close-on-click-modal="false"
      class="orderDetailDialog"
      :visible.sync="detailVisible"
      top="10px"
      width="1200px">
      <order-detail ref="orderDetail"></order-detail>
    </el-dialog>
    <pcount-edit @getList="getRecordInfo" ref="pcountEdit"></pcount-edit>
  </div>
</template>

<script>
import {
  getRetouchDailyReportItemList,
  editRetouchDailyReportItem,
  getRetouchOrderDetailList
} from '@/api/specialEdition/reportJs.js'
import OrderDetail from '@/components/orderDetail/orderDetail'
import {mapGetters} from 'vuex'
import pcountEdit from "@/views/specialEdition/components/pcountEdit";
import {doLocalPrint} from "@/utils";

export default {
  name: "list",
  components: {
    OrderDetail,
    pcountEdit
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  data() {
    return {
      recorLoading: false,
      pCount_Sum: "",
      titlePConut: "",
      formData: {
        PCount: ''
      },
      dialogFormVisible: false,
      detailVisible: false,
      rowData: {},
      gridData: [],
      dialogEditVisible: false,
      textarea: "",
      rowId: "",
      dialogTableVisible: false,
      listLoading: false,
      tableData: [],
      search: {
        keyWord: '',
        idUser: ""
      },
      listData: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      listData2: {
        total: 0,
        page: 1,
        pageSize: 50
      }
    }
  },
  mounted() {
    this.getTableInfo();
    // console.log(this.user);
  },
  methods: {
    handlePrint(row) {
      var _that = this;
      _that.$confirm('确定打印？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var itemMemos = ""
        if(row.itemMemos==null){
          itemMemos = "";
        }else {
          itemMemos = row.itemMemos
        }
        var parms = [{
          personName: row.personName,
          reportName: row.reportName,
          totalPCount: row.totalPCount,
          typePCount1: row.typePCount1,
          typePCount2: row.typePCount2,
          typePCount3: row.typePCount3,
          typePCount4: row.typePCount4,
          typePCount5: row.typePCount5,
          typePCount6: row.typePCount6,
          typePCount7: row.typePCount7,
          typePCount8: row.typePCount8,
          typePCount9: row.typePCount9,
          typePCount10: row.typePCount10,
          itemMemos: itemMemos
        }]
        // console.log(parms);
        const printData = {
          '_rootData': parms
        }
        const pData = {
          PrintTemplate: 'reportinfopersonal.fr3',
          NeedPreview: 1,
          PrintData: JSON.stringify(printData)
        }

        doLocalPrint(pData)

      }).catch(() => {

      });
    },
    handlePCount(row) {
      var _that = this;
      // _that.rowId = row.id;
      // _that.formData.PCount = row.pCount;
      // _that.pcountType = row.itemKind
      // _that.titlePConut = "修改订单P数"+"("+row.printOrder.orderName+")";
      _that.$refs.pcountEdit.dialogFormVisible = true;
      _that.$refs.pcountEdit.rowId = row.id;
      _that.$refs.pcountEdit.PCount = row.pCount;
      _that.$refs.pcountEdit.pcountType = row.itemKind;
      _that.$refs.pcountEdit.titlePConut = "修改订单P数" + "(" + row.printOrder.orderName + ")";
      _that.$refs.pcountEdit.getPcountTypeList();

    },
    openDetail(row) {
      var _that = this
      _that.detailVisible = true
      _that.$nextTick(() => {
        _that.$refs.orderDetail.idOrder = row.id
        _that.$refs.orderDetail.getInfo()
      })
    },
    handleRecord(row) {
      const _that = this;
      _that.dialogTableVisible = true;
      _that.rowData = row;
      _that.getRecordInfo();
    },
    getRecordInfo() {
      const _that = this;
      _that.recorLoading = true;
      var page = {
        pageIndex: _that.listData2.page,
        pageSize: _that.listData2.pageSize,
      }
      var infoParam = {
        "idUser": _that.user.id,
        "beginTime": JSON.stringify(_that.rowData.beginTime),
        "endTime": JSON.stringify(_that.rowData.endTime),
        "page": JSON.stringify(page),
      }
      // console.log(data);
      getRetouchOrderDetailList(infoParam).then(response => {
        console.log("tableData", response)
        const data = response.data
        // //  组合表单数据
        _that.gridData = data;
        _that.pCount_Sum = response.collection.pCount_Sum
        _that.listData2.total = response.total
        // console.log(_that.tableData)
        _that.recorLoading = false;
      }).catch(err => {
        _that.recorLoading = false;
      })
    },
    editSubmit() {
      const _that = this;
      _that.dialogEditVisible = false;
      const srcReportItem = {
        id: _that.rowId,
        itemMemos: _that.textarea
      };
      var data = {
        "srcReportItem": JSON.stringify(srcReportItem)
      }

      // return
      editRetouchDailyReportItem(data).then(response => {
        _that.$message.success('修改成功');
        // _that.listData.page = 1;
        _that.getTableInfo()
      }).catch(err => {
        // _that.$message.error(err)
      })
    },

    handleEdit(id) {
      //修改
      const _that = this;
      _that.rowId = id;
      _that.textarea = "";
      _that.dialogEditVisible = true;
    },
    //获取表格数据
    getTableInfo() {
      const _that = this
      _that.listLoading = true;
      _that.search.idUser = _that.user.id;
      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);
      getRetouchDailyReportItemList(data).then(response => {
        // console.log("tableData",response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data
        _that.listData.total = response.total
        // console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.listLoading = false
      })
    },
    //搜索
    searchData() {
      this.listData.page = 1;
      this.getTableInfo()
    },
    //序号
    indexMethod(index) {
      return index + 1;
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  background-color: #f0f2f5;
  padding: 30px;
  min-height: calc(100vh - 84px);
}

.filter-container {
  margin-bottom: 15px;
}
</style>

