<template>
  <div>
    <EMSTable 
      ref="deleteReceivable"
      :server="server"
      :columnsFn="getColumnsFun"
      :params="searchParams" 
      action="findRelLineNumberList"
      :autoFill="false">
      <div slot="table-bar">
        <Button type="warning" icon="" @click="cancel">取消</Button>
        <Button type="warning" icon="" @click="deleteReceivable">删除</Button>
      </div>
    </EMSTable>
    <div v-show="false">
      <SearchFormItem ref="searchItem" :elItem="searchParams"></SearchFormItem>
    </div>
  </div>
</template>

<script>
import TableConfig from "../receivableComponent/tableConfig.js";
import SearchFormItem from "../receivableComponent/searchFormItem";
import { EMSTable } from "ems-components";
import Server from "./server.js";

const server = new Server();
export default {
  name:"DeleteReceivable",
  components:{
    EMSTable,
    SearchFormItem
  },
  props:{
    title:{
      type:String,
      default:""
    },
    data:{
      type:Object,
      default:{}
    }
  },
  data(){
    return {
      server:server,
      searchParams:{
        receivablesRelLineNumber:this.data.receivablesRelLineNumber,
        _mainStatus:""
      }
    }
  },
  mounted:function(){
    this.$emit("SetTitle", this.title);
  },
  methods:{
    cancel(){
      this.$emit("Close");
    },
    deleteReceivable(){
      if(this.$refs["deleteReceivable"].tableData.length > 0){
        this.server.deleteRelLineNumberList({receivablesRelLineNumber:this.$refs["deleteReceivable"].tableData[0].receivablesRelLineNumber}).then(res=>{
          if(res.statusCode == "-1"){
            this.$Message.error(res.msg);
          }else{
            this.$Message.success("删除成功");
            this.$emit("Close");
          }
        })
      }else{
        this.$Message.info("暂无关联收款单号,无法删除");
      }
    },
    getColumnsFun() {
      let arr = [
        "原收款单号",
        "主表收款状态",
        "关联单号"
      ];
      let columns = new TableConfig(this, arr).getColumns();
      return columns;
    }
  }
}
</script>

