import {getLoading, copyProperties} from "@/utils"
import {deviceRepairApplyPage} from "@/api/dev/deviceRepairApplyApi"
import {deviceRepairApplyAdd} from "../../../api/dev/deviceRepairApplyApi";
import {deviceRepairApplyDetailStatus, deviceRepairApplyStatus} from "../../../utils/enum";
import {deviceRepairApplyDetailPage} from "../../../api/dev/deviceRepairApplyDetailApi";
import {deviceRepairByUserPage, finishRepairByUser} from "@/api/dev/deviceRepairApi";

let query = {
  page: 1,
  limit: 10,
  isFinish: null,
  deviceCode: null
}

export default {
  name: "deviceRepair",
  data() {
    return {
      maxFiles: 3, // 允许同时上传的最大文件数
      fileSizeLimit: 5, // 允许上传的文件大小限制（MB）
      uploadedFileNames: '', // 存储已上传文件名，逗号隔开

      showSearch: true,
      loading: false,
      finishFlag: false,
      currentRow: {},
      total: .0,
      list: [],
      query: {...query},
      user: null,
      finishLoading: false,
    }
  },
  created() {
    this.user = this.$store.getters.user
    this.getList()
  },
  methods: {
    /**
     * 父组件处理子组件发送的数据更改
     * @param params
     */
    component1DataChange(params) {
      this.currentRow.serviceLivePath = params;
    },
    finishFuncFlag(row){
      this.finishFlag = true
      this.currentRow = row
    },
    finishFuncFlagClose(){
      this.finishFlag = false
      this.currentRow = {}
    },
    finishFunc() {
      let row = this.currentRow
      // this.$confirm("确定完成维修吗", "提示", {
      //   confirmButtonText: '完成维修',
      //   cancelButtonText: "取消"
      // }).then((r) => {
        let loading = getLoading(this);
        this.finishLoading = true
        finishRepairByUser(row).then(res => {
          this.finishLoading = false
          loading.close()
          if (res.code != 20000) {
            this.$message.error(res.message)
            return
          }
          this.getList()
          this.finishFuncFlagClose()
        }).catch(e=>{
          this.finishLoading = false
          loading.close()
        })
      // })
    },
    search() {
      this.query.page = 1
      this.getList()
    },
    onReset() {
      this.query = {...query}
      this.getList()
    },
    getList() {
      this.loading = true
      deviceRepairByUserPage(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.loading = false
      })
    }
  }
}
