import {
  rectification,
  cutting,
  manualRotate,
  hd,
  copy,
  buckleSeal,
  recall,
  save,
  eraser,
  recallTwo
  //   close,
} from '@/api/scanIndex'
import {
  message
} from '@/utils/common'
const getDefaultState = () => {
  return {
    //手动纠偏状态
    RectificationStatus: false,
    //撤回记录
    num: -2,
    recallPath: "",
    //高清撤回
    gqNum: 0,
  }
}
const state = getDefaultState()
const mutations = {
  RESTIFI(state, data) {
    // state.num = state.num + 1

  },
  CUTTING(state, data) {
    state.num++
    message('success', '裁剪成功', 4000)
  },
  MANUAL(state, data) {
    state.num++
    state.RectificationStatus = false
  },

  SAVE(state, data) {
    // state.num++
  },
  ERASER(state, data) {
    state.gqNum++
    message('success', '修改成功', 4000)
  },

}
const actions = {
  async cutting({
    commit
  }, params) {
    await cutting(params).then(res => {
      try {
        commit('CUTTING', res.body)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async manualRotate({
    commit
  }, params) {
    await manualRotate(params).then(res => {
      try {
        message('success', '手动旋转成功', 4000)
        commit('MANUAL')
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async rectification({
    commit
  }, params) {
    await rectification(params).then(res => {
      try {
        commit('RESTIFI')
        message('success', '自动纠偏成功', 4000)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async hd({
    commit
  }, params) {
    await hd(params).then(res => {
      try {
        message('success', '生成高清成功', 4000)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async save({
    commit
  }, params) {
    await save(params).then(res => {
      try {
        commit('SAVE')
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async eraser({
    commit
  }, params) {
    await eraser(params).then(res => {
      try {
        commit('ERASER')
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async close({
    commit
  }, params) {
    await close(params).then(res => {
      try {

      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async copy({
    commit
  }, params) {
    await copy(params).then(res => {
      try {
        message('success', '复制成功', 4000)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async buckleSeal({
    commit
  }, params) {
    await buckleSeal(params).then(res => {
      try {
        message('success', '抠章成功', 4000)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async recall({
    commit
  }, params) {
    await recall(params).then(res => {
      try {
        // commit('RECALL', res.body)
        message('success', res.msg, 4000)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async recallTwo({
    commit
  }, params) {
    await recallTwo(params).then(res => {
      try {
        // commit('RECALL', res.body)
        message('success', res.msg, 4000)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
