index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. <list name="list" :list="list" :fields="fields" :page="page" :total="total" :pageSize="limit"
  10. @toPage="toPage" @toView="toView">
  11. </list>
  12. </view>
  13. <uni-popup ref="popup" background-color="#fff" type="center" :is-mask-click="false" @change="change">
  14. <view class="popup">
  15. <view class="close">
  16. <text>信息管理</text>
  17. <uni-icons @tap="toClose" type="close" size="20"></uni-icons>
  18. </view>
  19. <view class="info_1">
  20. <info name="info" :data="info" :infoFields="infoFields" :showList="showList"></info>
  21. </view>
  22. </view>
  23. </uni-popup>
  24. </view>
  25. </template>
  26. <script>
  27. import list from '@/components/list/index.vue';
  28. import info from '@/components/view/index.vue';
  29. export default {
  30. components: {
  31. list,
  32. info
  33. },
  34. data() {
  35. return {
  36. id: '',
  37. user: {},
  38. searchInfo: {},
  39. fields: [{
  40. label: '方向名称',
  41. model: 'name',
  42. is_name: true
  43. },
  44. {
  45. label: '方向带头人',
  46. model: 'person_id'
  47. },
  48. {
  49. label: '核心成员',
  50. model: 'persons'
  51. },
  52. {
  53. label: '是否启用',
  54. model: 'is_show',
  55. is_status: true
  56. },
  57. ],
  58. list: [],
  59. total: 0,
  60. skip: 0,
  61. limit: 5,
  62. page: 1,
  63. // 字典表
  64. userList: [],
  65. showList: [],
  66. // 查看
  67. info: {},
  68. infoFields: [],
  69. // 禁止滚动穿透
  70. show: false
  71. }
  72. },
  73. onLoad: async function(e) {
  74. const that = this;
  75. that.$set(that, `id`, e && e.id || '');
  76. uni.showLoading({
  77. title: '正在加载请稍后',
  78. mask: true
  79. })
  80. await that.searchOther();
  81. that.searchToken();
  82. await that.search();
  83. },
  84. onPullDownRefresh: async function() {
  85. const that = this;
  86. await that.search();
  87. uni.stopPullDownRefresh();
  88. },
  89. methods: {
  90. // 禁止滚动穿透
  91. change(e) {
  92. const that = this;
  93. that.show = e.show
  94. },
  95. searchToken() {
  96. const that = this;
  97. try {
  98. const res = uni.getStorageSync('token');
  99. if (res) {
  100. const user = that.$jwt(res);
  101. that.$set(that, `user`, user);
  102. } else {
  103. uni.navigateTo({
  104. url: `/pages/login/index`
  105. })
  106. }
  107. } catch (e) {
  108. uni.showToast({
  109. title: err.errmsg,
  110. icon: 'error',
  111. duration: 2000
  112. });
  113. }
  114. },
  115. async search() {
  116. const that = this;
  117. if (that.id) {
  118. let info = {
  119. skip: that.skip,
  120. limit: that.limit,
  121. lab_id: that.id
  122. }
  123. const res = await that.$api(`/direction`, 'GET', {
  124. ...info,
  125. ...that.searchInfo
  126. }, 'freeLabel')
  127. if (res.errcode == '0') {
  128. for (let val of res.data) {
  129. val.person_id = that.getDict(val.person_id, 'person_id')
  130. val.persons = that.getDict(val.persons, 'persons')
  131. val.is_show = that.getDict(val.is_show, 'is_show')
  132. }
  133. that.$set(that, `list`, res.data)
  134. that.$set(that, `total`, res.total)
  135. } else {
  136. uni.showToast({
  137. title: res.errmsg,
  138. });
  139. }
  140. }
  141. uni.hideLoading();
  142. },
  143. // 输入框
  144. toInput(e) {
  145. const that = this;
  146. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  147. else that.$set(that, `searchInfo`, {})
  148. that.search();
  149. },
  150. // 查询字典表
  151. getDict(e, model) {
  152. const that = this;
  153. if (!e) return '暂无'
  154. if (model == 'person_id') {
  155. let data = that.userList.find((i) => i._id == e);
  156. if (data) return data.name;
  157. else return '暂无';
  158. } else if (model == 'persons') {
  159. let list = [];
  160. if (e.length > 0) {
  161. for (const val of e) {
  162. let data = that.userList.find((i) => i._id == val);
  163. if (data) list.push(data.name);
  164. }
  165. return list.join(',');
  166. }
  167. } else if (model == 'is_show') {
  168. let data = that.showList.find((i) => i.dict_value == e);
  169. if (data) return data.dict_label;
  170. else return '暂无';
  171. }
  172. },
  173. // 查看详情
  174. async toView(item) {
  175. const that = this;
  176. let infoFields = [{
  177. label: '方向名称',
  178. model: 'name'
  179. },
  180. {
  181. label: '带头人',
  182. model: 'person_id'
  183. },
  184. {
  185. label: '核心成员',
  186. model: 'persons'
  187. },
  188. {
  189. label: '是否公开',
  190. model: 'is_show',
  191. is_show: true
  192. },
  193. {
  194. label: '附件',
  195. model: 'file',
  196. is_file: true
  197. },
  198. ];
  199. let res = await that.$api(`/direction/${item._id}`, 'GET', {}, 'freeLabel')
  200. if (res.errcode == '0') {
  201. let info = res.data;
  202. //  整理数据
  203. if (info && info.persons) info.persons = that.getDict(info.persons, 'persons');
  204. if (info && info.person_id) info.person_id = that.getDict(info.person_id, 'person_id');
  205. that.$set(that, `info`, info)
  206. that.$set(that, `infoFields`, infoFields)
  207. that.$refs.popup.open()
  208. }
  209. },
  210. // 关闭弹框
  211. toClose() {
  212. const that = this;
  213. that.$refs.popup.close();
  214. },
  215. // 分页
  216. toPage(data) {
  217. const that = this;
  218. uni.showLoading({
  219. title: '加载中',
  220. mask: true
  221. })
  222. that.$set(that, `page`, data.page);
  223. that.$set(that, `skip`, data.skip)
  224. that.search();
  225. },
  226. async searchOther() {
  227. const that = this;
  228. let res;
  229. //是否启用
  230. res = await that.$api('/dictData', 'GET', {
  231. dict_type: 'info_show',
  232. status: '0'
  233. }, 'jcyjdtglpt')
  234. if (res.errcode == '0') that.$set(that, `showList`, res.data);
  235. // 固定/流动人员 作者
  236. let personList = [];
  237. res = await that.$api('/fixedpersonnel', 'GET', {
  238. status: '0'
  239. }, 'freeLabel')
  240. if (res.errcode == '0') personList = res.data;
  241. res = await that.$api('/flowpersonnel', 'GET', {
  242. status: '0'
  243. }, 'freeLabel')
  244. if (res.errcode == '0') personList.push(...res.data);
  245. that.$set(that, `userList`, personList);
  246. },
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .main {
  252. display: flex;
  253. flex-direction: column;
  254. width: 100vw;
  255. height: 100vh;
  256. .one {
  257. padding: 2vw;
  258. input {
  259. padding: 2vw;
  260. background-color: var(--f1Color);
  261. font-size: var(--font14Size);
  262. border-radius: 5px;
  263. }
  264. }
  265. .two {
  266. background-color: var(--f9Color);
  267. }
  268. .uni-popup {
  269. z-index: 9999 !important;
  270. }
  271. .popup {
  272. display: flex;
  273. flex-direction: column;
  274. width: 90vw;
  275. height: 40vh;
  276. background-color: var(--f9Color);
  277. .close {
  278. display: flex;
  279. justify-content: space-between;
  280. padding: 2vw;
  281. text:first-child {
  282. font-size: var(--font16Size);
  283. font-weight: bold;
  284. }
  285. }
  286. .info_1 {
  287. position: relative;
  288. display: flex;
  289. flex-direction: column;
  290. padding: 2vw;
  291. }
  292. }
  293. }
  294. </style>