Quellcode durchsuchen

新增 easy-combobox 组件

陈龙 vor 3 Monaten
Ursprung
Commit
2399444312

+ 82 - 0
src/Auman.PieceWage.UniApp/components/easy-combobox-option/easy-combobox-option.vue

@@ -0,0 +1,82 @@
+<template>
+    <view :class="`easy-combobox-option${selected ? ' easy-combobox-selected' : ''}`" @tap="clickOption">
+        <slot>{{text}}</slot>
+    </view>
+</template>
+
+<script>
+    let root = null;
+    export default {
+        name: "easy-combobox-option",
+        props: {
+            value: {
+                default: ''
+            },
+            text: {
+                type: String
+            }
+        },
+        data() {
+            return {
+                selected: false
+            };
+        },
+        created() {
+            root = this.getParent();
+            root.addOption(this);
+            console.log('document:', document);
+        },
+        methods: {
+            select() {
+                this.selected = true;
+            },
+
+            unselect() {
+                this.selected = false;
+            },
+
+            clickOption() {
+                this.select();
+                root.select(this);
+            },
+
+            getOption() {
+                return {
+                    value: this.value,
+                    text: this.text
+                };
+            },
+
+            getParent(name = 'easy-combobox') {
+                let parent = this.$parent;
+                let parentName = parent.$options.name;
+                while (parentName !== name) {
+                    parent = parent.$parent;
+                    if (!parent) return false;
+                    parentName = parent.$options.name;
+                }
+                return parent;
+            }
+        }
+    }
+</script>
+
+<style lang="scss">
+    .easy-combobox-option {
+        position: relative;
+        font-size: 26upx;
+        padding: 0 30upx;
+        text-wrap: nowrap;
+        height: 70upx;
+        display: flex;
+        align-items: center;
+    }
+
+    .easy-combobox-option+.easy-combobox-option {
+        border-top: 1upx solid #dfdfdf;
+    }
+
+    .easy-combobox-option.easy-combobox-selected {
+        background-color: #cde6ff;
+    }
+</style>

+ 126 - 0
src/Auman.PieceWage.UniApp/components/easy-combobox/easy-combobox.vue

@@ -0,0 +1,126 @@
+<template>
+    <view class="easy-combobox" :style="`width:${comboboxWidth}`">
+        <view class="easy-combobox-view">
+            <view class="easy-combobox-view-text">{{text}}</view>
+            <uni-icons type="down" size="12"></uni-icons>
+        </view>
+        <view class="easy-combobox-panel">
+            <slot></slot>
+        </view>
+    </view>
+</template>
+
+<script>
+    import extend from '../../utils/extend';
+
+    let options = [];
+    let current = -1;
+
+    export default {
+        name: "easy-combobox",
+        props: {
+            selected: {
+                type: Number,
+                default: 0
+            },
+            width: {
+                type: Number
+            }
+        },
+        data() {
+            return {
+                comboboxWidth: '120upx',
+                text: ''
+            };
+        },
+        created() {
+            options = [];
+            current = this.selected;
+            if (extend.isNumber(this.width) || extend.isNumberString(this.width)) {
+                this.comboboxWidth = `${this.width}upx`;
+            } else if (extend.isNonEmptyString(this.width) && extend.isNumber(parseFloat(this.width))) {
+                this.comboboxWidth = this.width;
+            }
+        },
+        mounted() {
+            if (current < options.length && current >= 0) {
+                options[current].select();
+                this.select(current);
+            }
+        },
+        methods: {
+            addOption(option) {
+                if (extend.isObject(option)) {
+                    options.push(option);
+                }
+            },
+
+            /**
+             * 选择
+             * @param {number|object} option 选项,option 数组下标或者 option 组件本身
+             */
+            select(option) {
+                let i = 0;
+
+                if (typeof option === 'number') {
+                    current = option;
+                } else if (typeof option === 'object') {
+                    for (i = 0; i < options.length; i++) {
+                        if (options[i] === option) {
+                            current = i;
+                            break;
+                        }
+                    }
+                }
+                for (i = 0; i < options.length; i++) {
+                    if (current === i) {
+                        options[current].select();
+                        let opt = options[current].getOption();
+                        this.text = opt.text;
+                        this.$emit('change', opt);
+                    } else {
+                        options[i].unselect();
+                    }
+                }
+            }
+        }
+    }
+</script>
+
+<style lang="scss">
+    .easy-combobox {
+        position: relative;
+        box-sizing: border-box;
+        display: inline-block;
+        height: 70upx;
+
+        .easy-combobox-view {
+            position: relative;
+            box-sizing: border-box;
+            display: flex;
+            width: 100%;
+            height: 100%;
+            justify-content: space-between;
+            align-items: center;
+            border: 1upx solid #dfdfdf;
+            border-radius: 10upx;
+            padding: 10upx;
+        }
+        
+        .easy-combobox-view-text {
+            font-size: 24upx;
+        }
+
+        .easy-combobox-panel {
+            position: absolute;
+            box-sizing: border-box;
+            left: 0;
+            top: 70upx;
+            z-index: 100;
+            background-color: #ffffff;
+            border: 1upx solid #dfdfdf;
+            box-shadow: 0 0 20upx #999999;
+            border-radius: 10upx;
+        }
+    }
+</style>

+ 3 - 1
src/Auman.PieceWage.UniApp/components/easy-tab/easy-tab.vue

@@ -18,7 +18,9 @@
             }
         },
         data() {
-            return {};
+            return {
+                current: 0,
+            };
         },
         created() {
             this.items = [];

+ 8 - 2
src/Auman.PieceWage.UniApp/components/page-dispatch/page-dispatch.vue

@@ -1,6 +1,11 @@
 <template>
     <view class="flex direction-column height-100pre width-100per">
-        <view class="flex items-center padding-right">
+        <view class="flex items-center padding-lr">
+            <easy-combobox width="160">
+                <easy-combobox-option v-if="isDispatch" value="1" text="派工"></easy-combobox-option>
+                <easy-combobox-option v-if="isDispatch" value="2" text="派工确认"></easy-combobox-option>
+                <easy-combobox-option v-if="!isDispatch" value="3" text="报工"></easy-combobox-option>
+            </easy-combobox>
             <uni-search-bar placeholder="单号、型号" clearButton="none" class="grow-1" v-model="searchValue"
                 @confirm="load"></uni-search-bar>
             <button size="mini" type="primary" @tap="load">搜索</button>
@@ -103,7 +108,8 @@
                 items: [],
                 currentItem: null,
                 currentDescription: '',
-                currentWorkingTeam: null
+                currentWorkingTeam: null,
+                currentStatus: 1
             };
         },
         async created() {

+ 2 - 2
src/Auman.PieceWage.UniApp/manifest.json

@@ -2,8 +2,8 @@
     "name" : "生产流程管理",
     "appid" : "__UNI__0D07441",
     "description" : "生产流程管理",
-    "versionName" : "0.0.7",
-    "versionCode" : 7,
+    "versionName" : "0.0.8",
+    "versionCode" : 8,
     "transformPx" : false,
     /* 5+App特有相关 */
     "app-plus" : {

+ 254 - 3
src/Auman.PieceWage.UniApp/utils/extend.js

@@ -362,10 +362,11 @@ const extend = {
     /**
      * 是否是数字字符串
      * @param {string} str 
-     * @returns 
+     * @returns {Boolean}
      */
     isNumberString(str) {
-        return /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?this/.test(str);
+        let res = this.parseFloat(str);
+        return !isNaN(res);
     },
 
     /**
@@ -431,7 +432,7 @@ const extend = {
         // #ifdef APP
         return this.isLikeArray(arr);
         // #endif
-        
+
         return this.isObject(arr) && arr instanceof Array;
     },
 
@@ -626,6 +627,7 @@ const extend = {
      * @param {number} length 补位字符
      * @param {string} prefix 拼接长度, 默认值 0
      * value 值的长度 length 不够时, 将以前缀 prefix 填充, 比如: 001
+     * @returns {string}
      */
     padLeft(value, length, prefix) {
         if (this.isNumber(value)) {
@@ -643,6 +645,255 @@ const extend = {
         return (Array(length).join(prefix) + (value.length === 0 ? prefix : value)).slice(-length);
     },
 
+    /**
+     * 字符串后缀拼接
+     * @param {string | number} value 要拼接的值
+     * @param {number} length 补位字符
+     * @param {string} prefix 拼接长度, 默认值 0
+     * value 值的长度 length 不够时, 将以前缀 prefix 填充, 比如: 001
+     * @returns {string}
+     */
+    padRight(value, length, prefix) {
+        if (this.isNumber(value)) {
+            value = value.toString();
+        }
+        if (!this.isNonEmptyString(value)) {
+            value = '';
+        }
+        if (!this.isNumber(length) || value.length > length) {
+            length = value.length;
+        }
+        if (!this.isNonEmptyString(prefix)) {
+            prefix = '0';
+        }
+        return ((value.length === 0 ? prefix : value) + Array(length).join(prefix)).slice(0, length);
+    },
+
+    /**
+     * 转换成金额字符串
+     * @param {number} amount 金额
+     * @param {number} pointlength 保留小数位数, 默认 14,最大 14
+     * @returns {string} 金额字符串
+     */
+    parseAmount(amount, pointlength) {
+        if (!this.isNumber(amount)) {
+            amount = 0;
+        }
+        if (!this.isNumber(pointlength) || pointlength > 14) {
+            pointlength = 14;
+        }
+        if (pointlength > 0) {
+            amount = this.floatRound(amount, pointlength);
+        } else {
+            amount = Math.round(amount);
+        }
+        let text = amount.toString();
+        let temp = '';
+        let end = '';
+        let sign = '';
+        if (text.substring(0, 1) === '-') {
+            sign = '-';
+            text = text.substring(1);
+        }
+        // 格式化整数部分
+        if (text.indexOf('.') > 0) {
+            text = text.substring(0, text.indexOf('.'));
+        }
+        for (var i = 0; i < text.length; ++i) {
+            temp = text.substring(text.length - 1);
+            text = text.substring(0, text.length - 1);
+            if (temp.length > 0) {
+                if ((i + 1) % 3 === 0 && text.length > 0) {
+                    end = ',' + temp + end;
+                } else end = temp + end;
+            } else {
+                break;
+            }
+        }
+
+        // 格式化小数部分
+        text = amount.toString();
+        if (text.indexOf('.') > 0) {
+            text = text.substring(text.indexOf('.') + 1);
+        } else {
+            text = '';
+        }
+        if (text.length < pointlength) {
+            text = this.padRight(text, pointlength, '0');
+        }
+        end += `.${text}`;
+        return sign + end;
+    },
+
+    /**
+     * 转换成中文大写金额字符串
+     * @param {number} amount 金额
+     * @param {number} pointlength 保留小数位数, 默认 13
+     * @returns {string} 中文大写金额字符串
+     */
+    parseCNAmount(amount, pointlength) {
+        if (!this.isNumber(amount)) {
+            amount = 0;
+        }
+        if (!this.isNumber(pointlength) || pointlength > 13) {
+            pointlength = 13;
+        }
+        if (pointlength > 0) {
+            amount = this.floatRound(amount, pointlength);
+        } else {
+            amount = Math.round(amount);
+        }
+
+        let amountString = amount.toString();
+
+        // 定义中文数字集合
+        let assemble1 = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
+
+        // 定义小数中文集合
+        let assemble2 = ["角", "分", "厘", "毫", "丝", "忽", "微", "纤", "沙", "尘", "埃", "渺", "漠"];
+
+        // 定义拾佰仟集合
+        let assemble3 = ["", "拾", "佰", "仟"];
+
+        // 定义万以后的中文集合
+        let assemble4 = ["圆", "万", "亿", "兆", "京", "垓", "秭", "穰", "沟", "涧", "正", "载", "极", "归", "僧", "那", "思", "猴",
+            "格"
+        ];
+
+        // 定义整数字符串
+        let integerString = amountString.indexOf('.') > 0 ? amountString.substring(0, amountString.indexOf('.')) :
+            amountString;
+
+        // 定义小数字符串
+        let decimalString = amountString.indexOf('.') > 0 ? amountString.substring(amountString.indexOf('.') + 1) :
+            '';
+
+        // 定义转换后的文本
+        let text = '';
+
+        // 定义当前位是否是零
+        let currentIsZore = true;
+
+        // 定义上一位是否是零
+        let beforeIsZore = false;
+
+        // 定义位数
+        let index = 0;
+
+        // 格式化整数
+        // 算法:‘个拾佰仟’+‘阶位’
+        for (let i = integerString.length - 1; i >= 0; i--) {
+            // 判断当前位是否是0
+            currentIsZore = integerString[i] === '0';
+
+            // 计算阶位
+            let bitLevel = Math.floor((integerString.length - 1 - i) / 4);
+
+            // 如果第一位是0,则设置上一位是0
+            if (index === 0 && currentIsZore) {
+                beforeIsZore = true;
+            }
+
+            // 如果当前是第0位,则加大阶位
+            if (index === 0) {
+                text = assemble4[bitLevel] + text;
+            }
+
+            // 位当前为0
+            if (currentIsZore) {
+                // 前一位不是0,则加零
+                if (!beforeIsZore) {
+                    text = assemble1[integerString[i]] + text;
+                }
+            }
+
+            // 当前位不为0
+            else {
+                text = assemble1[integerString[i]] + assemble3[index] + text;
+            }
+
+            // 位数加1
+            index++;
+            index = index > 3 ? 0 : index;
+
+            // 设置上一位是否是0
+            beforeIsZore = currentIsZore;
+        }
+
+        // 格式化小数
+        for (let j = 0; j < decimalString.length; ++j) {
+            text += assemble1[decimalString[j]] + assemble2[j];
+        }
+
+        return text;
+    },
+
+    /**
+     * 转换浮点数
+     * @param {string | number} value 值
+     * @returns {number}
+     */
+    parseFloat(value) {
+        let res = NaN;
+        let temp = '';
+        if (this.isNumber(value)) {
+            return value;
+        } else if (this.isString(value)) {
+            temp = value;
+            if (temp.indexOf(',') >= 0) {
+                temp = value.replaceAll(',', '');
+            }
+            res = parseFloat(temp);
+        }
+        return res;
+    },
+
+    /**
+     * 日期字符串转换成日期对象
+     * @param {string} date 被转换字符串,必选
+     * @returns {Date} 日期对象
+     */
+    parseDate(date) {
+        let newDate = null;
+        if (this.isNumber(date)) {
+            if (date.toString().length === 10) {
+                date *= 1000;
+            }
+            date = 'Date(' + date + ')';
+        }
+        if (this.isNonEmptyString(date)) {
+            if (date.indexOf('Date') > 0) {
+                date = "new " + date.replace(/\//g, '');
+            }
+            date = date.replace(/-/g, '/');
+            date = date.replace(/T/g, ' ');
+            if (date.indexOf('Date') >= 0) {
+                newDate = eval(date);
+            } else {
+                let ms = 0;
+                let msIndex = date.indexOf('.');
+                if (msIndex > -1) {
+                    ms = parseInt(date.substring(msIndex + 1));
+                    date = date.substring(0, msIndex);
+                }
+                newDate = new Date(date);
+                if (!isNaN(ms)) {
+                    newDate.setMilliseconds(ms);
+                }
+            }
+        }
+        return newDate;
+    },
+
+    /**
+     * 转换浮点数
+     * @param {string | number} value 值
+     * @returns {number}
+     */
+    parseInt(value) {
+        return this.parseFloat(value);
+    },
+
     /**
      * 读取存储
      * @param {string} key