changeCalendar.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <view class="changeCalendar">
  3. <view class="zheZhao"></view>
  4. <view class="content">
  5. <view class="title">选择日期</view>
  6. <view class="cont">
  7. <view class="highLight" v-if="pcOrYd">
  8. <view
  9. class="left"
  10. :style="{ marginTop: top }"
  11. @touchstart="touchstart1"
  12. @touchmove="touchmove1"
  13. >
  14. <view
  15. v-for="(item, i) in yearList"
  16. :style="index1 == i ? { color: '#292C33' } : { color: '#DADEE6' }"
  17. >
  18. {{ item }}
  19. </view>
  20. </view>
  21. <view class="diagonalLine"> / </view>
  22. <view
  23. class="right"
  24. :style="{ marginTop: top2 }"
  25. @touchstart="touchstart2"
  26. @touchmove="touchmove2"
  27. >
  28. <view
  29. v-for="(item, i) in monthList"
  30. :style="index2 == i ? { color: '#292C33' } : { color: '#DADEE6' }"
  31. >
  32. {{ item }}
  33. </view>
  34. </view>
  35. </view>
  36. <view class="highLight" v-else>
  37. <view
  38. class="left"
  39. :style="{ marginTop: top }"
  40. @mousedown="mousedown1"
  41. >
  42. <view
  43. v-for="(item, i) in yearList"
  44. :style="index1 == i ? { color: '#292C33' } : { color: '#DADEE6' }"
  45. >
  46. {{ item }}
  47. </view>
  48. </view>
  49. <view class="diagonalLine"> / </view>
  50. <view
  51. class="right"
  52. :style="{ marginTop: top2 }"
  53. @mousedown="mousedown2"
  54. >
  55. <view
  56. v-for="(item, i) in monthList"
  57. :style="index2 == i ? { color: '#292C33' } : { color: '#DADEE6' }"
  58. >
  59. {{ item }}
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="change">
  65. <view class="cancel" @click="cancelCC">取消</view>
  66. <view class="sure" @click="sureCC">确定</view>
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import moment from "moment";
  73. export default {
  74. props: {
  75. changedYear: {},
  76. changedMonth: {},
  77. },
  78. data() {
  79. return {
  80. startYear: 1990,
  81. nowYear: moment().format("YYYY"),
  82. undYear: parseInt(moment().format("YYYY")) + 100,
  83. yearList: [],
  84. monthList: [
  85. "01",
  86. "02",
  87. "03",
  88. "04",
  89. "05",
  90. "06",
  91. "07",
  92. "08",
  93. "09",
  94. "10",
  95. "11",
  96. "12",
  97. ],
  98. top: "0rpx",
  99. top2: "0rpx",
  100. pageY: 0,
  101. pageY2: 0,
  102. index1: 0,
  103. index2: 0,
  104. pcOrYd: false,
  105. };
  106. },
  107. mounted() {
  108. if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
  109. this.pcOrYd = true;
  110. } else {
  111. this.pcOrYd = false;
  112. }
  113. let list = [];
  114. for (let i = this.startYear; i < this.undYear; i++) {
  115. list.push(i);
  116. }
  117. this.yearList = list;
  118. for (let i = 0; i < this.yearList.length; i++) {
  119. if (this.yearList[i] == this.changedYear) {
  120. this.top = -i * 80 + "rpx";
  121. this.index1 = i;
  122. }
  123. }
  124. for (let i = 0; i < this.monthList.length; i++) {
  125. if (this.monthList[i] == this.changedMonth) {
  126. this.top2 = -i * 80 + "rpx";
  127. this.index2 = i;
  128. }
  129. }
  130. },
  131. methods: {
  132. cancelCC() {
  133. this.$emit("cancelCC", false);
  134. },
  135. sureCC() {
  136. this.$emit(
  137. "sureCC",
  138. false,
  139. this.yearList[this.index1],
  140. this.monthList[this.index2]
  141. );
  142. },
  143. touchstart1() {
  144. this.pageY = event.touches[0].pageY;
  145. },
  146. touchmove1() {
  147. if (this.pageY < event.touches[0].pageY) {
  148. let dif = event.touches[0].pageY - this.pageY;
  149. this.index1 = this.index1 - Math.round(dif / 2);
  150. if (this.index1 <= 0) {
  151. this.index1 = 0;
  152. this.top = "0rpx";
  153. } else {
  154. this.top = -this.index1 * 80 + "rpx";
  155. }
  156. } else {
  157. let dif = this.pageY - event.touches[0].pageY;
  158. this.index1 = this.index1 + Math.round(dif / 2);
  159. if (this.index1 >= this.yearList.length - 1) {
  160. this.index1 = this.yearList.length - 1;
  161. this.top = -(this.yearList.length - 1) * 80 + "rpx";
  162. } else {
  163. this.top = -this.index1 * 80 + "rpx";
  164. }
  165. this.top = -this.index1 * 80 + "rpx";
  166. }
  167. this.pageY = event.touches[0].pageY;
  168. },
  169. touchstart2() {
  170. this.pageY2 = event.touches[0].pageY;
  171. },
  172. touchmove2() {
  173. if (this.pageY2 < event.touches[0].pageY) {
  174. let dif = event.touches[0].pageY - this.pageY2;
  175. this.index2 = this.index2 - Math.round(dif / 2);
  176. if (this.index2 <= 0) {
  177. this.index2 = 0;
  178. this.top2 = "0rpx";
  179. } else {
  180. this.top2 = -this.index2 * 80 + "rpx";
  181. }
  182. } else {
  183. let dif = this.pageY2 - event.touches[0].pageY;
  184. this.index2 = this.index2 + Math.round(dif / 2);
  185. if (this.index2 >= this.monthList.length - 1) {
  186. this.index2 = this.monthList.length - 1;
  187. this.top2 = -(this.monthList.length - 1) * 80 + "rpx";
  188. } else {
  189. this.top2 = -this.index2 * 80 + "rpx";
  190. }
  191. }
  192. this.pageY2 = event.touches[0].pageY;
  193. },
  194. mousedown1() {
  195. this.pageY = event.pageY;
  196. document.onmousemove = (e) => {
  197. if (this.pageY < e.pageY) {
  198. let dif = e.pageY - this.pageY;
  199. this.index1 = this.index1 - Math.round(dif / 2);
  200. if (this.index1 <= 0) {
  201. this.index1 = 0;
  202. this.top = "0rpx";
  203. } else {
  204. this.top = -this.index1 * 80 + "rpx";
  205. }
  206. } else {
  207. let dif = this.pageY - e.pageY;
  208. this.index1 = this.index1 + Math.round(dif / 2);
  209. if (this.index1 >= this.yearList.length - 1) {
  210. this.index1 = this.yearList.length - 1;
  211. this.top = -(this.yearList.length - 1) * 80 + "rpx";
  212. } else {
  213. this.top = -this.index1 * 80 + "rpx";
  214. }
  215. }
  216. this.pageY = e.pageY;
  217. };
  218. document.onmouseup = (e) => {
  219. document.onmousemove = null;
  220. document.onmouseup = null;
  221. };
  222. return false; //兼容firefox
  223. },
  224. mousedown2() {
  225. this.pageY2 = event.pageY;
  226. document.onmousemove = (e) => {
  227. if (this.pageY2 < e.pageY) {
  228. let dif = e.pageY - this.pageY2;
  229. this.index2 = this.index2 - Math.round(dif / 2);
  230. if (this.index2 <= 0) {
  231. this.index2 = 0;
  232. this.top2 = "0rpx";
  233. } else {
  234. this.top2 = -this.index2 * 80 + "rpx";
  235. }
  236. } else {
  237. let dif = this.pageY2 - e.pageY;
  238. this.index2 = this.index2 + Math.round(dif / 2);
  239. if (this.index2 >= this.monthList.length - 1) {
  240. this.index2 = this.monthList.length - 1;
  241. this.top2 = -(this.monthList.length - 1) * 80 + "rpx";
  242. } else {
  243. this.top2 = -this.index2 * 80 + "rpx";
  244. }
  245. }
  246. this.pageY2 = e.pageY;
  247. };
  248. document.onmouseup = (e) => {
  249. document.onmousemove = null;
  250. document.onmouseup = null;
  251. };
  252. return false; //兼容firefox
  253. },
  254. },
  255. };
  256. </script>
  257. <style lang="less">
  258. .changeCalendar {
  259. // margin-top: -105rpx;
  260. // width: 100%;
  261. // height: 100vh;
  262. // background: #12141A;
  263. // opacity: 0.5;
  264. // position: absolute;
  265. // left: 0rpx;
  266. // top: 0rpx;
  267. // z-index: 3;
  268. .zheZhao {
  269. width: 100%;
  270. height: calc(100% - 575rpx);
  271. background: #12141a;
  272. opacity: 0.5;
  273. position: absolute;
  274. left: 0rpx;
  275. top: 0rpx;
  276. z-index: 3;
  277. }
  278. .content {
  279. width: 100%;
  280. height: 600rpx;
  281. background-color: #fff;
  282. position: absolute;
  283. bottom: 0rpx;
  284. opacity: 1;
  285. z-index: 4;
  286. border-radius: 25rpx 25rpx 0rpx 0px;
  287. // height: 575rpx;
  288. .title {
  289. margin-top: 35rpx;
  290. margin-left: 40rpx;
  291. font-size: 30rpx;
  292. color: #292c33;
  293. }
  294. .cont {
  295. margin: 42.5rpx 0rpx 17.5rpx 0rpx;
  296. height: 400rpx;
  297. overflow: hidden;
  298. // .top{
  299. // height: 190rpx;
  300. // opacity: .3;
  301. // z-index: 4;
  302. // }
  303. .highLight {
  304. height: 80rpx;
  305. // z-index: 3;
  306. position: relative;
  307. // top: 222.5rpx;
  308. top: 160rpx;
  309. .left {
  310. padding-right: 62.5rpx;
  311. width: 49%;
  312. float: left;
  313. text-align: right;
  314. color: #dadee6;
  315. font-size: 40rpx;
  316. font-weight: bold;
  317. uni-view {
  318. line-height: 80rpx;
  319. }
  320. }
  321. .diagonalLine {
  322. width: 2%;
  323. float: left;
  324. text-align: center;
  325. font-size: 25rpx;
  326. font-weight: bold;
  327. line-height: 80rpx;
  328. }
  329. .right {
  330. padding-left: 62.5rpx;
  331. float: left;
  332. width: 49%;
  333. text-align: left;
  334. color: #dadee6;
  335. font-size: 40rpx;
  336. font-weight: bold;
  337. uni-view {
  338. line-height: 80rpx;
  339. }
  340. }
  341. }
  342. // .bottom{
  343. // height: 190rpx;
  344. // opacity: .3;
  345. // z-index: 4;
  346. // }
  347. }
  348. .change {
  349. text-align: center;
  350. border-top: 0.62rpx solid #dadee6;
  351. .cancel {
  352. padding: 26.25rpx 0rpx;
  353. display: inline-block;
  354. width: 50%;
  355. color: #3377ff;
  356. }
  357. .sure {
  358. padding: 26.25rpx 0rpx;
  359. display: inline-block;
  360. width: 50%;
  361. color: #fff;
  362. background-color: #3377ff;
  363. }
  364. }
  365. }
  366. }
  367. </style>