rli.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <div>
  3. <!-- <div class="calendar">
  4. <div class="arrow">
  5. <i class="el-icon-arrow-left" @click="arrow('left')"></i>
  6. <i class="el-icon-arrow-right" @click="arrow('right')"></i>
  7. </div>
  8. <el-calendar v-model="value" :range="dateRange"></el-calendar>
  9. </div> -->
  10. <!-- 下面的日历 -->
  11. <div class="date">
  12. <div class="arrow0">
  13. <i class="el-icon-arrow-left" @click="weekPre"></i>
  14. <i class="el-icon-arrow-right" @click="weekNext"></i>
  15. </div>
  16. <!-- 年份 月份 -->
  17. <div class="month">
  18. <p>{{ currentYear }}年{{ currentMonth }}月</p>
  19. </div>
  20. <!-- 星期 -->
  21. <ul class="weekdays">
  22. <li>一</li>
  23. <li>二</li>
  24. <li>三</li>
  25. <li>四</li>
  26. <li>五</li>
  27. <li>六</li>
  28. <li>日</li>
  29. </ul>
  30. <!-- 日期 -->
  31. <ul class="days">
  32. <li @click="pick(day)" v-for="(day, index) in days" :key="index">
  33. <!--本月-->
  34. <span v-if="day.getMonth() + 1 != currentMonth" class="other-month">{{ day.getDate() }}</span>
  35. <span v-else>
  36. <!--今天-->
  37. <span
  38. v-if="day.getFullYear() == new Date().getFullYear() && day.getMonth() == new Date().getMonth() && day.getDate() == new Date().getDate()"
  39. class="active">{{ day.getDate() }}</span>
  40. <span v-else>{{ day.getDate() }}</span>
  41. </span>
  42. </li>
  43. </ul>
  44. <el-table v-loading="loading" :data="tableData" style="width: 100%">
  45. <el-table-column prop="date" label="日期" width="180">
  46. </el-table-column>
  47. <el-table-column prop="name" label="姓名" width="180">
  48. </el-table-column>
  49. <el-table-column prop="address" label="地址">
  50. </el-table-column>
  51. </el-table>
  52. <el-pagination @current-change="currchange" :current-page="page" :page-size="size"
  53. layout="total,prev, pager, next" :total="total">
  54. </el-pagination>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. // 上
  63. value: "",
  64. endDate: "",
  65. dateRange: [],
  66. dateNum: 0,
  67. // 下
  68. currentYear: "", // 年份
  69. currentMonth: "", // 月份
  70. currentDay: "", // 日期
  71. currentWeek: "", // 星期
  72. days: [],
  73. tableData: [{
  74. date: '2016-05-02',
  75. name: '王小虎',
  76. address: '上海市普陀区金沙江路 1518 弄'
  77. }, {
  78. date: '2016-05-04',
  79. name: '王小虎',
  80. address: '上海市普陀区金沙江路 1517 弄'
  81. }, {
  82. date: '2016-05-01',
  83. name: '王小虎',
  84. address: '上海市普陀区金沙江路 1519 弄'
  85. }, {
  86. date: '2016-05-03',
  87. name: '王小虎',
  88. address: '上海市普陀区金沙江路 1516 弄'
  89. }],
  90. loading:false,
  91. params: {},
  92. page: 1, //第几页
  93. size: 10, //一页多少条
  94. total: 50, //总条目数
  95. }
  96. },
  97. created() {
  98. // 上面的日历
  99. this.dateList(this.dateNum);
  100. console.log(this.dateRange);
  101. // 下面的日历
  102. this.initData();
  103. this.getlist();
  104. },
  105. methods: {
  106. currchange(val) {
  107. console.log("翻页,当前为第几页", val);
  108. this.page = val;
  109. this.getlist(this.params, this.page);
  110. },
  111. getlist(v, n) {
  112. this.loading=true
  113. this.$http({
  114. url: "/market/waf/queryTodoBase",
  115. method: "post",
  116. headers: {
  117. "Content-Type": "application/json",
  118. page: '{"pageNo":"' + n + '","pageSize":"10"}',
  119. },
  120. data: { tableName: 'fxfk_process', },
  121. }).then((res) => {
  122. this.loading=false
  123. this.tableData = res.data.data;
  124. this.total = res.data.totalRecord;
  125. });
  126. },
  127. // 上面的日历
  128. // 获取当前时间的周一
  129. getMonday(date) {
  130. var day = date.getDay();
  131. var deltaDay;
  132. if (day == 0) {
  133. deltaDay = 6;
  134. } else {
  135. deltaDay = day - 1;
  136. }
  137. var monday = new Date(date.getTime() - deltaDay * 24 * 60 * 60 * 1000);
  138. monday.setHours(0);
  139. monday.setMinutes(0);
  140. monday.setSeconds(0);
  141. return monday; //返回选定时间的周一的0时0分0秒
  142. },
  143. getDateNew(time) {
  144. console.log(time);
  145. let times = new Date(time);
  146. let year = times.getFullYear();
  147. let month = times.getMonth() + 1 < 10 ? "0" + (times.getMonth() * 1 + 1) : times.getMonth() * 1 + 1;
  148. let day = times.getDate() < 10 ? "0" + times.getDate() * 1 : times.getDate() * 1;
  149. return year + "-" + month + "-" + day;
  150. },
  151. dateList(delta) {
  152. //将时间对象转换为时间戳并加几天后转换为时间对象
  153. var DateNews = this.getMonday(
  154. new Date((new Date().getTime() / 1000 + 86400 * 7 * delta) * 1000)
  155. );
  156. let startDate = this.getDateNew(DateNews, delta);
  157. this.endDate = this.getDateNew(
  158. new Date((DateNews.getTime() / 1000 + 6 * 86400) * 1000)
  159. );
  160. this.dateRange = [startDate, this.endDate];
  161. },
  162. arrow(arrow) {
  163. if (arrow == "left") {
  164. this.dateNum--;
  165. this.dateList(this.dateNum);
  166. } else if (arrow == "right") {
  167. this.dateNum++;
  168. this.dateList(this.dateNum);
  169. }
  170. },
  171. // 下面的日历
  172. formatDate(year, month, day) {
  173. const y = year
  174. let m = month
  175. if (m < 10) m = `0${m}`
  176. let d = day
  177. if (d < 10) d = `0${d}`
  178. return `${y}-${m}-${d}`
  179. },
  180. initData(cur) {
  181. let date = ''
  182. if (cur) {
  183. date = new Date(cur)
  184. } else {
  185. date = new Date()
  186. }
  187. this.currentDay = date.getDate() // 今日日期 几号
  188. this.currentYear = date.getFullYear() // 当前年份
  189. this.currentMonth = date.getMonth() + 1 // 当前月份
  190. this.currentWeek = date.getDay() // 1...6,0 // 星期几
  191. if (this.currentWeek === 0) {
  192. this.currentWeek = 7
  193. }
  194. const str = this.formatDate(this.currentYear, this.currentMonth, this.currentDay) // 今日日期 年-月-日
  195. this.days.length = 0
  196. // 今天是周日,放在第一行第7个位置,前面6个 这里默认显示一周,如果需要显示一个月,则第二个循环为 i<= 35- this.currentWeek
  197. /* eslint-disabled */
  198. for (let i = this.currentWeek - 1; i >= 0; i -= 1) {
  199. const d = new Date(str)
  200. d.setDate(d.getDate() - i)
  201. // console.log(y:" + d.getDate())
  202. this.days.push(d)
  203. }
  204. for (let i = 1; i <= 7 - this.currentWeek; i += 1) {
  205. const d = new Date(str)
  206. d.setDate(d.getDate() + i)
  207. this.days.push(d)
  208. }
  209. },
  210. // 上个星期
  211. weekPre() {
  212. const d = this.days[0] // 如果当期日期是7号或者小于7号
  213. d.setDate(d.getDate() - 7)
  214. this.initData(d)
  215. },
  216. // 下个星期
  217. weekNext() {
  218. const d = this.days[6] // 如果当期日期是7号或者小于7号
  219. d.setDate(d.getDate() + 7)
  220. this.initData(d)
  221. },
  222. // 上一個月 传入当前年份和月份
  223. pickPre(year, month) {
  224. const d = new Date(this.formatDate(year, month, 1))
  225. d.setDate(0)
  226. this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
  227. },
  228. // 下一個月 传入当前年份和月份
  229. pickNext(year, month) {
  230. const d = new Date(this.formatDate(year, month, 1))
  231. d.setDate(35)
  232. this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
  233. },
  234. // 当前选择日期
  235. pick(date) {
  236. alert(this.formatDate(date.getFullYear(), date.getMonth() + 1, date.getDate()))
  237. },
  238. },
  239. };
  240. </script>
  241. <style lang="scss" scoped>
  242. ul {
  243. padding: 0;
  244. }
  245. li {
  246. list-style-type: none;
  247. }
  248. /* 上面的日历 */
  249. .calendar {
  250. position: relative;
  251. width: 100%;
  252. background: #fff;
  253. margin-top: 20px;
  254. margin-left: 20px;
  255. }
  256. .el-calendar__header {
  257. display: block;
  258. }
  259. .el-calendar-table .el-calendar-day {
  260. height: auto;
  261. text-align: center;
  262. }
  263. .el-calendar-table td.is-selected {
  264. background-color: #24b18d;
  265. color: #fff;
  266. }
  267. .el-calendar-table .el-calendar-day:hover {
  268. background-color: #24b18d;
  269. color: #fff;
  270. }
  271. .el-calendar-table {
  272. border-bottom: 1px solid #e4e4e4;
  273. padding-bottom: 15px;
  274. }
  275. .el-calendar-table .next {
  276. color: rgb(143, 143, 143);
  277. }
  278. .el-calendar__title,
  279. .el-calendar__button-group {
  280. text-align: center;
  281. }
  282. .arrow {
  283. width: 100%;
  284. max-height: 46px;
  285. position: absolute;
  286. top: 15px;
  287. text-align: center;
  288. }
  289. .arrow i {
  290. font-size: 20px;
  291. cursor: pointer;
  292. }
  293. .arrow i:nth-child(1) {
  294. margin-right: 10%;
  295. text-align: left;
  296. }
  297. .arrow i:nth-child(2) {
  298. margin-left: 10%;
  299. text-align: right;
  300. }
  301. /* 下面的日历 */
  302. .date {
  303. position: relative;
  304. margin-top: 20px;
  305. padding: 10px 20px;
  306. background-color: #D3D3D3;
  307. }
  308. .arrow0 {
  309. width: 100%;
  310. max-height: 46px;
  311. position: absolute;
  312. top: 27px;
  313. left: 0px;
  314. text-align: center;
  315. }
  316. .arrow0 i {
  317. font-size: 20px;
  318. cursor: pointer;
  319. }
  320. .arrow0 i:nth-child(1) {
  321. margin-right: 10%;
  322. text-align: left;
  323. }
  324. .arrow0 i:nth-child(2) {
  325. margin-left: 10%;
  326. text-align: right;
  327. }
  328. .month {
  329. text-align: center;
  330. }
  331. .weekdays {
  332. display: flex;
  333. }
  334. .weekdays li {
  335. flex: 1;
  336. text-align: center;
  337. }
  338. .days {
  339. display: flex;
  340. }
  341. .days li {
  342. flex: 1;
  343. text-align: center;
  344. cursor: pointer;
  345. }
  346. .days li span {
  347. display: inline-block;
  348. width: 22px;
  349. height: 22px;
  350. }
  351. .days li span:hover {
  352. color: #fff;
  353. background-color: #409EFF;
  354. border-radius: 50%;
  355. }
  356. .active {
  357. display: inline-block;
  358. color: #fff;
  359. border-radius: 50%;
  360. background-color: #fa6854 !important;
  361. }
  362. .other-month {
  363. color: #e4393c;
  364. }
  365. </style>