fastSelectPatent.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // 选择专利js
  2. export const fastSelectPatent = {
  3. data() {
  4. return {
  5. // 数据
  6. tableData: [],
  7. //总数
  8. total: 0,
  9. //分页及选择专利的信息
  10. queryParams: {
  11. current: 1,
  12. size: 10,
  13. groupField: '0',
  14. selected: [],
  15. isAdd: [],
  16. isDelete: [],
  17. },
  18. //是否编辑//编辑按钮暂时隐藏,改为默认为true
  19. refresh: true,
  20. //选择的专利集合
  21. patentNoList: [],
  22. //选择总数
  23. selectedTotal: 0,
  24. //选择专利加载
  25. selectNumberLoading: false,
  26. // 起始位置
  27. startNumber: 1,
  28. // 结束位置
  29. endNumber: 0,
  30. // 判断是否是全部选择或范围选择
  31. quickSelect: false,
  32. quickSelectArr: [],
  33. }
  34. },
  35. methods: {
  36. // 是否刷新
  37. isRefresh() {
  38. this.refresh = false
  39. this.$nextTick(() => {
  40. this.refresh = true
  41. })
  42. },
  43. //快速选择
  44. handleSelectNumber(type) {
  45. switch (type) {
  46. case 0: //本页选择
  47. this.patentNoList = [...new Set(this.patentNoList.concat(this.$store.state.patent.records.map((item) => item.patentNo))),];
  48. this.queryParams.isAdd = [...new Set(this.queryParams.isAdd.concat(this.$store.state.patent.records.map((item) => item.patentNo))),];
  49. break;
  50. case 1: //全部选择
  51. this.startNumber = 1;
  52. this.endNumber = this.total;
  53. this.$set(this.queryParams, 'startNumber', 1)
  54. this.$set(this.queryParams, 'endNumber', this.total)
  55. case 2: //范围选择
  56. this.queryParams.isDelete = [];
  57. this.queryParams.isAdd = [];
  58. this.patentNoList = [];
  59. this.quickSelect = true;
  60. if (type == 2) {
  61. if (!Number(this.queryParams.startNumber) || !Number(this.queryParams.endNumber)) {
  62. this.$set(this.queryParams, 'startNumber', this.startNumber > 0 ? this.startNumber : 1)
  63. this.$set(this.queryParams, 'endNumber', this.endNumber > 0 ? this.endNumber : this.total)
  64. break;
  65. }
  66. this.startNumber = this.queryParams.startNumber;
  67. this.endNumber = this.queryParams.endNumber;
  68. }
  69. this.commonSwitch();
  70. break;
  71. }
  72. this.getSelectedTotal()
  73. this.isRefresh()
  74. },
  75. //每页全部选择或范围选择的专利
  76. commonSwitch() {
  77. var arr = []
  78. if (this.queryParams.size * this.queryParams.current >= this.startNumber) {
  79. if (this.queryParams.size * this.queryParams.current >= this.endNumber) {
  80. if (this.queryParams.size * (this.queryParams.current - 1) + 1 <= this.startNumber) {
  81. var a = this.startNumber - (this.queryParams.size * (this.queryParams.current - 1) + 1);
  82. var b = this.endNumber - (this.queryParams.size * (this.queryParams.current - 1) + 1);
  83. for (var y = a; y <= b; y++) {
  84. arr.push(this.tableData[y].patentNo)
  85. }
  86. } else {
  87. var a = this.queryParams.size * (this.queryParams.current - 1) + 1 - (this.queryParams.size * (this.queryParams.current - 1) + 1);
  88. var b = this.endNumber - (this.queryParams.size * (this.queryParams.current - 1) + 1);
  89. for (var y = a; y <= b; y++) {
  90. arr.push(this.tableData[y].patentNo)
  91. }
  92. }
  93. } else {
  94. if (this.queryParams.size * (this.queryParams.current - 1) + 1 <= this.startNumber) {
  95. var a = this.startNumber - (this.queryParams.size * (this.queryParams.current - 1) + 1);
  96. var b = this.queryParams.size * this.queryParams.current - (this.queryParams.size * (this.queryParams.current - 1) + 1);
  97. for (var y = a; y <= b; y++) {
  98. arr.push(this.tableData[y].patentNo)
  99. }
  100. } else {
  101. var a = this.queryParams.size * (this.queryParams.current - 1) + 1 - (this.queryParams.size * (this.queryParams.current - 1) + 1);
  102. var b = this.queryParams.size * this.queryParams.current - (this.queryParams.size * (this.queryParams.current - 1) + 1);
  103. for (var y = a; y <= b; y++) {
  104. arr.push(this.tableData[y].patentNo)
  105. }
  106. }
  107. }
  108. }
  109. // this.patentNoList = JSON.parse(JSON.stringify(arr))
  110. this.quickSelectArr = JSON.parse(JSON.stringify(arr))
  111. this.getHaveChoose(arr)
  112. },
  113. //获取已选择的专利
  114. getHaveChoose(arr) {
  115. var arr1 = [...new Set(arr.concat(this.queryParams.isAdd))]
  116. this.patentNoList = arr1.filter((x) => this.queryParams.isDelete.indexOf(x) == -1)
  117. },
  118. //获取已选择的总条数
  119. getSelectedTotal() {
  120. this.selectedTotal = Number(this.endNumber) - Number(this.startNumber) + 1 + Number(this.queryParams.isAdd.length) - Number(this.queryParams.isDelete.length)
  121. },
  122. //获取手动选择的专利
  123. getChoosePatentNo(patentNo) {
  124. if (this.quickSelect) {
  125. var index = this.queryParams.isDelete.findIndex(item => {
  126. return item == patentNo
  127. })
  128. if (index == -1) {
  129. var index2 = this.quickSelectArr.findIndex(item => {
  130. return item == patentNo
  131. })
  132. if (index2 == -1) {
  133. this.setIsAdd(patentNo)
  134. } else {
  135. this.queryParams.isDelete.push(patentNo)
  136. }
  137. } else {
  138. this.queryParams.isDelete.splice(index, 1)
  139. }
  140. } else {
  141. this.setIsAdd(patentNo)
  142. }
  143. this.getSelectedTotal()
  144. },
  145. //是否加入isAdd里面
  146. setIsAdd(patentNo) {
  147. var index = this.queryParams.isAdd.findIndex(item => {
  148. return item == patentNo
  149. })
  150. if (index != -1) {
  151. this.queryParams.isAdd.splice(index, 1)
  152. } else {
  153. this.queryParams.isAdd.push(patentNo)
  154. }
  155. },
  156. //取消选择
  157. handleCancelSelectNumber() {
  158. this.patentNoList = [];
  159. this.queryParams.isAdd = []
  160. this.queryParams.isDelete = []
  161. this.startNumber = 1
  162. this.queryParams.startNumber = 1
  163. this.queryParams.endNumber = this.total
  164. this.endNumber = 0
  165. this.quickSelect = false
  166. this.selectedTotal = 0
  167. // this.getList()
  168. this.isRefresh()
  169. },
  170. // 范围选择起始数字框
  171. change1(val) {
  172. if (!isNaN(val)) {
  173. if (!val || val <= 0) {
  174. this.queryParams.startNumber = 1
  175. } else {
  176. if (this.queryParams.startNumber > this.total) {
  177. this.queryParams.startNumber = this.total
  178. }
  179. }
  180. } else {
  181. this.queryParams.startNumber = 1
  182. }
  183. },
  184. // 范围选择截止数字框
  185. change2(val) {
  186. if (!isNaN(val)) {
  187. if (!val || val <= 0) {
  188. this.queryParams.endNumber = this.total
  189. } else {
  190. if (this.queryParams.endNumber > this.total) {
  191. this.queryParams.endNumber = this.total
  192. }
  193. }
  194. } else {
  195. this.queryParams.endNumber = this.total
  196. }
  197. },
  198. },
  199. }