selectList.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. export default {
  2. data() {
  3. return {
  4. /** 多选 */
  5. selectList: [],
  6. selectTabelList: [],
  7. multipleSelection_1: [],
  8. moveSelected: null,
  9. moveSelected1: null,
  10. flag: false,//是搜开启拖拽的标志
  11. oldLeft: 0,//鼠标按下时的left,top
  12. oldTop: 0,
  13. selectedList: [],//拖拽多选选中的块集合
  14. isToLeft: true,
  15. isToTop: true,
  16. }
  17. },
  18. mounted() {
  19. this.moveSelected = document.getElementById('moveSelected')
  20. this.moveSelected1 = document.getElementById('sm-scroll-box')
  21. },
  22. methods: {
  23. // 鼠标按下时开启拖拽多选,将遮罩定位并展现
  24. mousedownFun(event) {
  25. if(event.button != 0) return
  26. this.selectedList = []
  27. this.selectList = []
  28. if(event.srcElement.getAttribute('dragSelectId')){
  29. console.log("鼠标开始的的元素=====",event.srcElement)
  30. let obj = {
  31. Id: event.srcElement.getAttribute('dragSelectId'),
  32. index: event.srcElement.getAttribute('dragSelectIndex'),
  33. key: event.srcElement.getAttribute('dragSelectKey'),
  34. current: event.srcElement.getAttribute('dragSelectCurrent'),
  35. }
  36. this.selectedList.push(obj)
  37. }
  38. this.flag=true;
  39. let offsetTop = this.moveSelected1.getBoundingClientRect().y
  40. let offsetLeft = this.moveSelected1.getBoundingClientRect().x
  41. this.moveSelected.style.top=(event.pageY-offsetTop)+'px';
  42. this.moveSelected.style.left=(event.pageX-offsetLeft)+'px';
  43. this.oldLeft=event.pageX;
  44. this.oldTop=event.pageY;
  45. event.preventDefault(); // 阻止默认行为
  46. event.stopPropagation(); // 阻止事件冒泡
  47. },
  48. // 鼠标移动时计算遮罩的位置,宽 高
  49. mousemoveFun(event) {
  50. if(!this.flag) return;//只有开启了拖拽,才进行mouseover操作
  51. //console.log("经过的元素=====",event.srcElement)
  52. if(event.srcElement.getAttribute('dragSelectId')){
  53. let obj = {
  54. Id: event.srcElement.getAttribute('dragSelectId'),
  55. index: event.srcElement.getAttribute('dragSelectIndex'),
  56. key: event.srcElement.getAttribute('dragSelectKey'),
  57. current: event.srcElement.getAttribute('dragSelectCurrent'),
  58. }
  59. this.selectedList.push(obj)
  60. }
  61. let offsetTop = this.moveSelected1.getBoundingClientRect().y
  62. let offsetLeft = this.moveSelected1.getBoundingClientRect().x
  63. if(event.pageX<this.oldLeft){//向左拖
  64. this.isToLeft = true
  65. this.moveSelected.style.left=(event.pageX-offsetLeft)+'px';
  66. this.moveSelected.style.width=(this.oldLeft-event.pageX)+'px';
  67. }else{
  68. this.isToLeft = false
  69. this.moveSelected.style.width=(event.pageX-this.oldLeft)+'px';
  70. }
  71. if(event.pageY<this.oldTop){//向上
  72. this.isToTop = true
  73. this.moveSelected.style.top=(event.pageY-offsetTop)+'px';
  74. this.moveSelected.style.height=(this.oldTop-event.pageY)+'px';
  75. }else{
  76. this.isToTop = false
  77. this.moveSelected.style.height=(event.pageY-this.oldTop)+'px';
  78. }
  79. event.preventDefault(); // 阻止默认行为
  80. event.stopPropagation(); // 阻止事件冒泡
  81. },
  82. //鼠标抬起时计算遮罩的right 和 bottom,找出遮罩覆盖的块,关闭拖拽选中开关,清除遮罩数据
  83. mouseupFun(event) {
  84. if(event.button != 0) return
  85. if(event.srcElement.getAttribute('dragSelectId')){
  86. console.log("鼠标结束的的元素=====",event,event.srcElement)
  87. let obj = {
  88. Id: event.srcElement.getAttribute('dragSelectId'),
  89. index: event.srcElement.getAttribute('dragSelectIndex'),
  90. key: event.srcElement.getAttribute('dragSelectKey'),
  91. current: event.srcElement.getAttribute('dragSelectCurrent'),
  92. }
  93. this.selectedList.push(obj)
  94. }
  95. this.moveSelected.style.bottom=Number(this.moveSelected.style.top.split('px')[0])+Number(this.moveSelected.style.height.split('px')[0]) + 'px';
  96. this.moveSelected.style.right=Number(this.moveSelected.style.left.split('px')[0])+Number(this.moveSelected.style.width.split('px')[0])+'px';
  97. this.findSelected();
  98. this.flag=false;
  99. this.clearDragData();
  100. event.preventDefault(); // 阻止默认行为
  101. event.stopPropagation(); // 阻止事件冒泡
  102. },
  103. mouseleaveFun(event) {
  104. this.flag=false;
  105. this.moveSelected.style.width=0;
  106. this.moveSelected.style.height=0;
  107. this.moveSelected.style.top=0;
  108. this.moveSelected.style.left=0;
  109. event.preventDefault(); // 阻止默认行为
  110. event.stopPropagation(); // 阻止事件冒泡
  111. },
  112. findSelected(){
  113. let list = []
  114. if(this.selectedList && this.selectedList.length >= 2) {
  115. let firstObj = this.selectedList[0]
  116. let lastObj = this.selectedList[this.selectedList.length-1]
  117. this.tableData.forEach((item,index)=>{
  118. if(!this.isToLeft&&!this.isToTop){ // 向右下
  119. if(index>=firstObj.index && index<=lastObj.index) {
  120. item[firstObj.key].forEach((item1,index1)=>{
  121. if(index1>=firstObj.current && index1<=lastObj.current) {
  122. list.push(item1.tableId)
  123. }
  124. })
  125. }
  126. }else if(this.isToLeft&&!this.isToTop){ // 向左下
  127. if(index>=firstObj.index && index<=lastObj.index) {
  128. item[firstObj.key].forEach((item1,index1)=>{
  129. if(index1<=firstObj.current && index1>=lastObj.current) {
  130. list.push(item1.tableId)
  131. }
  132. })
  133. }
  134. }else if(this.isToLeft&&this.isToTop){ // 向左上
  135. if(index<=firstObj.index && index>=lastObj.index) {
  136. item[firstObj.key].forEach((item1,index1)=>{
  137. if(index1<=firstObj.current && index1>=lastObj.current) {
  138. list.push(item1.tableId)
  139. }
  140. })
  141. }
  142. }else if(!this.isToLeft&&this.isToTop){ // 向右上
  143. if(index<=firstObj.index && index>=lastObj.index) {
  144. item[firstObj.key].forEach((item1,index1)=>{
  145. if(index1>=firstObj.current && index1<=lastObj.current) {
  146. list.push(item1.tableId)
  147. }
  148. })
  149. }
  150. }
  151. })
  152. }else if(this.selectedList && this.selectedList.length == 1){
  153. list = this.selectedList[0].id
  154. }
  155. this.selectList = [...new Set(list)]
  156. console.log("e===",this.selectList)
  157. if(this.activeName=='select'){
  158. this.addSelectTabelList()
  159. }
  160. },
  161. findSelectedCopy(){
  162. return
  163. let blockList= document.getElementsByClassName('row-item');
  164. let selectedList = []
  165. for(let i=0;i<blockList.length;i++){
  166. //计算每个块的定位信息
  167. // let left=blockList[i].offsetLeft;
  168. // let right=blockList[i].style.width+left;
  169. // let top=blockList[i].offsetTop;
  170. // let bottom=blockList[i].style.height()+top;
  171. let left=$(blockList[i]).offset().left;
  172. let right=$(blockList[i]).width()+left;
  173. let top=$(blockList[i]).offset().top;
  174. let bottom=$(blockList[i]).height()+top;
  175. //判断每个块是否被遮罩盖住(即选中)
  176. let leftFlag=this.moveSelected.style.left.split('px')[0]<=left && left<=this.moveSelected.style.right.split('px')[0];
  177. let rightFlag=this.moveSelected.style.left.split('px')[0]<=right && right<=this.moveSelected.style.right.split('px')[0];
  178. let topFlag=this.moveSelected.style.top.split('px')[0]<=top && top<=this.moveSelected.style.bottom.split('px')[0];
  179. let bottomFlag=this.moveSelected.style.top.split('px')[0]<=bottom && bottom<=this.moveSelected.style.bottom.split('px')[0];
  180. if((leftFlag || rightFlag) && (topFlag || bottomFlag)){
  181. console.log("位置===",left,right,top,bottom)
  182. selectedList.push(blockList[i]);
  183. }
  184. }
  185. let list = []
  186. for(let i=0; i < selectedList.length; i++) {
  187. list.push(selectedList[i].getAttribute('dragSelectId'))
  188. }
  189. this.selectList = [...new Set(list)]
  190. console.log("e===",this.selectList)
  191. if(this.activeName=='select'){
  192. this.addSelectTabelList()
  193. }
  194. console.log("selectedList====",selectedList);
  195. console.log("list====",list);
  196. },
  197. clearDragData(){
  198. this.moveSelected.style.width=0;
  199. this.moveSelected.style.height=0;
  200. this.moveSelected.style.top=0;
  201. this.moveSelected.style.left=0;
  202. this.moveSelected.style.bottom=0;
  203. this.moveSelected.style.right=0;
  204. },
  205. /** 当前选择 开始 */
  206. /** 多选 */
  207. dragSelectChange(e){
  208. console.log("e===",e)
  209. if(e && e.div) {
  210. let list = JSON.parse(JSON.stringify(e.div))
  211. this.selectList = [...new Set(list)]
  212. console.log("e===",this.selectList)
  213. if(this.activeName=='select'){
  214. this.addSelectTabelList()
  215. }
  216. }
  217. },
  218. dragLostItemChange(e){
  219. console.log("最后一个===",e)
  220. },
  221. reSelect(e) {
  222. console.log("reSelect===",e)
  223. },
  224. addSelectTabelList(){
  225. if(this.selectList && this.selectList.length > 0) {
  226. let listTabel = []
  227. for(let i=0;i<this.selectList.length;i++){
  228. for(let j=0;j<this.tableDataAll.length;j++){
  229. if(this.selectList[i] == this.tableDataAll[j].styleCss.id){
  230. listTabel.push({
  231. ...this.tableDataAll[j],
  232. })
  233. break;
  234. }
  235. }
  236. }
  237. console.log("listTabel=====",listTabel)
  238. this.selectTabelList = JSON.parse(JSON.stringify(listTabel))
  239. }else {
  240. this.selectTabelList = []
  241. }
  242. },
  243. // 清除已选
  244. delSelectTabelList(){
  245. this.selectList = []
  246. this.selectTabelList = []
  247. },
  248. /** 当前选择 结束 */
  249. /** 批量修改 */
  250. // 座位状态
  251. selectBatchSetaDisableFun() {
  252. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  253. for(let i=0;i<this.selectTabelList.length;i++){
  254. for(let j=0;j<this.tableDataAll.length;j++){
  255. if(this.selectTabelList[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  256. listTabel[j] = {
  257. ...this.tableDataAll[j],
  258. status: this.formAll.status,
  259. }
  260. break;
  261. }
  262. }
  263. }
  264. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  265. console.log("this.tableDataAll=====",this.tableDataAll)
  266. // this.batchTableList = JSON.parse(JSON.stringify(this.tableDataAll))
  267. this.formDialogVisible = false
  268. this.handleQuery()
  269. this.dataProcess()
  270. },
  271. //批量修改座位类型
  272. selectBatchSetaTypeFun() {
  273. let color = ''
  274. let seatLabel = ''
  275. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  276. this.seatTypeList.forEach((item,index)=>{
  277. if(this.formAll.seatTypeId == item.id) {
  278. color = item.color
  279. seatLabel = item.name
  280. }
  281. })
  282. for(let i=0;i<this.selectTabelList.length;i++){
  283. for(let j=0;j<this.tableDataAll.length;j++){
  284. if(this.selectTabelList[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  285. listTabel[j] = {
  286. ...this.tableDataAll[j],
  287. seatLabel: seatLabel,
  288. color: color,// 座位类型对应的颜色
  289. seatTypeId: this.formAll.seatTypeId,
  290. }
  291. break;
  292. }
  293. }
  294. }
  295. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  296. console.log("this.tableDataAll=====",this.tableDataAll)
  297. // this.batchTableList = JSON.parse(JSON.stringify(this.tableDataAll))
  298. this.formDialogVisible = false
  299. this.dataProcess()
  300. this.addSelectTabelList()
  301. },
  302. // 批量修改名称
  303. selectBatchSetaNameFun() {
  304. if(this.formAll.seatWay == 1){ // 相同的
  305. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  306. for(let i=0;i<this.selectTabelList.length;i++){
  307. for(let j=0;j<this.tableDataAll.length;j++){
  308. if(this.selectTabelList[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  309. listTabel[j] = {
  310. ...this.tableDataAll[j],
  311. name: this.formAll.name
  312. }
  313. break;
  314. }
  315. }
  316. }
  317. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  318. }else if(this.formAll.seatWay == 2){
  319. let name = (this.formAll.name1?this.formAll.name1:'') + '${row}' + (this.formAll.name?this.formAll.name:'') + '${col}' + (this.formAll.name2?this.formAll.name2:'')
  320. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  321. for(let i=0;i<this.selectTabelList.length;i++){
  322. for(let j=0;j<this.tableDataAll.length;j++){
  323. if(this.selectTabelList[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  324. listTabel[j] = {
  325. ...this.tableDataAll[j],
  326. name: name.replace('${row}',this.tableDataAll[j].rowNo).replace('${col}',this.tableDataAll[j].columnNo)
  327. }
  328. break;
  329. }
  330. }
  331. }
  332. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  333. }
  334. this.formDialogVisible = false
  335. this.dataProcess()
  336. this.addSelectTabelList()
  337. },
  338. // 批量修改优先级
  339. selectBatchSetaPriorityFun(){
  340. if(this.formAll.seatPriorityWay == 1){
  341. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  342. for(let i=0;i<this.selectTabelList.length;i++){
  343. for(let j=0;j<this.tableDataAll.length;j++){
  344. if(this.selectTabelList[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  345. listTabel[j] = {
  346. ...this.tableDataAll[j],
  347. priority: this.formAll.setaPriorityNum
  348. }
  349. break;
  350. }
  351. }
  352. }
  353. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  354. }else{
  355. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  356. let listSelect = JSON.parse(JSON.stringify(this.selectTabelList))
  357. if(this.formAll.seatPriorityPosition == 2) {
  358. listSelect.reverse()
  359. }
  360. console.log("fsafsdfa=====",listSelect)
  361. let num = Number(this.formAll.setaPriorityNum)
  362. for(let i=0;i<listSelect.length;i++){
  363. for(let j=0;j<this.tableDataAll.length;j++){
  364. if(listSelect[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  365. listTabel[j] = {
  366. ...this.tableDataAll[j],
  367. priority: num
  368. }
  369. if(this.formAll.seatPriorityWay == 2){
  370. num = num + 1
  371. }else if(this.formAll.seatPriorityWay == 3){
  372. num = num - 1
  373. }
  374. break;
  375. }
  376. }
  377. }
  378. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  379. }
  380. this.formDialogVisible = false
  381. this.dataProcess()
  382. this.addSelectTabelList()
  383. },
  384. // 批量修改出票顺序
  385. selectTicketingSequenceFun(){
  386. console.log("this.formAll=====",this.formAll)
  387. if(this.formAll.printSortIdType == 1) {
  388. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  389. for(let i=0;i<this.selectTabelList.length;i++){
  390. for(let j=0;j<this.tableDataAll.length;j++){
  391. if(this.selectTabelList[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  392. listTabel[j] = {
  393. ...this.tableDataAll[j],
  394. printSortId: '按优先级出票'
  395. }
  396. break;
  397. }
  398. }
  399. }
  400. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  401. }else if(this.formAll.seatPriorityWay == 1){
  402. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  403. for(let i=0;i<this.selectTabelList.length;i++){
  404. for(let j=0;j<this.tableDataAll.length;j++){
  405. if(this.selectTabelList[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  406. listTabel[j] = {
  407. ...this.tableDataAll[j],
  408. printSortId: this.formAll.setaPriorityNum
  409. }
  410. break;
  411. }
  412. }
  413. }
  414. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  415. }else{
  416. let listTabel = JSON.parse(JSON.stringify(this.tableDataAll))
  417. let listSelect = JSON.parse(JSON.stringify(this.selectTabelList))
  418. if(this.formAll.seatPriorityPosition == 2) {
  419. listSelect.reverse()
  420. }
  421. console.log("fsafsdfa=====",listSelect)
  422. let num = Number(this.formAll.setaPriorityNum)
  423. for(let i=0;i<listSelect.length;i++){
  424. for(let j=0;j<this.tableDataAll.length;j++){
  425. if(listSelect[i].styleCss.id == this.tableDataAll[j].styleCss.id){
  426. listTabel[j] = {
  427. ...this.tableDataAll[j],
  428. printSortId: num
  429. }
  430. if(this.formAll.seatPriorityWay == 2){
  431. num = num + 1
  432. }else if(this.formAll.seatPriorityWay == 3){
  433. num = num - 1
  434. }
  435. break;
  436. }
  437. }
  438. }
  439. this.tableDataAll = JSON.parse(JSON.stringify(listTabel))
  440. }
  441. this.formDialogVisible = false
  442. this.dataProcess()
  443. this.addSelectTabelList()
  444. },
  445. },
  446. }