collection.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. ;
  2. var orderPage = new Vue({
  3. el: "#productList",
  4. data: {
  5. isRequset:true,
  6. noMore: false,
  7. listLoading: true,
  8. isHandle:false,
  9. isAllChecked:false,
  10. isProductChecked:false,
  11. checkedNum:0,
  12. productIds:'',
  13. listQuery:{
  14. userId:0,
  15. pageNum:1,
  16. pageSize:12,
  17. },
  18. listData:[],
  19. checkedList:[],
  20. listRecord: 0,
  21. pageInput: '1'
  22. },
  23. filters: {
  24. NumFormat:function(value) {
  25. return Number(value).toFixed(2);
  26. }
  27. },
  28. computed: {
  29. pageTotal: function () {
  30. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  31. return total > 0 ? total : 1;
  32. },
  33. showPageBtn: function () {
  34. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  35. total = total > 0 ? total : 1;
  36. var index = this.listQuery.pageNum, arr = [];
  37. if (total <= 6) {
  38. for (var i = 1; i <= total; i++) {
  39. arr.push(i);
  40. }
  41. return arr;
  42. }
  43. if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
  44. if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
  45. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
  46. }
  47. },
  48. methods: {
  49. toPagination: function (pageNum) {//点击切换分页
  50. if (pageNum <= this.pageTotal) {
  51. this.listQuery.pageNum = pageNum;
  52. this.getCollectionProductList();
  53. }
  54. },
  55. checkNum: function () {//输入跳转分页
  56. if (this.pageInput > this.pageTotal) {
  57. this.pageInput = this.pageTotal;
  58. } else if (this.pageInput < 1) {
  59. this.pageInput = 1;
  60. }
  61. },
  62. getCollectionProductList: function () {
  63. var _self = this;
  64. ProductApi.getProductUserLikeList(_self.listQuery,function (response) {
  65. if (response.code === 0 ) {
  66. var data = response.data;
  67. _self.listRecord = data.totalRecord;
  68. var list = data.results.map((el,index)=>{
  69. el.isChecked = false;
  70. return el
  71. });
  72. if(isPC){
  73. _self.listData = list;
  74. }else{
  75. _self.listData = _self.listData.concat(list);
  76. }
  77. console.log('listData',_self.listData)
  78. setTimeout(function(){
  79. // 图片懒加载
  80. $("img[data-original]").lazyload();
  81. },500);
  82. _self.listLoading = false;
  83. _self.requestFlag = true;
  84. }else {
  85. CAIMEI.Alert(res.msg, '确定');
  86. }
  87. });
  88. },
  89. PromotionsFormat:function(promo){//促销活动类型数据处理
  90. if(promo!=null){
  91. if(promo.type == 1 && promo.mode == 1){
  92. return true
  93. }else{
  94. return false
  95. }
  96. }
  97. return false
  98. },
  99. shoppingCart:function (pros) {
  100. var _self = this;
  101. ShoppingApi.ShoppingAddCart(
  102. {
  103. userID:_self.listQuery.userId,
  104. productID:pros.productId,
  105. productCount:1
  106. },
  107. function (response) {
  108. if(response.code === 0){
  109. globalHead.getHeadCart(_self.listQuery.userId);
  110. $.confirm({
  111. useBootstrap: false,
  112. boxWidth: (isPC?'338px':'74.6vw'),
  113. title: false,
  114. content:'<div class="cartAlert"><h6>商品已成功加入购物车!</h6><p>当前购物车共<em>'+response.data+'</em>种商品</p></div>',
  115. closeIcon: true,
  116. animation: 'opacity',
  117. closeAnimation: 'opacity',
  118. animateFromElement: false,
  119. scrollToPreviousElement: false,
  120. buttons: {
  121. login: {
  122. text: '去结算',
  123. btnClass: 'btn-to-cart',
  124. action: function(){
  125. window.location.href = '/shopping/cart.html';
  126. }
  127. },
  128. close: {
  129. text: '继续购物',
  130. btnClass: 'btn-to-goon'
  131. }
  132. }
  133. });
  134. } else {
  135. dialog("加入购物车失败!");
  136. }
  137. })
  138. },
  139. hanldBuyCart:function (pros,type) {// 1 加入购物车 2 立即购买
  140. var _self = this;
  141. console.log('pros',pros)
  142. console.log('type',type)
  143. if(type == 1) {
  144. _self.shoppingCart(pros);
  145. }else{
  146. window.location.href = '/shopping/confirm.html?type=2&id='+pros.productId+'&count='+pros.priceGrade;
  147. }
  148. },
  149. hanldAllAddCart:function () {// 批量加入购物车
  150. var _self = this;
  151. if(!_self.isProductChecked){
  152. CAIMEI.dialog('请先选择商品',false);
  153. }
  154. _self.productIds = _self.checkedList.join(",")
  155. },
  156. hanldCancel:function (pros) {// 取消收藏
  157. var _self = this;
  158. CAIMEI.Modal('确定要取消收藏吗?','取消','确定',function () {
  159. ProductApi.getDeleteUserLike({userId:_self.listQuery.userId,productIds:pros.productId+','},function(response){
  160. if(response.code == 0){
  161. CAIMEI.dialog('取消收藏成功',true,function () {
  162. _self.getCollectionProductList();
  163. });
  164. }else{
  165. CAIMEI.Alert(response.msg, '确定', false);
  166. }
  167. })
  168. })
  169. },
  170. hanldAllCancel:function () {// 批量取消收藏
  171. var _self = this;
  172. var checkedList =[];
  173. _self.productIds = '';
  174. if(!_self.isProductChecked){
  175. CAIMEI.dialog('请先选择商品',false);
  176. return;
  177. }
  178. _self.listData.forEach((el)=>{
  179. if(el.isChecked){
  180. checkedList.push(el.productId)
  181. }
  182. })
  183. _self.productIds = checkedList.join(",")
  184. console.log('_self.productIds2',_self.productIds);
  185. CAIMEI.Modal('确定要取消收藏吗?','取消','确定',function () {
  186. ProductApi.getDeleteUserLike({userId:_self.listQuery.userId,productIds:_self.productIds},function(response){
  187. if(response.code == 0){
  188. CAIMEI.dialog('取消收藏成功',true,function () {
  189. _self.getCollectionProductList();
  190. });
  191. }else{
  192. CAIMEI.Alert(response.msg, '确定', false);
  193. }
  194. })
  195. })
  196. },
  197. isCheckedAll(){//全选
  198. var _self = this;
  199. _self.isAllChecked = !_self.isAllChecked;
  200. _self.listData.forEach((el)=>{
  201. el.isChecked = _self.isAllChecked;
  202. })
  203. if(_self.isAllChecked){
  204. _self.isProductChecked = true;
  205. _self.checkedNum = _self.listData.length;
  206. }else{
  207. _self.isProductChecked = false;
  208. _self.checkedNum = 0;
  209. }
  210. },
  211. checkedSoperv:function (pros) {// 勾选
  212. console.log(pros)
  213. var _self = this;
  214. var goodsCheckedLength = 0;
  215. pros.isChecked = !pros.isChecked
  216. _self.listData.forEach(el => {
  217. if(el.isChecked) {
  218. goodsCheckedLength++;
  219. }
  220. })
  221. _self.checkedNum = goodsCheckedLength;
  222. _self.isAllChecked = goodsCheckedLength === _self.listData.length;
  223. if(goodsCheckedLength>0){
  224. _self.isProductChecked = true
  225. }else{
  226. _self.isProductChecked = false
  227. }
  228. },
  229. showHandle:function () {// 显示批量操作
  230. this.isHandle = true;
  231. },
  232. hideHandle:function () {
  233. this.isHandle = false;
  234. }
  235. },
  236. mounted: function () {
  237. var _self = this;
  238. if(globalUserData){
  239. _self.userId = globalUserData.userId;
  240. _self.listQuery.userId = this.userId;
  241. _self.getCollectionProductList();
  242. }
  243. }
  244. });