| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 | const getTime = require("../../utils/getTime");Component({    /**     * 组件的属性列表     */    properties: {        fromList: {            type: Array,            value: []        },        CompletedOrNot: Function, //完成与否回调    },    options: {        multipleSlots: true    },    /**     * 组件的初始数据     */    data: {        endTime: "", //结束时间        selectTime: "", //选择时间    },    lifetimes: {        attached: function () {            this.setData({                endTime: getTime.formatTime(new Date(), '-').split(' ')[0]            })        }    },    /**     * 组件的方法列表     */    methods: {        /* 输入 */        inputChange(e) {            let {                index,                item            } = e.currentTarget.dataset;            item.value = e.detail;            item.error = item.required && item.value == '' ? true : false;            let fromList = this.data.fromList;            fromList[index] = item;            if (item.callback) item.callback(item);            this.setData({                fromList            })            this.statistics();        },        /* 日期选择器 */        bindDateChange(e) {            const {                index            } = e.currentTarget.dataset;            let fromList = this.data.fromList;            fromList[index].value = e.detail.value;            fromList[index].error = false;            this.setData({                fromList            })            this.statistics();        },        /* 清空输入框 */        inputClear(e) {            console.log("清空", e.target.dataset.item.label)            this.statistics();        },        /* 统计是否完成全部必填项 */        statistics() {            let list = this.data.fromList,                sumCount = 0,                count = 0;            for (let i = 0; i < list.length; i++) {                if (list[i].required) {                    sumCount++;                    if (list[i].value != "") count++;                }            }            // console.log("必填总数", sumCount, '已填', count)            this.triggerEvent("CompletedOrNot", sumCount == count)        },        /* 提交 */        getData() {            let list = this.data.fromList,                returnData = {},                isReturn = true;            for (let i = 0; i < list.length; i++) {                if (list[i].required && list[i].value == "") {                    list[i].error = true;                    isReturn = false;                } else {                    returnData[list[i].valueName] = list[i].value;                }            }            this.setData({                fromList: list            })            return {                returnData,                isReturn            }        }    }})
 |