<!-- 异常出库 -->
<template>
  <div class="container">
    <my-table ref="table" :data="data" :columns="columns" :table-filter="tableFilter" :table-page="params" @event-handle="eventHandle" @on-change="changePage"></my-table>
    <my-form v-model="show" :id="id" @getlist="getList"></my-form>
  </div>
</template>

<script>
import { AbnormalOutStockPageList, AbnormalOutStockDeal } from '@/api/storageHome'
import MyTable from '_c/my-table/my-table'
import MyForm from './my-form'
export default {
  name: 'material_apply',
  components: {
    MyTable,
    MyForm
  },
  data () {
    return {
      id: '',
      show: false,
      data: [],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '异常类型',
          key: 'errorType',
          minWidth: 150
        },
        {
          title: '领料人',
          key: 'takeUser',
          minWidth: 150
        },
        {
          title: '领用时间',
          key: 'takeTime',
          minWidth: 150
        },
        {
          title: '申领物料',
          key: 'applyTakeMaterial',
          minWidth: 150
        },
        {
          title: '申领数量',
          key: 'applyTakeQty',
          minWidth: 150
        },
        {
          title: '实际领用',
          key: 'realTakeMaterial',
          minWidth: 150
        },
        {
          title: '领用数量',
          key: 'realTakeQty',
          minWidth: 150
        },
        {
          title: '处理情况',
          key: 'dealState',
          minWidth: 150
        },
        {
          title: '操作说明',
          key: 'dealRemark',
          minWidth: 150
        },
        {
          title: '操作',
          minWidth: 150,
          fixed: 'right',
          align: 'center',
          render: (h, params) => {
            let _this = this
            if (params.row.dealState === '未处理') {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '10px'
                  },
                  on: {
                    click (e) {
                      e.stopPropagation()
                      _this.show = true
                      _this.id = params.row.waterId
                    }
                  }
                }, '解除'),
                h('Button', {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  on: {
                    click (e) {
                      e.stopPropagation()
                      _this.$MyModal.show({ text: '是否忽略？' }).$on('confirm', () => {
                        AbnormalOutStockDeal({
                          waterId: params.row.waterId
                        }).then(res => {
                          if (res.code === 0) {
                            _this.$Message.info(res.msg || '操作成功')
                            _this.getList()
                          }
                        })
                      })
                    }
                  }
                }, '忽略')
              ])
            }
          }
        }
      ],
      tableFilter: [
        {
          name: 'Input',
          value: 'key',
          placeholder: '请输入关键字'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '查询',
          e: 'search'
        },
        {
          name: 'RadioGroup',
          value: 'isDeal',
          list: [
            { label: '未处理', value: 0 },
            { label: '已处理', value: 1 }
          ],
          e: 'state'
        }
      ],
      params: {
        pageIndex: 1,
        pageSize: 20,
        total: 0,
        isDeal: 0
      }
    }
  },
  methods: {
    cfm (type, formData) {
      if (type === 'add') {
        FacPriceAdd({
          ...formData,
          materialCode: formData.code
        }).then(res => {
          if (res.code === 0) {
            this.$Message.info(res.msg)
            this.getList()
          }
        })
      } else if (type === 'edit') {
        FacPriceChange({
          ...formData,
          factoryPriceId: formData.id
        }).then(res => {
          if (res.code === 0) {
            this.$Message.info(res.msg)
            this.getList()
          }
        })
      }
    },
    // 检索条件事件处理
    eventHandle (option) {
      console.log(option)
      switch (option._evnet) {
        case 'search':
          this.params.pageIndex = 1
          this.params.key = option.key
          this.params.isDeal = option.isDeal
          this.getList()
          break
        case 'add':
          this.formType = 'add'
          this.show = true
          break
      }
    },
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    getList () {
      AbnormalOutStockPageList(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>
