setswork.vue 12 KB

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