<style lang="less">
</style>
<template>
  <div>
    <Button @click="isSvrRunning">检测</Button>
    <Button @click="getPrintList">获取打印机</Button>
    <Row>
      <Col span="3">
        <Select v-model="printPort" filterable transfer="">
          <Option :value="item.value"  v-for="item in printList" v-bind:key="item.value">{{item.name}}</Option>
        </Select>
      </Col>
    </Row>
  </div>
</template>
<script>
export default {
  name: 'print',
  props: {
    employmentInfo: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  watch: {
  },
  data () {
    return {
      printList: [
      ],
      printPort: ''
    }
  },
  computed: {
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    }
  },
  methods: {
    initService () {
      DSInitService()
      web_Wait(1000, function (res) {
        if (!res) {
          console.log('服务未启动，将启动服务；')
          DSLaunchApp()
          web_Wait(15000, function (res) {
            if (!res) {
              console.log('启动服务失败')
            } else {
              console.log('启动服务成功')
            }
          })
        } else {
          console.log('启动服务成功')
        }
      })
    },
    getPrintList () {
      let that = this
      web_DSEnumPrinter(function callBackFun (retVal) {
        if (retVal.RtnVal === null) { return }
        console.log(retVal, 'llll')
        if (retVal.RtnCode === 0) {
          console.log('成功枚举' + retVal.RtnVal.length + '台打印机！')
          for (var i in retVal.RtnVal) {
            // var ii = i + 1
            let name = retVal.RtnVal[i]
            let val = {
              name: name,
              value: name.substr(name.indexOf('@') + 1, name.length - name.indexOf('@') + 1)
            }
            that.printList.push(val)
          }
          console.log(that.printList, 'hhhhhh')
        }
      })
    },
    isSvrRunning () {
      if (web_DSisConnectOn()) {
        alert('服务在运行')
      } else {
        alert('服务未运行')
      }
    }
  },
  created () {

  },
  mounted () {
    let that = this
    this.initService()
    setTimeout(function () {
      that.getPrintList()
    }, 1000)
  }
}
</script>
