index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div>
  3. <van-field
  4. readonly
  5. clickable
  6. name="datetimePicker"
  7. v-model="peoples"
  8. :required="isRequired"
  9. :label="inpitLabel"
  10. placeholder="请选择人员"
  11. @click="show = true"
  12. />
  13. <van-action-sheet class="bigsheetbox" v-model="show" position="bottom" title="选择人员">
  14. <van-row>
  15. <van-col span="24">
  16. <van-search
  17. v-model="searchVal"
  18. show-action
  19. placeholder="请输入搜索关键词"
  20. @input="onSearch"
  21. @cancel="onCancel"
  22. />
  23. </van-col>
  24. </van-row>
  25. <van-row>
  26. <van-col span="24">
  27. <van-checkbox-group v-model="peoplesId">
  28. <van-cell-group>
  29. <van-cell v-for="item in peopleListCpoy" clickable :key="item.id" :title="`${item.name}`">
  30. <template #right-icon>
  31. <van-checkbox :name="item.id" />
  32. </template>
  33. </van-cell>
  34. </van-cell-group>
  35. </van-checkbox-group>
  36. </van-col>
  37. </van-row>
  38. <van-row class="bottomdiv">
  39. <van-col span="24">
  40. <van-button class="btns" size="small" type="info" @click="submitHandler">确认</van-button>
  41. </van-col>
  42. </van-row>
  43. </van-action-sheet>
  44. </div>
  45. </template>
  46. <script>
  47. import { deptTreeList } from '@/api/toConsult.js'
  48. import { getOrgPeople } from '@/api/public.js'
  49. import OrgTree from '@/components/orgTree'
  50. export default {
  51. name: 'SocAppIndex',
  52. components: {
  53. OrgTree
  54. },
  55. props: {
  56. organizationId: {
  57. //机构ID
  58. },
  59. userList: {
  60. type: Array,
  61. default: () => {
  62. return []
  63. }
  64. },
  65. isRequired: {
  66. //是否必填
  67. type: Boolean,
  68. default: false
  69. },
  70. inpitLabel: {
  71. type: String,
  72. default: '参与人员'
  73. },
  74. fieldNames: {
  75. //树行配置映射项
  76. type: Object,
  77. default: () => {
  78. return {
  79. text: 'name',
  80. value: 'id',
  81. children: 'children'
  82. }
  83. }
  84. }
  85. },
  86. data() {
  87. return {
  88. orgId: this.organizationId || '',
  89. show: false,
  90. value1: '',
  91. showcascader: false,
  92. cascaderValue: '',
  93. loading: false,
  94. options: [], //机构列表
  95. peoplesId: [], //人员ID集合
  96. searchVal: '', //搜索值
  97. peopleList: [], //人员列表
  98. peopleListCpoy: [], //人员列表2
  99. orgName: '', //机构名称
  100. peoples: '' //人员列表
  101. }
  102. },
  103. watch: {
  104. organizationId(val) {
  105. this.orgId = val + ''
  106. this.getpeople()
  107. },
  108. //监听弹框是否打开
  109. show(val){
  110. if(val){
  111. this.getpeople()
  112. }
  113. },
  114. //监听人员数组变化
  115. userList(val) {
  116. this.peoplesId=[]
  117. this.$set(this.$data,'peoples',val.map(item => item.userName).join(','))
  118. val.map(item => {
  119. this.peoplesId.push(item.userId)
  120. })
  121. }
  122. },
  123. created() {},
  124. mounted() {},
  125. methods: {
  126. onLoad() {},
  127. getpeople() {
  128. getOrgPeople(this.orgId).then(res => {
  129. let { code, data, msg } = res
  130. if (code == 200) {
  131. this.peopleList = data
  132. this.peopleList.forEach(item=>{
  133. item.userName=item.name
  134. item.username=item.name
  135. item.userId=item.id
  136. })
  137. this.peopleListCpoy = JSON.parse(JSON.stringify(this.peopleList))
  138. this.peopleListCpoy.forEach(item => {
  139. this.peoplesId.forEach(i => {
  140. console.log(this.peoplesId);
  141. if (item.userId === i) {
  142. this.$set(item, 'checked', true)
  143. }else{
  144. this.$set(item, 'checked', false)
  145. }
  146. })
  147. })
  148. }
  149. })
  150. },
  151. onSearch(val) {
  152. this.peopleListCpoy = this.peopleList.filter(item => {
  153. if (item.name.indexOf(val) != -1) {
  154. return item
  155. }
  156. })
  157. },
  158. onCancel() {
  159. this.searchVal = ''
  160. this.peopleListCpoy = this.peopleList
  161. },
  162. submitHandler() {
  163. let list = []
  164. this.peopleListCpoy.filter(item => {
  165. this.peoplesId.forEach(r => {
  166. if (r == item.id) {
  167. list.push(item)
  168. }
  169. })
  170. })
  171. // this.peoples = list.map(item => item.name).join(',')
  172. this.$set(this.$data,'peoples',list.map(item => item.name).join(','))
  173. // 抛出已选择人员信息
  174. this.$emit('userList', list)
  175. this.show = false
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. .van-action-sheet {
  182. min-height: 90%;
  183. }
  184. .btns {
  185. width: 100%;
  186. }
  187. .bottomdiv {
  188. width: 100%;
  189. bottom: 0%;
  190. position: fixed;
  191. }
  192. .bigsheetbox {
  193. height: calc(100vh - 100px);
  194. }
  195. .line {
  196. width: 100%;
  197. height: 3px;
  198. background-color: #1989fa;
  199. }
  200. </style>