1. 程式人生 > >iosselect簡單使用(三級聯動)

iosselect簡單使用(三級聯動)

export default { name: 'UserDatum', data () { return { iosProvinces:[], iosCitys:[], iosCountys:[] } }, methods: { topath: function (name) { this.$router.push({path:name}); }, changeMastDisplay: function (name) { this.$store.commit('mastdisplay'
,name); }, initIosSelect: function () { let showContactDom = this.$refs.show_contact; let contactProvinceCodeDom = this.$refs.contact_province_code; let contactCityCodeDom = this.$refs.contact_city_code; let sccode = showContactDom.getAttribute('data-city-code'); let
scname = showContactDom.getAttribute('data-city-name'); let oneLevelId = showContactDom.getAttribute('data-province-code'); let twoLevelId = showContactDom.getAttribute('data-city-code'); let threeLevelId = showContactDom.getAttribute('data-district-code'); let iosSelect = new
IosSelect(3, [this.iosProvinces, this.iosCitys, this.iosCountys], { itemHeight: 35, itemShowCount: 5, relation: [1, 1], oneLevelId: oneLevelId, twoLevelId: twoLevelId, threeLevelId: threeLevelId, callback: function (selectOneObj, selectTwoObj, selectThreeObj) { contactProvinceCodeDom.value = selectOneObj.id; contactProvinceCodeDom.setAttribute('data-province-name', selectOneObj.value); contactCityCodeDom.value = selectTwoObj.id; contactCityCodeDom.setAttribute('data-city-name', selectTwoObj.value); showContactDom.setAttribute('data-province-code', selectOneObj.id); showContactDom.setAttribute('data-city-code', selectTwoObj.id); showContactDom.setAttribute('data-district-code', selectThreeObj.id); showContactDom.innerHTML = selectOneObj.value + ' ' + selectTwoObj.value + ' ' + selectThreeObj.value; } }); }, getareadata: function () { this.API.getareadata().then((response) => { response.filter((item,index) => { //拼接三級聯動資料 let area = { parentId:item.region_type, id:item.region_id, value:item.region_name, ...item }; //過濾省市區的資料 if(item.parent_id == 1){ this.iosProvinces.push(area); }else if(item.parent_id == 2){ this.iosCitys.push(area); }else if(item.parent_id == 3){ this.iosCountys.push(area); } }); }, (response) => { mui.toast('網路錯誤'); }); } }, components: { }, computed: { }, created: function () { this.getareadata(); } }