checkIn.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <view class="home">
  3. <view class="nav">
  4. <view :style="{ paddingTop }">
  5. <view class="title" :style="[{ height }, { lineHeight: height }]">
  6. <view class="back" @click="goBack()">
  7. <u-icon name="arrow-left" color="#ffffff" size="22"></u-icon>
  8. </view>
  9. <text>打卡</text>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="main">
  14. <view class="main-header">
  15. <view class="user-info">
  16. <image class="user-img" src="@/static/images/user.jpg" mode="scaleToFill" />
  17. <view class="info flex1 flex-column flex_1">
  18. <u-text :lines="1" size="32rpx" :bold="true" :text="nickName"></u-text>
  19. <u-text :lines="1" size="24rpx" :text="postName"></u-text>
  20. </view>
  21. </view>
  22. <view class="more" @click="showCheckList">
  23. <u-icon name="order" size="60rpx"></u-icon>
  24. <u-text :lines="1" size="24rpx" text="打卡记录"></u-text>
  25. </view>
  26. </view>
  27. <view class="main-form" v-if="!showList">
  28. <u-form :model="form" :rules="rules" ref="form" label-width="0">
  29. <u-form-item prop="punchVal" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showCheckType = true">
  30. <view class="form-label flex_l">
  31. <view class="label-tag"></view>
  32. 打卡类型
  33. </view>
  34. <u-input
  35. :readonly="true"
  36. placeholder="请选择销售模式"
  37. v-model="form.punchVal"
  38. border="none"
  39. suffixIcon="arrow-down"
  40. suffixIconStyle="color:#CDCDCD"
  41. clearable
  42. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  43. </u-form-item>
  44. <u-form-item
  45. prop="targetName"
  46. borderBottom
  47. customStyle="padding:40rpx 0 30rpx"
  48. v-if="form.punchType > 10"
  49. @click="openSelectUser()">
  50. <view class="form-label flex_l">
  51. <view class="label-tag"></view>
  52. {{ form.punchType == 20 ? '客户' : form.punchType == 30 ? '经销商' : '代理商' }}
  53. </view>
  54. <u-input
  55. :readonly="true"
  56. :placeholder="`请选择${form.punchType == 20 ? '客户' : form.punchType == 30 ? '经销商' : '代理商'}`"
  57. v-model="form.targetName"
  58. border="none"
  59. suffixIcon="arrow-down"
  60. suffixIconStyle="color:#CDCDCD"
  61. clearable
  62. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  63. </u-form-item>
  64. </u-form>
  65. </view>
  66. <view class="main-container">
  67. <template v-if="!showList">
  68. <view class="btn" @click="checkIn">打卡</view>
  69. <view class="location">
  70. <u-text @click="getLocation" :lines="1" :block="true" align="center" size="32rpx" :text="address"></u-text>
  71. <u-loading-icon mode="circle" size="24rpx" :show="show"></u-loading-icon>
  72. </view>
  73. </template>
  74. <u-list height="calc(100vh - 410rpx)" @scrolltolower="scrolltolower" v-else>
  75. <u-list-item v-for="(item, index) in checkList" :key="index">
  76. <u-cell :title="item.punchTime" :label="item.punchLocation"></u-cell>
  77. </u-list-item>
  78. </u-list>
  79. </view>
  80. </view>
  81. <u-toast ref="uToast"></u-toast>
  82. <!-- <uni-file-picker file-mediatype="all" v-model="imageValue" @select="select" @progress="progress" @success="success"
  83. @fail="fail" ref="upload" limit="1">
  84. <view class="upload-btn">
  85. <u-icon name="plus-circle-fill" color="blue" size="28"></u-icon>
  86. </view>
  87. </uni-file-picker> -->
  88. <!-- 打卡类型 -->
  89. <u-picker
  90. :show="showCheckType"
  91. :columns="[checkTypeColumns]"
  92. keyName="value"
  93. @cancel="showCheckType = false"
  94. @confirm="pickCheckType"></u-picker>
  95. <!-- 选择经销商 -->
  96. <select-dealer ref="dealer" :distrId="form.punchType" dist @close="closeDealer($event)"></select-dealer>
  97. <!-- 选择客户 -->
  98. <select-customer ref="cust" @close="closeCust($event)"></select-customer>
  99. <u-notify ref="uNotify"></u-notify>
  100. </view>
  101. </template>
  102. <script>
  103. import { mapGetters } from 'vuex'
  104. import to from 'await-to-js'
  105. import api from '@/api/system'
  106. import SelectDealer from 'components/SelectDealer'
  107. import SelectCustomer from 'components/SelectCustomer'
  108. export default {
  109. components: {
  110. SelectDealer,
  111. SelectCustomer,
  112. },
  113. data() {
  114. return {
  115. height: '',
  116. paddingTop: '',
  117. address: '获取定位',
  118. showCheckType: false,
  119. form: {
  120. targetId: undefined, //经销商/代理商ID
  121. targetName: undefined, //经销商/代理商名称
  122. punchType: '', //打卡类型
  123. punchVal: '',
  124. punchLat: 0,
  125. punchLng: 0,
  126. punchLocation: '',
  127. punchImg: '',
  128. },
  129. show: false,
  130. imageValue: [],
  131. showList: false,
  132. checkList: [],
  133. queryForm: {
  134. pageNum: 1,
  135. pageSize: 10,
  136. },
  137. total: 0,
  138. checkTypeColumns: [
  139. {
  140. key: '10',
  141. value: '居家',
  142. },
  143. {
  144. key: '20',
  145. value: '客户',
  146. },
  147. {
  148. key: '30',
  149. value: '经销商',
  150. },
  151. { key: '40', value: '代理商' },
  152. ],
  153. rules: {
  154. punchVal: [
  155. {
  156. required: true,
  157. trigger: ['blur', 'change'],
  158. message: '请选择打卡类型',
  159. },
  160. ],
  161. targetName: [
  162. {
  163. required: true,
  164. trigger: ['blur', 'change'],
  165. message: `请选择用户`,
  166. },
  167. ],
  168. },
  169. }
  170. },
  171. computed: {
  172. ...mapGetters(['nickName', 'postName']),
  173. },
  174. created() {
  175. this.getLocation()
  176. const navData = uni.getMenuButtonBoundingClientRect()
  177. this.height = navData.height + 'px'
  178. this.paddingTop = navData.top + 'px'
  179. },
  180. watch: {
  181. 'form.punchType'(val) {
  182. this.form.targetId = undefined
  183. this.form.targetName = undefined
  184. },
  185. },
  186. methods: {
  187. // 选择打卡类型
  188. pickCheckType(e) {
  189. this.form.punchType = e.value[0].key
  190. this.form.punchVal = e.value[0].value
  191. this.showCheckType = false
  192. },
  193. // 经销商
  194. closeDealer(dealer) {
  195. if (dealer) {
  196. this.form.targetId = dealer.id
  197. this.form.targetName = dealer.name
  198. }
  199. },
  200. // 关闭选择客户
  201. closeCust(user) {
  202. if (user) {
  203. this.form.targetId = user.id
  204. this.form.targetName = user.name
  205. }
  206. },
  207. openSelectUser() {
  208. if (this.form.punchType == '20') {
  209. this.$refs.cust.open()
  210. } else {
  211. this.$refs.dealer.open()
  212. }
  213. },
  214. getLocation() {
  215. this.show = true
  216. const _this = this
  217. uni.getLocation({
  218. type: 'wgs84',
  219. success: function (res) {
  220. const latitude = res.latitude.toString()
  221. const longitude = res.longitude.toString()
  222. uni.request({
  223. header: {
  224. 'Content-Type': 'application/text',
  225. },
  226. url:
  227. process.uniEnv.VUE_APP_PROTOCOL +
  228. 'apis.map.qq.com/ws/geocoder/v1/?location=' +
  229. latitude +
  230. ',' +
  231. longitude +
  232. '&key=6REBZ-BRN6J-BMAFY-FIRI3-SMK43-G3FXU',
  233. success(re) {
  234. if (re.statusCode === 200) {
  235. _this.address = re.data.result.address
  236. _this.form.punchLat = latitude
  237. _this.form.punchLng = longitude
  238. _this.form.punchLocation = re.data.result.address
  239. _this.show = false
  240. } else {
  241. _this.address = '点击重试'
  242. this.$refs.uToast.show({
  243. type: 'error',
  244. message: '定位失败,请重试',
  245. })
  246. }
  247. },
  248. fail: (err) => (_this.show = false),
  249. })
  250. },
  251. fail: (err) => (_this.show = false),
  252. })
  253. },
  254. async checkIn() {
  255. const [fail, resp] = await to(this.$refs.form.validate())
  256. if (fail && fail.length > 0) {
  257. this.$refs.uNotify.show({
  258. top: this.height + this.paddingTop + 10,
  259. type: 'warning',
  260. message: fail[0].message,
  261. duration: 1000 * 3,
  262. })
  263. return
  264. }
  265. if (!this.form.punchLat || !this.form.punchLng) {
  266. this.address = '点击重试'
  267. return this.$refs.uToast.show({
  268. type: 'error',
  269. message: '定位失败,请重试',
  270. })
  271. }
  272. const [err, res] = await uni.chooseImage({
  273. count: 1, //默认9
  274. sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
  275. sourceType: ['camera'],
  276. })
  277. if (err) return
  278. this.select(res)
  279. res.tempFiles[0].name = new Date().getTime() + ''
  280. res.tempFiles[0].type = ''
  281. },
  282. // // 选择上传触发函数
  283. select(e) {
  284. let url = process.uniEnv.VUE_APP_UPLOAD_WEED
  285. uni.request({
  286. url, //仅为示例,并非真实接口地址。
  287. success: (res) => {
  288. this.uploadFiles(e, res.data)
  289. },
  290. })
  291. },
  292. // 上传函数
  293. async uploadFiles(e, res) {
  294. let action = process.uniEnv.VUE_APP_PROTOCOL + res.publicUrl + '/' + res.fid
  295. uni.uploadFile({
  296. url: action,
  297. filePath: e.tempFilePaths[0],
  298. name: 'file',
  299. formData: {
  300. file: e.tempFiles[0],
  301. },
  302. success: (res) => {
  303. this.form.punchImg = action
  304. api.checkIn(this.form).then((res) => {
  305. this.$refs.uToast.show({
  306. type: 'success',
  307. message: '打卡成功',
  308. })
  309. })
  310. },
  311. fail: () => {
  312. console.log('err')
  313. },
  314. })
  315. },
  316. showCheckList() {
  317. if (!this.showList) {
  318. this.queryForm.pageNum = 1
  319. this.checkList = []
  320. this.loadCheckList()
  321. }
  322. this.showList = !this.showList
  323. },
  324. async loadCheckList() {
  325. this.loadStatus = 'loading'
  326. const [err, res] = await to(api.getCheckList(this.queryForm))
  327. if (err) {
  328. this.loadStatus = 'nomore'
  329. return
  330. }
  331. if (res && res.code == 200) {
  332. this.checkList = [...this.checkList, ...(res.data.list || [])]
  333. // this.checkList = res.data.list
  334. this.total = res.data.total
  335. this.loadStatus = this.checkList.length == this.total ? 'nomore' : 'loadmore'
  336. } else {
  337. this.loadStatus = 'nomore'
  338. }
  339. },
  340. scrolltolower() {
  341. if (this.checkList.length < this.total && this.loadStatus != 'loading') {
  342. this.queryForm.pageNum++
  343. this.$u.throttle(this.loadCheckList(), 2000, false)
  344. }
  345. },
  346. goBack() {
  347. uni.navigateBack({
  348. //关闭当前页面,返回上一页面或多级页面。
  349. delta: 1,
  350. })
  351. },
  352. },
  353. }
  354. </script>
  355. <style lang="scss" scoped>
  356. /deep/ .uni-file-picker {
  357. display: none;
  358. }
  359. .home {
  360. padding-top: 188rpx;
  361. height: 100%;
  362. .nav {
  363. position: absolute;
  364. left: 0;
  365. top: 0;
  366. width: 100%;
  367. height: 284rpx;
  368. background: #3e7ef8;
  369. .title {
  370. position: relative;
  371. text-align: center;
  372. font-size: 32rpx;
  373. font-weight: bold;
  374. color: #ffffff;
  375. .back {
  376. position: absolute;
  377. top: 0;
  378. bottom: 0;
  379. margin: auto;
  380. left: 70rpx;
  381. display: flex;
  382. }
  383. }
  384. }
  385. .main {
  386. display: flex;
  387. flex-direction: column;
  388. position: absolute;
  389. width: 100%;
  390. height: calc(100vh - 188rpx);
  391. background: #ffffff;
  392. box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
  393. border-radius: 31rpx 31rpx 0 0;
  394. padding: 0 32rpx;
  395. overflow: hidden;
  396. padding-bottom: 64rpx;
  397. .main-header {
  398. padding: 20rpx 40rpx;
  399. display: flex;
  400. justify-content: space-between;
  401. .user-info {
  402. display: flex;
  403. .user-img {
  404. width: 116rpx;
  405. height: 116rpx;
  406. border-radius: 50%;
  407. margin-right: 32rpx;
  408. }
  409. .info {
  410. height: 116rpx;
  411. margin-right: 32rpx;
  412. }
  413. }
  414. .more {
  415. display: flex;
  416. flex-direction: column;
  417. align-items: center;
  418. }
  419. }
  420. .main-container {
  421. flex: 1;
  422. display: flex;
  423. flex-direction: column;
  424. align-items: center;
  425. justify-content: center;
  426. .btn {
  427. width: 300rpx;
  428. height: 300rpx;
  429. border-radius: 50%;
  430. background: linear-gradient(70deg, #3e7ef8, #1d66dc);
  431. display: flex;
  432. justify-content: center;
  433. align-items: center;
  434. color: #fff;
  435. font-size: 48rpx;
  436. font-weight: bold;
  437. box-shadow: 0 6rpx 19rpx 2rpx rgba(29, 102, 220, 0.2);
  438. margin-bottom: 40rpx;
  439. }
  440. .location {
  441. display: flex;
  442. height: 32rpx;
  443. line-height: 32rpx;
  444. }
  445. }
  446. }
  447. }
  448. </style>