Yb-components Yb-components
首页
开发规范
yb-cli
  • 开发指南
  • 更新日志
  • 组件
关于
首页
开发规范
yb-cli
  • 开发指南
  • 更新日志
  • 组件
关于
  • 开发指南
  • 更新日志
  • 数据展示

    • YbTable 表格
    • YbCardList 卡片列表
    • YbTree 树
    • YbCascaderList 级联列表
    • YbSimpleTablePage 分页查询表格
    • YbSimpleCardPage 分页卡片列表
    • YbBasicProfile 基础详情数据展示
    • YbOutscrollLayout 固定在滚动区域外
    • YbOutscrollTree 固定在滚动区域外的Tree
    • YbInfoLayout 信息页布局
    • YbEditLayout 编辑页布局
  • 数据录入

    • YbRowsPopoverForm 浮层多行表单
    • YbFormily 配置式表单
    • YbForm 表单
    • YbRowsForm 多行表单
    • YbCollapseForm 折叠表单
    • YbQueryFilter 筛选表单
    • YbFilesSelect 文件选择器
    • YbRangeWrapper 范围结构
    • YbRangeDatepicker 日期范围
    • YbRange 范围
    • YbFormulaInput 简单运算公式输入
      • YbCron 表达式生成器
      • YbTreeSelect 树型选择器
      • YbInputgroupWrapper 复合组
      • YbThemeSelect 主题风格选择器
      • YbSelect 选择器
      • YbPaginationSelect 分页选择器
      • YbCodemirror 代码编辑器
      • YbCodemirrorSql SQL编辑器
      • YbCodemirrorJson JSON编辑器
      • YbCodemirrorXml XML编辑器
      • YbCombiDatepicker 组合时间
      • YbQuarterPicker 季度选择器
      • YbRangeQuarterPicker 季度范围选择器
      • YbConditionSelect 条件选择器
      • YbCheckboxGroup 多选框组
      • YbIconSelect 选择器
      • YbTagsInput 标签输入框
    • 其他组件

      • YbBallLoading 加载中
      • YbSymbolIcon 多色小图标
      • YbKeybuttonsPopover
      • YbPercentBattery 电池百分比
      • YbAffix 固钉
      • YbPagination 分页器
      • YbCollapse 折叠面板
      • YbScrollTool 滚动工具
    • 物料

      • YbMainSideMenu 侧栏菜单
      • YbLoadRemote 远程应用加载
      • YbLayoutPro 布局
      • YbMainPro 主页
      • YbAppMain 应用主页
      • YbAppLogin 普通登录页
      • YbAppPortal Portal登录页
    • 指令

      • v-fixed-in-scroller
    • Mixins

      • pageList_mixin
      • getScopedSlot_mixin
      • editFormPage_mixin
      • uploadProgressPage_mixin
      • rowActions_mixin
      • rowDeletes_mixin
      • drawerToRouterTab_mixin
    • 实验室

      • YbSwiper 轮播
    • 组件
    • 数据录入
    zougt
    2022-08-24

    YbFormulaInput 简单运算公式输入

    编写加减乘除基本的运算公式,并且运算数值可以用字段占位,再使用 yb-value-formaula 库得到计算结果

    # 基本使用

    公式JSON:["#预估费用 #","(","totalCost","/","2420","-","1",")","*","profitLossConfigChildren.diseasePrice","# 元#"]
    显示结果的文本:
    <template>
        <div>
            <yb-formula-input
                :fields="formulafields"
                v-model="formulaValue"
                width="836"
                autosize
                :rows="6"
                @change="formulaChange"
            >
                <template #buttonAppended>
                    <el-input
                        class="yb-config-push-button"
                        v-model="inputValue"
                    ></el-input
                    ><el-button
                        style="margin-top: 10px"
                        class="yb-config-push-button"
                        size="mini"
                        type="primary"
                        @click="inputValueToChar(formulaValue, $event)"
                        >插入文本</el-button
                    >
                </template>
            </yb-formula-input>
            <div style="margin-top:10px;">公式JSON:{{jsonText}}</div>
            <div style="margin-top:10px;">显示结果的文本:{{valueResultText}}</div>
        </div>
    </template>
    <script>
        export default {
            data() {
                return {
                    errorStack: '',
                    inputValue: '',
                    formulafields: [
                        {
                            prop: 'score',
                            label: '病种分值',
                            rowKey: '6',
                        },
                        {
                            prop: 'totalCost',
                            label: '总费用',
                            rowKey: '11',
                        },
                        {
                            prop: 'profitLossConfigChildren.diseasePrice',
                            label: '病种单价',
                            rowKey: '12',
                        },
                        {
                            prop: 'profitLossConfigChildren.standardDiseasePrice',
                            label: '上上年度每分值费用',
                            rowKey: '13',
                        },
                        {
                            prop: 'hospitalCoefficient',
                            label: '上年度同级别定点医疗(医院加成系数)',
                            rowKey: '14',
                        },
                    ],
                    formulaValue: [
                        '#预估费用 #',
                        '(',
                        'totalCost',
                        '/',
                        '2420',
                        '-',
                        '1',
                        ')',
                        '*',
                        'profitLossConfigChildren.diseasePrice',
                        '# 元#',
                    ],
                    valueResultText: '',
                };
            },
            mounted() {
                this.formulaChange();
            },
            computed: {
                jsonText() {
                    let text = JSON.stringify(this.formulaValue);
                    const spaceArr = text.match(/#[^#]+#/g);
                    if (spaceArr) {
                        spaceArr.forEach((str) => {
                            text = text.replace(str, str.replace(/\s/g, '\u00a0'));
                        });
                    }
                    return text;
                },
            },
            methods: {
                inputValueToChar() {
                    if (this.inputValue) {
                        this.formulaValue = [
                            ...this.formulaValue,
                            `#${this.inputValue}#`,
                        ];
                        this.inputValue = '';
                    }
                },
                formulaChange(val, errorMsg) {
                    if (errorMsg && errorMsg.length) {
                        return;
                    }
                    try {
                        //$valueFormaula 来源 import {  getCalculatedValueText,  getExecExpressionFunction,  getFormulaValue } from 'yb-value-formaula';
                        var executeExpression =
                            this.$valueFormaula.getExecExpressionFunction({
                                fieldsData: {
                                    profitLossConfigChildren: {
                                        deptCoefficient: 0,
                                        diseasePrice: 14.3,
                                        hospitalDiseasePrice: 14.3,
                                        standardDiseasePrice: 14.3,
                                    },
                                    quotas: 10510.5,
                                    score: 735,
                                    totalCost: 40000,
                                    totalScore: 2283,
                                },
                                //$Decimal 来源 import Decimal from 'decimal.js'
                                Decimal: this.$Decimal,
                            });
                        var valueText = this.$valueFormaula.getCalculatedValueText({
                            valueScriptText: [...this.formulaValue],
                            // 保留两位小数
                            decimalPoint: 2,
                            executeExpression,
                        });
                        this.valueResultText = valueText;
                    } catch (e) {
                        this.errorStack = e.stack;
                    }
                },
            },
        };
    </script>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    显示 复制 复制

    # 公式输入框的特性或者编辑规则:

    1. [字段名] 用中括号包裹的表示字段引用,例如:[cost] / ( [core] * 1 0 . 9 6 ) ,字段名必须非数字(英文字母等)开头,不能用纯数字:[8437374],中括号内第一个字符不能再是中括号符:[[myanynone]
    2. #文本# 表示常量文本的引用,例如计算公式与常量文本结合:#费用:# [cost] / ( [core] * 1 0 . 9 6 ) ,显示的结果如同:费用:49000
    3. 多段计算公式中间用"-"分隔,例如:( [totalCost]/[quotas]-1 )_ [score] _ [diseasePrice] # - # ( [totalCost]/[quotas] ) _ [score] _ [diseasePrice],显示结果如同:5600 - 7800
    4. 计算运算符:. + - * / ( ) ,小括号必须要闭合;条件运算符:< (小于)> (大于)<= (小于等于)>=(大于等于)!= (不等于);
    5. 输入框可以任意输入和删除文本,输入的文本无法认定为数字、运算符、常量文本时,都会认定为字段名;
    6. 当输入框内的文本不是有效的公式时,有一定的提醒;
    7. 字段名、常量文本、运算符之间的空格或者换行,不会影响公式计算;[字 段名 ]内的空格会认为是字段名的一部分;# 文 本# 内的空格会认为是常量文本的一部分;

    # Props

    参数 说明 类型 可选值 默认值
    value/v-model 绑定值 array -- --
    inputType 输入框类型 string 原生 input 的 type 值 'textarea'
    rows textarea 的 rows number - 2
    disabled 输入框 的 disabled boolean - -
    clearable 输入框 的 clearable ,是否可清空 boolean - -
    autosize textarea 的 autosize ,自适应内容高度 boolean |object - -
    fields 设置额外字段 array -- []
    fields[].label 字段显示中文名称 string -- --
    fields[].prop 字段名 string -- --
    fields[].rowKey rowKey string -- --
    fields[].children 字段子集 array -- --
    currentFieldsRowKey 设置当前字段的 rowKey string -- --
    showConditionKeys 是否显示条件运算符 boolean -- true
    showOperatorKeys 是否显示算术运算符 boolean -- true
    width 软键盘宽度 string | number -- 1200
    request 异步加载fields,返回 Promise , 提供搜索框的值 queryWord function({queryWord}){return Promise.resolve(fields)} -- --

    # Events

    参数 说明 回调参数
    change 值改变时触发 value,errorMsgs

    # Slots

    name 说明
    buttonAppended 清空全部按钮后面插入的内容
    上次更新: 2024/09/25, 19:33:20
    YbRange 范围
    YbCron 表达式生成器

    ← YbRange 范围 YbCron 表达式生成器→

    Theme by Vdoing | Copyright © 2021-2025 YB-GZ | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式