<!-- 采购入库单 -->
<template>
  <modal v-model="modal" width="700px" :footer-hide="true" class-name="vertical-center-modal">
    <div class="title" slot="header">
      批量单减扣记录
    </div>
    <!--  表单主要内容  -->
    <div class="content" ref="print">
      <my-table
        ref="table"
        :data="data"
        :columns="columns"
        :table-filter="tableFilter"
        :table-page="params"
        :multiple="true"
        @event-handle="eventHandle"
        @on-change="changePage"
      >
      </my-table>
    </div>
  </modal>
</template>

<script>
import MyTable from '_c/my-table/my-table'
import MyModalMaterial from '_c/my-modal-form/my-modal-material'
import { DelMaterialUse, GetMaterialUseList } from '@/api/stock'
export default {
  name: 'store-in-form',
  data () {
    return {
      show: false,
      modal: false,
      material: {},
      data: [],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '录入日期',
          key: 'date',
          minWidth: 150
        },
        {
          title: '物料编码',
          key: 'materialCode',
          minWidth: 150,
          sortable: true
        },
        {
          title: '物料名称',
          key: 'materialName',
          minWidth: 100
        },
        {
          title: '减扣数量',
          key: 'quantity',
          minWidth: 100
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          width: '100px',
          fixed: 'right',
          render: (h, params) => {
            // let _this = this
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  style: {
                  },
                  on: {
                    click: () => {
                      this.$MyModal.show({ text: '是否删除？' }).$on('confirm', () => {
                        DelMaterialUse({
                          id: params.row.id
                        }).then(res => {
                          if (res.code === 0) {
                            this.$Message.info(res.msg)
                            this.getList()
                          }
                        })
                      })
                    }
                  }
                },
                '删除'
              )
            ])
          }
        }
      ],
      tableFilter: [
        {
          name: 'Input',
          value: 'key',
          placeholder: '请输入关键字'
        },
        {
          name: 'DatePicker',
          type: 'daterange',
          placeholder: '请选择日期'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '查询',
          e: 'search'
        }
      ],
      params: {
        pageIndex: 1,
        pageSize: 20,
        total: 0
      }
    }
  },
  components: {
    MyModalMaterial,
    MyTable
  },
  props: {
    value: {
      type: Boolean,
      default: false,
      require: true
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
      if (n) {
        this.getList()
      }
    }
  },
  methods: {
    // 检索条件事件处理
    eventHandle (option) {
      switch (option._evnet) {
        case 'search':
          console.log(option)
          this.params.pageIndex = 1
          this.params.key = option.key
          this.params.beginTime = option.StartTime
          this.params.endTime = option.EndTime
          this.getList()
          break
      }
    },
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    getList () {
      GetMaterialUseList(this.params).then(res => {
        if (res.code === 0) {
          this.data = res.result.list
          this.params.total = res.result.totalCount
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.content {
  height: 500px;
  .sub-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px;
    font-size: 14px;
    font-weight: bold;
    &.border {
      border-bottom: 1px solid #000000;
    }
    .go {
      font-size: 10px;
      font-weight: normal;
      color: #0000ff;
    }
    a {
      font-size: 12px;
    }
  }
  .row {
    padding: 0 10px;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .col {
      flex: 1;
      display: flex;
      align-items: center;
      .value {
        flex: 1;
      }
      .table {
        width: 100%;
        table {
          border-collapse:collapse;
          border:none;
          width: 100%;
          tr {
            td,th {
              padding: 5px;
              text-align: center;
              border:solid #dcdee2 1px;
              position: relative;
              font-size: 12px;
              th {
                background-color: #eeeeee;
              }
            }
          }
        }
      }
    }
  }
  .card {
    margin-bottom: 5px;
    background-color: #FFFFFF;
    border: 1px solid rgba(215, 215, 215, 1);
    border-radius: 5px;
    .border {
      border-bottom: 1px solid #5d6c7b;
    }
    .line {
      width: 100%;
      border-bottom: 1px solid #5d6c7b;
    }
  }
}
</style>
