美文网首页
弹窗和minix

弹窗和minix

作者: 抽疯的稻草绳 | 来源:发表于2021-01-22 15:53 被阅读0次
     <form-dialog v-if="formParams.dialogVisible" v-model="formParams.dialogVisible" :formParams="formParams" :queryData="queryData" @refreshList="refreshList"></form-dialog>
      // 关闭弹窗
        handleClose() {
          this.$emit("input", false);
          this.dialogVisible = false;
        },
    
    import api from '@/api/Main/Order/prodmin.js';
    export const myMixins = {
        data() {
            let _minTime = null;
            let _maxTime = null;
            return {
                pickerOptions: {
                    onPick(time) {
                        // 如果选择了只选择了一个时间
                        if (!time.maxDate) {
                            let timeRange = 6 * 24 * 60 * 60 * 1000; // 6天
                            _minTime = time.minDate.getTime() - timeRange; // 最小时间
                            _maxTime = time.minDate.getTime() + timeRange; // 最大时间
                            // 如果选了两个时间,那就清空本次范围判断数据,以备重选
                        } else {
                            _minTime = _maxTime = null;
                        }
                    },
                    disabledDate(time) {
                        // onPick后触发
                        // 返回false表示该日期禁选
                        if (_minTime && _maxTime) {
                            return time.getTime() < _minTime || time.getTime() > _maxTime;
                        }
                    }
                },
                initListQuery: {}
            };
        },
        mounted() {
            this.init();
        },
    
        methods: {
            init() {
                if (!!this.listQuery) {
                    // 备份listQuery空的查询数据用来重置
                    this.initListQuery = JSON.parse(JSON.stringify(this.listQuery));
                }
            },
            //获取表格数据
            async fetchList() {
                const res = await api.getList(this.listQuery);
    
                this.tableData = res.data.body;
    
                this.total = res.data.records;
            },
            //查询
            handleFilter() {
                // 查询操作
                this.listQuery.page = 1;
                this.fetchList();
            },
            // 重置按钮
            handleReset() {
    
                this.time = []
                this.listQuery = JSON.parse(JSON.stringify(this.initListQuery));
    
            },
            //导出文件
            async handleExportTem() {
                const res = await api.exportExcel(this.listQuery);
    
                if (res.data.code != 200) {
                    return this.$message.error('数据导入失败');
                }
                this.$message.success('数据导出中,请到导出控制台查看');
            },
            // 原因措施
            handleEdit() {
                console.log(this.selectionData);
                if (!this.selectionData.length) {
                    return this.$message.error('请选择数据');
                }
                this.dialogVisible = true;
    
                this.getOptions(
                    'getCategoryCombox', {},
                    'reasonsType',
                    'formOptions',
                    '',
                    ''
                );
    
                this.getOptions(
                    'queryMeasureCombox', {},
                    'actionList',
                    'formOptions',
                    '',
                    ''
                );
            },
            //父分页事件
            handleCurrentChange(val) {
    
                this.listQuery.page = val;
    
                this.fetchList();
            },
            // 关闭报警
            async handleClose() {
                if (!this.selectionData.length) {
                    return this.$message.error('请选择数据');
                }
                const confirmRes = await this.$confirm('是否关闭该报警?', '提示', {
                    type: 'warning'
                }).catch((error) => {
                    console.log(error);
                });
                if (confirmRes != 'confirm') {
                    return this.$message.info('取消删除');
                }
                let ids = this.selectionData.reduce((pre, cur) => {
                    pre.push(cur.taskId);
                    return pre;
                }, []);
    
                const res = await api.manualCloseItems({ taskIdList: ids });
                if (res.data.code == 200) {
                    this.$message.success('操作成功');
                }
    
                // this.getOptions("manualCloseItems", { taskIdList: ids })
            },
            //反馈原因保存
            async handleSubmit(val) {
                console.log(val);
                let ids = this.selectionData.reduce((pre, cur) => {
                    pre.push(cur.taskId);
                    return pre;
                }, []);
    
                let queryData = {
                    taskIdList: ids,
                    reason: val.reason,
                    measureId: val.measureId,
                    flag: 1
                };
    
                const res = await api.saveProblem(queryData);
                if (res.data.code != 200) {
                    return this.$message.error('提交失败,请重新操作');
                }
                this.$message.success('提交成功');
                this.dialogVisible = false;
                this.fetchList();
            },
            // 关闭报警弹窗
            async closeAlarm(val) {
                const confirmRes = await this.$confirm('是否关闭该报警?', '提示', {
                    type: 'warning'
                }).catch((error) => {
                    console.log(error);
                });
                if (confirmRes != 'confirm') {
                    return this.$message.info('取消删除');
                }
                let ids = this.selectionData.reduce((pre, cur) => {
                    pre.push(cur.taskId);
                    return pre;
                }, []);
                let queryData = {
                    taskIdList: ids,
                    reason: val.reason,
                    measureId: val.measureId,
                    flag: 1
                };
                const res = await api.closeAlarm(queryData);
                if (res.data.code == 200) {
                    this.$message.success('操作成功');
                    this.dialogVisible = false;
                    this.fetchList();
                }
            },
    
            //父表格排序
            handleSortChange({ prop, order }) {
                if (prop && order) {
                    let params = [{
                        property: prop,
                        direction: order === 'ascending' ? 'ASC' : 'DESC'
                    }];
                    this.listQuery.sort = JSON.stringify(params);
                } else {
                    this.listQuery.sort = null;
                }
                this.fetchList();
            },
    
            //获取数据方法
            /**
             *
             * @param {*} methods  方法
             * @param {*} params   参数
             * @param {*} options  字段
             * @param {*} p1       查询字段
             * @param {*} p2       表单字段
             * @param {*} mode     mode参数
             */
            getOptions(methods, params, options, p1 = 'queryData', p2, mode = '') {
                // 获取下拉框数据
                if (methods && this.api[methods]) {
                    this.api[methods](params)
                        .then(({ data: res } = {}) => {
                            const { body } = res;
                            if (p1 && this[p1] && this[p1][options]) {
                                this[p1][options] =
                                    mode == '1' ? [{ id: '', text: '全选' }, ...body] : body;
                            }
                            if (p2 && this[p2] && this[p2][options]) {
                                this[p2][options] = body;
                            }
                        })
                        .catch((err) => {
                            this.$message({
                                message: err.message || '获取数据失败',
                                type: 'warning'
                            });
                        });
                }
            }
        }
    };
    

    相关文章

      网友评论

          本文标题:弹窗和minix

          本文链接:https://www.haomeiwen.com/subject/bryiaktx.html