患者1.2
This commit is contained in:
@@ -26,7 +26,6 @@ var defaultFieldNames = {
|
||||
title: String,
|
||||
value: {
|
||||
type: String,
|
||||
observer: 'updateValue',
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
@@ -39,7 +38,6 @@ var defaultFieldNames = {
|
||||
options: {
|
||||
type: Array,
|
||||
value: [],
|
||||
observer: 'updateOptions',
|
||||
},
|
||||
swipeable: {
|
||||
type: Boolean,
|
||||
@@ -69,15 +67,20 @@ var defaultFieldNames = {
|
||||
textKey: FieldName.TEXT,
|
||||
valueKey: FieldName.VALUE,
|
||||
childrenKey: FieldName.CHILDREN,
|
||||
innerValue: '',
|
||||
},
|
||||
watch: {
|
||||
options: function () {
|
||||
this.updateTabs();
|
||||
},
|
||||
value: function (newVal) {
|
||||
this.updateValue(newVal);
|
||||
},
|
||||
},
|
||||
created: function () {
|
||||
this.updateTabs();
|
||||
},
|
||||
methods: {
|
||||
updateOptions: function (val, oldVal) {
|
||||
var isAsync = !!(val.length && oldVal.length);
|
||||
this.updateTabs(isAsync);
|
||||
},
|
||||
updateValue: function (val) {
|
||||
var _this = this;
|
||||
if (val !== undefined) {
|
||||
@@ -86,6 +89,7 @@ var defaultFieldNames = {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.innerValue = val;
|
||||
this.updateTabs();
|
||||
},
|
||||
updateFieldNames: function () {
|
||||
@@ -110,12 +114,15 @@ var defaultFieldNames = {
|
||||
}
|
||||
}
|
||||
},
|
||||
updateTabs: function (isAsync) {
|
||||
updateTabs: function () {
|
||||
var _this = this;
|
||||
if (isAsync === void 0) { isAsync = false; }
|
||||
var _a = this.data, options = _a.options, value = _a.value;
|
||||
if (value !== undefined) {
|
||||
var selectedOptions = this.getSelectedOptionsByValue(options, value);
|
||||
var options = this.data.options;
|
||||
var innerValue = this.innerValue;
|
||||
if (!options.length) {
|
||||
return;
|
||||
}
|
||||
if (innerValue !== undefined) {
|
||||
var selectedOptions = this.getSelectedOptionsByValue(options, innerValue);
|
||||
if (selectedOptions) {
|
||||
var optionsCursor_1 = options;
|
||||
var tabs_1 = selectedOptions.map(function (option) {
|
||||
@@ -146,16 +153,6 @@ var defaultFieldNames = {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 异步更新
|
||||
if (isAsync) {
|
||||
var tabs = this.data.tabs;
|
||||
tabs[tabs.length - 1].options =
|
||||
options[options.length - 1][this.data.childrenKey];
|
||||
this.setData({
|
||||
tabs: tabs,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
tabs: [
|
||||
{
|
||||
@@ -171,6 +168,9 @@ var defaultFieldNames = {
|
||||
onClickTab: function (e) {
|
||||
var _a = e.detail, tabIndex = _a.index, title = _a.title;
|
||||
this.$emit('click-tab', { title: title, tabIndex: tabIndex });
|
||||
this.setData({
|
||||
activeTab: tabIndex,
|
||||
});
|
||||
},
|
||||
// 选中
|
||||
onSelect: function (e) {
|
||||
@@ -206,11 +206,13 @@ var defaultFieldNames = {
|
||||
tabs: tabs,
|
||||
});
|
||||
var selectedOptions = tabs.map(function (tab) { return tab.selected; }).filter(Boolean);
|
||||
var value = option[valueKey];
|
||||
var params = {
|
||||
value: option[valueKey],
|
||||
value: value,
|
||||
tabIndex: tabIndex,
|
||||
selectedOptions: selectedOptions,
|
||||
};
|
||||
this.innerValue = value;
|
||||
this.$emit('change', params);
|
||||
if (!option[childrenKey]) {
|
||||
this.$emit('finish', params);
|
||||
|
||||
@@ -37,14 +37,14 @@
|
||||
wx:for="{{ tab.options }}"
|
||||
wx:for-item="option"
|
||||
wx:key="index"
|
||||
class="{{ option.className }} {{ utils.optionClass(tab, textKey, option) }}"
|
||||
style="{{ utils.optionStyle({ tab, textKey, option, activeColor }) }}"
|
||||
class="{{ option.className }} {{ utils.optionClass(tab, valueKey, option) }}"
|
||||
style="{{ utils.optionStyle({ tab, valueKey, option, activeColor }) }}"
|
||||
data-option="{{ option }}"
|
||||
data-tab-index="{{ tabIndex }}"
|
||||
bind:tap="onSelect"
|
||||
>
|
||||
<text>{{ option[textKey] }}</text>
|
||||
<van-icon wx:if="{{ utils.isSelected(tab, textKey, option) }}" name="success" size="18" />
|
||||
<van-icon wx:if="{{ utils.isSelected(tab, valueKey, option) }}" name="success" size="18" />
|
||||
</view>
|
||||
</view>
|
||||
<!-- 暂不支持 -->
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
var utils = require('../wxs/utils.wxs');
|
||||
var style = require('../wxs/style.wxs');
|
||||
|
||||
function isSelected(tab, textKey, option) {
|
||||
return tab.selected && tab.selected[textKey] === option[textKey]
|
||||
function isSelected(tab, valueKey, option) {
|
||||
return tab.selected && tab.selected[valueKey] === option[valueKey]
|
||||
}
|
||||
|
||||
function optionClass(tab, textKey, option) {
|
||||
return utils.bem('cascader__option', { selected: isSelected({ tab, textKey, option }), disabled: option.disabled })
|
||||
function optionClass(tab, valueKey, option) {
|
||||
return utils.bem('cascader__option', { selected: isSelected(tab, valueKey, option), disabled: option.disabled })
|
||||
}
|
||||
|
||||
function optionStyle(data) {
|
||||
var color = data.option.color || (isSelected(data.tab, data.textKey, data.option) ? data.activeColor : undefined);
|
||||
var color = data.option.color || (isSelected(data.tab, data.valueKey, data.option) ? data.activeColor : undefined);
|
||||
return style({
|
||||
color
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user