// import {deviceCheckPage, deviceCheckPrint, deviceCheckPrintByDeviceCode} from "@/api/dev/deviceCheckApi";
// import {deviceCheckDetailPage} from "@/api/dev/deviceCheckDetailApi";
// import {deviceCheckDetailItemPage} from "@/api/dev/deviceCheckDetailItemApi";
import {getLoading} from "@/utils";
import { deviceUpkeepPage, deviceCheckPrint, deviceCheckPrintByDeviceCode } from '@/api/dev/deviceUpkeepApi'
import { deviceUpkeepDetailItemPage } from '@/api/dev/deviceUpkeepDetailItemApi'
import { deviceUpkeepDetailPage } from '@/api/dev/deviceUpkeepDetailApi'
import deptDeviceUpkeepDetail from "@/views/dev/deptDeviceUpkeepDetail";



let query = {
  page: 1,
  limit: 10,
  chargeDeptCode: null,
  finishFlag: null,
}


let detailQuery = {
  page: 1,
  limit: 10,
  taskId: null,
  deviceCode: null,
}

let itemQuery = {
  page: 1,
  limit: 10,
  taskId: null,
  deviceCode: null,
}


export default {
  name: "deviceUpkeep",
  computed: {},
  components: {
    deptDeviceUpkeepDetail
  },
  data() {
    return {
      loading: false,
      total: .0,
      list: [],
      query: {...query},
      showSearch: true,
      clickRow: null,
      //保养设备详情=============
      detailLoading: false,
      detailQuery: {...detailQuery},
      detailList: [],
      detailTotal: 0,
      showLog: false,
      itemDialogFlag:false,
      itemQuery: {...itemQuery},
      itemTotal:0,
      itemList:[],
      itemLoading:false,
      checkTipDialogVisible:false,
      curDeviceData: null,
      //===================================================
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // print(taskId, deviceCode) {
    //   let loading = getLoading(this)
    //   if (deviceCode) {
    //     deviceCheckPrintByDeviceCode(taskId, deviceCode).then(res => {
    //       loading.close()
    //       if (res.code != 20000) {
    //         this.$message.error(res.message)
    //         return
    //       }
    //       this.checkPrintData = {...res.data}
    //       setTimeout(() => {
    //         let html = document.getElementById("printDiv").innerHTML;
    //         let newWindow = this.openNewWindow("")
    //         newWindow.document.write(html)
    //         newWindow.print()
    //       }, 500)
    //
    //     }).catch(() => {
    //       loading.close()
    //     })
    //   } else {
    //     deviceCheckPrint(taskId).then(res => {
    //       loading.close()
    //       if (res.code != 20000) {
    //         this.$message.error(res.message)
    //         return
    //       }
    //       this.checkPrintData = {...res.data}
    //       setTimeout(() => {
    //         let html = document.getElementById("printDiv").innerHTML;
    //         let newWindow = this.openNewWindow("")
    //         newWindow.document.write(html)
    //         newWindow.print()
    //       }, 500)
    //
    //     }).catch(() => {
    //       loading.close()
    //     })
    //   }
    // },
    closeCheckDialog() {
      this.checkTipDialogVisible = false
      this.getDetailItemList()
    },
    startUpkeep(row) {
      this.itemQuery = {
        ...itemQuery,
        taskId: row.taskId,
        deviceCode: row.deviceCode,
        title: `[${row.deviceCode}]--${row.productName}(${row.nameCode})`
      }
      this.curDeviceData = row
      this.checkTipDialogVisible = true
    },
    openItem(row) {
      // console.log("wobuzhidao sehns ")
      this.itemQuery = {
        ...itemQuery,
        taskId: row.taskId,
        deviceCode: row.deviceCode,
        title: `[${row.deviceCode}]--${row.productName}(${row.nameCode})`
      }
      this.itemDialogFlag = true
      this.getDetailItemList()
    },
    getDetailItemList() {
      this.itemLoading = true
      deviceUpkeepDetailItemPage(this.itemQuery).then(res => {
        this.itemLoading = false
        if (res.code != 20000) {
          this.$message.error(res.message)
          return
        }
        this.itemList = res.data.list || []
        this.itemTotal = res.data.total || 0
      }).catch(e => {
        this.itemLoading = false
        this.itemList = []
        this.itemTotal = 0
      })
    },
    rowClick(row) {
      if (this.clickRow && row.taskId == this.clickRow.taskId) {
        return false
      }
      this.clickRow = row
      this.detailQuery = {...detailQuery, taskId: row.taskId}
      // console.log("什么意思？？？？")
      this.getDetailList()
    },
    getDetailList() {
      this.detailLoading = true
      deviceUpkeepDetailPage(this.detailQuery).then(res => {
        this.detailLoading = false
        if (res.code != 20000) {
          this.$message.error(res.message)
          return
        }
        this.detailList = res.data.list || []
        this.detailTotal = res.data.total || 0
      }).catch(e => {
        this.detailLoading = false
      })
    },
    search() {
      this.query.page = 1
      this.getList()
    },
    onReset() {
      this.query = {...query}
      this.getList()
    },
    getList() {
      this.loading = true
      deviceUpkeepPage(this.query).then(res => {
        this.loading = false
        if (res.code != 20000) {
          this.$message.error(res.message)
          return
        }
        this.list = res.data.list || []
        this.total = res.data.total || 0

      }).catch(e => {
        this.list = []
        this.total = 0
        this.loading = false
      })
    }
  }


}
