import { Message } from 'element-ui'
function init_active_xobject(flage) {
  let r = null
  try {
    r = flage || new ActiveXObject('BarTenderActiveX.BarTenderHelper')
  } catch (error) {
    alert(error)
  }
  return r
}
function barTenderPrint(data, XObject, callback) {
  var path = 'D://BarTender//label.btw' // 配置打印标签的全路径地址'/'用'//'表示
  if (!data) {
    throw new Error('参数无效，请检查')
  }
  try {
    // var _activeXobj = new ActiveXObject('BarTenderActiveX.BarTenderHelper')
    var _activeXobj = XObject
    var _activeXstr = JSON.stringify(data)
    console.log('打印数据??????:)))', _activeXstr)
    const success_ids = []
    if (_activeXobj.Print(path, _activeXstr)) {
      Message.success({
        message: '打印成功'
      })
      // 计数打印成功的BarCode
      success_ids.push(data.BarCode)
    } else {
      Message.success({
        message: '打印失败'
      })
    }
    if (callback && success_ids.length) {
      callback(success_ids)
    }
  } catch (error) {
    alert(error)
  }
}
export default barTenderPrint
