index.vue 4.8 KB

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