myLike.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view class="box">
  3. <u-navbar :autoBack="true" title="我的" bgColor="rgba(255,255,255,0)" :placeholder="true" titleStyle="font-weight:bold;color:#121212"></u-navbar>
  4. <view class="box_tab">
  5. <u-tabs
  6. @click="TabBtn"
  7. :duration="200"
  8. :list="listTab"
  9. :lineWidth="25"
  10. :lineHeight="12"
  11. :current="id1"
  12. lineColor="#4E7198"
  13. :lineColor="`url(${tabImg}) 100% 100%`"
  14. :activeStyle="{
  15. color: '#4E7198',
  16. fontSize: '34rpx'
  17. }"
  18. ></u-tabs>
  19. </view>
  20. <!-- 投稿 -->
  21. <view class="pubu">
  22. <!-- 瀑布流 -->
  23. <u-checkbox-group v-model="deleteList" placement="column" @change="checkboxChange">
  24. <uv-waterfall ref="waterfall" v-model="list" :add-time="10" left-gap="10" right-gap="10" :column-gap="columnGap" @changeList="changeList">
  25. <!-- 第一列数据 -->
  26. <template v-slot:list1>
  27. <!-- 为了磨平部分平台的BUG,必须套一层view -->
  28. <view>
  29. <view @click="ceshi(index)" v-for="(item, index) in list1" :key="item.id" class="waterfall-item">
  30. <view class="waterfall-item__image" :style="[imageStyle(item)]">
  31. <image :src="item.image" mode="widthFix" style="border-radius: 25rpx 60rpx 0rpx 30rpx" :style="{ width: item.width + 'px' }"></image>
  32. </view>
  33. <view class="waterfall-item__ft">
  34. <view class="waterfall-item__ft__title">
  35. <text class="value">{{ item.title }}</text>
  36. <view v-if="checkboxShow" class="" style="position: relative">
  37. <view class="box_checkbox">
  38. <u-checkbox :value="item.id" :name="item.id" :customStyle="{ marginBottom: '8px' }" shape="circle"></u-checkbox>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- </u-checkbox-group> -->
  45. </view>
  46. </template>
  47. <!-- 第二列数据 -->
  48. <template v-slot:list2>
  49. <!-- 为了磨平部分平台的BUG,必须套一层view -->
  50. <view>
  51. <!-- <u-checkbox-group v-model="deleteList" placement="column" @change="checkboxChange2"> -->
  52. <view @click="ceshi(index)" v-for="(item, index) in list2" :key="item.id" class="waterfall-item">
  53. <view class="waterfall-item__image" :style="[imageStyle(item)]">
  54. <image :src="item.image" mode="widthFix" style="border-radius: 25rpx 60rpx 0rpx 30rpx" :style="{ width: item.width + 'px' }"></image>
  55. </view>
  56. <view class="waterfall-item__ft">
  57. <view class="waterfall-item__ft__title">
  58. <text class="value">{{ item.title }}</text>
  59. <view v-if="checkboxShow" class="" style="position: relative">
  60. <view class="box_checkbox">
  61. <u-checkbox :value="item.id" :name="item.id" :customStyle="{ marginBottom: '8px' }" shape="circle"></u-checkbox>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. </uv-waterfall>
  70. </u-checkbox-group>
  71. <!-- 底部删除管理 -->
  72. <view class="guanLi">
  73. <view style="display: flex; align-items: center" v-if="checkboxShow">
  74. <view style="margin-right: 260rpx">
  75. <u-checkbox-group @change="deleteAll" v-model="checkboxValue2" placement="column">
  76. <u-checkbox :customStyle="{ marginBottom: '8px' }" shape="circle" label="全部"></u-checkbox>
  77. </u-checkbox-group>
  78. </view>
  79. <view class="sc" @click="deleteShow = true">
  80. <uni-icons type="trash" color=" #ffffff" size="20"></uni-icons>
  81. <view class="">删除</view>
  82. </view>
  83. </view>
  84. <view class="guanLi2" @click="checkboxShow = !checkboxShow">
  85. <view class="left_jl">
  86. <uni-icons type="gear" size="20"></uni-icons>
  87. </view>
  88. <view class="">
  89. <view v-if="checkboxShow" class="left_jl">退出管理</view>
  90. <view v-else class="left_jl">管理</view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. <!-- 删除弹层 -->
  96. <u-popup :show="deleteShow" @close="close" mode="center" customStyle="width:600rpx;padding: 30rpx;" round="20rpx">
  97. <view style="text-align: center">确认是否删除所选内容?</view>
  98. <view class="bt_box">
  99. <view class="bt1" @click="deleteShow = false">取消</view>
  100. <view @click="deleteBtn" class="bt2">删除</view>
  101. </view>
  102. </u-popup>
  103. </view>
  104. </template>
  105. <script>
  106. import { guid } from '@/uni_modules/uv-ui-tools/libs/function/index.js';
  107. let that;
  108. export default {
  109. data() {
  110. return {
  111. id1: 0,
  112. main_body_id: '',
  113. deleteShow: false /* 弹层 */,
  114. checkboxShow: false /*多选框 */,
  115. tabImg: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/tab.png',
  116. listTab: [
  117. {
  118. name: '我的投稿',
  119. tabid: 1
  120. },
  121. {
  122. name: '我的收藏',
  123. tabid: 2
  124. },
  125. {
  126. name: '我的喜欢',
  127. tabid: 3
  128. }
  129. ],
  130. list: [],
  131. list1: [], // 瀑布流第一列数据
  132. list2: [], // 瀑布流第二列数据
  133. columnGap: 10,
  134. checkboxValue2: [],
  135. deleteList: [] /*, 要删除的 */,
  136. n: [],
  137. ad: []
  138. };
  139. },
  140. onLoad(o) {
  141. that = this;
  142. this.id1 = o.id;
  143. this.main_body_id = this.$db.get('main_body_id');
  144. this.getUserLike(this.id1);
  145. },
  146. computed: {
  147. imageStyle(item) {
  148. return (item) => {
  149. const v = uni.upx2px(750) - this.leftGap - this.rightGap - this.columnGap;
  150. const w = v / 2;
  151. const rate = w / item.w;
  152. const h = rate * item.h;
  153. return {
  154. width: w + 'px',
  155. height: h + 'px'
  156. };
  157. };
  158. }
  159. },
  160. methods: {
  161. deleteAll(a) {
  162. if (a.length > 0) {
  163. let aa = [];
  164. this.list.forEach((item, index) => {
  165. aa.push(item.id);
  166. });
  167. this.deleteList = aa;
  168. } else {
  169. this.deleteList = [];
  170. }
  171. },
  172. // 导航
  173. TabBtn(index) {
  174. that.list = [];
  175. that.$refs.waterfall.clear();
  176. that.list1 = [];
  177. that.list2 = [];
  178. this.id1 = index.index;
  179. this.getUserLike(index.index);
  180. },
  181. getUserLike(i) {
  182. if (i == 2) {
  183. // 我得喜欢
  184. this.$api.getUserLike(
  185. {
  186. main_body_id: this.main_body_id
  187. },
  188. function (res) {
  189. // // 假设res.data是一个包含对象的数组
  190. res.data.forEach((item) => {
  191. item.checked = false;
  192. });
  193. that.list = res.data;
  194. // console.log(that.list, '555555555555');
  195. }
  196. );
  197. }
  198. if (i == 1) {
  199. this.$api.getUserCollect(
  200. {
  201. main_body_id: this.main_body_id
  202. },
  203. function (res) {
  204. console.log('收藏', res);
  205. that.list = res.data;
  206. }
  207. );
  208. } else {
  209. that.list = [];
  210. }
  211. },
  212. changeList(e) {
  213. // console.log(e, '瀑布流');
  214. this[e.name].push(e.value);
  215. },
  216. ceshi(i) {
  217. console.log(i, 111111111111);
  218. },
  219. // 选框
  220. checkboxChange(n) {
  221. console.log('change', n);
  222. this.deleteList = [...this.deleteList, ...n];
  223. },
  224. checkboxChange2(n) {
  225. console.log('change', n);
  226. this.deleteList = [...this.deleteList, ...n];
  227. },
  228. // 删除
  229. deleteBtn() {
  230. //取消点赞
  231. if (this.id1 == 2) {
  232. this.$api.unLike(
  233. {
  234. main_body_id: this.main_body_id,
  235. content_ids: this.deleteList
  236. },
  237. function (res) {
  238. if (res.code == 1) {
  239. that.$common.successToShow('删除成功');
  240. that.deleteShow = false;
  241. that.list = [];
  242. that.$refs.waterfall.clear();
  243. that.list1 = [];
  244. that.list2 = [];
  245. that.getUserLike(2);
  246. } else {
  247. that.$common.errorToShow('请选择要删除的内容');
  248. }
  249. }
  250. );
  251. }
  252. // 取消收藏
  253. if (this.id1 == 1) {
  254. this.$api.uncollect(
  255. {
  256. main_body_id: this.main_body_id,
  257. content_ids: this.deleteList
  258. },
  259. function (res) {
  260. if (res.code == 1) {
  261. that.$common.successToShow('删除成功');
  262. that.deleteShow = false;
  263. that.list = [];
  264. that.$refs.waterfall.clear();
  265. that.list1 = [];
  266. that.list2 = [];
  267. that.getUserLike(1);
  268. } else {
  269. that.$common.errorToShow('删除失败请稍后在试');
  270. }
  271. }
  272. );
  273. }
  274. },
  275. close() {
  276. this.deleteShow = false;
  277. }
  278. }
  279. };
  280. </script>
  281. <style>
  282. /deep/.u-tabs__wrapper__nav__item.data-v-48634e29 {
  283. padding: 0 40rpx !important;
  284. }
  285. /deep/.u-tabs__wrapper__nav__line.data-v-48634e29 {
  286. bottom: 16rpx !important;
  287. }
  288. /deep/.u-tabs__wrapper__nav__item.data-v-48634e29 {
  289. align-items: end !important;
  290. }
  291. .box_checkbox {
  292. position: absolute;
  293. top: -50rpx;
  294. left: 20rpx;
  295. z-index: 99;
  296. }
  297. .box {
  298. height: auto;
  299. width: 100%;
  300. padding-bottom: 80rpx;
  301. background-color: #f8f8f8;
  302. }
  303. .box_tab {
  304. margin: 45rpx 32rpx 0 32rpx;
  305. }
  306. .waterfall-item {
  307. margin-bottom: 20rpx;
  308. }
  309. .waterfall-item__ft {
  310. position: relative;
  311. }
  312. .waterfall-item__ft__title {
  313. width: 100%;
  314. height: 65rpx;
  315. position: absolute;
  316. bottom: 0;
  317. left: 0;
  318. line-height: 65rpx;
  319. background-color: #ca5642;
  320. font-size: 30rpx;
  321. text-align: center;
  322. color: #ffffff;
  323. border-radius: 0 0 10rpx 10rpx;
  324. }
  325. .pubu {
  326. margin: 10rpx 32rpx 0 32rpx;
  327. }
  328. .title_pubu {
  329. width: 100%;
  330. height: 65rpx;
  331. line-height: 65rpx;
  332. background-color: #ca5642;
  333. font-size: 30rpx;
  334. text-align: center;
  335. color: #ffffff;
  336. position: absolute;
  337. bottom: 0;
  338. left: 0;
  339. }
  340. .box_checkbox {
  341. position: absolute;
  342. top: -50rpx;
  343. left: 20rpx;
  344. z-index: 99;
  345. }
  346. .guanLi {
  347. display: flex;
  348. justify-content: flex-end;
  349. position: fixed;
  350. bottom: 0;
  351. left: 0;
  352. z-index: 99;
  353. width: 96%;
  354. background: #ffffff;
  355. }
  356. .guanLi2 {
  357. display: flex;
  358. align-items: center;
  359. height: 80rpx;
  360. /* width: 160rpx; */
  361. background-color: #efefef;
  362. }
  363. .sc {
  364. display: flex;
  365. align-items: center;
  366. height: 80rpx;
  367. width: 160rpx;
  368. padding-left: 28rpx;
  369. color: #ffffff;
  370. background-color: #ca5642;
  371. }
  372. .bt_box {
  373. display: flex;
  374. margin-top: 50rpx;
  375. justify-content: space-around;
  376. }
  377. .bt1 {
  378. width: 244rpx;
  379. height: 78rpx;
  380. border: 1px solid #312520;
  381. border-radius: 39rpx;
  382. text-align: center;
  383. line-height: 78rpx;
  384. color: black;
  385. }
  386. .bt2 {
  387. width: 244rpx;
  388. height: 78rpx;
  389. background: #ca5642;
  390. border-radius: 39rpx;
  391. text-align: center;
  392. line-height: 78rpx;
  393. color: #ffffff;
  394. }
  395. </style>