index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <!-- 禁止滚动穿透 -->
  3. <page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta>
  4. <view class="main">
  5. <view class="one">
  6. <view class="one_1">
  7. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索群组名称">
  8. </view>
  9. <view class="one_2">
  10. <button size="mini" class="button" type="primary" @click="toAdd">添加</button>
  11. </view>
  12. </view>
  13. <view class="two">
  14. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  15. <view class="list-scroll-view">
  16. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  17. <view class="name">{{item.name||'暂无群组名称'}}</view>
  18. <view class="other textOver">
  19. 简介:{{item.content||'暂无'}}
  20. </view>
  21. <view class="button">
  22. <button class="warning" size="mini" type="warn" @tap.stop="toEdit(item)">修改</button>
  23. <button class="warning" size="mini" type="warn" @tap.stop="toCode(item)">二维码</button>
  24. <button class="warning" size="mini" type="warn" @tap.stop="toPerson(item)">成员</button>
  25. <button class="danger" size="mini" type="warn" @tap.stop="toDel(item)">删除</button>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="is_bottom" v-if="is_bottom">
  30. <text>{{config.bottom_title||'到底了!'}}</text>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. <!-- 修改/添加信息 -->
  35. <uni-popup ref="popup" background-color="#fff" type="center" :is-mask-click="false" @change="change">
  36. <view class="popup">
  37. <view class="close">
  38. <text>信息管理</text>
  39. <uni-icons @tap="toClose" type="close" size="20"></uni-icons>
  40. </view>
  41. <view class="info_1">
  42. <uni-forms ref="valiForm" :rules="rules" :modelValue="form">
  43. <uni-forms-item label="群名" required name="name">
  44. <uni-easyinput v-model="form.name" placeholder="请输入群名" />
  45. </uni-forms-item>
  46. <uni-forms-item label="简介" required name="content">
  47. <uni-easyinput type="textarea" autoHeight v-model="form.content" placeholder="请输入简介" />
  48. </uni-forms-item>
  49. </uni-forms>
  50. <button class="button" size="mini" type="primary" @click="submit('valiForm')">保存</button>
  51. </view>
  52. </view>
  53. </uni-popup>
  54. <uni-popup ref="code" background-color="#fff" type="center" :is-mask-click="false" @change="change">
  55. <view class="popup">
  56. <view class="close">
  57. <text>二维码</text>
  58. <uni-icons @tap="toClose" type="close" size="20"></uni-icons>
  59. </view>
  60. <view class="info_1">
  61. 二维码
  62. <button class="button" size="mini" type="primary" @click="submit('valiForm')">保存二维码</button>
  63. </view>
  64. </view>
  65. </uni-popup>
  66. </view>
  67. </template>
  68. <script>
  69. export default {
  70. data() {
  71. return {
  72. user: {},
  73. config: {},
  74. searchInfo: {},
  75. list: [],
  76. total: 0,
  77. skip: 0,
  78. limit: 10,
  79. page: 0,
  80. form: {},
  81. // 校验规则
  82. rules: {
  83. name: {
  84. rules: [{
  85. required: true,
  86. errorMessage: '群名不能为空'
  87. }]
  88. },
  89. content: {
  90. rules: [{
  91. required: true,
  92. errorMessage: '简介不能为空'
  93. }]
  94. }
  95. },
  96. // 数据是否触底
  97. is_bottom: false,
  98. scrollTop: 0,
  99. // 禁止滚动穿透
  100. show: false
  101. }
  102. },
  103. onShow: async function() {
  104. const that = this;
  105. that.clearPage();
  106. await that.searchToken();
  107. await that.searchConfig();
  108. await that.search();
  109. },
  110. onPullDownRefresh: async function() {
  111. const that = this;
  112. that.clearPage();
  113. await that.search();
  114. uni.stopPullDownRefresh();
  115. },
  116. methods: {
  117. // 禁止滚动穿透
  118. change(e) {
  119. const that = this;
  120. that.show = e.show
  121. },
  122. searchToken() {
  123. const that = this;
  124. try {
  125. const res = uni.getStorageSync('token');
  126. if (res) {
  127. const user = that.$jwt(res);
  128. that.$set(that, `user`, user);
  129. }
  130. } catch (e) {}
  131. },
  132. searchConfig() {
  133. const that = this;
  134. try {
  135. const res = uni.getStorageSync('config');
  136. if (res) that.$set(that, `config`, res);
  137. } catch (e) {}
  138. },
  139. async search() {
  140. const that = this;
  141. let user = that.user;
  142. let info = {
  143. skip: that.skip,
  144. limit: that.limit,
  145. }
  146. if (that.user.role == 'Doctor') info.doctor = that.user._id
  147. else info.doctor = that.user.doctor
  148. const res = await that.$api(`/group`, 'GET', {
  149. ...info,
  150. ...that.searchInfo
  151. })
  152. if (res.errcode == '0') {
  153. let list = [...that.list, ...res.data];
  154. that.$set(that, `list`, list)
  155. that.$set(that, `total`, res.total)
  156. } else {
  157. uni.showToast({
  158. title: res.errmsg,
  159. });
  160. }
  161. },
  162. // 输入框
  163. toInput(e) {
  164. const that = this;
  165. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  166. else that.$set(that, `searchInfo`, {})
  167. that.clearPage();
  168. that.search();
  169. },
  170. // 添加
  171. toAdd() {
  172. const that = this;
  173. that.$refs.popup.open()
  174. },
  175. // 二维码
  176. toCode(item) {
  177. const that = this;
  178. console.log(item);
  179. that.$refs.code.open()
  180. },
  181. // 成员
  182. toPerson(item) {
  183. const that = this;
  184. uni.navigateTo({
  185. url: `/pagesMy/person/index?id=${item.id||item._id}`
  186. })
  187. },
  188. // 修改
  189. async toEdit(item) {
  190. const that = this;
  191. const res = await that.$api(`/group/${item._id}`, 'GET', {})
  192. if (res.errcode == '0') {
  193. that.$set(that, `form`, res.data)
  194. that.$refs.popup.open()
  195. } else {
  196. uni.showToast({
  197. title: res.errmsg,
  198. icon: 'none'
  199. });
  200. }
  201. },
  202. // 保存
  203. submit(ref) {
  204. const that = this;
  205. const form = that.form;
  206. that.$refs[ref].validate().then(async data => {
  207. let res;
  208. if (that.user.role == 'Doctor') data.doctor = that.user._id
  209. else data.doctor = that.user.doctor
  210. if (form._id) res = await that.$api(`/group/${form._id}`, 'POST', data)
  211. else res = await that.$api(`/group`, 'POST', data)
  212. if (res.errcode == '0') {
  213. that.toClose();
  214. that.clearPage();
  215. that.search();
  216. } else {
  217. uni.showToast({
  218. title: res.errmsg,
  219. icon: 'none'
  220. });
  221. }
  222. })
  223. },
  224. // 删除
  225. async toDel(item) {
  226. const that = this;
  227. uni.showModal({
  228. title: '提示',
  229. content: '您确定删除该数据吗?',
  230. success: async function(res) {
  231. if (res.confirm) {
  232. const res = await that.$api(`/group/${item._id||item.id}`, 'DELETE', {})
  233. if (res.errcode == 0) {
  234. that.clearPage();
  235. that.search();
  236. } else {
  237. uni.showToast({
  238. title: res.errmsg,
  239. icon: 'none'
  240. })
  241. }
  242. }
  243. }
  244. });
  245. },
  246. // 关闭弹框
  247. toClose() {
  248. const that = this;
  249. that.$set(that, `form`, {})
  250. that.$refs.popup.close();
  251. that.$refs.code.close();
  252. },
  253. // 详情
  254. toInfo(item) {
  255. uni.navigateTo({
  256. url: `/pagesHome/group/index?id=${item.id||item._id}&title=${item.name}`
  257. })
  258. },
  259. // 分页
  260. toPage(e) {
  261. const that = this;
  262. let list = that.list;
  263. let limit = that.limit;
  264. if (that.total > list.length) {
  265. uni.showLoading({
  266. title: '加载中',
  267. mask: true
  268. })
  269. let page = that.page + 1;
  270. that.$set(that, `page`, page)
  271. let skip = page * limit;
  272. that.$set(that, `skip`, skip)
  273. that.search();
  274. uni.hideLoading();
  275. } else that.$set(that, `is_bottom`, true)
  276. },
  277. toScroll(e) {
  278. const that = this;
  279. let up = that.scrollTop;
  280. that.$set(that, `scrollTop`, e.detail.scrollTop);
  281. let num = Math.sign(up - e.detail.scrollTop);
  282. if (num == 1) that.$set(that, `is_bottom`, false);
  283. },
  284. // 清空列表
  285. clearPage() {
  286. const that = this;
  287. that.$set(that, `list`, [])
  288. that.$set(that, `skip`, 0)
  289. that.$set(that, `limit`, 10)
  290. that.$set(that, `page`, 0)
  291. }
  292. }
  293. }
  294. </script>
  295. <style lang="scss" scoped>
  296. .main {
  297. display: flex;
  298. flex-direction: column;
  299. width: 100vw;
  300. height: 100vh;
  301. .one {
  302. display: flex;
  303. justify-content: center;
  304. align-items: center;
  305. padding: 2vw;
  306. .one_1 {
  307. padding: 0 2vw;
  308. width: 75vw;
  309. input {
  310. padding: 2vw;
  311. background-color: var(--f1Color);
  312. font-size: var(--font14Size);
  313. border-radius: 5px;
  314. }
  315. }
  316. .one_2 {
  317. padding: 2vw 0;
  318. .button {
  319. background-color: var(--f3CColor);
  320. color: var(--mainColor);
  321. }
  322. }
  323. }
  324. .two {
  325. position: relative;
  326. flex-grow: 1;
  327. background-color: var(--f9Color);
  328. .list:first-child {
  329. margin: 2vw;
  330. }
  331. .list {
  332. background-color: var(--mainColor);
  333. border: 1px solid var(--f5Color);
  334. padding: 2vw;
  335. margin: 0 2vw 2vw 2vw;
  336. border-radius: 5px;
  337. .name {
  338. font-size: var(--font14Size);
  339. font-weight: bold;
  340. padding: 2vw 0;
  341. }
  342. .other {
  343. font-size: var(--font12Size);
  344. color: var(--f85Color);
  345. }
  346. .button {
  347. margin: 2vw 0 0 0;
  348. text-align: center;
  349. .warning {
  350. background: var(--f3CColor);
  351. }
  352. .danger {
  353. background: var(--fF0Color);
  354. }
  355. button {
  356. margin: 0 1vw 0 0;
  357. }
  358. }
  359. }
  360. }
  361. .uni-popup {
  362. z-index: 9999 !important;
  363. }
  364. .popup {
  365. display: flex;
  366. flex-direction: column;
  367. width: 90vw;
  368. height: 45vh;
  369. background-color: var(--f9Color);
  370. .close {
  371. display: flex;
  372. justify-content: space-between;
  373. padding: 2vw;
  374. text:first-child {
  375. font-size: var(--font16Size);
  376. font-weight: bold;
  377. }
  378. }
  379. .info_1 {
  380. position: relative;
  381. display: flex;
  382. flex-direction: column;
  383. max-height: 40vh;
  384. padding: 2vw;
  385. .button {
  386. background-color: var(--f3CColor);
  387. color: var(--mainColor);
  388. font-size: var(--font14Size);
  389. }
  390. }
  391. }
  392. }
  393. .scroll-view {
  394. position: absolute;
  395. top: 0;
  396. left: 0;
  397. right: 0;
  398. bottom: 0;
  399. .list-scroll-view {
  400. display: flex;
  401. flex-direction: column;
  402. }
  403. }
  404. .is_bottom {
  405. width: 100%;
  406. text-align: center;
  407. text {
  408. padding: 2vw 0;
  409. display: inline-block;
  410. color: var(--f85Color);
  411. font-size: var(--font14Size);
  412. }
  413. }
  414. </style>