<template>
  <div class="sms-page op-page">
    <cs-dynamic-table ref="child" :prop="csTable" :parent="this">
      <template slot="form" scope="props">
        <vendor-form
          :entity="props.obj"
          :action="props.action"
          :tableVm="props.tableVm"
          @closeModal="props.closeModal"
          :tableInfo="props.tableInfo"
          ref="form"
        ></vendor-form>
      </template>
    </cs-dynamic-table>
  </div>
</template>
<script lang="ts">
import { Component, Prop, Vue, Emit } from "vue-property-decorator";
import VendorForm from "./sms-vendor-form.vue";

@Component({
  components: {
    VendorForm
  }
})
export default class SmsVendor extends Vue {
  private csTable: any = {
    formWidth: 35,
    parentVm: this,
    dataSrc: this.$msPrefix.sms + "/api/v1/data/all/vendorProfile",
    delSrc: this.$msPrefix.sms + "/api/v1/data/delete/vendorProfile/",
    batchDelUri: this.$msPrefix.sms + "/api/v1/data/batch/vendorProfile",
    dataProp: "data.content",
    postMethod: false,
    pageableProp: {
      pageSize: "data.size",
      total: "data.totalElements",
      currentPage: "data.number"
    },
    showIndex: true,
    emptyModel: {
      name: "",
      version: "",
      type: null,
      jarName: "",
      beanName: ""  
    },
    columns: [
      {
        type: "selection",
        width: 60,
        align: "center"
      },
      {
        key: "name",
        title: "名称",
        align: "center"
      },
      {
        key: "version",
        title: "版本",
        align: "center"
      },
      {
        title: "操作",
        key: "action",

        align: "center",
        render: (h, params) => {
          let menus = [
            {
              icon: "ios-eye",
              action: "detail",
              label: "详情",
              type: "info"
            },
            {
              icon: "ios-create-outline",
              action: "update",
              label: "编辑",
              type: "primary"
            },
            {
              icon: "md-trash",
              action: "delete",
              label: "删除",
              type: "error"
            }
          ];
          let clickEvent = this.clickEvent;
          return h("div", [
            h("CsButton", {
              props: {
                actions: menus,
                click: clickEvent,
                data: params.row,
                size: "small",
                styleCss: "marginRight:5px",
                disabled: params.row._disabled
              }
            })
          ]);
        }
      }
    ]
  };

  clickEvent(name: string, obj: any) {
    if (name == "delete") {
      (this.$refs.child as any).handleDelete(obj.id);
    } else {
      (this.$refs.child as any).formInfo.title =
        name == "update" ? "编辑" : "详情";
      (this.$refs.child as any).formInfo.action =
        name == "update" ? "update" : "detail";
      (this.$refs.child as any).formInfo.model = _.cloneDeep(obj);
      (this.$refs.child as any).dialogVisible = true;
    }
  }
}
</script>