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. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索实验室名称">
  7. </view>
  8. <view class="two">
  9. <tabs :tabs="tabs" @tabsChange="tabsChange">
  10. <view class="tabsList">
  11. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  12. <view class="list-scroll-view">
  13. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  14. <view class="name">{{item.name||'暂无名称'}}</view>
  15. <view class="other">
  16. <view class="other_1 textOne">
  17. 批建时间:{{item.build_time||'暂无'}}
  18. </view>
  19. <view class="other_1 textOne">
  20. 依托单位名称:{{item.unit_name||'暂无'}}
  21. </view>
  22. <view class="other_1 textOne" v-if="item.assistant">
  23. 科研助理姓名:<text :user-select='true'
  24. :selectable="true">{{item.assistant.name||'暂无'}}</text>
  25. </view>
  26. <view class="other_1 textOne" v-if="item.assistant">
  27. 科研助理手机号:<text :user-select='true'
  28. :selectable="true">{{item.assistant.phone||'暂无'}}</text>
  29. </view>
  30. <view class="status textOne">
  31. 状态:{{item.zhStatus||'暂无'}}
  32. </view>
  33. </view>
  34. <view class="button">
  35. <button class="warning" v-if="user.role_type == '0' || user.role_type == '1'"
  36. size="mini" type="warn" @tap.stop="toEdit(item)">修改</button>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="is_bottom" v-if="is_bottom">
  41. <text>没数据到底了!</text>
  42. </view>
  43. </scroll-view>
  44. </view>
  45. </tabs>
  46. </view>
  47. <uni-popup ref="popup" background-color="#fff" type="center" :is-mask-click="false" @change="change">
  48. <view class="popup">
  49. <view class="close">
  50. <text>信息管理</text>
  51. <uni-icons @tap="toClose" type="close" size="20"></uni-icons>
  52. </view>
  53. <view class="info_1">
  54. <view class="info">
  55. <uni-forms class="form" ref="form" :rules="rules" :modelValue="form" label-width='90'>
  56. <uni-forms-item label="状态" name="status">
  57. <uni-data-select v-model="form.status" :localdata="statusList" @change="statusChange">
  58. </uni-data-select>
  59. </uni-forms-item>
  60. <uni-forms-item label="批建时间" required name="build_time">
  61. <uni-datetime-picker type="date" v-model="form.build_time" />
  62. </uni-forms-item>
  63. </uni-forms>
  64. <view class="bottom">
  65. <button size="mini" class="button" type="primary" @click="submit('form')">提交保存</button>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </uni-popup>
  71. </view>
  72. </template>
  73. <script>
  74. import tabs from '../../components/tabs/index.vue';
  75. export default {
  76. components: {
  77. tabs
  78. },
  79. data() {
  80. return {
  81. user: {},
  82. searchInfo: {},
  83. status: '-10',
  84. tabs: {
  85. active: '-10',
  86. bgColor: '#ffffff',
  87. menu: []
  88. },
  89. form: {},
  90. // 校验规则
  91. rules: {
  92. status: {
  93. rules: [{
  94. required: true,
  95. errorMessage: '请选择状态'
  96. }]
  97. }
  98. },
  99. list: [],
  100. total: 0,
  101. skip: 0,
  102. limit: 6,
  103. page: 0,
  104. // 数据是否触底
  105. is_bottom: false,
  106. scrollTop: 0,
  107. // 字典表
  108. statusList: [],
  109. // 禁止滚动穿透
  110. show: false
  111. }
  112. },
  113. onShow: async function() {
  114. const that = this;
  115. that.clearPage();
  116. await that.searchOther();
  117. await that.searchToken();
  118. await that.search();
  119. },
  120. onPullDownRefresh: async function() {
  121. const that = this;
  122. that.clearPage();
  123. await that.search();
  124. uni.stopPullDownRefresh();
  125. },
  126. methods: {
  127. // 禁止滚动穿透
  128. change(e) {
  129. const that = this;
  130. that.show = e.show
  131. },
  132. searchToken() {
  133. const that = this;
  134. try {
  135. const res = uni.getStorageSync('token');
  136. if (res) {
  137. const user = that.$jwt(res);
  138. that.$set(that, `user`, user);
  139. } else {
  140. uni.navigateTo({
  141. url: `/pages/login/index`
  142. })
  143. }
  144. } catch (e) {
  145. uni.showToast({
  146. title: err.errmsg,
  147. icon: 'error',
  148. duration: 2000
  149. });
  150. }
  151. },
  152. async search() {
  153. const that = this;
  154. let user = that.user;
  155. let status = that.status;
  156. let info = {
  157. skip: that.skip,
  158. limit: that.limit,
  159. }
  160. if (status != '-10') info.status = status
  161. const res = await that.$api(`/basic`, 'GET', {
  162. ...info,
  163. ...that.searchInfo
  164. }, 'freeLabel')
  165. if (res.errcode == '0') {
  166. let list = [...that.list, ...res.data];
  167. for (let val of list) {
  168. const status = that.statusList.find(i => i.value == val.status)
  169. if (status) val.zhStatus = status.text
  170. }
  171. that.$set(that, `list`, list)
  172. that.$set(that, `total`, res.total)
  173. } else {
  174. uni.showToast({
  175. title: res.errmsg,
  176. });
  177. }
  178. },
  179. // 选择选项卡
  180. tabsChange(e) {
  181. const that = this;
  182. that.$set(that.tabs, `active`, e.active)
  183. that.$set(that, `status`, e.active)
  184. that.clearPage();
  185. that.search()
  186. },
  187. // 输入框
  188. toInput(e) {
  189. const that = this;
  190. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  191. else that.$set(that, `searchInfo`, {})
  192. that.clearPage();
  193. that.search();
  194. },
  195. // 查看
  196. toView(item) {
  197. uni.navigateTo({
  198. url: `/pagesBasic/basic/info?id=${item._id||item.id}`
  199. })
  200. },
  201. // 修改
  202. toEdit(item) {
  203. const that = this;
  204. that.$set(that, `form`, item)
  205. that.$refs.popup.open()
  206. },
  207. statusChange(status) {
  208. const that = this;
  209. that.$set(that.form, `status`, status);
  210. },
  211. submit(ref) {
  212. const that = this;
  213. const form = that.form;
  214. that.$refs[ref].validate().then(async data => {
  215. let res = await that.$api(`/basic/${form._id}`, 'POST', data, 'freeLabel');
  216. if (res.errcode == '0') {
  217. uni.showToast({
  218. title: '信息维护成功',
  219. icon: 'none'
  220. })
  221. that.toClose()
  222. } else {
  223. uni.showToast({
  224. title: res.errmsg,
  225. icon: 'none'
  226. })
  227. }
  228. }).catch(err => {
  229. console.log('err', err);
  230. })
  231. },
  232. // 关闭弹框
  233. toClose() {
  234. const that = this;
  235. that.$refs.popup.close();
  236. },
  237. async searchOther() {
  238. const that = this;
  239. let res;
  240. //状态
  241. res = await that.$api('/dictData', 'GET', {
  242. dict_type: 'label_status',
  243. status: '0'
  244. }, 'jcyjdtglpt')
  245. if (res.errcode == '0') {
  246. const statusList = res.data.map((item) => {
  247. return {
  248. value: item.dict_value,
  249. text: item.dict_label
  250. }
  251. })
  252. that.$set(that, `statusList`, statusList);
  253. const menu = res.data.map((item) => {
  254. return {
  255. title: item.dict_label,
  256. active: item.dict_value
  257. }
  258. })
  259. menu.unshift({
  260. title: '全部',
  261. active: '-10'
  262. })
  263. that.$set(that.tabs, `menu`, menu)
  264. }
  265. },
  266. // 分页
  267. toPage(e) {
  268. const that = this;
  269. let list = that.list;
  270. let limit = that.limit;
  271. if (that.total > list.length) {
  272. uni.showLoading({
  273. title: '加载中',
  274. mask: true
  275. })
  276. let page = that.page + 1;
  277. that.$set(that, `page`, page)
  278. let skip = page * limit;
  279. that.$set(that, `skip`, skip)
  280. that.search();
  281. uni.hideLoading();
  282. } else that.$set(that, `is_bottom`, true)
  283. },
  284. toScroll(e) {
  285. const that = this;
  286. let up = that.scrollTop;
  287. that.$set(that, `scrollTop`, e.detail.scrollTop);
  288. let num = Math.sign(up - e.detail.scrollTop);
  289. if (num == 1) that.$set(that, `is_bottom`, false);
  290. },
  291. // 清空列表
  292. clearPage() {
  293. const that = this;
  294. that.$set(that, `list`, [])
  295. that.$set(that, `skip`, 0)
  296. that.$set(that, `limit`, 6)
  297. that.$set(that, `page`, 0)
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss" scoped>
  303. .main {
  304. display: flex;
  305. flex-direction: column;
  306. width: 100vw;
  307. height: 100vh;
  308. .one {
  309. padding: 2vw;
  310. input {
  311. padding: 2vw;
  312. background-color: var(--f1Color);
  313. font-size: var(--font14Size);
  314. border-radius: 5px;
  315. }
  316. }
  317. .two {
  318. position: relative;
  319. flex-grow: 1;
  320. background-color: var(--f9Color);
  321. .tabsList {
  322. position: relative;
  323. width: 100vw;
  324. height: 80vh;
  325. .list:first-child {
  326. margin: 2vw;
  327. }
  328. .list {
  329. background-color: var(--mainColor);
  330. border: 1px solid var(--f5Color);
  331. padding: 2vw;
  332. margin: 0 2vw 2vw 2vw;
  333. border-radius: 5px;
  334. .name {
  335. font-size: var(--font14Size);
  336. font-weight: bold;
  337. }
  338. .other {
  339. padding: 2px 0 0 0;
  340. font-size: var(--font12Size);
  341. color: var(--f85Color);
  342. }
  343. .status{
  344. padding: 2px 0 0 0;
  345. font-size: var(--font12Size);
  346. color: var(--fF0Color);
  347. }
  348. .button {
  349. margin: 2vw 0 0 0;
  350. text-align: center;
  351. .warning {
  352. background: var(--f3CColor);
  353. }
  354. button {
  355. margin: 0 1vw 0 0;
  356. }
  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: 35vh;
  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: 25vh;
  384. padding: 2vw;
  385. .info {
  386. .bottom {
  387. text-align: center;
  388. .button {
  389. background-color: var(--f07CColor);
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. .scroll-view {
  397. position: absolute;
  398. top: 0;
  399. left: 0;
  400. right: 0;
  401. bottom: 0;
  402. .list-scroll-view {
  403. display: flex;
  404. flex-direction: column;
  405. }
  406. }
  407. .is_bottom {
  408. width: 100%;
  409. text-align: center;
  410. text {
  411. padding: 2vw 0;
  412. display: inline-block;
  413. color: var(--f85Color);
  414. font-size: var(--font14Size);
  415. }
  416. }
  417. </style>