index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="添加人员"
  5. :visible.sync="drawer"
  6. append-to-body
  7. direction="rtl"
  8. width="60%">
  9. <div class="flex-align-center flex-between " style="margin-top:-10px;margin-bottom: 10px">
  10. <div class="flex-align-center">
  11. <el-input size="small" suffix-icon="el-icon-search" v-model="param.content.where.condition" placeholder="人员名称" @keyup.enter.native="listData(param.content.pageNumber = 1)" @clear="listData(param.content.pageNumber = 1)" clearable></el-input>&nbsp;
  12. </div>
  13. <el-button type="primary" size="mini" @click="onSbmit" :disabled="selectRowId.length == 0">批量添加</el-button>
  14. </div>
  15. <div class="produtMag-panel" style="margin-top: 10px">
  16. <el-table
  17. @select="selectionChange"
  18. @select-all="selectAll"
  19. border
  20. ref="tables"
  21. :data="list"
  22. style="width: 100%">
  23. <el-table-column
  24. type="selection"
  25. width="42"
  26. fixed>
  27. </el-table-column>
  28. <el-table-column
  29. prop="accountno"
  30. label="账号">
  31. </el-table-column>
  32. <el-table-column
  33. prop="name"
  34. label="账号名称">
  35. </el-table-column>
  36. <el-table-column
  37. prop="phonenumber"
  38. label="联系电话">
  39. </el-table-column>
  40. <el-table-column
  41. prop="usertypename"
  42. label="用户类型"
  43. width="160">
  44. </el-table-column>
  45. </el-table>
  46. <div>
  47. <div style="float: left">已选:{{selectRowId.length}}个人员</div>
  48. <div style="margin-top:16px;text-align:right">
  49. <el-pagination
  50. background
  51. small
  52. @size-change="handleSizeChange"
  53. @current-change="handleCurrentChange"
  54. :current-page="currentPage"
  55. :page-size="param.content.pageSize"
  56. layout="total, prev, pager, next, jumper"
  57. :total="total">
  58. </el-pagination>
  59. </div>
  60. </div>
  61. </div>
  62. </el-dialog>
  63. <slot name="input"></slot>
  64. </div>
  65. </template>
  66. <script>
  67. export default {
  68. props:['data','idName'],
  69. components:{
  70. },
  71. data () {
  72. return {
  73. drawer:false,
  74. param:{
  75. "id": 20221031141102,
  76. "content": {
  77. "pageSize":20,
  78. "pageNumber":1,
  79. "where": {
  80. "condition": "",
  81. }
  82. }
  83. },
  84. list:[],
  85. currentPage:0,
  86. total:0,
  87. selectRowId:[],
  88. selectAllData:[]
  89. }
  90. },
  91. watch: {
  92. list (val) {
  93. this.list.forEach((row) => {
  94. this.selectRowId.forEach(item => {
  95. if (row.userid == item) {
  96. this.$nextTick(() => {
  97. this.$refs["tables"].toggleRowSelection(row, true);
  98. })
  99. }
  100. })
  101. });
  102. },
  103. },
  104. methods:{
  105. async listData () {
  106. this.param.content.sa_salesforecastbillid = this.$route.query.id
  107. const res = await this.$api.requested(this.param)
  108. console.log(res.data,"人员列表")
  109. this.list = res.data
  110. this.total = res.total
  111. this.currentPage = res.pageNumber
  112. },
  113. selectionChange (arrs,arr) {
  114. let index = this.selectRowId.findIndex(item => item == arr.userid)
  115. if (index != -1) {
  116. this.selectAllData.splice(index,1)
  117. this.selectRowId.splice(index,1)
  118. } else {
  119. this.selectRowId.push(arr.userid)
  120. this.selectAllData.push(arr)
  121. }
  122. },
  123. normalSetId () {
  124. this.listData()
  125. this.selectAllData = this.data.userids.map(item => {
  126. return {
  127. userid: item,
  128. name: this.data.usermsg[item]
  129. }
  130. })
  131. console.log(this.selectAllData);
  132. this.selectRowId = this.data.userids
  133. },
  134. selectAll (val) {
  135. if (val.length == 0) {
  136. this.data.forEach((item,index) => {
  137. this.selectAllData.splice(item,1)
  138. this.selectRowId.splice(index,1)
  139. })
  140. } else {
  141. val.forEach(item => {
  142. let res = this.selectAllData.every(item2 => item[this.idName] != item2[this.idName])
  143. console.log(res);
  144. res ? this.selectAllData.push(item) : ''
  145. })
  146. }
  147. },
  148. onSbmit () {
  149. this.$emit('onResult',this.selectAllData)
  150. this.$refs.tables.clearSelection()
  151. console.log(this.$refs.tables.clearSelection);
  152. this.selectAllData = []
  153. this.selectRowId = []
  154. this.drawer = false
  155. },
  156. handleSizeChange(val) {
  157. // console.log(`每页 ${val} 条`);
  158. this.param.content.pageSize = val
  159. this.listData()
  160. },
  161. handleCurrentChange(val) {
  162. // console.log(`当前页: ${val}`);
  163. this.param.content.pageNumber = val
  164. this.listData()
  165. },
  166. },
  167. mounted () {
  168. }
  169. }
  170. </script>
  171. <style>
  172. </style>