<template>
    <lj-win-common title="员工-选择">
        <div slot="body">
            <div style="margin-top:10px">
                <lj-grid :table-data="columns" :columns="columnProperties" :editing="true"
                         @cell-click="handleGridCellClick"/>
            </div>
        </div>
        <template slot="footer">
            <mu-button large color="primary" @click="chooseCommit" style="width:100%">选择</mu-button>
        </template>
    </lj-win-common>
</template>

<script>
    import ljWinCommon from 'components/lj-win-common'
    import LjGrid from "components/lj-grid";

    export default {
        components: {
            ljWinCommon,
            LjGrid,
        },
        data() {
            return {
                columns: [],
                columnProperties: [
                    {
                        property: "checked",
                        width: screen.width * 0.1,
                        type: "selection",
                        editable: true,
                        headerType: "selection"
                    },
                    {property: "Empcode", label: "员工编号", width: screen.width * 0.45,},
                    {property: "Empname", label: "员工姓名", width: screen.width * 0.45,},
                    {property: "handtel", label: "联系电话", width: screen.width * 0.45,},
                    {property: "workgroupname", label: "所著工作中心", width: screen.width * 0.45,},
                    // {property: "empid", label: "员工ID", width: screen.width * 0.3, invisible: true},
                ],
                empSelect: [],
                item: {},
            }
        },
        created() {
            var pageParm = $lj.getPageParam();
            this.item = pageParm.item;
            this.GetL1EmpSelection()
        },
        methods: {
            GetL1EmpSelection() {
                let self = this;
                $lj.postLJRequest("GetL1EmpSelection", {
                    token: $lj.getStorage("token"),
                    workgroupid: self.item.workgroupid,
                }, function (ret) {
                    self.columns = ret.EmpOptionsList;
                })
            },
            handleGridCellClick({column, row, index}) {
                if (!column) {
                    return;
                }
            },
            chooseCommit() {
                this.empSelect = [];
                var empstr = "";
                var empidstr = "";
                for (let i = 0; i < this.columns.length; i++) {
                    if (this.columns[i].checked) {
                        empstr += this.columns[i].Empname+ ",";
                        empidstr += this.columns[i].empid+ ",";
                        this.columns[i].pid = this.item.printid;
                        this.empSelect.push(this.columns[i]);
                    }
                }
                if (this.empSelect.length <= 0) {
                    $lj.toast('请选择员工');
                    return;
                }
                var extraObject = {};
                extraObject.printid = this.item.printid;
                extraObject.empList = this.empSelect;
                extraObject.empstr = empstr.substring(0, empstr.length-1);
                extraObject.empidstr = empidstr.substring(0, empidstr.length-1);
                $lj.sendEvent("emp_select", extraObject);
                $lj.closeWin();
            }
        },
    }
</script>

<style>

</style>