<!-- 供应商价格维护 -->
<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-pay
      v-model="show"
      :type="formType"
      :data="formData"
      :showSider="false"
      @cfm="getList"
    >
    </my-form-pay>
  </div>
</template>

<script>
import { GetApplyPurchasePageList } from '@/api/applyPurchase'
import MyTable from '_c/my-table/my-table'
import MyFormPay from '_c/my-modal-pay'
export default {
  name: 'material_apply',
  components: {
    MyTable,
    MyFormPay
  },
  data () {
    return {
      formType: '',
      formData: {},
      show: false,
      data: [],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '申购单号',
          key: 'applyBillNo',
          minWidth: 150,
          render: (h, params) => {
            let _this = this
            return h(
              'a',
              {
                on: {
                  click () {
                    _this.formType = 'form'
                    _this.formData = params.row
                    _this.show = true
                  }
                }
              },
              params.row.applyBillNo
            )
          }
        },
        {
          title: '申购类型',
          key: 'applyPurType',
          minWidth: 150
        },
        {
          title: '申购日期',
          key: 'applyTime',
          minWidth: 150
        },
        {
          title: '申购部门',
          key: 'departName',
          minWidth: 150
        },
        {
          title: '请购人',
          key: 'userName',
          minWidth: 150
        },
        {
          title: '审批状态',
          key: 'applyState',
          minWidth: 150
        },
        {
          title: '申购说明',
          key: 'applyAccount',
          minWidth: 200
        }
      ],
      tableFilter: [
        {
          name: 'Input',
          value: 'key',
          placeholder: '请输入关键字'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '查询',
          e: 'search'
        },
        {
          name: 'RadioGroup',
          value: 'purBillState',
          list: [
            { label: '审批中', value: 0 },
            { label: '历史申购', value: 1 },
            { label: '已驳回', value: 2 }
          ]
        },
        {
          name: 'Button',
          type: 'primary',
          text: '发起申购',
          align: 'right',
          e: 'add'
        }
        // {
        //   name: 'Button',
        //   type: 'primary',
        //   text: '申购明细',
        //   align: 'right',
        //   e: 'toDetail'
        // }
      ],
      params: {
        pageIndex: 1,
        pageSize: 20,
        total: 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) {
      switch (option._evnet) {
        case 'search':
          this.params.pageIndex = 1
          this.params.keyWord = option.key
          this.params.purBillState = option.purBillState
          this.getList()
          break
        case 'add':
          this.formType = 'add'
          this.show = true
          break
        case 'toDetail':
          this.$router.push({
            name: 'material_apply_detail'
          })
          break
      }
    },
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    getList () {
      GetApplyPurchasePageList(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>
