picTextList.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="app-content">
  3. <view class="list-wrap">
  4. <block v-if="!$util.isEmpty(list.data)">
  5. <block v-for="(item, index) in list.data" :key="index">
  6. <view class="list">
  7. <view class="list-det" @click="edit(item.id)">
  8. <view class="app-size-26 app-color-0" style="margin-right: 32upx">{{ item.id }}</view>
  9. </view>
  10. <view class="list-det" @click="edit(item.id)">
  11. <view class="app-size-30 app-color-0" style="font-weight: bold; max-width: 420rpx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">{{ item.title }}</view>
  12. </view>
  13. <view v-if="mode === 'selectPicText'">
  14. <view class="icon-wrapper select" v-if="selectedId == item.id">
  15. <zui-svg-icon icon="general-selected" :width="40" :height="40" />
  16. </view>
  17. <button style="position: absolute; top: 40upx; right: 40upx" class="admin-button-com middle" @click.stop="selectPicTextFn(item.id, cId)" v-else>
  18. 选择
  19. </button>
  20. </view>
  21. <view v-else>
  22. <view class="icon-wrapper delete" @click.stop.prevent="delPicText(item.id)">
  23. <zui-svg-icon icon="general-delete" :width="28" :height="28" />
  24. </view>
  25. <view class="icon-wrapper edit" @click.stop="edit(item.id)">
  26. <zui-svg-icon icon="general-edit-pencil" :width="27" :height="27" />
  27. </view>
  28. </view>
  29. </view>
  30. </block>
  31. </block>
  32. <block v-else>
  33. <app-wrapper-empty title="暂无数据" :is-empty="$util.isEmpty(list.data)" />
  34. </block>
  35. </view>
  36. <view class="app-footer">
  37. <!-- <button class="admin-button-com" @click="svgDemoFn">SVG示例</button>
  38. <button class="admin-button-com" @click="demoPicTextFn">图文示例</button> -->
  39. <button class="admin-button-com big blue" @click="addPicTextFn">新增图文</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import AppWrapperEmpty from '@/components/app-wrapper-empty';
  45. import { list } from '@/mixins';
  46. import { picTextDel, picTextList, UpdateCategoryId } from '@/api/pic-text';
  47. export default {
  48. name: 'picTextList',
  49. components: {
  50. AppWrapperEmpty
  51. },
  52. mixins: [list],
  53. data() {
  54. return {
  55. cId: null, // 分类id, 用于识别是否选择图文模式
  56. mode: '',
  57. selectedId: 0
  58. };
  59. },
  60. onPullDownRefresh() {
  61. this.resetList();
  62. this._list().then((res) => {
  63. uni.stopPullDownRefresh();
  64. });
  65. },
  66. onReachBottom() {
  67. if (!this.list.finished) {
  68. this._list().then((res) => {
  69. uni.stopPullDownRefresh();
  70. });
  71. } else {
  72. uni.stopPullDownRefresh();
  73. }
  74. },
  75. onLoad(option) {
  76. console.log('option: ', option);
  77. if (option.cId) {
  78. this.cId = option.cId;
  79. this.selectedId = option.picTextId;
  80. this.mode = 'selectPicText';
  81. uni.setNavigationBarTitle({
  82. title: '选择图文'
  83. })
  84. }
  85. // 监听来自创建或编辑页面的刷新事件
  86. uni.$on('refreshListPage', this._list);
  87. },
  88. methods: {
  89. init() {
  90. this._list();
  91. },
  92. edit(id) {
  93. uni.navigateTo({
  94. url: `/admin/picText/picTextAdd?id=${id}`
  95. });
  96. },
  97. svgDemoFn() {
  98. uni.navigateTo({
  99. url: '/admin/picText/svg-demo'
  100. });
  101. },
  102. demoPicTextFn() {
  103. uni.navigateTo({
  104. url: '/admin/picText/viewerDemo'
  105. });
  106. },
  107. addPicTextFn() {
  108. uni.navigateTo({
  109. url: '/admin/picText/picTextAdd'
  110. });
  111. },
  112. _list() {
  113. return picTextList().then((res) => {
  114. let data = { code: res.code, msg: res.msg, data: { list: res.data.list } };
  115. this.completes(res);
  116. });
  117. },
  118. delPicText(id) {
  119. let that = this;
  120. uni.showModal({
  121. title: '提示',
  122. content: '确认删除?',
  123. success: function (res) {
  124. if (res.confirm) {
  125. picTextDel({ id: id }).then((res) => {
  126. if (res.code == 1) {
  127. that.resetList();
  128. that._list();
  129. that.$msg('已删除');
  130. }
  131. });
  132. }
  133. }
  134. });
  135. },
  136. selectPicTextFn(id, cId) {
  137. UpdateCategoryId({ id: id, categoryId: cId }).then((res) => {
  138. if (res.code == 1) {
  139. this.$msg('图文变更成功');
  140. this.selectedId = id;
  141. // 把变更的信息发给父页面
  142. uni.$emit('updateCategoryIdEvent', { picTextId: id, categoryId: cId });
  143. uni.navigateBack({ delta: 1 });
  144. this.$msg('选择成功');
  145. }
  146. });
  147. }
  148. }
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. .app-content {
  153. min-height: calc(100vh - 100upx);
  154. padding-bottom: 100upx;
  155. }
  156. .list-wrap {
  157. position: relative;
  158. background-color: #fff;
  159. .list {
  160. height: 160upx;
  161. @include disFlex(center, flex-start);
  162. padding: 30upx 0;
  163. margin: 0 30upx;
  164. color: $fontColor3;
  165. border-bottom: 1px solid $borderColor;
  166. position: relative;
  167. .list-img {
  168. width: 130upx;
  169. height: 130upx;
  170. image {
  171. width: 130upx;
  172. height: 130upx;
  173. border-radius: 20upx;
  174. }
  175. }
  176. .list-det {
  177. margin-left: 20upx;
  178. & > div {
  179. margin-top: 14upx;
  180. &:first-child {
  181. margin-top: 0;
  182. }
  183. }
  184. }
  185. .icon-wrapper {
  186. position: absolute;
  187. top: 50upx;
  188. width: 60upx;
  189. height: 60upx;
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. z-index: 2;
  194. &.delete {
  195. right: 155upx;
  196. }
  197. &.edit {
  198. right: 30upx;
  199. }
  200. &.select {
  201. right: 60upx;
  202. }
  203. }
  204. }
  205. }
  206. .app-footer {
  207. justify-content: flex-end;
  208. .admin-button-com {
  209. width: 200upx;
  210. margin-right: 30upx;
  211. }
  212. }
  213. </style>