<!-- web标签创建待绑定标签 -->
<template>
  <div class="container">
    <my-table :data="data" :columns="columns" :table-filter="tableFilter" :table-page="params" @event-handle="eventHandle" @on-change="changePage"></my-table>
    <my-form v-model="show" @getlist="getList" :type="formType" :data="formData"></my-form>
  </div>
</template>

<script>
import { GetStockTagData } from '@/api/stock'
import MyTable from '_c/my-table/my-table'
import MyForm from './my-form'
export default {
  name: 'apply_manage',
  components: {
    MyTable,
    MyForm
  },
  data () {
    return {
      formType: '',
      formData: {},
      show: false,
      data: [],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '物料编码',
          key: 'materialCode',
          minWidth: 150
        },
        {
          title: '物料名称',
          key: 'materialName',
          minWidth: 150
        },
        {
          title: '申请数量',
          key: 'quantity',
          minWidth: 100
        },
        {
          title: '单位',
          key: 'unitName',
          align: 'center',
          minWidth: 100
        }
      ],
      tableFilter: [
        {
          name: 'Input',
          value: 'key',
          placeholder: '请输入关键字'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '查询',
          e: 'search'
        },
        // {
        //   name: 'RadioGroup',
        //   value: 'takeState',
        //   list: [
        //     { label: '审批中', value: 0 },
        //     { label: '待领料', value: 1 },
        //     { label: '已完成', value: 2 }
        //   ]
        // },
        {
          name: 'Button',
          type: 'primary',
          text: '添加标签',
          e: 'add',
          align: 'right'
        }
      ],
      params: {
        pageIndex: 1,
        pageSize: 20,
        total: 0
      }
    }
  },
  methods: {
    // 检索条件事件处理
    eventHandle (option) {
      switch (option._evnet) {
        case 'search':
          this.params.pageIndex = 1
          this.params.keyWord = option.key
          this.getList()
          break
        case 'add':
          this.formType = 'add'
          this.show = true
          break
        case 'back':
          this.$router.go(-1)
          break
      }
    },
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    getList () {
      GetStockTagData(this.params).then(res => {
        if (res.code === 0) {
          this.data = res.result.list
          this.params.total = res.result.totalCount
        }
      })
    }
  },
  mounted () {
    this.getList()
  }
}
</script>

<style lang="less" scoped>
.container {
  height: 100%;
}
</style>
