Sign.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <div>
  3. <common @asynCallBack="asynCallBack"></common>
  4. <top-header :pageTitle="pageTitle"></top-header>
  5. <div class="mui-content vongi-wordcard">
  6. <div class="mui-content-padded vongi-wordcard-padded">
  7. <h5>当前打卡班次</h5>
  8. <h3>{{tjForm.workAttendanceDate}}<span v-text="tjForm.workAttendanceTime"></span></h3>
  9. </div>
  10. <div class="mui-content-padded">
  11. <form class="mui-input-group">
  12. <div class="mui-input-row">
  13. <label><span class="colorfe616c">*</span>审批人</label>
  14. <div class="mui-navigate-right" @click="selectPerson">
  15. <button class="mui-btn mui-btn-block" type='button' v-text="approvalPersonName"></button>
  16. </div>
  17. </div>
  18. </form>
  19. </div>
  20. <div class="mui-content-padded">
  21. <h5><span class="colorfe616c">*</span>定位</h5>
  22. <button class="vongi-yidi-location">{{tjForm.address}}<span class="mui-icon mui-icon-location"></span></button>
  23. </div>
  24. <div class="mui-content-padded">
  25. <h5>备注</h5>
  26. <div class="mui-input-row">
  27. <textarea v-model="tjForm.content" rows="5" placeholder="请输入"></textarea>
  28. </div>
  29. </div>
  30. <div class="mui-content-padded">
  31. <h5>上传照片</h5>
  32. <div class="fyy-upphoto">
  33. <div class="mui-col-xs-3 fyy-upphoto-close" v-for="(item,index) in picList">
  34. <img :src="item" />
  35. <a class="mui-icon mui-icon-closeempty" @click="delPic(item)"></a>
  36. </div>
  37. <div class="mui-col-xs-3" @click="chooseImage">
  38. <a><span class="mui-icon mui-icon-plusempty"></span></a>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="vongi-btn">
  43. <button class="mui-btn mui-btn-primary" type="button" @click="submit">
  44. 提交
  45. </button>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. require('$project/assets/js/mui.picker.min.js');
  52. import * as API_Attendance from '@/apis/Master/attendance'
  53. import Common from '$project/components/Common.vue'
  54. import Loading from '$project/components/Loading.vue'
  55. import TopHeader from '$project/components/TopHeader.vue'
  56. import {
  57. mapGetters,
  58. mapMutations
  59. } from 'vuex'
  60. import * as WxJsApi from '$project/utils/wxJsApi'
  61. import MapLoader from '$project/utils/AMap'
  62. export default {
  63. name: 'MasterAttendanceSign',
  64. components: {
  65. Common,
  66. Loading,
  67. TopHeader
  68. },
  69. data() {
  70. return {
  71. pageTitle: '异地打卡',
  72. isLoading: false,
  73. subForm: {
  74. workAttendanceId: ''
  75. },
  76. tjForm: {
  77. alarmConfigId: '',
  78. workAttendanceDate: '',
  79. workAttendanceTime: '',
  80. type: '1', //外勤打卡/补卡(1/2)
  81. content: '',
  82. approvalPersonId: '',
  83. workAttendanceId: '',
  84. photoFile: '',
  85. longitude: 112.276527,
  86. latitude: 30.306427,
  87. address: '',
  88. },
  89. //typeName: '',
  90. approvalPersonName: '',
  91. personList: [],
  92. picList: [],
  93. }
  94. },
  95. created() {
  96. },
  97. methods: {
  98. //获取详情
  99. getTime() {
  100. this.isLoading = true;
  101. API_Attendance.patchCard(this.subForm).then(response => {
  102. this.tjForm.workAttendanceDate = response.workAttendanceDate;
  103. this.tjForm.workAttendanceTime = response.workAttendanceTime;
  104. this.tjForm.alarmConfigId = response.alarmConfigId;
  105. this.isLoading = false;
  106. }).catch(error => {
  107. this.isLoading = false;
  108. mui.toast(error);
  109. })
  110. },
  111. //获取审核人列表
  112. getPsersonList() {
  113. this.isLoading = true;
  114. API_Attendance.getApprovalList().then(response => {
  115. this.personList = response.data;
  116. this.isLoading = false;
  117. }).catch(error => {
  118. this.isLoading = false;
  119. mui.toast(error);
  120. })
  121. },
  122. //微信选择图片
  123. chooseImage() {
  124. WxJsApi.chooseImage().then(res => {
  125. var localData = res.localData;
  126. if (localData.indexOf('data:image') != 0) {
  127. //判断是否有这样的头部
  128. localData = 'data:image/jpeg;base64,' + localData
  129. }
  130. localData = localData.replace(/\r|\n/g, '').replace('data:image/jgp', 'data:image/jpeg')
  131. this.imgBase64 = localData;
  132. //显示裁剪图片
  133. //_this.showCropper(field);
  134. this.uploadpic();
  135. }).catch(error => {
  136. mui.toast(error);
  137. })
  138. },
  139. //上传图片
  140. uploadpic() {
  141. this.isLoading = true;
  142. WxJsApi.uploadPic(this.imgBase64).then(response => {
  143. this.isLoading = false;
  144. this.picList.push(response);
  145. }).catch(error => {
  146. this.isLoading = false;
  147. mui.toast(error);
  148. })
  149. },
  150. //选择审核人
  151. selectPerson() {
  152. var _this = this;
  153. var picker = new mui.PopPicker();
  154. picker.setData(_this.syPersonList);
  155. picker.show(function(selectItems) {
  156. _this.tjForm.approvalPersonId = selectItems[0].value;
  157. _this.approvalPersonName = selectItems[0].text;
  158. })
  159. },
  160. //表单检测
  161. checkFrom() {
  162. if (!this.tjForm.type) {
  163. mui.toast('请选择打卡类型');
  164. return false;
  165. } else if (!this.tjForm.approvalPersonId) {
  166. mui.toast('请选择审批人');
  167. return false;
  168. } else if (!this.tjForm.content) {
  169. mui.toast('请输入申请内容');
  170. return false;
  171. } else {
  172. return true;
  173. }
  174. },
  175. //提交
  176. submit() {
  177. this.tjForm.photoFile = this.picList.join(',');
  178. if (this.checkFrom()) {
  179. this.isLoading = true;
  180. API_Attendance.postPatchCard(this.tjForm).then(response => {
  181. this.isLoading = false;
  182. this.$router.push({
  183. name: 'Master',
  184. query: {}
  185. })
  186. }).catch(error => {
  187. this.isLoading = false;
  188. mui.toast(error);
  189. })
  190. }
  191. },
  192. //删除图片
  193. delPic(item) {
  194. let picList = this.picList;
  195. let index = picList.indexOf(item);
  196. if (index > -1) {
  197. picList.splice(index, 1);
  198. }
  199. this.picList = picList;
  200. },
  201. //获取经纬度
  202. getPoint() {
  203. this.isLoading = true;
  204. WxJsApi.getLocation().then((res) => {
  205. this.isLoading = false;
  206. this.tjForm.latitude = parseFloat(res.latitude);
  207. this.tjForm.longitude = parseFloat(res.longitude);
  208. console.log(this.tjForm)
  209. //获取定位地址
  210. this.getPositionByLonLats()
  211. })
  212. },
  213. //获取定位地址
  214. getPositionByLonLats() {
  215. var _this = this;
  216. MapLoader().then(AMap => {
  217. var lnglatXY = [_this.tjForm.longitude, _this.tjForm.latitude];
  218. AMap.service('AMap.Geocoder', function() {
  219. let geocoder = new AMap.Geocoder({});
  220. geocoder.getAddress(lnglatXY, function(status, result) {
  221. console.log(lnglatXY);
  222. console.log(status, result);
  223. if (status === 'complete' && result.info === 'OK') {
  224. var address = result.regeocode.formattedAddress;
  225. console.log(address);
  226. _this.tjForm.address = address;
  227. } else {
  228. _this.tjForm.address = '无法获取定位';
  229. }
  230. });
  231. });
  232. }).catch(error => {
  233. console.log(error)
  234. })
  235. },
  236. asynCallBack() {
  237. },
  238. },
  239. mounted() {
  240. //获取微信配置
  241. WxJsApi.getWxConfig(['chooseImage', 'getLocalImgData', 'getLocation']);
  242. //获取经纬度
  243. this.getPoint();
  244. this.getTime();
  245. this.getPsersonList();
  246. },
  247. destroyed() {},
  248. computed: {
  249. syPersonList: {
  250. // getter
  251. get: function() {
  252. let list = [];
  253. this.personList.forEach(function(item, index) {
  254. list.push({
  255. value: item.id,
  256. text: item.name
  257. });
  258. })
  259. return list;
  260. },
  261. // setter
  262. set: function(newValue) {
  263. console.log(newValue)
  264. }
  265. },
  266. typeName: {
  267. // getter
  268. get: function() {
  269. if (this.tjForm.type == '1') {
  270. return '外勤打卡';
  271. } else if (this.tjForm.type == '2') {
  272. return '补卡';
  273. } else {
  274. return '无';
  275. }
  276. },
  277. // setter
  278. set: function(newValue) {
  279. console.log(newValue)
  280. }
  281. },
  282. ...mapGetters({
  283. openId: 'wx_openid',
  284. token: 'token',
  285. })
  286. }
  287. }
  288. </script>
  289. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  290. <style src="$project/assets/css/mui.picker.min.css"></style>
  291. <style scoped>
  292. </style>