<template>
    <!-- 新建任务弹窗-->
    <div>
        <el-dialog title="新建任务" :visible.sync="showNewTask" width="450px" :close-on-click-modal="false" center>
            <el-form label-width="100px">
                <el-form-item label="任务类型 ">
                    <el-select v-model="addnewTaskData.rtype" placeholder="请选择任务类型" clearable>
                        <span v-for="(item,index) in ticketTaskDict.taskType" :key="index" :name="index" >
                        <el-option :value="item.type" :label="item.typeDesc" v-if="item.tasktype==taskType" />
                        </span>
                    </el-select>
                </el-form-item>

                <el-form-item label="关联单据">
                    <el-input style="width:205px;" v-model="addnewTaskData.rId" readonly placeholder="关联单据" />
                </el-form-item>

                <el-form-item label="任务来源">
                    <el-select v-model="addnewTaskData.taskSourceType" placeholder="请选择任务来源" clearable>
                        <el-option v-for="(item,index) in ticketTaskDict.taskSourceType" :key="index" :name="index" :value="item.type" :label="item.typeName" />
                    </el-select>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="showNewTask = false">取消</el-button>
                <el-button type="primary" @click="saveCreateTask">确定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>
import { getTicketTaskDict, createNewTicket } from "@/api/customertask";
export default {
    components: {},
    props: { 
    },
    data() {
        return {
            taskType:'', 
            ticketTaskDict: {
                taskType: [],
                taskSourceType: [],
                // followType: [],
            },
            showNewTask: false, //新建任务弹窗
            addnewTaskData: {
                employRelationId: "",
                createUserId: "",
                rtype: "",
                rId: "",
                taskSourceType: "",
            },
        };
    },
    created() {
 
    },
    activated() {},
    methods: {
        saveCreateTask() {
            //保存创建的任务
            if (this.addnewTaskData.rId == "") {
                this.$message.error("关联单据不能为空");
                return;
            }
            if (this.addnewTaskData.rtype == "") {
                this.$message.error("请选择任务类型");
                return;
            }
            if (this.addnewTaskData.taskSourceType == "") {
                this.$message.error("请选择任务来源");
                return;
            }

            createNewTicket(this.addnewTaskData)
                .then((res) => {
                    if (res.data.errno == 0) {
                        this.$message.success("创建成功");
                        this.showNewTask = false;
                        // this.getTaskListData();
                         this.$emit("callFunction");
                    } else {
                        this.$message.error(res.data.errmsg);
                    }
                })
                .catch((e) => {
                    this.$message.error(e.data.errmsg);
                });
        },

        clickshowNewTask(taskType,rid, employRelationId, userButlerId,ticketId) {
            //下拉框展示的不同类型数据， 关联业务关系id，三者关系id，hmappuser管家id，工单id(手动在工单里创建任务时)
            //taskType: //1打卡任务类(保姆任务未完成，保姆考勤问题，保姆服务质量质疑)；2（管家服务资料质疑-拜访类）；3工单（雇主反馈，保姆反馈其他问题）
            //点击创建任务,关联crm工单，不是关联通知
            this.taskType=taskType;
            this.getDict();
            this.showNewTask = true;
            this.addnewTaskData = {
                employRelationId: employRelationId,
                createUserId: userButlerId, //管家自己，hmappuser的id
                rtype: "",
                rId: rid,
                taskSourceType: "",
                ticketId:ticketId//只有在工单列表里新建才有
            };
        },
        getDict() {
            getTicketTaskDict()
                .then((res) => {
                    if (res.data.errno == 0) {
                        this.ticketTaskDict = res.data.data;
                    }
                })
                .catch((e) => {
                    this.$message.error(e.data.errmsg);
                });
        },
    },
};
</script>
