<template>
  <div>
    <el-dialog
      title="报销类型选择"
      :close-on-click-modal="false"
      v-dialogDrag
      width="1100px"
      height="500px"
      append-to-body
      @close="close"
      @keyup.enter.native=""
      :visible.sync="visible">
      <div style="height: calc(100% - 80px);">
        <el-form size="small" :inline="true" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
          <!-- 搜索框-->
          <el-form-item label="报销类型名称" prop="name">
            <el-input size="small" v-model="searchForm.name" placeholder="请输入报销类型名称" clearable></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="list()" size="small" icon="el-icon-search">查询</el-button>
            <el-button @click="resetSearch()" size="small" icon="el-icon-refresh-right">重置</el-button>
          </el-form-item>
        </el-form>
        <vxe-table
          border="inner"
          auto-resize
          resizable
          height="500px"
          :loading="loading"
          size="small"
          ref="typeTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :menu-config="{}"
          :sort-config="{remote:true}"
          :data="dataList"
          :tree-config="{transform: true, rowField: 'id', parentField: 'parentId',expandAll: true}"
          :row-config="{isCurrent: true}"
          :radio-config="{trigger: 'row'}">
          <vxe-column type="seq" width="60" title="序号"></vxe-column>
          <vxe-column type="radio" width="40" ></vxe-column>
          <vxe-column title="报销内容名称" field="name" align="left" tree-node></vxe-column>
          <vxe-column width="100" title="序号" field="sort"></vxe-column>
        </vxe-table>
      </div>
      <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="close()" icon="el-icon-circle-close">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="getProgramForType" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>
  // import ReimbursementTypeService from '@/api/sys/ReimbursementTypeService'
  import ReimbursementApprovalTypeService from '@/api/cw/reimbursementApproval/ReimbursementApprovalTypeService'
  export default {
    data () {
      return {
        searchForm: {
          name: ''
        },
        dataList: [],
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        title: '',
        method: '',
        visible: false,
        loading: false,
        like: '',
        officeId: ''
      }
    },
    // reimbursementTypeService: null,
    reimbursementApprovalTypeService: null,
    created () {
      // this.reimbursementTypeService = new ReimbursementTypeService()
      this.reimbursementApprovalTypeService = new ReimbursementApprovalTypeService()
    },
    components: {
    },
    methods: {
      init (like, deptName) {
        console.log('进来了')
        console.log('like', like)
        if (like === '1') {
          this.like = '1'
        } else {
          this.like = ''
        }
        this.officeId = deptName
        console.log('this.officeId', this.officeId)
        this.visible = true
        this.list()
      },
      // 表单提交
      getProgramForType () {
        let rows
        if (this.commonJS.isEmpty(this.$refs.typeTable.getRadioRecord())) {
          this.$message.error('请选择一条数据')
          return
        }
        rows = this.$refs.typeTable.getRadioRecord()
        this.dataList.forEach((item) => {
          if (item.parentId === rows.id) {
            this.$message.error('只可以选择最小节点的数据')
            throw new Error('只可以选择最小节点的数据')
          }
        })
        this.$emit('getProgramForType', rows)
        this.close()
      },
      list () {
        this.loading = true
        this.searchForm.like = this.like
        this.searchForm.officeId = this.officeId
        this.reimbursementApprovalTypeService.bxList({...this.searchForm}).then(({data}) => {
          this.dataList = data
          this.loading = false
          this.$nextTick(() => {
            this.$refs.typeTable.setAllTreeExpand(true)
          })
        })
        // this.reimbursementTypeService.list({...this.searchForm}).then(({data}) => {
        //   this.dataList = data
        //   this.loading = false
        // })
      },
      // 当前页
      currentChangeHandle ({currentPage, pageSize}) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.list()
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.list()
      },
      close () {
        this.detail = ''
        this.visible = false
      }
    }
  }
</script>
<style>
  .messageZindex {
    z-index:9999 !important;
  }
</style>
