calendarBox.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 calendar-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. props: {
  48. channelType: {
  49. type: [String]
  50. }
  51. },
  52. data() {
  53. return {
  54. title: "编辑",
  55. loading: false,
  56. model: "EDIT",
  57. open: false,
  58. loading: false,
  59. timeValue: null,
  60. perFormList: []
  61. };
  62. },
  63. created() {
  64. },
  65. methods: {
  66. /**
  67. * 打开弹框
  68. * @date 2023-11-22
  69. * @param {any} obj
  70. * @returns {any}
  71. */
  72. async openDialog(title, obj, type) {
  73. this.open = true;
  74. this.getSelectByIdFun({priceId: obj.id})
  75. },
  76. /** 查询日期列表 */
  77. async getList(params) {
  78. try {
  79. this.loading = true;
  80. let res = await getCalendarList({...params,pageNum: 1,
  81. pageSize: 10000})
  82. if(res.code == 200) {
  83. this.perFormList = res.data || []
  84. this.loading = false;
  85. }
  86. this.loading = false;
  87. } catch (error) {
  88. this.loading = false;
  89. }
  90. },
  91. /** 查询详情 */
  92. async getSelectByIdFun(params) {
  93. try {
  94. this.perFormList = []
  95. this.loading = true;
  96. let res = await getCalendarList({...params,pageNum: 1,
  97. pageSize: 10000})
  98. if(res.code == 200) {
  99. this.loading = false;
  100. if(res.data && res.data.length>0){
  101. this.perFormList = res.data || []
  102. // let date = new Date(res.data[0].priceDate)
  103. // this.timeValue = date
  104. this.$set(this,'timeValue',new Date())
  105. //this.getRange(date)
  106. }
  107. }
  108. this.loading = false;
  109. } catch (error) {
  110. this.loading = false;
  111. console.error("error===",error)
  112. }
  113. },
  114. getPerFormList(data) {
  115. let list = [
  116. ]
  117. this.perFormList.forEach((item,index)=>{
  118. if(item.priceDate && item.priceDate.indexOf(data.day) != -1) {
  119. list = [
  120. { title: '划线价', money: item.originalAmount + '元' },
  121. { title: '销售价', money: item.saleAmount + '元' },
  122. ]
  123. if(this.channelType == "retail") {
  124. list = [
  125. { title: '销售价', money: item.originalAmount + '元' },
  126. { title: '分销价', money: item.saleAmount + '元' },
  127. { title: '佣金', money: item.retailAmount + '元' },
  128. ]
  129. }else if(this.channelType == "applet"){
  130. list = [
  131. { title: '划线价', money: item.originalAmount + '元' },
  132. { title: '销售价', money: item.saleAmount + '元' },
  133. ]
  134. }else if(this.channelType == "window"){
  135. list = [
  136. { title: '销售价', money: item.saleAmount + '元' },
  137. ]
  138. }
  139. }
  140. })
  141. return list
  142. },
  143. /**
  144. * 关闭弹框
  145. * @date 2023-11-22
  146. * @returns {any}
  147. */
  148. cancel() {
  149. this.open = false;
  150. },
  151. // 获取日历显示时间范围
  152. getRange(date){
  153. // 日历第一天
  154. let firstDay = '';
  155. // 日历最后一天
  156. let lastDay = '';
  157. // 今天
  158. const today = date ? date : new Date()
  159. // 上月
  160. const m = today.getMonth()
  161. // 本月
  162. const cm = m + 1
  163. // 下月
  164. const lm = m + 2 > 12 ? 1 : m + 2
  165. // 要显示的本月
  166. const currentMonth = cm < 10 ? '0' + cm : cm
  167. // 要显示的本本年
  168. const currentYear = today.getFullYear()
  169. // 要显示的上个月的年份,m = 0 则当前1月,上月则是去年12月
  170. const prevYear = m == 0 ? currentYear - 1 : currentYear
  171. const prevMonth = m == 0 ? 12 : m < 10 ? '0' + m : m
  172. // 上个月天数
  173. const pmd = new Date(prevYear, m, 0).getDate()
  174. // 下个月的年份,当前12月,则需要加一年
  175. const lastYear = cm + 1 > 12 ? currentYear + 1 : currentYear
  176. const lastMonth = lm < 10 ? '0' + lm : lm
  177. // 1号是周几
  178. const firstWeek = new Date(today.setDate(1)).getDay()
  179. // 如果是周日,则不需要显示上个月
  180. if (firstWeek == 0) {
  181. firstDay = `${currentYear}-${currentMonth}-01`
  182. }
  183. // 其他周几,对应用上个月的天数往前推算
  184. else {
  185. firstDay = `${prevYear}-${prevMonth}-${pmd - (firstWeek - 1)}`
  186. }
  187. // 这个月天数
  188. const currentMonthDate = new Date(currentYear, cm, 0).getDate()
  189. // 最后一天是周几
  190. const lastWeek = new Date(today.setDate(currentMonthDate)).getDay()
  191. // 周六显示当月最后一天
  192. if (lastWeek == 6) {
  193. lastDay = `${currentYear}-${currentMonth}-${currentMonthDate}`
  194. }
  195. // 其他周几,对应往后推算
  196. else {
  197. const day = ['06', '05', '04', '03', '02', '01']
  198. lastDay = `${lastYear}-${lastMonth}-${day[lastWeek]}`
  199. }
  200. console.log('第一天', firstDay)
  201. console.log('最后一天', lastDay)
  202. this.getList({
  203. beginPriceDate: firstDay,
  204. endPriceDate: lastDay,
  205. });
  206. }
  207. },
  208. watch:{
  209. timeValue(newValue,oldValue){
  210. // if (newValue.getFullYear() !== oldValue.getFullYear() || newValue.getMonth() !== oldValue.getMonth()) {
  211. // this.getRange(newValue)
  212. // }
  213. }
  214. }
  215. };
  216. </script>
  217. <style lang="scss" scoped>
  218. .dialog {
  219. height: 70vh;
  220. overflow-y: auto;
  221. }
  222. .dialog {
  223. .upload-btn {
  224. width: 100px;
  225. height: 100px;
  226. background-color: #fbfdff;
  227. border: dashed 1px #c0ccda;
  228. border-radius: 5px;
  229. i {
  230. font-size: 30px;
  231. margin-top: 20px;
  232. }
  233. &-text {
  234. margin-top: -10px;
  235. }
  236. }
  237. .avatar {
  238. cursor: pointer;
  239. }
  240. }
  241. .calendar-dialog ::v-deep .el-calendar-table .el-calendar-day {
  242. height: auto;
  243. min-height: 86px;
  244. }
  245. </style>