使用场景

  • 添加品牌-车系-车型的交互
  • 编辑品牌-车系-车型的交互

引入模块

//.wxml
    <import src="../../components/carPicker/carPicker.wxml"/>
    <template is="carPicker" data="{{wiiCarPicker}}"/>
//.js
var carPicker  = require('../../components/carPicker/carPicker');

配置组件数据

var carPickerOption = {
    data:{
        wiiCarPicker:{
            'carPickerUrl':'/wxapp/api',
            'carPickerKey':{
                'getBrandList':'wxapp:auto:car:get_brand_list',
                'getSerialList':'wxapp:auto:car:get_serial_list',
                'getModelList':'wxapp:auto:car:get_model_list_by_year',
                'setCarInfo':'wxapp:service:user:set_car_info'
            },
            'carPickerStyle':{

            },
            'carPickerIndexText':'选择品牌页面左上角的返回按钮文案,如首页、我的爱车等等'
        }
    }
}
carPicker = utils.assign(carPicker,carPickerOption)

seleCar(obj)

添加车型或者编辑车型时调用;当编辑车型时,传入obj,包含该车型在数据库中的id{id:xxx}

示例
//.wxml
        <text>您选择的车型信息为{{carInfo.model_name}}</text>
         <button class="wii-btn" bindtap="seleCar">选择车型</button>
         <button class="wii-btn" data-id="123" bindtap="editCar">编辑车型123{{editCarInfo.model_name}}</button>

//.js
var carPicker  = require('../../components/carPicker/carPicker');
var pageSetting = {
    ...
    callback:function(){
        var _this = this;
        switch(arguments[0]){
            case 'carPicker':
                var carInfoData = arguments[1];
                console.log(carInfoData)
                var type = arguments[2];
                if(type == 'add'){
                //添加车型时的回调
                    _this.setData({
                        carInfo:carInfoData
                    });
                }else if(type == 'edit'){
                //编辑车型时的回调
                    _this.setData({
                        editCarInfo:carInfoData
                    });
                }
                break;
            default:
                break;
        }
    },
    editCar:function(e){
        var id = e.currentTarget.dataset.id;
        this.seleCar({id:id});
    }
    ...
}

results matching ""

    No results matching ""