selectList.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. startX: 0,
  17. startY: 0,
  18. endX: 0,
  19. endY: 0,
  20. isMousemove: false,
  21. scrollTop: 0,
  22. scrollLeft: 0,
  23. }
  24. },
  25. mounted() {
  26. this.flag = false
  27. this.$refs.seatbox.addEventListener('mousemove', this.mousemoveFun);
  28. this.$refs.seatbox.addEventListener('mouseup', this.mouseupFun);
  29. this.moveSelected = document.getElementById('moveSelected')
  30. this.moveSelected1 = document.getElementById('sm-scroll-box')
  31. },
  32. methods: {
  33. // 鼠标按下时开启拖拽多选,将遮罩定位并展现
  34. mousedownFun(event) {
  35. console.log("鼠标按下!!!",event.target.scrollTop,event.target.scrollLeft)
  36. if(event.button != 0) return
  37. //this.selectedList = []
  38. // this.selectList = []
  39. this.flag=true;
  40. let offsetTop = this.moveSelected1.getBoundingClientRect().y
  41. let offsetLeft = this.moveSelected1.getBoundingClientRect().x
  42. this.moveSelected.style.top=( event.pageY - offsetTop - 5 + this.screenTop )+'px';
  43. this.moveSelected.style.left=( event.pageX - offsetLeft - 5 + this.scrollLeft )+'px';
  44. this.oldLeft=event.pageX;
  45. this.oldTop=event.pageY;
  46. this.startX=event.pageX;
  47. this.startY=event.pageY;
  48. event.preventDefault(); // 阻止默认行为
  49. event.stopPropagation(); // 阻止事件冒泡
  50. },
  51. // 鼠标移动时计算遮罩的位置,宽 高
  52. mousemoveFun(event) {
  53. if(!this.flag) return;//只有开启了拖拽,才进行mouseover操作
  54. console.log("鼠标移动!!!",this.moveSelected.style.width,this.moveSelected.style.height)
  55. this.endX=event.pageX;
  56. this.endY=event.pageY;
  57. let offsetTop = this.moveSelected1.getBoundingClientRect().y
  58. let offsetLeft = this.moveSelected1.getBoundingClientRect().x
  59. if(event.pageX<this.oldLeft){//向左拖
  60. this.isToLeft = true
  61. this.moveSelected.style.left=(event.pageX-offsetLeft + this.scrollLeft)+'px';
  62. this.moveSelected.style.width=(this.oldLeft-event.pageX)+'px';
  63. }else{
  64. this.isToLeft = false
  65. this.moveSelected.style.width=(event.pageX-this.oldLeft)+'px';
  66. }
  67. if(event.pageY<this.oldTop){//向上
  68. this.isToTop = true
  69. this.moveSelected.style.top=(event.pageY-offsetTop + this.screenTop )+'px';
  70. this.moveSelected.style.height=(this.oldTop-event.pageY)+'px';
  71. }else{
  72. this.isToTop = false
  73. this.moveSelected.style.height=(event.pageY-this.oldTop)+'px';
  74. }
  75. if((this.moveSelected.style.width && Number(this.moveSelected.style.width.replace('px','')) > 10) ||
  76. (this.moveSelected.style.height && Number(this.moveSelected.style.height.replace('px','')) > 10)){
  77. this.isMousemove = true
  78. }
  79. event.preventDefault(); // 阻止默认行为
  80. event.stopPropagation(); // 阻止事件冒泡
  81. },
  82. //鼠标抬起时计算遮罩的right 和 bottom,找出遮罩覆盖的块,关闭拖拽选中开关,清除遮罩数据
  83. mouseupFun(event) {
  84. console.log("鼠标抬起!!!")
  85. if(event.button != 0) return
  86. this.moveSelected.style.bottom=Number(this.moveSelected.style.top.split('px')[0])+Number(this.moveSelected.style.height.split('px')[0]) + 'px';
  87. this.moveSelected.style.right=Number(this.moveSelected.style.left.split('px')[0])+Number(this.moveSelected.style.width.split('px')[0])+'px';
  88. this.flag=false;
  89. if( this.isMousemove){
  90. this.getSelectItem()
  91. }else {
  92. // let id = event.srcElement.getAttribute('dragSelectId')
  93. // if(id){
  94. // this.seatMapListKey.forEach((item1,index1)=>{
  95. // this.seatMapList[item1.key].forEach((item,index)=>{
  96. // if(id = item.id){
  97. // this.seatClick(this.seatMapList[item1.key][index])
  98. // this.seatMapList[item1.key][index].isSelect = !this.seatMapList[item1.key][index].isSelect
  99. // }
  100. // })
  101. // })
  102. // this.$forceUpdate()
  103. // }
  104. }
  105. this.isMousemove = false
  106. this.clearDragData();
  107. event.preventDefault(); // 阻止默认行为
  108. event.stopPropagation(); // 阻止事件冒泡
  109. },
  110. mouseleaveFun(event) {
  111. this.flag=false;
  112. this.moveSelected.style.width='0px';
  113. this.moveSelected.style.height='0px';
  114. this.moveSelected.style.top='0px';
  115. this.moveSelected.style.left='0px';
  116. event.preventDefault(); // 阻止默认行为
  117. event.stopPropagation(); // 阻止事件冒泡
  118. },
  119. clearDragData(){
  120. this.moveSelected.style.width='0px';
  121. this.moveSelected.style.height='0px';
  122. this.moveSelected.style.top='0px';
  123. this.moveSelected.style.left='0px';
  124. this.moveSelected.style.bottom='0px';
  125. this.moveSelected.style.right='0px';
  126. },
  127. /** 批量判断元素的位置 */
  128. getSelectItem(){
  129. let list = document.getElementsByClassName('seat-item-class')
  130. let listCopy = []
  131. let drawDialog = document.getElementById("moveSelected");
  132. // 获取div元素的坐标点
  133. let rect = drawDialog.getBoundingClientRect();
  134. for(let i = 0; i < list.length; i++) {
  135. let rect_div = list[i].getBoundingClientRect();
  136. //console.log("rect===",list[i].getAttribute('index'),rect_div.top,rect_div.left)
  137. if(rect.top < (rect_div.top + rect_div.height) && rect.bottom > (rect_div.bottom - rect_div.height) &&
  138. rect.left < (rect_div.left + rect_div.width) && rect.right > (rect_div.right - rect_div.width)) {
  139. listCopy.push(list[i].getAttribute("dragSelectId"));
  140. }
  141. }
  142. let listCopy1 = [] // 已选择的座位
  143. listCopy.forEach((item,index)=>{
  144. this.setList.forEach((item1,index1)=>{
  145. if(item == item1.id ) {
  146. listCopy1.push(item1)
  147. }
  148. })
  149. })
  150. let flog = false;
  151. let seatTypeId = null
  152. let occupyStatus = listCopy1.length>0?listCopy1[0].occupyStatus:null
  153. for(let i = 0; i<listCopy1.length; i++) {
  154. let row = listCopy1[i]
  155. console.log("occupyStatus====",occupyStatus,row.occupyStatus)
  156. if(row.occupyStatus != occupyStatus) {
  157. this.$message.error('不能同时选择不同状态的座位!!!');
  158. flog = true
  159. break;
  160. }
  161. occupyStatus = row.occupyStatus
  162. // if(row.occupyStatus == 0) {
  163. // this.$message.error('不能选择已锁定的座位');
  164. // flog = true
  165. // break;
  166. // }
  167. if(row.isDisabled || row.status == 2) {
  168. this.$message.error('不能选择已售或不可售座位!!!');
  169. flog = true
  170. break;
  171. }
  172. if(row.channelType != 'window') {
  173. if(row.channelType) {
  174. this.$message.error(`不能选择非窗口出售的座位!!!`);
  175. flog = true
  176. break;
  177. }else if(row.isUse == 2){
  178. this.$message.error(`不能选择非窗口出售的座位!!!`);
  179. flog = true
  180. break;
  181. }
  182. }
  183. }
  184. if(flog){
  185. return
  186. }
  187. if(this.seatSelectListNo.length>0) {
  188. for(let i = 0; i<listCopy1.length; i++) {
  189. let row = listCopy1[i]
  190. if(row.occupyStatus != 0) {
  191. this.$message.error('你已选择锁定座位,只能再选择被锁定的座位!!!');
  192. flog = true
  193. break;
  194. }
  195. }
  196. }
  197. if(flog){
  198. return
  199. }
  200. if(this.seatSelectList.length>0) {
  201. for(let i = 0; i<listCopy1.length; i++) {
  202. let row = listCopy1[i]
  203. if(row.occupyStatus == 0) {
  204. this.$message.error('此座已被锁定,请先解锁!!!');
  205. flog = true
  206. break;
  207. }
  208. }
  209. }
  210. if(flog){
  211. return
  212. }
  213. listCopy1.forEach((item,index)=>{
  214. if(index == 0) {
  215. seatTypeId = item.seatTypeId
  216. }else {
  217. if(item.seatTypeId != seatTypeId) {
  218. flog = true
  219. }
  220. }
  221. })
  222. if(flog){
  223. this.$message.error('只能选同一类型的座位');
  224. return
  225. }
  226. listCopy1.forEach((item,index)=>{
  227. this.seatSelectList.forEach((item1,index1)=>{
  228. if(item.seatTypeId != item1.seatTypeId) {
  229. flog = true
  230. }
  231. })
  232. })
  233. if(flog){
  234. this.$message.error('只能选同一类型的座位');
  235. return
  236. }
  237. listCopy.forEach((item,index)=>{
  238. this.seatMapListKey.forEach((item1,index1)=>{
  239. this.seatMapList[item1.key].forEach((item,index)=>{
  240. if(listCopy.includes(item.id)){
  241. this.seatMapList[item1.key][index].isSelect = true
  242. }
  243. })
  244. })
  245. })
  246. let listCopy2 = []
  247. listCopy1.forEach((item,index)=>{
  248. let flag1 = false
  249. this.seatSelectList.forEach((item1,index1)=>{
  250. if(item.id == item1.id) {
  251. flag1 = true
  252. }
  253. })
  254. if(!flag1){
  255. listCopy2.push(item)
  256. }
  257. })
  258. if(occupyStatus == 0){
  259. this.seatSelectListNo = this.seatSelectListNo.concat(listCopy2)
  260. // 配置该用户 可以购买锁定票
  261. if(this.isBuylock === 1) {
  262. console.log(this.isBuylock,'this.isBuylock11');
  263. this.seatSelectList = this.seatSelectList.concat(listCopy2)
  264. }
  265. }else {
  266. this.seatSelectList = this.seatSelectList.concat(listCopy2)
  267. }
  268. this.$forceUpdate()
  269. console.log("listCopy===",listCopy)
  270. console.log("listCopy1===",listCopy1)
  271. },
  272. /** 清除全部已选 */
  273. clearSeatSelectListAll () {
  274. this.seatMapListKey.forEach((item1,index1)=>{
  275. this.seatMapList[item1.key].forEach((item,index)=>{
  276. this.seatMapList[item1.key][index].isSelect = false
  277. })
  278. })
  279. this.seatSelectList = []
  280. this.seatSelectListNo = []
  281. this.$forceUpdate()
  282. },
  283. /** 滚动的位置 */
  284. scrollFun(event) {
  285. console.log("滚动===!!!",event.target.scrollTop,event.target.scrollLeft)
  286. this.screenTop = event.target.scrollTop
  287. this.scrollLeft = event.target.scrollLeft
  288. },
  289. /** 座位大小 拖动变化是 */
  290. scaleNumInput() {
  291. console.log("sfasdfsfd===")
  292. this.$refs.seatbox.removeEventListener('mousemove', this.mousemoveFun);
  293. this.$refs.seatbox.removeEventListener('mouseup', this.mouseupFun);
  294. },
  295. scaleNumChange() {
  296. console.log("sfasdfsfd11111===")
  297. this.$refs.seatbox.removeEventListener('mousemove', this.mousemoveFun);
  298. this.$refs.seatbox.removeEventListener('mouseup', this.mouseupFun);
  299. setTimeout(()=>{
  300. this.$refs.seatbox.addEventListener('mousemove', this.mousemoveFun);
  301. this.$refs.seatbox.addEventListener('mouseup', this.mouseupFun);
  302. },500)
  303. }
  304. },
  305. watch: {
  306. scaleNum(){
  307. this.scaleNumInput()
  308. }
  309. },
  310. destroyed() {
  311. if(this.$refs.seatbox) {
  312. this.$refs.seatbox.removeEventListener('mousemove', this.mousemoveFun);
  313. this.$refs.seatbox.removeEventListener('mouseup', this.mouseupFun);
  314. }
  315. },
  316. }