collection.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="collection">
  3. <view class="topEditOpar" v-if="list.length>0">
  4. <view class="check" v-if="isEdit">
  5. <u-checkbox shape="circle" active-color="#ed3f14" icon-size="16" v-model="checkAllStauts" @change="checkAllGoods"></u-checkbox>
  6. <text>全选</text>
  7. </view>
  8. <view class="text opartxt" v-if="isEdit" @click="delCollection">
  9. 移出收藏夹
  10. </view>
  11. <view class="text" v-else @click="isEdit = true">
  12. 管理
  13. </view>
  14. </view>
  15. <view class="list">
  16. <view class="list_item" v-for="(item, index) in list" :key="index">
  17. <view class="selcheck" v-if="isEdit">
  18. <u-checkbox shape="circle" active-color="#ed3f14" icon-size="16" :disabled="goods.status==2"
  19. v-model="item.checked"></u-checkbox>
  20. </view>
  21. <view class="infobox">
  22. <collection :data="item"></collection>
  23. </view>
  24. </view>
  25. </view>
  26. <NoData v-if="finish&&list.length<1"></NoData>
  27. <LoadMore v-else :loadtype="{page, loading, finish}"></LoadMore>
  28. </view>
  29. </template>
  30. <script>
  31. var _self;
  32. import collection from '@/pages/mall/components/collection.vue';
  33. export default {
  34. components: {
  35. collection
  36. },
  37. data() {
  38. return {
  39. isEdit:false,
  40. checkAllStauts: false,
  41. page:1,
  42. loading:false,
  43. finish:false,
  44. list: [],
  45. pullDown:false,
  46. };
  47. },
  48. computed: {
  49. checkAll() {
  50. if (this.list.length < 1) {
  51. this.checkAllStauts = false;
  52. return;
  53. }
  54. this.list.map(item => (item.checked ? (this.totalPrice += Number(item.amount) * item.nums) : 0));
  55. if (this.list.filter(item => item.checked).length == this.list.length) {
  56. this.checkAllStauts = true;
  57. } else {
  58. this.checkAllStauts = false;
  59. }
  60. },
  61. },
  62. onLoad(ops) {
  63. // if (ops.isSelect) this.isSelect = ops.isSelect;
  64. _self = this;
  65. this.getCollectionList();
  66. },
  67. onReachBottom(){
  68. this.getCollectionList();
  69. },
  70. onPullDownRefresh(){
  71. this.pullDown = true;
  72. this.reData();
  73. },
  74. methods: {
  75. // 刷新数据
  76. reData(){
  77. this.page=1;
  78. this.finish=false;
  79. this.list=[];
  80. this.getCollectionList();
  81. },
  82. getCollectionList(){
  83. if(this.finish)return false;
  84. if(this.loading)return false;
  85. this.$u.api.collectionListAjax(this.page).then(({code,data})=>{
  86. console.log(code,data)
  87. if(this.pullDown){
  88. uni.stopPullDownRefresh();
  89. this.pullDown = false;
  90. }
  91. this.loading = false;
  92. let returnData = data.data;
  93. if(code==1){
  94. if(data.last_page<=data.current_page){
  95. this.finish = true;
  96. }
  97. returnData.forEach(e => {
  98. e.checked = false;
  99. })
  100. if(data.current_page==1){
  101. this.list = returnData;
  102. }else{
  103. this.list=this.list.concat(returnData);
  104. }
  105. }else{
  106. this.finish = true;
  107. }
  108. this.page++;
  109. }).catch(()=>{
  110. this.loading = false;
  111. this.finish = true;
  112. if(this.pullDown){
  113. uni.stopPullDownRefresh();
  114. this.pullDown = false;
  115. }
  116. })
  117. },
  118. checkAllGoods() {
  119. if (this.checkAllStauts) {
  120. this.list.forEach(item => (item.checked = false));
  121. } else {
  122. this.list.forEach(item => (item.checked = true));
  123. }
  124. // this.$forceUpdate();
  125. },
  126. // 移出收藏夹
  127. delCollection(){
  128. let selItems = this.list.filter(item => item.checked);
  129. if(selItems.length >0){
  130. uni.showModal({
  131. title: '提示',
  132. content: '确认要移出收藏夹?',
  133. success: function(res) {
  134. if (res.confirm) {
  135. _self.comfirmF(selItems)
  136. }
  137. }
  138. });
  139. }else{
  140. this.isEdit = false;
  141. }
  142. },
  143. comfirmF(selItems){
  144. let ids = selItems.map(e=>e.id);
  145. console.log(ids);
  146. this.$u.api.delCollectionAjax(ids.toString()).then(({code,msg})=>{
  147. this.$u.toast(msg);
  148. if(code==1){
  149. this.reData();
  150. }
  151. })
  152. },
  153. }
  154. };
  155. </script>
  156. <style lang="scss" scoped>
  157. .collection {
  158. padding: 20rpx;
  159. min-height: 100vh;
  160. box-sizing: border-box;
  161. }
  162. .list {
  163. background-color: #fff;
  164. border-radius: 20rpx;
  165. }
  166. .list_item{
  167. display: flex;
  168. align-items: center;
  169. .infobox{
  170. flex: 1;
  171. }
  172. }
  173. .selcheck{
  174. width: 80rpx;
  175. padding-left: 20rpx;
  176. }
  177. .topEditOpar{
  178. display: flex;
  179. padding: 10rpx 20rpx;
  180. display: flex;
  181. align-items: center;
  182. justify-content: space-between;
  183. text-align: center;
  184. .text{
  185. flex: 1;
  186. text-align: right;
  187. font-weight: bold;
  188. font-size: 32rpx;
  189. }
  190. .opartxt{
  191. color: $app-theme-deep-color;
  192. }
  193. }
  194. </style>