| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- var app = new Vue({
- 'el': '#app',
- 'data': {
- // 列表数据
- dataList: [],
- // 参数
- params: {
- page: 1,
- pageSize: 6,
- },
- info: {},
- loading: false,
- submitting: false,
- loaded: false,
- modalStatus: false,
- op: '',
- },
- created: function(){
- this.getDataList(0);
- this.op = getParam('op');
- },
- mounted: function(){
- var _this = this;
- $(window).scroll(function(){
- var scrollHeight = $(this).scrollTop();
- var height = $('body')[0].scrollHeight;
- var docHeight = $(this).outerHeight();
- if(docHeight+scrollHeight >= height-1){
- if(_this.loading || _this.loaded){
- return false;
- }
- _this.params.page++;
- _this.getDataList(1);
- }
- })
- },
- methods: {
- // 详情
- getInfo: function(id){
- if(id>0){
- var _this = this;
- $.post('/weixin/address/getInfo', {id:id}, function (res) {
- if(res.code == 'success'){
- _this.info = res.data;
- }else{
- $.toast(res.message);
- }
- },"json");
- }
- },
- // 弹窗
- switchPopup: function(id){
- if(this.modalStatus){
- this.modalStatus = false;
- $.closePopup();
- }else{
- this.modalStatus = true;
- $("#modal").popup();
- this.getInfo(id);
- }
- },
- // 提交地址
- doSubmit: function(){
- var _this = this;
- if(_this.submitting){
- return false;
- }
- if(_this.info.realname == '' || _this.info.realname == null){
- $.toast("请填写收货人姓名");
- return false;
- }
- if(_this.info.mobile == '' || _this.info.mobile == null){
- $.toast("请填写收货人手机号");
- return false;
- }
- if(_this.info.address == '' || _this.info.address == null){
- $.toast("请填写收货地址");
- return false;
- }
- _this.submitting = true;
- $.showLoading("数据提交中...");
- $.post('/weixin/address/doSubmit', _this.info, function (res) {
- _this.submitting = false;
- $.hideLoading();
- if(res.code == 'success'){
- // $.toast('操作成功');
- _this.params.page = 1;
- _this.switchPopup(0);
- _this.getDataList(0);
- }else if(res.code == 'login'){
- login(res.data.url);
- }else{
- $.toast(res.message);
- }
- },"json");
- },
- // 删除
- doDelete: function(ele, id){
- if(id>0){
- var _this = this;
- if(confirm('确定删除该地址?')){
- $.post('/weixin/address/doDelete', {id:id}, function (res) {
- if(res.code == 'success'){
- $.toast('删除成功');
- $(ele.target).parents('.weui-panel').detach();
- // _this.params.page = 1;
- // _this.getDataList(0);
- }else if(res.code == 'login'){
- login(res.data.url);
- }else{
- $.toast(res.message);
- }
- },"json");
- }
- }
- },
- // 设置默认
- setDefault: function(id){
- if(id>0){
- var _this = this;
- $.post('/weixin/address/setDefault', {id:id}, function (res) {
- if(res.code == 'success'){
- $.showLoading("设置成功");
- setTimeout(function () {
- if(_this.op){
- history.go(-1);
- }else{
- _this.params.page = 1;
- _this.getDataList(0);
- }
- }, 500)
- }
- },"json");
- }
- },
- // 获取列表数据
- getDataList: function(more){
- var _this = this;
- $.hideLoading();
- $.showLoading("数据加载中...");
- _this.loading = true;
- $.post('/weixin/address/getList', _this.params, function (res) {
- $.hideLoading();
- _this.loading = false;
- if (res.code == 'success') {
- if(res.data.data.length<=0){
- _this.loaded = true;
- $.toast("已加载完全部...",'text');
- return false;
- }
- if(more){
- $.each(res.data.data, function(k,item){
- console.log(item);
- _this.dataList.push(item);
- });
- }else{
- _this.dataList = res.data.data
- }
- }else if(res.code == 'login'){
- login(res.data.url);
- }
- }, "json");
- },
- }
- })
|