Blame view
src/components/uni-swipe-action-item/mpalipay.js
2.81 KB
61d825263 确认订单修改 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
export default { data() { return { isshow: false, viewWidth: 0, buttonWidth: 0, disabledView: false, x: 0, transition: false } }, watch: { show(newVal) { if (this.autoClose) return if (newVal) { this.open() } else { this.close() } }, }, created() { if (this.swipeaction.children !== undefined) { this.swipeaction.children.push(this) } }, beforeDestroy() { this.swipeaction.children.forEach((item, index) => { if (item === this) { this.swipeaction.children.splice(index, 1) } }) }, mounted() { this.isopen = false this.transition = true setTimeout(() => { this.getQuerySelect() }, 50) }, methods: { onClick(index, item) { this.$emit('click', { content: item, index }) }, touchstart(e) { let { pageX, pageY } = e.changedTouches[0] this.transition = false this.startX = pageX if (this.autoClose) { this.swipeaction.closeOther(this) } }, touchmove(e) { let { pageX, } = e.changedTouches[0] this.slide = this.getSlide(pageX) if (this.slide === 0) { this.disabledView = false } }, touchend(e) { this.stop = false this.transition = true if (this.isopen) { if (this.moveX === -this.buttonWidth) { this.close() return } this.move() } else { if (this.moveX === 0) { this.close() return } this.move() } }, open() { this.x = this.moveX this.$nextTick(() => { this.x = -this.buttonWidth this.moveX = this.x if(!this.isopen){ this.isopen = true this.$emit('change', true) } }) }, close() { this.x = this.moveX this.$nextTick(() => { this.x = 0 this.moveX = this.x if(this.isopen){ this.isopen = false this.$emit('change', false) } }) }, move() { if (this.slide === 0) { this.open() } else { this.close() } }, onChange(e) { let x = e.detail.x this.moveX = x if (x >= this.buttonWidth) { this.disabledView = true this.$nextTick(() => { this.x = this.buttonWidth }) } }, getSlide(x) { if (x >= this.startX) { this.startX = x return 1 } else { this.startX = x return 0 } }, getQuerySelect() { const query = uni.createSelectorQuery().in(this); query.selectAll('.viewWidth-hook').boundingClientRect(data => { this.viewWidth = data[0].width this.buttonWidth = data[1].width this.transition = false this.$nextTick(() => { this.transition = true }) if (!this.buttonWidth) { this.disabledView = true } if (this.autoClose) return if (this.show) { this.open() } }).exec(); } } } |