define(["zepto", "vue", "medtap"], function($, Vue, medtap) { var addressList = { list: [], portType:getEnvironment(), getAddressList: function() { medtap.jzz(1); medtap._ajax({ url: '/shop/address/getAddress', type: 'get', async: false, portType:addressList.portType, data: {}, success: function(data) { medtap.jzz(0); if(data.success) { addressList.list = data.content.addressVO; } else { medtap.winPop(data.resultDesc); } }, error: function(err) { medtap.jzz(0); medtap.winPop("请求失败"); } }); }, init: function() { new Vue({ el: "#app", data: addressList }); }, bind: function() { $("#add").on("click", function() { medtap.pushNewWindow('addAddress.html?v=1.0.1&type=0'); }); $(".addressList").on("click", ".bianji", function() { var a = $(this).attr("addressId"); var wechatId = medtap.getRequest('wechatId') || (!!localStorage.medtapGlobalData ? JSON.parse(localStorage.medtapGlobalData).wechatId : ''); medtap.pushNewWindow('addAddress.html?v=1.0.0&type=1&addressId=' + a + '&wechatId=' + wechatId); }); $(".addressList").on("click", ".txt,.moren", function() { medtap.jzz(1); var index = $(this).attr("index"), addressId = $(this).attr("addressId"); //修改默认地址 addressList.list[index].isDefault = "1"; medtap._ajax({ url: '/shop/address/saveAddress', type: 'post', async: true, contentType: "application/json", portType:addressList.portType, data: addressList.list[index], success: function(data) { medtap.jzz(0); if(data.success) { var list = addressList.list; for(var i = 0, len = list.length; i < len; i++){ if(i == index){ continue; } list[i].isDefault = "0"; } medtap.popWindow(); } else { medtap.winPop(data.resultDesc); } }, error: function(err) { medtap.jzz(0); medtap.winPop("请求失败"); } }); }); } } addressList.init(); addressList.getAddressList(); addressList.bind(); window.viewDidAppear = function() { addressList.getAddressList(); } })