setswork.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <view class="lists">
  3. <view class="lbox">
  4. <view class="list" @click="getAdres">
  5. <view class="listl">考勤地址</view>
  6. <view class="listr">{{formData.locations||'请选择考勤地址'}}</view>
  7. </view>
  8. <view class="list">
  9. <view class="listl">考勤范围(米)</view>
  10. <input class="listi" v-model="formData.distance" placeholder-style="color:#aaaaaa" placeholder="请输入半径米数(单位默认:米)"/>
  11. <image :src="rimg"></image>
  12. </view>
  13. <!-- <view class="list" @click="getDeptname">
  14. <view class="listl">考勤部门</view>
  15. <view class="listi" :style="formData.deptName?'':'color:#AAAAAA;'">{{formData.deptName||'选择部门'}}</view>
  16. <image :src="rimg"></image>
  17. </view> -->
  18. <view class="list" >
  19. <view class="listl">是否开启考勤拍照</view>
  20. <!-- <view class="listi" > -->
  21. <picker @change="bindPickerChanges" range-key='label' :value="indexs" :range="surelist" class="listi">
  22. <view class="f15" :style="isPicture?'':'color: #AAAAAA;'">{{isPicture||"请选择是否开启考勤拍照"}}</view>
  23. </picker>
  24. <image :src="rimg"></image>
  25. </view>
  26. </view>
  27. <view class="lbox">
  28. <!-- <view class="list">
  29. <view class="listl">打卡次数</view>
  30. <picker @change="bindPickerChange" :value="index" :range="array" class="listi">
  31. <view :style="formData.kaNum?'':'color: #AAAAAA;'">{{formData.kaNum||"请选择打卡次数"}}</view>
  32. </picker>
  33. <image :src="rimg"></image>
  34. </view>
  35. <block v-if="formData.kaNum==4">
  36. <view class="list" @click="showDatePicker(0)">
  37. <view class="listl">上午上班时间</view>
  38. <view class="listi" :style="formData.kaTimeAmIn?'':'color: #AAAAAA;'">{{formData.kaTimeAmIn||"请选择上班时间"}}</view>
  39. <image :src="rimg"></image>
  40. </view>
  41. <view class="list" @click="showDatePicker(1)">
  42. <view class="listl">上午下班时间</view>
  43. <view class="listi" :style="formData.kaTimeAmOut?'':'color: #AAAAAA;'">{{formData.kaTimeAmOut||"请选择上班时间"}}</view>
  44. <image :src="rimg"></image>
  45. </view>
  46. <view class="list" @click="showDatePicker(2)">
  47. <view class="listl">下午上班时间</view>
  48. <view class="listi" :style="formData.kaTimePmIn?'':'color: #AAAAAA;'">{{formData.kaTimePmIn||"请选择上班时间"}}</view>
  49. <image :src="rimg"></image>
  50. </view>
  51. <view class="list" @click="showDatePicker(3)">
  52. <view class="listl">下午下班时间</view>
  53. <view class="listi" :style="formData.kaTimePmOut?'':'color: #AAAAAA;'">{{formData.kaTimePmOut||"请选择下班时间"}}</view>
  54. <image :src="rimg"></image>
  55. </view>
  56. </block>
  57. <block v-else> -->
  58. <view class="list" @click="showDatePicker(0)">
  59. <view class="listl">上班时间</view>
  60. <view class="listi" :style="formData.startWorkTime?'':'color: #AAAAAA;'">{{formData.startWorkTime||"请选择上班时间"}}</view>
  61. <image :src="rimg"></image>
  62. </view>
  63. <view class="list" @click="showDatePicker(3)">
  64. <view class="listl">下班时间</view>
  65. <view class="listi" :style="formData.endWorkTime?'':'color: #AAAAAA;'">{{formData.endWorkTime||"请选择下班时间"}}</view>
  66. <image :src="rimg"></image>
  67. </view>
  68. <!-- </block> -->
  69. </view>
  70. <view class="listbtn" @click="getSure">确认</view>
  71. <dataTimePicke ref="setpicker" type="time" toolBarTitle="请选择时间" @change="timeChange"></dataTimePicke>
  72. <!-- 部门 -->
  73. <selectMorePicker ref="picker" :title="auiPicker.title" :layer="auiPicker.layer" :titflag='auiPicker.titflag'
  74. :data="auiPicker.data" @callback="pickerCallback"></selectMorePicker>
  75. </view>
  76. </template>
  77. <script>
  78. import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
  79. import dataTimePicke from "@/components/timepick/dataTimePicke.vue"
  80. import selectMorePicker from "@/components/selectMorePicker.vue"
  81. import {getMapconfig,getBaoconfig,getXiuconfig,getdeptTreeNow} from "@/api/work/check.js"
  82. export default{
  83. data(){
  84. return{
  85. rimg:require("@/work/static/clock/right.png"),
  86. type:'add',
  87. kaTimeAmIn:'',
  88. formData:{
  89. "locations": "",
  90. "lon": "",
  91. "lat": "",
  92. "isPicture":'Y',
  93. "distance": "100",
  94. "startWorkTime": "09:00:00",
  95. "endWorkTime": "18:00:00",
  96. },
  97. deptName:"",
  98. array: ['2', '4',],
  99. index: 0,
  100. deptId:this.$store.state.user.deptId,
  101. typetime:"time",
  102. show:false,
  103. value:'',
  104. timeidx:-1,
  105. auiPicker: {
  106. title: '选择部门',
  107. layer: null,
  108. titflag: true,
  109. data: []
  110. },
  111. indexs:0,
  112. isPicture:'是',
  113. surelist:[{
  114. "label": '是',
  115. "value":'Y'
  116. },{
  117. "label": '否',
  118. "value":'N'
  119. }],
  120. dutyId:'',
  121. fromurl:'rule',//从哪来的
  122. }
  123. },
  124. components:{
  125. dataTimePicke,selectMorePicker
  126. },
  127. onLoad(e) {
  128. var that=this;
  129. // 判断是否修改
  130. uni.$on('refreshaddr',(e) => {
  131. const value = uni.getStorageSync('location');
  132. that.formData.locations=value.address;
  133. that.formData.lon=value.lng;
  134. that.formData.lat=value.lat;
  135. })
  136. // 考勤列表
  137. if(e.id){
  138. this.dutyId=e.id
  139. this.type='update'
  140. this.getMapconfig();
  141. }else{
  142. this.type='add';
  143. this.formData.locations=e.address||"";
  144. this.formData.lon=e.lng||'';
  145. this.formData.lat=e.lat||"";
  146. }
  147. if(e.fromurl){
  148. this.fromurl=e.fromurl
  149. }
  150. },
  151. onUnload(){
  152. uni.$off('refreshaddr')
  153. },
  154. mounted() {
  155. // this.getdeptTreeNow();
  156. },
  157. methods:{
  158. checkPermi,checkRole,
  159. //是否拍照
  160. showNucleic(){
  161. this.$refs.nucleinselet.show();
  162. },
  163. vacSureChange(e){
  164. this.formData.isPicture=e[0].value;
  165. },
  166. showDatePicker (e) {
  167. this.timeidx=e;
  168. this.$refs.setpicker.show();
  169. },
  170. getDeptname(){
  171. this.$refs.picker.open().then(function() {
  172. });
  173. },
  174. pickerCallback(e) {
  175. const _this = this;
  176. let result = '';
  177. e.data.forEach(function(item, index) {
  178. if (index == 0) {
  179. result += item.label;
  180. } else {
  181. result += '/' + item.label;
  182. }
  183. });
  184. var len = e.data.length - 1
  185. _this.deptName = e.data[len].label;
  186. _this.formData.deptId = e.data[len].id;
  187. _this.formData.deptName = e.data[len].label;
  188. },
  189. getdeptTreeNow() {
  190. getdeptTreeNow().then(res => {
  191. if (res.code == 200) {
  192. if(res.data){
  193. this.auiPicker.data = res.data;
  194. // this.formData.deptName=res.data[0].label
  195. // this.formData.deptId=res.data[0].id
  196. }
  197. } else {
  198. this.$toast(res.msg)
  199. }
  200. })
  201. },
  202. timeChange(e){
  203. var that=this;
  204. if(this.timeidx==0){
  205. var endTime=this.formData.endWorkTime;
  206. if(endTime){
  207. var flag=this.getTimeFn(e,endTime)
  208. if(flag!=1){
  209. this.$toast('上班时间晚于下班时间')
  210. this.formData.endWorkTime=''
  211. }
  212. }
  213. this.formData.startWorkTime=e
  214. }else if(this.timeidx==3){
  215. var startt=this.formData.startWorkTime;
  216. if(!startt){
  217. this.$toast('请选择上班时间')
  218. setTimeout(function(){
  219. that.formData.endWorkTime='';
  220. },200)
  221. return
  222. }
  223. var flag=this.getTimeFn(startt,e)
  224. if(flag!=1){
  225. setTimeout(function(){
  226. that.formData.endWorkTime='';
  227. },200)
  228. this.$toast('下班时间早于上班时间')
  229. return
  230. }
  231. this.formData.endWorkTime=e
  232. }
  233. },
  234. // 时间比较
  235. getTimeFn(start,end){
  236. var timea=new Date();
  237. var timeb=new Date();
  238. var timeArra=start.split(':');
  239. timea.setHours(timeArra[0], timeArra[1], timeArra[2], 0);
  240. var timestra=timea.getTime();
  241. var timeArrb=end.split(':');
  242. timeb.setHours(timeArrb[0], timeArrb[1], timeArrb[2], 0);
  243. var timestrb=timeb.getTime();
  244. if(timestra>timestrb){
  245. return 0
  246. }else{
  247. return 1
  248. }
  249. },
  250. cancelFn() {
  251. this.show = false;
  252. },
  253. confirmFn(e) {
  254. // this.inputValue = this.value
  255. this.show = false;
  256. },
  257. getAdres(){
  258. this.$tab.navigateTo("/work/pages/clock/setwoek?address="+this.formData.locations+'&lng='+this.formData.lon+"&lat="+this.formData.lat+'&type='+this.type+'&fromurl='+this.fromurl)
  259. },
  260. bindPickerChange(e){
  261. var val=e.detail.value
  262. this.formData.kaNum=this.array[val];
  263. },
  264. bindPickerChanges(e){
  265. var val=e.detail.value;
  266. this.indexs=val
  267. this.isPicture=this.surelist[val].label
  268. this.formData.isPicture=this.surelist[val].value;
  269. },
  270. bindStartTimeChange(e){
  271. this.formData.kaTimeAmIn = e.detail.value
  272. },
  273. bindStartTimeChanges(e){
  274. this.formData.kaTimeAmOut = e.detail.value
  275. },
  276. bindEndTimeChanges(e){
  277. this.formData.kaTimePmIn = e.detail.value
  278. },
  279. bindEndTimeChange(e){
  280. this.formData.kaTimePmOut = e.detail.value
  281. },
  282. getMapconfig(){
  283. getMapconfig(this.dutyId).then(res=>{
  284. if(res.code==200){
  285. var that=this;
  286. this.formData=res.data
  287. var isPicture=res.data.isPicture
  288. if(isPicture=='Y'){
  289. this.isPicture='是';
  290. this.indexs=0;
  291. }else{
  292. this.isPicture='否';
  293. this.indexs=1;
  294. }
  295. }else{
  296. this.$toast(res.msg)
  297. }
  298. })
  299. },
  300. getSure(){
  301. if (this.formData.locations === "") {
  302. this.$toast('请选择考勤地址')
  303. return
  304. }
  305. if (this.formData.distance === "") {
  306. this.$toast('请输入打卡半径')
  307. return
  308. }
  309. // if (this.formData.deptId === "") {
  310. // this.$toast('请选择打卡部门')
  311. // return
  312. // }
  313. if (this.formData.isPicture === "") {
  314. this.$toast('请选择是否开启拍照打卡')
  315. return
  316. }
  317. if(this.formData.startWorkTime === ""){
  318. this.$toast('请选择上班时间')
  319. return
  320. }
  321. if(this.formData.endWorkTime === ""){
  322. this.$toast('请选择下班时间')
  323. return
  324. }
  325. // if(this.formData.kaNum==2){
  326. // if(this.formData.kaTimeAmIn === ""){
  327. // this.$toast('请选择上班时间')
  328. // return
  329. // }
  330. // if(this.formData.kaTimePmOut === ""){
  331. // this.$toast('请选择下班班时间')
  332. // return
  333. // }
  334. // this.formData.kaTimeAmOut='';
  335. // this.formData.kaTimePmIn='';
  336. // }else{
  337. // if(this.formData.kaTimeAmIn === ""){
  338. // this.$toast('请选择上午上班时间')
  339. // return
  340. // }
  341. // if(this.formData.kaTimeAmOut === ""){
  342. // this.$toast('请选择上午下班时间')
  343. // return
  344. // }
  345. // if(this.formData.kaTimePmIn === ""){
  346. // this.$toast('请选择下午上班时间')
  347. // return
  348. // }
  349. // if(this.formData.kaTimePmOut === ""){
  350. // this.$toast('请选择下午下班时间')
  351. // return
  352. // }
  353. // }
  354. // 保存
  355. if(this.type=='add'){
  356. getBaoconfig(this.formData).then(res=>{
  357. if(res.code==200){
  358. var that=this;
  359. this.$toast("保存成功")
  360. setTimeout(function(){
  361. uni.$emit('reashlist')
  362. uni.navigateBack({
  363. delta:1
  364. })
  365. },1200)
  366. }else{
  367. this.$toast(res.msg)
  368. }
  369. })
  370. }else{
  371. // 修改
  372. getXiuconfig(this.formData).then(res=>{
  373. if(res.code==200){
  374. var that=this;
  375. this.$toast("修改成功")
  376. setTimeout(function(){
  377. uni.$emit('reashlist')
  378. uni.navigateBack({
  379. delta:1
  380. })
  381. },1200)
  382. }else{
  383. this.$toast(res.msg)
  384. }
  385. })
  386. }
  387. }
  388. }
  389. }
  390. </script>
  391. <style scoped lang="scss">
  392. .lbox{background: #FFFFFF;padding: 0 32rpx;margin-bottom: 28rpx;
  393. box-shadow: 0px 4rpx 6rpx 0px rgba(189,189,189,0.35);
  394. border-radius: 10rpx;}
  395. .lists{padding: 20rpx 32rpx;
  396. .list{padding:30rpx 0;display: flex;align-items: center;
  397. .listl{font-size:30rpx;font-weight: bold;
  398. color: #343434;flex:0 0 auto;margin-right: 26rpx;}
  399. .listr{font-size: 30rpx;color: #1678FF;flex: 1 ;text-decoration: underline;text-align: right;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
  400. .listi{font-size:30rpx;color: #343434;flex:1;text-align: right;}
  401. image{width: 10rpx;height: 18rpx;flex: 0 0 auto;margin-left: 26rpx;}
  402. }
  403. .listbtn{width: 100%;height: 76rpx;background: #1678FF;
  404. border-radius: 6px;font-size: 30rpx;color: #FFFFFF;margin-top:70rpx;line-height: 76rpx;text-align: center;}
  405. }
  406. .boxtopbb{text-decoration: none;}
  407. </style>