index.vue 6.2 KB

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