collection.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. setTimeout(function(){
  78. // 图片懒加载
  79. $("img[data-original]").lazyload();
  80. },500);
  81. _self.listLoading = false;
  82. _self.requestFlag = true;
  83. }else {
  84. CAIMEI.Alert(res.msg, '确定');
  85. }
  86. });
  87. },
  88. PromotionsFormat:function(promo){//促销活动类型数据处理
  89. if(promo!=null){
  90. if(promo.type == 1 && promo.mode == 1){
  91. return true
  92. }else{
  93. return false
  94. }
  95. }
  96. return false
  97. },
  98. shoppingCart:function (pros) {// 加入购物车
  99. var _self = this;
  100. ShoppingApi.ShoppingAddCart(
  101. {
  102. userID:_self.listQuery.userId,
  103. productID:pros.productId,
  104. productCount:pros.minBuyNumber
  105. },
  106. function (response) {
  107. if(response.code === 0){
  108. globalHead.getHeadCart(_self.listQuery.userId);
  109. $.confirm({
  110. useBootstrap: false,
  111. boxWidth: (isPC?'338px':'74.6vw'),
  112. title: false,
  113. content:'<div class="cartAlert"><h6>商品已成功加入购物车!</h6><p>当前购物车共<em>'+response.data+'</em>种商品</p></div>',
  114. closeIcon: true,
  115. animation: 'opacity',
  116. closeAnimation: 'opacity',
  117. animateFromElement: false,
  118. scrollToPreviousElement: false,
  119. buttons: {
  120. login: {
  121. text: '去结算',
  122. btnClass: 'btn-to-cart',
  123. action: function(){
  124. window.location.href = '/shopping/cart.html';
  125. }
  126. },
  127. close: {
  128. text: '继续购物',
  129. btnClass: 'btn-to-goon'
  130. }
  131. }
  132. });
  133. } else {
  134. dialog("加入购物车失败!");
  135. }
  136. })
  137. },
  138. hanldBuyCart:function (pros,type) {// 1 加入购物车 2 立即购买
  139. var _self = this;
  140. console.log('pros',pros)
  141. console.log('type',type)
  142. if(type == 1) {
  143. _self.shoppingCart(pros);
  144. }else{
  145. window.location.href = '/shopping/confirm.html?type=2&id='+pros.productId+'&count='+pros.priceGrade;
  146. }
  147. },
  148. hanldAllAddCart:function () {// 批量加入购物车
  149. var _self = this;
  150. var checkedList = [];
  151. if(!_self.isProductChecked){
  152. CAIMEI.dialog('请先选择商品',false);
  153. }
  154. _self.listData.forEach((el)=>{
  155. if(el.isChecked){
  156. checkedList.push(el.productId);
  157. }
  158. })
  159. ShoppingApi.ShoppingAddCarts({userId:_self.listQuery.userId,productIds:checkedList.join(",")},function(response){
  160. if(response.code === 0){
  161. globalHead.getHeadCart(_self.listQuery.userId);
  162. $.confirm({
  163. useBootstrap: false,
  164. boxWidth: (isPC?'338px':'74.6vw'),
  165. title: false,
  166. content:'<div class="cartAlert"><h6>商品已成功加入购物车!</h6><p>当前购物车共<em>'+response.data+'</em>种商品</p></div>',
  167. closeIcon: true,
  168. animation: 'opacity',
  169. closeAnimation: 'opacity',
  170. animateFromElement: false,
  171. scrollToPreviousElement: false,
  172. buttons: {
  173. login: {
  174. text: '去结算',
  175. btnClass: 'btn-to-cart',
  176. action: function(){
  177. window.location.href = '/shopping/cart.html';
  178. }
  179. },
  180. close: {
  181. text: '继续购物',
  182. btnClass: 'btn-to-goon'
  183. }
  184. }
  185. });
  186. } else {
  187. dialog("加入购物车失败!");
  188. }
  189. })
  190. },
  191. hanldCancel:function (pros) {// 取消收藏
  192. var _self = this;
  193. CAIMEI.Modal('确定要取消收藏吗?','取消','确定',function () {
  194. ProductApi.getDeleteUserLike({userId:_self.listQuery.userId,productIds:pros.productId+','},function(response){
  195. if(response.code == 0){
  196. CAIMEI.dialog('取消收藏成功',true,function () {
  197. _self.getCollectionProductList();
  198. });
  199. }else{
  200. CAIMEI.Alert(response.msg, '确定', false);
  201. }
  202. })
  203. })
  204. },
  205. hanldAllCancel:function () {// 批量取消收藏
  206. var _self = this;
  207. var checkedList =[];
  208. _self.productIds = '';
  209. if(!_self.isProductChecked){
  210. CAIMEI.dialog('请先选择商品',false);
  211. return;
  212. }
  213. _self.listData.forEach((el)=>{
  214. if(el.isChecked){
  215. checkedList.push(el.productId)
  216. }
  217. })
  218. _self.productIds = checkedList.join(",")
  219. console.log('_self.productIds2',_self.productIds);
  220. CAIMEI.Modal('确定要取消收藏吗?','取消','确定',function () {
  221. ProductApi.getDeleteUserLike({userId:_self.listQuery.userId,productIds:_self.productIds},function(response){
  222. if(response.code == 0){
  223. CAIMEI.dialog('取消收藏成功',true,function () {
  224. _self.getCollectionProductList();
  225. });
  226. }else{
  227. CAIMEI.Alert(response.msg, '确定', false);
  228. }
  229. })
  230. })
  231. },
  232. isCheckedAll(){//全选
  233. var _self = this;
  234. _self.isAllChecked = !_self.isAllChecked;
  235. _self.listData.forEach((el)=>{
  236. el.isChecked = _self.isAllChecked;
  237. })
  238. if(_self.isAllChecked){
  239. _self.isProductChecked = true;
  240. _self.checkedNum = _self.listData.length;
  241. }else{
  242. _self.isProductChecked = false;
  243. _self.checkedNum = 0;
  244. }
  245. },
  246. checkedSoperv:function (pros) {// 勾选
  247. console.log(pros)
  248. var _self = this;
  249. var goodsCheckedLength = 0;
  250. pros.isChecked = !pros.isChecked
  251. _self.listData.forEach(el => {
  252. if(el.isChecked) {
  253. goodsCheckedLength++;
  254. }
  255. })
  256. _self.checkedNum = goodsCheckedLength;
  257. _self.isAllChecked = goodsCheckedLength === _self.listData.length;
  258. if(goodsCheckedLength>0){
  259. _self.isProductChecked = true
  260. }else{
  261. _self.isProductChecked = false
  262. }
  263. },
  264. showHandle:function () {// 显示批量操作
  265. this.isHandle = true;
  266. },
  267. hideHandle:function () {
  268. this.isHandle = false;
  269. }
  270. },
  271. mounted: function () {
  272. var _self = this;
  273. if(globalUserData){
  274. _self.userId = globalUserData.userId;
  275. _self.listQuery.userId = this.userId;
  276. _self.getCollectionProductList();
  277. }
  278. }
  279. });