notice.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view>
  3. <!-- 添加公告 -->
  4. <u-popup v-model="popupShow" mode="center" width="650" :closeable="true" border-radius="10">
  5. <view style="padding: 60rpx 40rpx 10rpx;">
  6. <u-form label-width="150" :model="form">
  7. <u-form-item label="标题" :required="true"><u-input v-model="form.title" /></u-form-item>
  8. <u-form-item label="内容" >
  9. <u-input v-model="form.notice" />
  10. </u-form-item>
  11. <u-form-item label="下发小区" :required="true">
  12. <u-input :placeholder="residentialPlaceholder" type="select" disabled @click="showResidential" v-model="residentialNames" />
  13. </u-form-item>
  14. </u-form>
  15. <view @click="submit" class="flex cu-btn bg-blue" style="margin: 60rpx 0 10rpx;padding: 40rpx;">
  16. 提交
  17. </view>
  18. </view>
  19. </u-popup>
  20. <u-toast ref="uToast"/>
  21. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  22. <view @click="goDetail(item)" class="card" v-for="(item,index) in dataList" :key="index">
  23. <view class="title">
  24. <view>
  25. <text class="text-bold">标题:</text>
  26. <text class="">{{item.title}}</text>
  27. </view>
  28. <view class="time">
  29. <text class="cuIcon-time padding-right-10"></text>
  30. <text>{{new Date(item.createDate).getTime() | date('yyyy-mm-dd') }}</text>
  31. </view>
  32. </view>
  33. <view class="content ">
  34. <text class="text-cut-2">{{item.notice}}</text>
  35. </view>
  36. <view class="bottom">
  37. <view @click.stop="delItem(item)" class="cu-btn bg-red round sm">
  38. <u-icon top="-1" name="trash-fill" size="25"></u-icon>
  39. <text class="padding-left-10">删除</text>
  40. </view>
  41. <view @click.stop="edit(item)" class="cu-btn bg-blue round sm margin-left-20">
  42. <u-icon top="-1" name="edit-pen-fill" size="25"></u-icon>
  43. <text class="padding-left-10">编辑</text>
  44. </view>
  45. </view>
  46. </view>
  47. </mescroll-body>
  48. <wm-list-add bgColor="#7fc6ac" ref="add" @clickAdd="add"/>
  49. <!-- 小区列表 -->
  50. <u-popup border-radius="20" height="70%" mode="bottom" v-model="residentialShow">
  51. <view class="fixed cu-bar search bg-white">
  52. <view class="search-form round">
  53. <text class="cuIcon-search"></text>
  54. <u-input style="width: 90%;" v-model="keyword" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  55. </view>
  56. </view>
  57. <scroll-view @scrolltolower="scrolltolower" v-if="!$isEmpty(residentialList)" style="padding: 0rpx 0 88rpx;height: 100%;" :scroll-y="true" >
  58. <view style="padding: 110rpx 30rpx 20rpx;">
  59. <u-checkbox-group width ="50%" size="40" >
  60. <u-checkbox
  61. @change="checkboxChange"
  62. v-model="item.checked"
  63. v-for="(item, index) in residentialList" :key="index"
  64. :name="item.name"
  65. >{{item.name}}</u-checkbox>
  66. </u-checkbox-group>
  67. </view>
  68. <view class="padding-top-20">
  69. <u-loadmore :status="status" />
  70. </view>
  71. </scroll-view>
  72. <u-empty v-else name="search"></u-empty>
  73. <view @click="confirmChecked" class="cu-btn bg-blue" style="position: fixed;bottom: 0;right: 0;left: 0;padding: 40rpx;">
  74. 确认选择
  75. </view>
  76. </u-popup>
  77. </view>
  78. </template>
  79. <script>
  80. import wmListAdd from '@/components/wm-list-add/wm-list-add';
  81. import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
  82. export default {
  83. mixins:[MescrollMixin],
  84. components:{
  85. wmListAdd
  86. },
  87. data() {
  88. return {
  89. residentialNames:'',
  90. agencyId:'',
  91. isFirst:false,
  92. dataList:[],
  93. popupShow:false,
  94. residentialShow:false,
  95. residentialList:[],
  96. residentialPlaceholder:'请选择要下发的小区',
  97. status:'',
  98. current:1,
  99. total:0,
  100. keyword:'',
  101. form:{}
  102. }
  103. },
  104. onShow() {
  105. this.mescroll.resetUpScroll()
  106. },
  107. onLoad() {
  108. this.getResidentailList()
  109. },
  110. watch:{
  111. keyword(){
  112. let that=this
  113. //节流函数
  114. if (this.timer){
  115. clearTimeout(this.timer)//阻止setTimeout函数的执行
  116. }
  117. this.timer = setTimeout(() => {
  118. this.residentialList=[]
  119. this.current=1
  120. this.getResidentailList()
  121. }, 500)
  122. }
  123. },
  124. methods: {
  125. add(){
  126. this.form={}
  127. this.popupShow=true
  128. },
  129. submit(){
  130. if (this.$isEmpty(this.form.title)) {
  131. this.$u.toast('请输入标题')
  132. }
  133. if (this.$isEmpty(this.form.notice)) {
  134. this.$u.toast('请输入内容')
  135. return
  136. }
  137. if (this.$isEmpty(this.form.residentialIds)) {
  138. this.$u.toast('请选择要下发的小区')
  139. }
  140. this.$api.notice.submit(this.form).then(res=>{
  141. if (res.data==true) {
  142. this.$u.toast('操作成功')
  143. this.popupShow=false
  144. this.mescroll.resetUpScroll()
  145. }else{
  146. this.$u.toast(res.msg)
  147. }
  148. })
  149. },
  150. scrolltolower(e){
  151. if(this.residentialList.length==this.total){
  152. this.status='nomore'
  153. return
  154. }else{
  155. this.status='loading'
  156. this.current++
  157. this.getResidentailList()
  158. }
  159. },
  160. checkboxChange(e) {
  161. console.log(e);
  162. },
  163. confirmChecked(){
  164. let tmpNames=[]
  165. let tmpIds=[]
  166. this.residentialList.forEach(item=>{
  167. if (item.checked==true) {
  168. tmpNames.push(item.name)
  169. tmpIds.push(item.id)
  170. }
  171. })
  172. this.residentialNames=tmpNames.join(",")
  173. this.form.residentialIds=tmpIds.join(",")
  174. this.residentialShow=false
  175. },
  176. showResidential(){
  177. if (this.$isEmpty(this.form.id)) {
  178. this.residentialShow=true
  179. }
  180. },
  181. getResidentailList(){
  182. let params={
  183. current:this.current,
  184. size:50,
  185. name:this.keyword
  186. }
  187. let list=[]
  188. this.$api.residential.pageBycondition(params).then(res=>{
  189. res.data.records.forEach(item=>{
  190. let obj={
  191. name:item.name,
  192. id:item.id,
  193. checked:false
  194. }
  195. list.push(obj)
  196. })
  197. this.total=res.total
  198. this.residentialList=[...this.residentialList,...list]
  199. })
  200. },
  201. goDetail(item){
  202. getApp().globalData.noticeDetail=item
  203. uni.navigateTo({
  204. url:"./detail",
  205. })
  206. },
  207. delItem(item){
  208. let that=this
  209. this.$showModel('确定要删除该公告吗?').then(res=>{
  210. this.$api.notice.remove(item.id).then(res=>{
  211. if (res.data==true) {
  212. this.$u.toast('删除成功')
  213. setTimeout(()=>{
  214. that.mescroll.resetUpScroll()
  215. },500)
  216. }else{
  217. this.$u.toast(res.msg)
  218. }
  219. })
  220. })
  221. },
  222. edit(item){
  223. this.popupShow=true
  224. this.residentialPlaceholder='下发小区不可编辑'
  225. this.form.id=item.id
  226. this.form.title=item.title
  227. this.form.notice=item.notice
  228. this.form.residentialIds=item.residentialIds
  229. },
  230. /**
  231. * 下拉回调
  232. */
  233. downCallback(){
  234. setTimeout(()=>{
  235. this.mescroll.resetUpScroll()
  236. },1500)
  237. },
  238. /**
  239. * 上拉回调
  240. * @param {Object} mescroll
  241. */
  242. upCallback(mescroll) {
  243. try{
  244. let params={
  245. current:mescroll.num,
  246. size:mescroll.size
  247. }
  248. this.$api.notice.page(params).then(res=>{
  249. let data=res.data.records
  250. let length=data.length
  251. let total=res.data.total
  252. mescroll.endBySize(length, total);
  253. if(mescroll.num == 1) this.dataList = [];
  254. this.dataList=this.dataList.concat(data);
  255. })
  256. }catch(e){
  257. mescroll.endErr();
  258. }
  259. },
  260. }
  261. }
  262. </script>
  263. <style lang="scss">
  264. .line-red{
  265. border: 1rpx solid #dc0000;
  266. color: #dc0000;
  267. }
  268. .card{
  269. background-color: #FFFFFF;
  270. border-radius: 20rpx;
  271. margin: 20rpx;
  272. .title{
  273. display: flex;
  274. justify-content: space-between;
  275. padding: 20rpx;
  276. font-size: 30rpx;
  277. border-bottom: 0.5rpx solid #e6e5e8;
  278. .time{
  279. padding-top: 8rpx;
  280. font-size: 28rpx;
  281. color: #8d8d8d;
  282. }
  283. }
  284. .content{
  285. color: #737373;
  286. height: 150rpx;
  287. padding:30rpx 20rpx;
  288. }
  289. .bottom{
  290. padding: 20rpx;
  291. display: flex;
  292. justify-content: flex-end;
  293. }
  294. }
  295. </style>