creation.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <view class="content">
  3. <view class="navbar">
  4. <view v-for="(item, index) in navList" :key="index" class="nav-item"
  5. :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  6. </view>
  7. <swiper :current="tabCurrentIndex" :style="{ height: height }" class="swiper-box" duration="300"
  8. @change="changeTab">
  9. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  10. <scroll-view scroll-y="true" class="list-scroll-content" :class="{ yan: tabCurrentIndex == 0 }"
  11. @scrolltolower="loadData">
  12. <!-- 空白页 -->
  13. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  14. <!-- 订单列表 -->
  15. <view v-else>
  16. <view class="order-item flex" v-for="(item, index) in tabItem.orderList" :key="index"
  17. @click="navTo('/pages/info/myarticle?id=' + item.id + '&type=' + tabCurrentIndex)">
  18. <view class="order-image">
  19. <image :src="item.image_input[0]" mode=""></image>
  20. </view>
  21. <view class="order-info">
  22. <view class="order-title clamp2">{{ item.title }}</view>
  23. <view class="order-info-main flex">
  24. <view class="order-time">{{ item.add_time }}</view>
  25. <view class="order-btnBox flex" v-if="tabCurrentIndex == 0">
  26. <view class="order-btn-item"
  27. @click.stop="navTo('/pages/info/myarticle?id=' + item.id)">
  28. <view class="order-btn-icon">
  29. <image src="../../static/icon/bj.png" mode=""></image>
  30. </view>
  31. <view class="order-btn-font">编辑</view>
  32. </view>
  33. <view class="order-btn-item" @click.stop="del(item.id)">
  34. <view class="order-btn-icon1">
  35. <image src="../../static/icon/sc.png" mode=""></image>
  36. </view>
  37. <view class="order-btn-font1">删除</view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="cgsb" v-if="item.check_status !=0">
  43. {{item.check_status == 1?'审核成功':'审核失败'}}
  44. </view>
  45. </view>
  46. </view>
  47. <uni-load-more :status="tabItem.loadingType"
  48. v-if="!(tabItem.orderList.length == 0 && tabItem.loaded)"></uni-load-more>
  49. </scroll-view>
  50. <view class="btn" @click="navTo('/pages/info/myarticle')" v-if="tabCurrentIndex == 0">发帖</view>
  51. </swiper-item>
  52. </swiper>
  53. </view>
  54. </template>
  55. <script>
  56. import empty from '@/components/empty';
  57. import {
  58. delete_article,
  59. my_article
  60. } from '@/api/activity.js';
  61. import {
  62. getTime
  63. } from '@/utils/rocessor.js'
  64. export default {
  65. components: {
  66. empty
  67. },
  68. data() {
  69. return {
  70. height: '',
  71. tabCurrentIndex: 0,
  72. navList: [{
  73. type: 0,
  74. state: -1,
  75. text: '草稿箱',
  76. loadingType: 'more',
  77. orderList: [],
  78. page: 1, //当前页数
  79. limit: 10 //每次信息条数
  80. },
  81. {
  82. type: 1,
  83. state: 1,
  84. text: '已审核',
  85. loadingType: 'more',
  86. orderList: [],
  87. page: 1, //当前页数
  88. limit: 10 //每次信息条数
  89. },
  90. {
  91. type: 1,
  92. state: 0,
  93. text: '审核中',
  94. loadingType: 'more',
  95. orderList: [],
  96. page: 1, //当前页数
  97. limit: 10 //每次信息条数
  98. }
  99. ]
  100. };
  101. },
  102. onLoad(opt) {
  103. this.tabCurrentIndex = opt.id * 1;
  104. },
  105. onShow() {
  106. this.loadData();
  107. },
  108. onReachBottom() {},
  109. onReady(res) {
  110. var _this = this;
  111. uni.getSystemInfo({
  112. success: resu => {
  113. const query = uni.createSelectorQuery();
  114. query.select('.swiper-box').boundingClientRect();
  115. query.exec(function(res) {
  116. _this.height = resu.windowHeight - res[0].top + 'px';
  117. console.log('打印页面的剩余高度', _this.height);
  118. });
  119. },
  120. fail: res => {}
  121. });
  122. },
  123. methods: {
  124. //swiper 切换
  125. changeTab(e) {
  126. this.tabCurrentIndex = e.target.current;
  127. this.loadData('tabChange');
  128. },
  129. //顶部tab点击
  130. tabClick(index) {
  131. this.tabCurrentIndex = index;
  132. },
  133. navTo(url) {
  134. uni.navigateTo({
  135. url
  136. });
  137. },
  138. // 删除草稿
  139. del(id) {
  140. const obj = this;
  141. uni.showModal({
  142. title: '提示',
  143. content: '是否删除这个草稿',
  144. success: function(res) {
  145. if (res.confirm) {
  146. delete_article({}, id).then(({
  147. data
  148. }) => {
  149. obj.$api.msg('删除成功');
  150. obj.loadData('shua');
  151. });
  152. } else if (res.cancel) {
  153. console.log('用户点击取消');
  154. }
  155. }
  156. });
  157. },
  158. async loadData(source) {
  159. let obj = this;
  160. //这里是将订单挂载到tab列表下
  161. let index = this.tabCurrentIndex;
  162. let navItem = this.navList[index];
  163. let state = navItem.state;
  164. let type = navItem.type;
  165. if (source === 'shua') {
  166. navItem.loadingType = 'more';
  167. navItem.page = 1;
  168. navItem.limit = 10;
  169. navItem.orderList = [];
  170. }
  171. if (source === 'tabChange' && navItem.loaded === true) {
  172. //tab切换只有第一次需要加载数据
  173. return;
  174. }
  175. if (navItem.loadingType === 'loading') {
  176. //防止重复加载
  177. return;
  178. }
  179. // 修改当前对象状态为加载中
  180. navItem.loadingType = 'loading';
  181. my_article({
  182. page: navItem.page,
  183. limit: navItem.limit,
  184. state: state
  185. }, type)
  186. .then(({
  187. data
  188. }) => {
  189. let arr = []
  190. if (state == -1) {
  191. arr = data.list
  192. }
  193. if (state == 0) {
  194. arr = data.list.filter(e => {
  195. return e.check_status == 0
  196. })
  197. }
  198. if (state == 1) {
  199. arr = data.list.filter(e => {
  200. return e.check_status != 0
  201. })
  202. }
  203. console.log(arr);
  204. console.log(data, '123456');
  205. arr.forEach(e => {
  206. e.add_time = getTime(e.add_time)
  207. })
  208. navItem.orderList = navItem.orderList.concat(arr);
  209. navItem.page++;
  210. if (navItem.limit == data.list.length) {
  211. navItem.loadingType = 'more';
  212. } else {
  213. navItem.loadingType = 'noMore';
  214. }
  215. obj.$set(navItem, 'loaded', true);
  216. })
  217. .catch(e => {
  218. console.log(e);
  219. });
  220. }
  221. }
  222. };
  223. </script>
  224. <style lang="scss">
  225. page,
  226. .content {
  227. min-height: 100%;
  228. height: auto;
  229. }
  230. .navbar {
  231. display: flex;
  232. height: 88rpx;
  233. padding: 0 5px;
  234. background: #fff;
  235. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  236. position: relative;
  237. z-index: 10;
  238. .nav-item {
  239. flex: 1;
  240. display: flex;
  241. justify-content: center;
  242. align-items: center;
  243. height: 100%;
  244. font-size: 15px;
  245. color: #999999;
  246. position: relative;
  247. &.current {
  248. color: #000;
  249. &:after {
  250. content: '';
  251. position: absolute;
  252. left: 50%;
  253. bottom: 0;
  254. transform: translateX(-50%);
  255. width: 44px;
  256. height: 0;
  257. border-bottom: 2px solid #c54b4a;
  258. }
  259. }
  260. }
  261. }
  262. //列表
  263. .swiper-box {
  264. margin-top: 20rpx;
  265. .order-item {
  266. padding: 22rpx 24rpx 24rpx;
  267. border-bottom: 1px solid #eeeeee;
  268. justify-content: flex-start;
  269. position: relative;
  270. .cgsb {
  271. position: absolute;
  272. bottom: 30rpx;
  273. right: 30rpx;
  274. color: red;
  275. font-size: 30rpx;
  276. font-family: PingFang SC;
  277. font-weight: 500;
  278. }
  279. image {
  280. width: 100%;
  281. height: 100%;
  282. }
  283. .order-image {
  284. flex-shrink: 0;
  285. width: 200rpx;
  286. height: 160rpx;
  287. }
  288. .order-info {
  289. margin-left: 16rpx;
  290. width: 100%;
  291. display: flex;
  292. flex-direction: column;
  293. justify-content: space-between;
  294. .order-title {
  295. font-size: 30rpx;
  296. font-family: PingFang SC;
  297. font-weight: 500;
  298. color: #333333;
  299. }
  300. .order-info-main {
  301. margin-top: 20rpx;
  302. .order-time {
  303. font-size: 24rpx;
  304. font-family: PingFang SC;
  305. font-weight: 500;
  306. color: #999999;
  307. }
  308. .order-btnBox {
  309. justify-content: flex-start;
  310. .order-btn-item {
  311. display: flex;
  312. align-items: center;
  313. margin: 0 10rpx;
  314. .order-btn-icon {
  315. width: 30rpx;
  316. height: 30rpx;
  317. }
  318. .order-btn-font {
  319. margin-left: 10rpx;
  320. font-size: 26rpx;
  321. font-family: PingFang SC;
  322. font-weight: 500;
  323. color: #000000;
  324. }
  325. .order-btn-icon1 {
  326. width: 30rpx;
  327. height: 30rpx;
  328. }
  329. .order-btn-font1 {
  330. margin-left: 10rpx;
  331. font-size: 26rpx;
  332. font-family: PingFang SC;
  333. font-weight: 500;
  334. color: #ff4c4c;
  335. }
  336. }
  337. }
  338. }
  339. }
  340. }
  341. }
  342. .list-scroll-content {
  343. background: #ffffff;
  344. height: 100%;
  345. .yan {
  346. padding-bottom: 100rpx;
  347. }
  348. }
  349. .tab-content {
  350. position: relative;
  351. }
  352. .btn {
  353. position: absolute;
  354. bottom: 20rpx;
  355. left: 0;
  356. right: 0;
  357. display: flex;
  358. justify-content: center;
  359. align-items: center;
  360. width: 560rpx;
  361. height: 76rpx;
  362. background: #000000;
  363. border-radius: 38rpx;
  364. font-size: 34rpx;
  365. font-family: PingFang SC;
  366. font-weight: 500;
  367. color: #ffffff;
  368. margin: 0 auto;
  369. }
  370. </style>