157 lines
3.3 KiB
JavaScript
157 lines
3.3 KiB
JavaScript
// template/selectMore/selectMore.js
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
img:String,
|
|
title:String,
|
|
multiple:Boolean,
|
|
list:Object,
|
|
propertyValue:String,
|
|
propertyValueArr:Array,
|
|
formSelect: Boolean,//是否用在发布表格中
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
arr1:[],
|
|
value1:'',
|
|
value2:'',
|
|
valueSingle:0,
|
|
valueArr:[],
|
|
show:false,
|
|
name:'',
|
|
name2:"",
|
|
},
|
|
name: '',
|
|
name2: "",
|
|
// lifetimes: {
|
|
// attached: function () {
|
|
// this.attachedIn()
|
|
// },
|
|
// },
|
|
// attached: function () {
|
|
// this.attachedIn()
|
|
// },
|
|
observers: {
|
|
"formSelect":function(e){
|
|
if(e && this.data.value1==''){
|
|
this.setData({
|
|
value1: '1',
|
|
value2: '1',
|
|
})
|
|
}
|
|
},
|
|
"propertyValue": function (e) {
|
|
// if (!this.properties.formSelect) {
|
|
if(e){
|
|
this.setData({
|
|
name: this.properties.list[e],
|
|
name2: this.properties.list[Math.floor(e)] + '>' +this.properties.list[e],
|
|
value1: Math.floor(e) + '',
|
|
value2:e
|
|
})
|
|
}else{
|
|
this.setData({
|
|
name: '',
|
|
value1: this.properties.formSelect ? '1':'',
|
|
value2: this.properties.formSelect ? '1' : '',
|
|
})
|
|
}
|
|
console.log(this.data.value1)
|
|
|
|
// }
|
|
},
|
|
"propertyValueArr": function (e) {
|
|
if (!this.properties.formSelect && e.length>0) {
|
|
|
|
this.setData({
|
|
name: this.properties.list[Math.floor(e[0]) + ''] + '/...',
|
|
value1: Math.floor(e[0]) + ''
|
|
})
|
|
}
|
|
}
|
|
|
|
},
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
// attachedIn(){
|
|
// // this.setList()
|
|
// },
|
|
catchmove() { },
|
|
showAlert(e) {
|
|
this.setData({
|
|
show: e.currentTarget.dataset.show == 1 ? true : false
|
|
})
|
|
// if(!this.data.arr1){
|
|
this.setList()
|
|
// }
|
|
},
|
|
setList() {
|
|
if (this.data.arr1.length > 0) { return false }
|
|
for (let i in this.properties.list) {
|
|
if (i == Math.floor(i)) {
|
|
this.data.arr1.push({
|
|
name: this.properties.list[i],
|
|
value: i
|
|
})
|
|
}
|
|
}
|
|
this.setData({
|
|
arr1: this.data.arr1
|
|
})
|
|
},
|
|
|
|
// 选择一级选项
|
|
selectItem(e) {
|
|
var value = e.currentTarget.dataset.value;
|
|
// 清空二级选项数据
|
|
|
|
this.setData({
|
|
value1: value,
|
|
value2: value
|
|
})
|
|
|
|
},
|
|
// 选择二级选项
|
|
selectItem2(e) {
|
|
let { value } = e.currentTarget.dataset;
|
|
|
|
this.setData({
|
|
value2: value
|
|
})
|
|
|
|
this.submit()
|
|
},
|
|
// 计算多选的情况下显示的name
|
|
calculateName(){
|
|
if(this.data.value1>0){
|
|
this.setData({
|
|
name2: this.properties.list[this.data.value1] + ' > ' + this.properties.list[this.data.value2],// 表格
|
|
name: this.properties.list[this.data.value1] + '/...'
|
|
})
|
|
}else{
|
|
this.setData({
|
|
name2: '',// 表格
|
|
name: ''
|
|
})
|
|
}
|
|
|
|
},
|
|
submit(){
|
|
|
|
this.triggerEvent('submit', { data: this.data.value2 })
|
|
this.calculateName()
|
|
|
|
this.setData({
|
|
show:false,
|
|
})
|
|
}
|
|
}
|
|
})
|