index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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"></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: 'contact'
  47. },
  48. {
  49. label: '联系人电话',
  50. model: 'phone'
  51. },
  52. {
  53. label: '单位类别',
  54. model: 'type'
  55. },
  56. {
  57. label: '单位性质',
  58. model: 'nature'
  59. },
  60. {
  61. label: '隶属',
  62. model: 'subjection'
  63. },
  64. ],
  65. list: [],
  66. total: 0,
  67. skip: 0,
  68. limit: 5,
  69. page: 1,
  70. // 查看
  71. info: {},
  72. infoFields: [],
  73. // 禁止滚动穿透
  74. show: false
  75. }
  76. },
  77. onLoad: async function(e) {
  78. const that = this;
  79. that.$set(that, `id`, e && e.id || '');
  80. uni.showLoading({
  81. title: '正在加载请稍后',
  82. mask: true
  83. })
  84. that.searchToken();
  85. await that.search();
  86. },
  87. onPullDownRefresh: async function() {
  88. const that = this;
  89. await that.search();
  90. uni.stopPullDownRefresh();
  91. },
  92. methods: {
  93. // 禁止滚动穿透
  94. change(e) {
  95. const that = this;
  96. that.show = e.show
  97. },
  98. searchToken() {
  99. const that = this;
  100. try {
  101. const res = uni.getStorageSync('token');
  102. if (res) {
  103. const user = that.$jwt(res);
  104. that.$set(that, `user`, user);
  105. } else {
  106. uni.navigateTo({
  107. url: `/pages/login/index`
  108. })
  109. }
  110. } catch (e) {
  111. uni.showToast({
  112. title: err.errmsg,
  113. icon: 'error',
  114. duration: 2000
  115. });
  116. }
  117. },
  118. async search() {
  119. const that = this;
  120. if (that.id) {
  121. let info = {
  122. skip: that.skip,
  123. limit: that.limit,
  124. lab_id: that.id
  125. }
  126. const res = await that.$api(`/company`, 'GET', {
  127. ...info,
  128. ...that.searchInfo
  129. }, 'freeLabel')
  130. if (res.errcode == '0') {
  131. that.$set(that, `list`, res.data)
  132. that.$set(that, `total`, res.total)
  133. } else {
  134. uni.showToast({
  135. title: res.errmsg,
  136. });
  137. }
  138. }
  139. uni.hideLoading();
  140. },
  141. // 输入框
  142. toInput(e) {
  143. const that = this;
  144. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  145. else that.$set(that, `searchInfo`, {})
  146. that.search();
  147. },
  148. // 查看详情
  149. async toView(item) {
  150. const that = this;
  151. let infoFields = [{
  152. label: '单位名称',
  153. model: 'name'
  154. },
  155. {
  156. label: '联系人',
  157. model: 'contact'
  158. },
  159. {
  160. label: '联系人电话',
  161. model: 'phone'
  162. },
  163. {
  164. label: '单位类别',
  165. model: 'type'
  166. },
  167. {
  168. label: '单位性质',
  169. model: 'nature'
  170. },
  171. {
  172. label: '隶属',
  173. model: 'subjection'
  174. },
  175. ];
  176. let res = await that.$api(`/company/${item._id}`, 'GET', {}, 'freeLabel')
  177. if (res.errcode == '0') {
  178. let info = res.data;
  179. that.$set(that, `info`, info)
  180. that.$set(that, `infoFields`, infoFields)
  181. that.$refs.popup.open()
  182. }
  183. },
  184. // 关闭弹框
  185. toClose() {
  186. const that = this;
  187. that.$refs.popup.close();
  188. },
  189. // 分页
  190. toPage(data) {
  191. const that = this;
  192. uni.showLoading({
  193. title: '加载中',
  194. mask: true
  195. })
  196. that.$set(that, `page`, data.page);
  197. that.$set(that, `skip`, data.skip)
  198. that.search();
  199. }
  200. }
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .main {
  205. display: flex;
  206. flex-direction: column;
  207. width: 100vw;
  208. height: 100vh;
  209. .one {
  210. padding: 2vw;
  211. input {
  212. padding: 2vw;
  213. background-color: var(--f1Color);
  214. font-size: var(--font14Size);
  215. border-radius: 5px;
  216. }
  217. }
  218. .two {
  219. background-color: var(--f9Color);
  220. }
  221. .uni-popup {
  222. z-index: 9999 !important;
  223. }
  224. .popup {
  225. display: flex;
  226. flex-direction: column;
  227. width: 90vw;
  228. height: 40vh;
  229. background-color: var(--f9Color);
  230. .close {
  231. display: flex;
  232. justify-content: space-between;
  233. padding: 2vw;
  234. text:first-child {
  235. font-size: var(--font16Size);
  236. font-weight: bold;
  237. }
  238. }
  239. .info_1 {
  240. position: relative;
  241. display: flex;
  242. flex-direction: column;
  243. padding: 2vw;
  244. }
  245. }
  246. }
  247. </style>