wuHanReimbursementSelectDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="选择"
  5. width="1100px"
  6. :close-on-click-modal="false"
  7. :append-to-body="true"
  8. v-dialogDrag
  9. class="userDialog"
  10. :visible.sync="visible">
  11. <el-container style="height: 500px">
  12. <el-container>
  13. <el-header style="text-align: left; font-size: 12px;height:30px">
  14. <el-form size="small" :inline="true" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
  15. <el-form-item prop="invoiceNumber">
  16. <el-input size="small" v-model="searchForm.invoiceNumber" placeholder="发票号码" clearable></el-input>
  17. </el-form-item>
  18. <el-form-item prop="proposer">
  19. <el-input size="small" v-model="searchForm.proposer" placeholder="项目经理" clearable></el-input>
  20. </el-form-item>
  21. <el-form-item prop="partner">
  22. <el-input size="small" v-model="searchForm.partner" placeholder="部门" clearable></el-input>
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="primary" @click="refreshList()" size="small" icon="el-icon-search">查询</el-button>
  26. <el-button @click="resetSearch()" size="small" icon="el-icon-refresh-right">重置</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </el-header>
  30. <el-main>
  31. <el-table
  32. :data="dataList"
  33. v-loading="loading"
  34. size="small"
  35. border
  36. ref="userTable"
  37. @selection-change="selectionChangeHandle"
  38. @sort-change="sortChangeHandle"
  39. height="calc(100% - 40px)"
  40. style="width: 100%;">
  41. <el-table-column
  42. header-align="center"
  43. align="center"
  44. v-if="limit <= 1"
  45. width="50">
  46. <template slot-scope="scope">
  47. <el-radio :label="scope.row.id" :value="dataListAllSelections[0]&&dataListAllSelections[0].id" @change.native="getTemplateRow(scope.$index,scope.row)"><span></span></el-radio>
  48. </template>
  49. </el-table-column>
  50. <el-table-column
  51. type="selection"
  52. header-align="center"
  53. v-if="limit > 1"
  54. align="center"
  55. width="50">
  56. </el-table-column>
  57. <el-table-column
  58. prop="invoiceNumber"
  59. header-align="center"
  60. align="center"
  61. min-width="90"
  62. label="发票号码">
  63. </el-table-column>
  64. <el-table-column
  65. prop="money"
  66. header-align="center"
  67. align="center"
  68. min-width="90"
  69. label="金额">
  70. </el-table-column>
  71. <el-table-column
  72. prop="tax"
  73. header-align="center"
  74. align="center"
  75. min-width="110"
  76. label="税额">
  77. </el-table-column>
  78. <el-table-column
  79. prop="income"
  80. header-align="center"
  81. align="center"
  82. min-width="110"
  83. label="收入">
  84. </el-table-column>
  85. <el-table-column
  86. prop="proposer"
  87. header-align="center"
  88. align="center"
  89. min-width="110"
  90. label="项目经理">
  91. </el-table-column>
  92. <el-table-column
  93. prop="partner"
  94. header-align="center"
  95. align="center"
  96. min-width="110"
  97. label="部门">
  98. </el-table-column>
  99. </el-table>
  100. <el-pagination
  101. @size-change="sizeChangeHandle"
  102. @current-change="currentChangeHandle"
  103. :current-page="pageNo"
  104. :page-sizes="[5, 10, 50, 100]"
  105. :page-size="pageSize"
  106. :total="total"
  107. layout="total, sizes, prev, pager, next, jumper">
  108. </el-pagination>
  109. </el-main>
  110. </el-container>
  111. <el-aside width="200px">
  112. <el-tag
  113. :key="tag.id"
  114. v-for="tag in dataListAllSelections"
  115. closable
  116. :disable-transitions="false"
  117. @close="del(tag)">
  118. {{tag.invoiceNumber}}
  119. </el-tag>
  120. </el-aside>
  121. </el-container>
  122. <span slot="footer" class="dialog-footer">
  123. <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
  124. <el-button size="small" type="primary" icon="el-icon-circle-check" @click="doSubmit()">确定</el-button>
  125. </span>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. export default {
  131. data () {
  132. return {
  133. searchForm: {
  134. invoiceNumber: '',
  135. proposer: '',
  136. partner: ''
  137. },
  138. filterText: '',
  139. dataListAllSelections: [], // 所有选中的数据包含跨页数据
  140. dataListSelections: [],
  141. idKey: 'id', // 标识列表数据中每一行的唯一键的名称(需要按自己的数据改一下)
  142. dataList: [],
  143. dynamicTags: [],
  144. officeTreeData: [],
  145. pageNo: 1,
  146. pageSize: 10,
  147. total: 0,
  148. orders: [],
  149. loading: false,
  150. visible: false
  151. }
  152. },
  153. props: {
  154. selectData: {
  155. type: Array,
  156. default: () => { return [] }
  157. },
  158. limit: {
  159. type: Number,
  160. default: 999999
  161. }
  162. },
  163. watch: {
  164. filterText (val) {
  165. this.$refs.officeTree.filter(val)
  166. }
  167. },
  168. methods: {
  169. init () {
  170. this.visible = true
  171. this.$nextTick(() => {
  172. this.dataListAllSelections = JSON.parse(JSON.stringify(this.selectData))
  173. this.refreshTree()
  174. this.resetSearch()
  175. })
  176. },
  177. renderContent (h, { node, data, store }) {
  178. return (
  179. <span class="custom-tree-node">
  180. {
  181. data.type === '1' ? <i class="fa fa-sitemap"></i> : <i class="fa fa-users"></i>
  182. }
  183. <span class="text">{node.label}</span>
  184. </span>
  185. )
  186. },
  187. getTemplateRow (index, row) { // 获取选中数据
  188. this.dataListSelections = [row]
  189. this.$nextTick(() => {
  190. this.changePageCoreRecordData()
  191. })
  192. },
  193. // 设置选中的方法
  194. setSelectRow () {
  195. if (!this.dataListAllSelections || this.dataListAllSelections.length <= 0) {
  196. this.$refs.userTable.clearSelection()
  197. return
  198. }
  199. // 标识当前行的唯一键的名称
  200. let idKey = this.idKey
  201. let selectAllIds = []
  202. this.dataListAllSelections.forEach(row => {
  203. selectAllIds.push(row[idKey])
  204. })
  205. this.$refs.userTable.clearSelection()
  206. for (var i = 0; i < this.dataList.length; i++) {
  207. if (selectAllIds.indexOf(this.dataList[i][idKey]) >= 0) {
  208. // 设置选中,记住table组件需要使用ref="table"
  209. this.$refs.userTable.toggleRowSelection(this.dataList[i], true)
  210. }
  211. }
  212. },
  213. // 记忆选择核心方法
  214. changePageCoreRecordData () {
  215. // 标识当前行的唯一键的名称
  216. let idKey = this.idKey
  217. let that = this
  218. // 如果总记忆中还没有选择的数据,那么就直接取当前页选中的数据,不需要后面一系列计算
  219. if (this.dataListAllSelections.length <= 0) {
  220. this.dataListSelections.forEach(row => {
  221. that.dataListAllSelections.push(row)
  222. })
  223. return
  224. }
  225. // 总选择里面的key集合
  226. let selectAllIds = []
  227. this.dataListAllSelections.forEach(row => {
  228. selectAllIds.push(row[idKey])
  229. })
  230. let selectIds = []
  231. // 获取当前页选中的id
  232. this.dataListSelections.forEach(row => {
  233. selectIds.push(row[idKey])
  234. // 如果总选择里面不包含当前页选中的数据,那么就加入到总选择集合里
  235. if (selectAllIds.indexOf(row[idKey]) < 0) {
  236. that.dataListAllSelections.push(row)
  237. }
  238. })
  239. let noSelectIds = []
  240. // 得到当前页没有选中的id
  241. this.dataList.forEach(row => {
  242. if (selectIds.indexOf(row[idKey]) < 0) {
  243. noSelectIds.push(row[idKey])
  244. }
  245. })
  246. noSelectIds.forEach(id => {
  247. if (selectAllIds.indexOf(id) >= 0) {
  248. for (let i = 0; i < that.dataListAllSelections.length; i++) {
  249. if (that.dataListAllSelections[i][idKey] === id) {
  250. // 如果总选择中有未被选中的,那么就删除这条
  251. that.dataListAllSelections.splice(i, 1)
  252. break
  253. }
  254. }
  255. }
  256. })
  257. },
  258. // 得到选中的所有数据
  259. getAllSelectionData () {
  260. // 再执行一次记忆勾选数据匹配,目的是为了在当前页操作勾选后直接获取选中数据
  261. this.changePageCoreRecordData()
  262. },
  263. filterNode (value, data) {
  264. if (!value) return true
  265. return data.name.indexOf(value) !== -1
  266. },
  267. del (tag) {
  268. this.dataListAllSelections.splice(this.dataListAllSelections.indexOf(tag), 1)
  269. this.$nextTick(() => {
  270. this.setSelectRow()
  271. })
  272. },
  273. // 获取数据列表
  274. refreshList () {
  275. this.loading = true
  276. this.$http({
  277. url: '/wuHanReimbursement/list',
  278. method: 'get',
  279. params: {
  280. 'current': this.pageNo,
  281. 'size': this.pageSize,
  282. 'orders': this.orders,
  283. ...this.searchForm
  284. }
  285. }).then(({data}) => {
  286. this.dataList = data.records
  287. this.total = data.total
  288. this.pageNo = data.current
  289. this.loading = false
  290. this.$nextTick(() => {
  291. this.setSelectRow()
  292. })
  293. })
  294. },
  295. refreshTree () {
  296. this.$http({
  297. url: `/sys/office/treeData`,
  298. method: 'get'
  299. }).then(({data}) => {
  300. this.officeTreeData = data
  301. })
  302. },
  303. // 每页数
  304. sizeChangeHandle (val) {
  305. this.pageSize = val
  306. this.pageNo = 1
  307. this.refreshList()
  308. this.$nextTick(() => {
  309. this.changePageCoreRecordData()
  310. })
  311. },
  312. // 当前页
  313. currentChangeHandle (val) {
  314. this.pageNo = val
  315. this.refreshList()
  316. this.$nextTick(() => {
  317. this.changePageCoreRecordData()
  318. })
  319. },
  320. // 多选
  321. selectionChangeHandle (val) {
  322. this.dataListSelections = val
  323. this.$nextTick(() => {
  324. this.changePageCoreRecordData()
  325. })
  326. },
  327. // 排序
  328. sortChangeHandle (column) {
  329. this.orders = []
  330. if (column.order != null) {
  331. this.orders.push({column: this.$utils.toLine(column.prop), asc: column.order === 'ascending'})
  332. }
  333. this.refreshList()
  334. },
  335. resetSearch () {
  336. this.$refs.searchForm.resetFields()
  337. this.refreshList()
  338. },
  339. doSubmit () {
  340. if (this.limit < this.dataListAllSelections.length) {
  341. this.$message.error(`你最多只能选择${this.limit}个发票信息`)
  342. return
  343. }
  344. this.visible = false
  345. this.$emit('doSubmit', this.dataListAllSelections)
  346. }
  347. }
  348. }
  349. </script>
  350. <style lang="scss">
  351. .org {
  352. height: 100%;
  353. .el-card__header {
  354. padding: 10px;
  355. }
  356. .el-card__body {
  357. padding: 10px;
  358. max-height: 520px;
  359. overflow: auto;
  360. }
  361. }
  362. .userDialog{
  363. .el-dialog__body {
  364. padding: 10px 0px 0px 10px;
  365. color: #606266;
  366. font-size: 14px;
  367. word-break: break-all;
  368. }
  369. .el-main {
  370. padding: 20px 20px 5px 20px;
  371. .el-pagination{
  372. margin-top: 5px;
  373. }
  374. }
  375. }
  376. </style>