index.vue 7.5 KB

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