address.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 列表数据
  5. dataList: [],
  6. // 参数
  7. params: {
  8. page: 1,
  9. pageSize: 6,
  10. },
  11. info: {},
  12. loading: false,
  13. submitting: false,
  14. loaded: false,
  15. modalStatus: false,
  16. op: '',
  17. },
  18. created: function(){
  19. this.getDataList(0);
  20. this.op = getParam('op');
  21. },
  22. mounted: function(){
  23. var _this = this;
  24. $(window).scroll(function(){
  25. var scrollHeight = $(this).scrollTop();
  26. var height = $('body')[0].scrollHeight;
  27. var docHeight = $(this).outerHeight();
  28. if(docHeight+scrollHeight >= height-1){
  29. if(_this.loading || _this.loaded){
  30. return false;
  31. }
  32. _this.params.page++;
  33. _this.getDataList(1);
  34. }
  35. })
  36. },
  37. methods: {
  38. // 详情
  39. getInfo: function(id){
  40. if(id>0){
  41. var _this = this;
  42. $.post('/weixin/address/getInfo', {id:id}, function (res) {
  43. if(res.code == 'success'){
  44. _this.info = res.data;
  45. }else{
  46. $.toast(res.message);
  47. }
  48. },"json");
  49. }
  50. },
  51. // 弹窗
  52. switchPopup: function(id){
  53. if(this.modalStatus){
  54. this.modalStatus = false;
  55. $.closePopup();
  56. }else{
  57. this.modalStatus = true;
  58. $("#modal").popup();
  59. this.getInfo(id);
  60. }
  61. },
  62. // 提交地址
  63. doSubmit: function(){
  64. var _this = this;
  65. if(_this.submitting){
  66. return false;
  67. }
  68. if(_this.info.realname == '' || _this.info.realname == null){
  69. $.toast("请填写收货人姓名");
  70. return false;
  71. }
  72. if(_this.info.mobile == '' || _this.info.mobile == null){
  73. $.toast("请填写收货人手机号");
  74. return false;
  75. }
  76. if(_this.info.address == '' || _this.info.address == null){
  77. $.toast("请填写收货地址");
  78. return false;
  79. }
  80. _this.submitting = true;
  81. $.showLoading("数据提交中...");
  82. $.post('/weixin/address/doSubmit', _this.info, function (res) {
  83. _this.submitting = false;
  84. $.hideLoading();
  85. if(res.code == 'success'){
  86. // $.toast('操作成功');
  87. _this.params.page = 1;
  88. _this.switchPopup(0);
  89. _this.getDataList(0);
  90. }else if(res.code == 'login'){
  91. login(res.data.url);
  92. }else{
  93. $.toast(res.message);
  94. }
  95. },"json");
  96. },
  97. // 删除
  98. doDelete: function(ele, id){
  99. if(id>0){
  100. var _this = this;
  101. if(confirm('确定删除该地址?')){
  102. $.post('/weixin/address/doDelete', {id:id}, function (res) {
  103. if(res.code == 'success'){
  104. $.toast('删除成功');
  105. $(ele.target).parents('.weui-panel').detach();
  106. // _this.params.page = 1;
  107. // _this.getDataList(0);
  108. }else if(res.code == 'login'){
  109. login(res.data.url);
  110. }else{
  111. $.toast(res.message);
  112. }
  113. },"json");
  114. }
  115. }
  116. },
  117. // 设置默认
  118. setDefault: function(id){
  119. if(id>0){
  120. var _this = this;
  121. $.post('/weixin/address/setDefault', {id:id}, function (res) {
  122. if(res.code == 'success'){
  123. $.showLoading("设置成功");
  124. setTimeout(function () {
  125. if(_this.op){
  126. history.go(-1);
  127. }else{
  128. _this.params.page = 1;
  129. _this.getDataList(0);
  130. }
  131. }, 500)
  132. }
  133. },"json");
  134. }
  135. },
  136. // 获取列表数据
  137. getDataList: function(more){
  138. var _this = this;
  139. $.hideLoading();
  140. $.showLoading("数据加载中...");
  141. _this.loading = true;
  142. $.post('/weixin/address/getList', _this.params, function (res) {
  143. $.hideLoading();
  144. _this.loading = false;
  145. if (res.code == 'success') {
  146. if(res.data.data.length<=0){
  147. _this.loaded = true;
  148. $.toast("已加载完全部...",'text');
  149. return false;
  150. }
  151. if(more){
  152. $.each(res.data.data, function(k,item){
  153. console.log(item);
  154. _this.dataList.push(item);
  155. });
  156. }else{
  157. _this.dataList = res.data.data
  158. }
  159. }else if(res.code == 'login'){
  160. login(res.data.url);
  161. }
  162. }, "json");
  163. },
  164. }
  165. })