index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="works-time">
  3. <nav-bar></nav-bar>
  4. <div class="form-box">
  5. <org-tree v-model="formData.orgId" @change="orgChange"></org-tree>
  6. <!-- 选择日期 -->
  7. <van-collapse v-model="activeCalendar">
  8. <van-collapse-item title="日期" :label="formData.ymdDate" name="1">
  9. <calendar ref="calendar" :orgId="formData.orgId" @change="onChange" @copy="getCopyData"></calendar>
  10. </van-collapse-item>
  11. </van-collapse>
  12. <!-- 选择状态 -->
  13. <van-radio-group :disabled="formData.isDisabled" v-model="formData.isEnable">
  14. <van-cell-group>
  15. <van-cell title="营业" clickable @click="formData.isDisabled?null: changeRadio(1)">
  16. <template #right-icon>
  17. <van-radio :name="1" />
  18. </template>
  19. </van-cell>
  20. <van-cell title="歇业" clickable @click="formData.isDisabled?null: changeRadio(0)">
  21. <template #right-icon>
  22. <van-radio :name="0" />
  23. </template>
  24. </van-cell>
  25. </van-cell-group>
  26. </van-radio-group>
  27. <!-- 选择时间 -->
  28. <van-cell-group >
  29. <date-cell :disabled="formData.isDisabled || !formData.isEnable" title="营业开始" v-model="formData.workTime" date-type="time"></date-cell>
  30. <date-cell :disabled="formData.isDisabled || !formData.isEnable" title="营业结束" v-model="formData.workOffTime" date-type="time"></date-cell>
  31. <!-- <van-cell title="开始时间" is-link :label="formData.workTime" @click="formData.isDisabled?null:showTimePopup(1)"/>-->
  32. <!-- <van-cell title="结束时间" is-link :label="formData.workOffTime" @click="formData.isDisabled?null:showTimePopup(0)"/>-->
  33. <van-popup v-model="showTime" round position="bottom" >
  34. <van-datetime-picker
  35. v-model="selectedTime"
  36. type="time"
  37. min-hour="0"
  38. max-hour="23"
  39. @confirm="datePickerConfirm"
  40. :columns-order="['hour', 'minute']"
  41. />
  42. </van-popup>
  43. <!-- 操作 -->
  44. </van-cell-group>
  45. <van-cell center title="是否复制到全月" v-if="!formData.isDisabled">
  46. <template #right-icon>
  47. <van-button round size="small" type="info" @click="copyMouth">点击复制</van-button>
  48. </template>
  49. </van-cell>
  50. <van-button type="info" size="large" v-show="!formData.isDisabled" @click="onsubmit">提交</van-button>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import NavBar from '@/components/NavBar';
  56. import Calendar from '@/components/Calendar';
  57. import OrgTree from '@/components/orgTree';
  58. import DateCell from '@/components/dateCell';
  59. import {mapGetters} from "vuex";
  60. import {deptTreeList} from "@/api/public";
  61. import {editWorkTime} from "@/views/menu/workTime/api";
  62. import {dataList} from "@/views/menu/educationStatistics/api";
  63. export default {
  64. components:{NavBar,Calendar,OrgTree,DateCell},
  65. data(){
  66. return{
  67. // orgInfo:{
  68. // orgId:null,
  69. // orgName:null,
  70. // },
  71. formData:{
  72. workTime:null,
  73. workOffTime:null,
  74. isEnable:null,
  75. ymdDate:null,
  76. isDisabled:false,
  77. orgId:null,
  78. },
  79. dates:[],
  80. activeCalendar:['1'],
  81. options: [],
  82. showOrg:false,
  83. calendar:true,
  84. activeNames: ['1'],
  85. showTime:false,
  86. selectedTime:null,
  87. fieldNames: {
  88. text: 'name',
  89. value: 'id',
  90. children: 'children',
  91. },
  92. timeFlag:true,
  93. selectDate:null,
  94. isCopy:false,
  95. }
  96. },
  97. mounted() {
  98. this.formData.orgId = this.orgId;
  99. },
  100. computed:{
  101. ...mapGetters(['orgName','orgId']),
  102. },
  103. methods:{
  104. orgChange(){
  105. // let data = {
  106. // ...this.query
  107. // }
  108. // data.date = `${this.query.date}-01`;
  109. // if(!this.query.orgId) return this.$toast('请选择机构');
  110. // dataList(data).then(res=>{
  111. // this.dataList = res.data;
  112. // })
  113. },
  114. //切换状态
  115. changeRadio(s){
  116. this.formData.isEnable = s;
  117. },
  118. //获取复制的数据
  119. getCopyData(arr){
  120. this.dates = arr;
  121. },
  122. copyMouth(){
  123. if(!this.formData.ymdDate) return this.$toast('请选择日期');
  124. this.$refs.calendar.copyMouth(this.formData);
  125. this.isCopy = true;
  126. },
  127. //根据状态切换选择时间
  128. datePickerConfirm(date){
  129. if(this.timeFlag) {
  130. this.formData.workTime = date;
  131. }else{
  132. this.formData.workOffTime = date;
  133. }
  134. this.showTime = false;
  135. },
  136. //获取机构树
  137. getTreeList(){
  138. deptTreeList(this.orgId).then(res=>{
  139. this.options = res.data;
  140. this.orgInfo.orgId = this.orgId;
  141. this.orgInfo.orgName = this.orgName;
  142. console.log(res,'3333')
  143. })
  144. },
  145. //改变机构后将重新发起请求
  146. changeTree({selectedOptions}){
  147. console.log(selectedOptions,'aaaaaa')
  148. this.formData.orgId = selectedOptions[selectedOptions.length-1].id;
  149. this.formData.orgName = selectedOptions[selectedOptions.length-1].name;
  150. },
  151. // 全部选项选择完毕后,会触发 finish 事件
  152. onFinish({ selectedOptions }) {
  153. this.showOrg = false;
  154. this.fieldValue = selectedOptions.map((option) => option.text).join('/');
  155. },
  156. //显示日历
  157. showCalendar(){
  158. this.calendar = !this.calendar;
  159. },
  160. //显示机构选择
  161. showPopup() {
  162. this.showOrg = true;
  163. },
  164. //显示时间选择
  165. showTimePopup(key){
  166. this.timeFlag = key;
  167. this.showTime = true;
  168. },
  169. //提交
  170. onsubmit(){
  171. if(!this.formData.orgId) return this.$toast('请选择机构');
  172. if(this.isCopy){
  173. let data = {
  174. orgIdList:[this.formData.orgId],
  175. workTimeList:this.dates
  176. }
  177. editWorkTime(data).then(res=>{
  178. this.$refs.calendar.queryMoth(); //刷新日历的状态
  179. this.$toast.success('操作成功');
  180. this.isCopy = false;
  181. })
  182. }else {
  183. let data = {
  184. orgIdList:[this.formData.orgId],
  185. workTimeList:[this.formData]
  186. }
  187. editWorkTime(data).then(res => {
  188. this.$refs.calendar.queryMoth(); //刷新日历的状态
  189. this.$toast.success('操作成功');
  190. this.isCopy = false;
  191. })
  192. }
  193. },
  194. //日期选择
  195. onChange(day){
  196. this.selectDate = day;
  197. console.log(this.selectDate,'this.date')
  198. this.formData.ymdDate = this.selectDate.ymdDate;
  199. this.formData.isEnable = this.selectDate.isEnable;
  200. this.formData.workTime = this.selectDate.workTime;
  201. this.formData.workOffTime = this.selectDate.workOffTime;
  202. this.formData.isDisabled = this.selectDate.isDisabled;
  203. },
  204. }
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. .works-time{
  209. }
  210. .form-box{
  211. height: calc(100vh - 200px);
  212. padding: 30px;
  213. overflow: auto;
  214. }
  215. .radio-box{
  216. height: 100px;
  217. padding: 30px;
  218. }
  219. .org-name{
  220. font-size: 30px;
  221. line-height: 80px;
  222. height: 80px;
  223. text-align: center;
  224. }
  225. </style>