<!-- 仓库维护 -->
<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-modal-form v-model="show" :title="title" :config="formConfig" :rule-validate="ruleValidate" :data="formData" :type="formType" @confirm="cfm"></my-modal-form>
    </div>
  </template>
  
  <script>
  import { GetStockHousePageList, StockHouseAdd, StockHouseUpdate, StockHouseDelete } from '@/api/baseData'
  import MyTable from '_c/my-table/my-table'
  import MyModalForm from '_c/my-modal-form/my-modal-form'
  import axios from 'axios'
  export default {
    name: 'warehouse_maintenance',
    components: {
      MyTable,
      MyModalForm
    },
    data () {
      return {
        title: '',
        show: false,
        data: [],
        deleteId: '',
        formType: '',
        formData: {
            type:null,
            versionName:null,
            apkName:null,
            apkUrl:null,
        },
        ruleValidate: {
          name: [
            { required: true, message: '仓库名称不能为空', trigger: 'blur' }
          ]
        },
        formConfig: [
          {
            type: 'input',
            label: '版本名称',
            key: 'versionName',
            placeholder: '请输入版本名称'
          },
          {
            type: 'input',
            label: 'apk名称',
            key: 'apkName',
            placeholder: '请输入apk名称'
          },
          {
            type: 'input',
            label: '类型名称',
            key: 'type',
            placeholder: '请输入唯一标识'
          },
          {
            type: 'upload-app',
            comType: 'textarea',
            label: 'apk文件',
            key: 'apkUrl',
            placeholder: '请输入仓库说明'
          }
        ],
        columns: [
          {
            title: '序号',
            type: 'index',
            width: 60,
            align: 'center'
          },
          {
            title: '版本名称',
            key: 'versionName',
            minWidth: 150
          },
          
          {
            title: 'app名称',
            key: 'apkName',
          },
          {
            title: '类型名称',
            key: 'type',
          },
          {
            title: '操作',
            key: 'action',
            fixed: 'right',
            align: 'center',
            width: '200px',
            render: (h, params) => {
              return h('div', [
                h(
                  'Icon',
                  {
                    props: {
                      custom: 'iconfont icon-edit',
                      size: '20',
                      color: '#087BE1'
                    },
                    style: {
                      marginRight: '20px'
                    },
                    on: {
                      click: () => {
                        for (const key in params.row) {
                          this.formData[key] = params.row[key]
                        }
                        this.title = '修改'
                        this.formType = 'edit'
                        this.show = true
                      }
                    }
                  },
                  '修改'
                ),
                h(
                  'Icon',
                  {
                    props: {
                      custom: 'iconfont icon-delete',
                      size: '20',
                      color: 'red'
                    },
                    on: {
                      click: () => {
                        this.$MyModal.show({ text: '是否删除？' }).$on('confirm', () => {
                          StockHouseDelete({
                            id: params.row.id
                          }).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: 'Button',
            type: 'primary',
            text: '添加',
            align: 'right',
            e: 'add'
          }
        ],
        params: {
          pageIndex: 1,
          pageSize: 20,
          total: 0
        }
      }
    },
    methods: {
      cfm (type, formData) {
        if (type === 'add') {
          console.log(formData)
          axios.post('/cloudApi/apkVersion/add',{...formData}).then(res => {
            this.show = false
            this.$Message.info('新增成功')
            this.getList()
          })
          // StockHouseAdd(formData).then(res => {
          //   if (res.code === 0) {
          //     this.show = false
          //     this.$Message.info(res.msg)
          //     this.getList()
          //   }
          // })
        } else if (type === 'edit') {
          axios.post('/cloudApi/apkVersion/edit',{...formData}).then(res => {
            this.show = false
            this.$Message.info('编辑成功')
            this.getList()
          })
        }
      },
      // 检索条件事件处理
      eventHandle (option) {
        switch (option._evnet) {
          case 'search':
            this.params.pageIndex = 1
            this.params.warehouseName = option.key
            this.getList()
            break
          case 'add':
            this.title = '添加'
            this.formType = 'add'
            this.show = true
            break
        }
      },
      changePage (pageIndex) {
        this.params.pageIndex = pageIndex
        this.getList()
      },
      getList () {
        const v = this
        axios.post('/cloudApi/apkVersion/page',v.params).then(res => {
          this.data = res.data.data.records
        })
        
      }
    },
    mounted () {
      this.getList()
    }
  }
  </script>
  
  <style lang="less" scoped>
  .container {
    height: 100%;
  }
  </style>
  