index.vue 5.0 KB

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