1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import {
- getCustomItems
- } from "../../../../../utils/customItemType";
- Component({
- properties: {
- topHei: {
- type: String,
- value: "20rpx"
- },
- onChange: {
- type: Function
- }
- },
- options: {
- multipleSlots: true
- },
- externalClasses: ["external-custom-box", "external-custom-label", "external-custom-stepper-box", "external-explain", "external-active", "external-custom-option"],
- data: {
- list: []
- },
- methods: {
- init(data, prefix = '') {
- return new Promise((resolve) => {
- getCustomItems(data, prefix).then(list => {
- console.log("list", list)
- this.setData({
- list
- });
- this.getResult();
- resolve(list.length);
- });
- });
- },
- onOption(e) {
- const {
- index,
- value
- } = e.currentTarget.dataset;
- if (this.data.list[index].value == value) return;
- this.setData({
- [`list[${index}].value`]: value
- });
- this.getResult();
- },
- getResult(isSubmit = false) {
- let obj = {};
- let breakOff = false;
- this.data.list.filter(v => {
- if (breakOff) return;
- if (v.type == '自定义') {
- if (!v.value) v.value = 0;
- }
- obj[v.key] = v.value || '';
- if (isSubmit && !obj[v.key]) {
- wx.showToast({
- title: `请完成定制"${v.label}"选项`,
- icon: "none"
- })
- breakOff = true;
- } else if (v.tips) {
- wx.showToast({
- title: v.tips,
- icon: "none"
- })
- breakOff = true;
- }
- })
- this.triggerEvent("onChange", breakOff ? false : obj)
- return breakOff ? false : obj
- },
- valueChange(e) {
- const {
- index,
- item
- } = e.currentTarget.dataset;
- wx.hideToast()
- item.tips = '';
- item.value = (e.detail.value - 0).toFixed(item.decimalplaces);
- if (item.value > item.max) item.tips = `自定义${item.label}超出可选范围!`;
- if (item.value < item.min) item.tips = `自定义${item.label}少于可选范围!`;
- if (item.tips) wx.showToast({
- title: item.tips,
- icon: "none"
- })
- this.setData({
- [`list[${index}]`]: item
- })
- }
- }
- })
|