calendarBox.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: Sugar.
  6. * @LastEditTime: 2023-11-24 13:55:00
  7. * @FilePath: \cattle_webui\src\views\venue\schedulingMr\dialog\AddOrEditDialog.vue
  8. * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
  9. -->
  10. <template>
  11. <el-dialog
  12. :visible.sync="open"
  13. width="70%"
  14. class="text-dia-log-class"
  15. append-to-body
  16. :close-on-click-modal="false"
  17. @close="cancel"
  18. >
  19. <div class="dialog" v-loading="loading">
  20. <el-calendar v-model="timeValue">
  21. <template
  22. slot="dateCell"
  23. slot-scope="{date, data}">
  24. <div>
  25. <span>{{ data.day.split('-').slice(1).join('-') }}</span>
  26. <div style="width: 100%; display: flex;flex-wrap: wrap;" >
  27. <div
  28. :key="index"
  29. v-for="(item,index) in getPerFormList(data)"
  30. >
  31. {{ item.title }}:{{ item.money }}
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. </el-calendar>
  37. </div>
  38. <span slot="footer" class="dialog-footer">
  39. <el-button @click="cancel">返回</el-button>
  40. </span>
  41. </el-dialog>
  42. </template>
  43. <script>
  44. import { getSelectById,getCalendarList } from "@/api/priceConfiguration/index";
  45. export default {
  46. name: "addAndEdit",
  47. data() {
  48. return {
  49. title: "编辑",
  50. loading: false,
  51. model: "EDIT",
  52. open: false,
  53. loading: false,
  54. timeValue: null,
  55. perFormList: []
  56. };
  57. },
  58. created() {
  59. },
  60. methods: {
  61. /**
  62. * 打开弹框
  63. * @date 2023-11-22
  64. * @param {any} obj
  65. * @returns {any}
  66. */
  67. async openDialog(title, obj, type) {
  68. this.open = true;
  69. this.getSelectByIdFun({priceId: obj.id})
  70. },
  71. /** 查询日期列表 */
  72. async getList(params) {
  73. try {
  74. this.loading = true;
  75. let res = await getCalendarList(params)
  76. if(res.code == 200) {
  77. this.perFormList = res.rows || []
  78. this.loading = false;
  79. }
  80. this.loading = false;
  81. } catch (error) {
  82. this.loading = false;
  83. }
  84. },
  85. /** 查询详情 */
  86. async getSelectByIdFun(params) {
  87. try {
  88. this.loading = true;
  89. let res = await getCalendarList(params)
  90. if(res.code == 200) {
  91. this.loading = false;
  92. if(res.rows && res.rows.length>0){
  93. let date = new Date(res.rows[0].priceDate)
  94. //this.timeValue = date
  95. this.getRange(date)
  96. }
  97. }
  98. this.loading = false;
  99. } catch (error) {
  100. this.loading = false;
  101. console.error("error===",error)
  102. }
  103. },
  104. getPerFormList(data) {
  105. let list = []
  106. this.perFormList.forEach((item,index)=>{
  107. if(item.priceDate && item.priceDate.indexOf(data.day) != -1) {
  108. list = [
  109. { title: '划线价', money: item.originalAmount + '元' },
  110. { title: '销售价', money: item.saleAmount + '元' },
  111. ]
  112. }
  113. })
  114. return list
  115. },
  116. /**
  117. * 关闭弹框
  118. * @date 2023-11-22
  119. * @returns {any}
  120. */
  121. cancel() {
  122. this.open = false;
  123. },
  124. // 获取日历显示时间范围
  125. getRange(date){
  126. // 日历第一天
  127. let firstDay = '';
  128. // 日历最后一天
  129. let lastDay = '';
  130. // 今天
  131. const today = date ? date : new Date()
  132. // 上月
  133. const m = today.getMonth()
  134. // 本月
  135. const cm = m + 1
  136. // 下月
  137. const lm = m + 2 > 12 ? 1 : m + 2
  138. // 要显示的本月
  139. const currentMonth = cm < 10 ? '0' + cm : cm
  140. // 要显示的本本年
  141. const currentYear = today.getFullYear()
  142. // 要显示的上个月的年份,m = 0 则当前1月,上月则是去年12月
  143. const prevYear = m == 0 ? currentYear - 1 : currentYear
  144. const prevMonth = m == 0 ? 12 : m < 10 ? '0' + m : m
  145. // 上个月天数
  146. const pmd = new Date(prevYear, m, 0).getDate()
  147. // 下个月的年份,当前12月,则需要加一年
  148. const lastYear = cm + 1 > 12 ? currentYear + 1 : currentYear
  149. const lastMonth = lm < 10 ? '0' + lm : lm
  150. // 1号是周几
  151. const firstWeek = new Date(today.setDate(1)).getDay()
  152. // 如果是周日,则不需要显示上个月
  153. if (firstWeek == 0) {
  154. firstDay = `${currentYear}-${currentMonth}-01`
  155. }
  156. // 其他周几,对应用上个月的天数往前推算
  157. else {
  158. firstDay = `${prevYear}-${prevMonth}-${pmd - (firstWeek - 1)}`
  159. }
  160. // 这个月天数
  161. const currentMonthDate = new Date(currentYear, cm, 0).getDate()
  162. // 最后一天是周几
  163. const lastWeek = new Date(today.setDate(currentMonthDate)).getDay()
  164. // 周六显示当月最后一天
  165. if (lastWeek == 6) {
  166. lastDay = `${currentYear}-${currentMonth}-${currentMonthDate}`
  167. }
  168. // 其他周几,对应往后推算
  169. else {
  170. const day = ['06', '05', '04', '03', '02', '01']
  171. lastDay = `${lastYear}-${lastMonth}-${day[lastWeek]}`
  172. }
  173. console.log('第一天', firstDay)
  174. console.log('最后一天', lastDay)
  175. this.getList({
  176. beginPriceDate: firstDay,
  177. endPriceDate: lastDay,
  178. });
  179. }
  180. },
  181. watch:{
  182. timeValue(newValue,oldValue){
  183. if (newValue.getFullYear() !== oldValue.getFullYear() || newValue.getMonth() !== oldValue.getMonth()) {
  184. this.getRange(newValue)
  185. }
  186. }
  187. }
  188. };
  189. </script>
  190. <style lang="scss" scoped>
  191. .dialog {
  192. height: 70vh;
  193. overflow-y: auto;
  194. }
  195. .dialog {
  196. .upload-btn {
  197. width: 100px;
  198. height: 100px;
  199. background-color: #fbfdff;
  200. border: dashed 1px #c0ccda;
  201. border-radius: 5px;
  202. i {
  203. font-size: 30px;
  204. margin-top: 20px;
  205. }
  206. &-text {
  207. margin-top: -10px;
  208. }
  209. }
  210. .avatar {
  211. cursor: pointer;
  212. }
  213. }
  214. </style>