checkIn.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. {{ selectLable(form.punchType) }}
  53. </view>
  54. <u-input
  55. :readonly="true"
  56. :placeholder="`请选择${selectLable(form.punchType)}`"
  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. <!-- 合作伙伴联系人 -->
  65. <u-form-item
  66. prop="partnerContactName"
  67. borderBottom
  68. customStyle="padding:40rpx 0 30rpx"
  69. v-if="form.punchType == 50 && form.targetId"
  70. @click="openPartnersConcat()">
  71. <view class="form-label flex_l">合作伙伴联系人</view>
  72. <u-input
  73. :readonly="true"
  74. placeholder="请选择合作伙伴联系人"
  75. v-model="form.partnerContactName"
  76. border="none"
  77. suffixIcon="arrow-down"
  78. suffixIconStyle="color:#CDCDCD"
  79. clearable
  80. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  81. </u-form-item>
  82. <!-- END -->
  83. </u-form>
  84. </view>
  85. <view class="main-container">
  86. <template v-if="!showList">
  87. <view class="btn" @click="checkIn">打卡</view>
  88. <view class="location">
  89. <u-text @click="getLocation" :lines="1" :block="true" align="center" size="32rpx" :text="address"></u-text>
  90. <u-loading-icon mode="circle" size="24rpx" :show="show"></u-loading-icon>
  91. </view>
  92. </template>
  93. <u-list height="calc(100vh - 410rpx)" @scrolltolower="scrolltolower" v-else>
  94. <u-list-item v-for="(item, index) in checkList" :key="index">
  95. <u-cell :title="item.punchTime" :label="item.punchLocation"></u-cell>
  96. </u-list-item>
  97. </u-list>
  98. </view>
  99. </view>
  100. <u-toast ref="uToast"></u-toast>
  101. <!-- <uni-file-picker file-mediatype="all" v-model="imageValue" @select="select" @progress="progress" @success="success"
  102. @fail="fail" ref="upload" limit="1">
  103. <view class="upload-btn">
  104. <u-icon name="plus-circle-fill" color="blue" size="28"></u-icon>
  105. </view>
  106. </uni-file-picker> -->
  107. <!-- 打卡类型 -->
  108. <u-picker
  109. :show="showCheckType"
  110. :columns="[checkTypeColumns]"
  111. keyName="value"
  112. @cancel="showCheckType = false"
  113. @confirm="pickCheckType"></u-picker>
  114. <!-- 选择经销商 -->
  115. <select-dealer ref="dealer" :distrId="form.punchType" dist @close="closeDealer($event)"></select-dealer>
  116. <!-- 选择客户 -->
  117. <select-customer ref="cust" @close="closeCust($event)"></select-customer>
  118. <!-- 选择合作伙伴 -->
  119. <select-partners ref="partners" @close="closePartners($event)"></select-partners>
  120. <select-partners-concat
  121. ref="partnersConcat"
  122. :queryParams="{ partnerId: form.targetId }"
  123. @close="closePartnersConcat($event)"></select-partners-concat>
  124. <u-notify ref="uNotify"></u-notify>
  125. <u-popup :show="shwoSuccess" mode="center" :safeAreaInsetBottom="false" overlayOpacity="0" round="10">
  126. <view class="tips-wrap">
  127. <u-image :src="form.punchImg" mode="scaleToFill" width="80vw" height="500px" />
  128. <view class="tips-content">
  129. <view class="success-icon-wrap">
  130. <u-icon name="checkmark-circle-fill" color="#409EFF" size="60"></u-icon>
  131. </view>
  132. <view class="tit">签到成功</view>
  133. <view class="content">
  134. <view class="mb20">{{ getNowTime() }}</view>
  135. <view class="mb20">{{ form.punchLocation }}</view>
  136. <view class="mb20">打卡人:{{ nickName }}</view>
  137. <view class="mb20">打卡类型:{{ form.punchVal }}</view>
  138. <view class="mb20" v-if="form.targetName">{{ form.punchVal }}名称:{{ form.targetName }}</view>
  139. </view>
  140. <view class="confirm">
  141. <u-button type="primary" text="确定" @click="shwoSuccess = false"></u-button>
  142. </view>
  143. </view>
  144. </view>
  145. </u-popup>
  146. </view>
  147. </template>
  148. <script>
  149. import { mapGetters } from 'vuex'
  150. import to from 'await-to-js'
  151. import api from '@/api/system'
  152. import SelectDealer from 'components/SelectDealer'
  153. import SelectCustomer from 'components/SelectCustomer'
  154. import SelectPartners from 'components/SelectPartners'
  155. import SelectPartnersConcat from 'components/SelectPartnersConcat'
  156. export default {
  157. components: {
  158. SelectDealer,
  159. SelectCustomer,
  160. SelectPartners,
  161. SelectPartnersConcat,
  162. },
  163. data() {
  164. return {
  165. shwoSuccess: false,
  166. height: '',
  167. paddingTop: '',
  168. address: '获取定位',
  169. showCheckType: false,
  170. form: {
  171. targetId: undefined, //经销商/代理商ID
  172. targetName: undefined, //经销商/代理商名称
  173. punchType: '', //打卡类型
  174. punchVal: '',
  175. punchLat: 0,
  176. punchLng: 0,
  177. punchLocation: '',
  178. punchImg: 'https://oms.dashoo.cn/weed1/5,01456eecb7e4a8',
  179. partnerContactId: null,
  180. partnerContactName: null,
  181. },
  182. show: false,
  183. imageValue: [],
  184. showList: false,
  185. checkList: [],
  186. queryForm: {
  187. pageNum: 1,
  188. pageSize: 10,
  189. },
  190. total: 0,
  191. checkTypeColumns: [
  192. {
  193. key: '10',
  194. value: '居家',
  195. },
  196. {
  197. key: '20',
  198. value: '客户',
  199. },
  200. {
  201. key: '30',
  202. value: '经销商',
  203. },
  204. { key: '40', value: '代理商' },
  205. { key: '50', value: '合作伙伴' },
  206. ],
  207. rules: {
  208. punchVal: [
  209. {
  210. required: true,
  211. trigger: ['blur', 'change'],
  212. message: '请选择打卡类型',
  213. },
  214. ],
  215. targetName: [
  216. {
  217. required: true,
  218. trigger: ['blur', 'change'],
  219. message: `请选择用户`,
  220. },
  221. ],
  222. },
  223. }
  224. },
  225. computed: {
  226. ...mapGetters(['nickName', 'postName']),
  227. },
  228. created() {
  229. this.getLocation()
  230. const navData = uni.getMenuButtonBoundingClientRect()
  231. this.height = navData.height + 'px'
  232. this.paddingTop = navData.top + 'px'
  233. },
  234. watch: {
  235. 'form.punchType'(val) {
  236. this.form.targetId = undefined
  237. this.form.targetName = undefined
  238. this.form.partnerContactId = null
  239. this.form.partnerContactName = null
  240. },
  241. 'form.targetId'(val) {
  242. this.form.partnerContactId = null
  243. this.form.partnerContactName = null
  244. },
  245. },
  246. methods: {
  247. selectLable(type) {
  248. if (type) {
  249. const findItem = this.checkTypeColumns.find((item) => item.key == type)
  250. return findItem.value
  251. }
  252. },
  253. // 选择打卡类型
  254. pickCheckType(e) {
  255. this.form.punchType = e.value[0].key
  256. this.form.punchVal = e.value[0].value
  257. this.showCheckType = false
  258. },
  259. // 经销商
  260. closeDealer(dealer) {
  261. if (dealer) {
  262. this.form.targetId = dealer.id
  263. this.form.targetName = dealer.name
  264. }
  265. },
  266. // 关闭选择客户
  267. closeCust(user) {
  268. if (user) {
  269. this.form.targetId = user.id
  270. this.form.targetName = user.name
  271. }
  272. },
  273. closePartners(partners) {
  274. if (partners) {
  275. this.form.targetId = partners.id
  276. this.form.targetName = partners.name
  277. }
  278. },
  279. closePartnersConcat(concat) {
  280. if (concat) {
  281. this.form.partnerContactId = concat.id
  282. this.form.partnerContactName = concat.name
  283. }
  284. },
  285. openSelectUser() {
  286. if (this.form.punchType == '20') {
  287. this.$refs.cust.open()
  288. } else if (this.form.punchType == '30' || this.form.punchType == '40') {
  289. this.$refs.dealer.open()
  290. } else if (this.form.punchType == '50') {
  291. this.$refs.partners.open()
  292. }
  293. },
  294. openPartnersConcat() {
  295. this.$refs.partnersConcat.open(this.form.partnerContactId)
  296. },
  297. getLocation() {
  298. this.show = true
  299. const _this = this
  300. uni.getLocation({
  301. type: 'wgs84',
  302. success: function (res) {
  303. const latitude = res.latitude.toString()
  304. const longitude = res.longitude.toString()
  305. uni.request({
  306. header: {
  307. 'Content-Type': 'application/text',
  308. },
  309. url:
  310. process.uniEnv.VUE_APP_PROTOCOL +
  311. 'apis.map.qq.com/ws/geocoder/v1/?location=' +
  312. latitude +
  313. ',' +
  314. longitude +
  315. '&key=6REBZ-BRN6J-BMAFY-FIRI3-SMK43-G3FXU',
  316. success(re) {
  317. if (re.statusCode === 200) {
  318. _this.address = re.data.result.address
  319. _this.form.punchLat = latitude
  320. _this.form.punchLng = longitude
  321. _this.form.punchLocation = re.data.result.address
  322. _this.show = false
  323. } else {
  324. _this.address = '点击重试'
  325. this.$refs.uToast.show({
  326. type: 'error',
  327. message: '定位失败,请重试',
  328. })
  329. }
  330. },
  331. fail: (err) => (_this.show = false),
  332. })
  333. },
  334. fail: (err) => (_this.show = false),
  335. })
  336. },
  337. async checkIn() {
  338. const [fail, resp] = await to(this.$refs.form.validate())
  339. if (fail && fail.length > 0) {
  340. this.$refs.uNotify.show({
  341. top: this.height + this.paddingTop + 10,
  342. type: 'warning',
  343. message: fail[0].message,
  344. duration: 1000 * 3,
  345. })
  346. return
  347. }
  348. if (!this.form.punchLat || !this.form.punchLng) {
  349. this.address = '点击重试'
  350. return this.$refs.uToast.show({
  351. type: 'error',
  352. message: '定位失败,请重试',
  353. })
  354. }
  355. const [err, res] = await uni.chooseImage({
  356. count: 1, //默认9
  357. sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
  358. sourceType: ['camera'],
  359. })
  360. if (err) return
  361. this.select(res)
  362. res.tempFiles[0].name = new Date().getTime() + ''
  363. res.tempFiles[0].type = ''
  364. },
  365. // // 选择上传触发函数
  366. select(e) {
  367. let url = process.uniEnv.VUE_APP_UPLOAD_WEED
  368. uni.request({
  369. url, //仅为示例,并非真实接口地址。
  370. success: (res) => {
  371. this.uploadFiles(e, res.data)
  372. },
  373. })
  374. },
  375. // 上传函数
  376. async uploadFiles(e, res) {
  377. let action = process.uniEnv.VUE_APP_PROTOCOL + res.publicUrl + '/' + res.fid
  378. uni.uploadFile({
  379. url: action,
  380. filePath: e.tempFilePaths[0],
  381. name: 'file',
  382. formData: {
  383. file: e.tempFiles[0],
  384. },
  385. success: (res) => {
  386. this.form.punchImg = action
  387. api.checkIn(this.form).then((res) => {
  388. this.shwoSuccess = true
  389. // this.$refs.uToast.show({
  390. // type: 'success',
  391. // message: '打卡成功',
  392. // })
  393. })
  394. },
  395. fail: () => {
  396. console.log('err')
  397. },
  398. })
  399. },
  400. showCheckList() {
  401. if (!this.showList) {
  402. this.queryForm.pageNum = 1
  403. this.checkList = []
  404. this.loadCheckList()
  405. }
  406. this.showList = !this.showList
  407. },
  408. async loadCheckList() {
  409. this.loadStatus = 'loading'
  410. const [err, res] = await to(api.getCheckList(this.queryForm))
  411. if (err) {
  412. this.loadStatus = 'nomore'
  413. return
  414. }
  415. if (res && res.code == 200) {
  416. this.checkList = [...this.checkList, ...(res.data.list || [])]
  417. // this.checkList = res.data.list
  418. this.total = res.data.total
  419. this.loadStatus = this.checkList.length == this.total ? 'nomore' : 'loadmore'
  420. } else {
  421. this.loadStatus = 'nomore'
  422. }
  423. },
  424. scrolltolower() {
  425. if (this.checkList.length < this.total && this.loadStatus != 'loading') {
  426. this.queryForm.pageNum++
  427. this.$u.throttle(this.loadCheckList(), 2000, false)
  428. }
  429. },
  430. goBack() {
  431. uni.navigateBack({
  432. //关闭当前页面,返回上一页面或多级页面。
  433. delta: 1,
  434. })
  435. },
  436. getNowTime() {
  437. let now = new Date()
  438. let year = now.getFullYear() //获取完整的年份(4位,1970-????)
  439. let month = now.getMonth() + 1 //获取当前月份(0-11,0代表1月)
  440. let today = now.getDate() //获取当前日(1-31)
  441. let hour = now.getHours() //获取当前小时数(0-23)
  442. let minute = now.getMinutes() //获取当前分钟数(0-59)
  443. let nowTime = ''
  444. nowTime =
  445. year +
  446. '-' +
  447. this.fillZero(month) +
  448. '-' +
  449. this.fillZero(today) +
  450. ' ' +
  451. this.fillZero(hour) +
  452. ':' +
  453. this.fillZero(minute)
  454. return nowTime
  455. },
  456. fillZero(str) {
  457. var realNum
  458. if (str < 10) {
  459. realNum = '0' + str
  460. } else {
  461. realNum = str
  462. }
  463. return realNum
  464. },
  465. },
  466. }
  467. </script>
  468. <style lang="scss" scoped>
  469. /deep/ .uni-file-picker {
  470. display: none;
  471. }
  472. .home {
  473. padding-top: 188rpx;
  474. height: 100%;
  475. .nav {
  476. position: absolute;
  477. left: 0;
  478. top: 0;
  479. width: 100%;
  480. height: 284rpx;
  481. background: #3e7ef8;
  482. .title {
  483. position: relative;
  484. text-align: center;
  485. font-size: 32rpx;
  486. font-weight: bold;
  487. color: #ffffff;
  488. .back {
  489. position: absolute;
  490. top: 0;
  491. bottom: 0;
  492. margin: auto;
  493. left: 70rpx;
  494. display: flex;
  495. }
  496. }
  497. }
  498. .main {
  499. display: flex;
  500. flex-direction: column;
  501. position: absolute;
  502. width: 100%;
  503. height: calc(100vh - 188rpx);
  504. background: #ffffff;
  505. box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
  506. border-radius: 31rpx 31rpx 0 0;
  507. padding: 0 32rpx;
  508. overflow: hidden;
  509. padding-bottom: 64rpx;
  510. .main-header {
  511. padding: 20rpx 40rpx;
  512. display: flex;
  513. justify-content: space-between;
  514. .user-info {
  515. display: flex;
  516. .user-img {
  517. width: 116rpx;
  518. height: 116rpx;
  519. border-radius: 50%;
  520. margin-right: 32rpx;
  521. }
  522. .info {
  523. height: 116rpx;
  524. margin-right: 32rpx;
  525. }
  526. }
  527. .more {
  528. display: flex;
  529. flex-direction: column;
  530. align-items: center;
  531. }
  532. }
  533. .main-container {
  534. flex: 1;
  535. display: flex;
  536. flex-direction: column;
  537. align-items: center;
  538. justify-content: center;
  539. .btn {
  540. width: 300rpx;
  541. height: 300rpx;
  542. border-radius: 50%;
  543. background: linear-gradient(70deg, #3e7ef8, #1d66dc);
  544. display: flex;
  545. justify-content: center;
  546. align-items: center;
  547. color: #fff;
  548. font-size: 48rpx;
  549. font-weight: bold;
  550. box-shadow: 0 6rpx 19rpx 2rpx rgba(29, 102, 220, 0.2);
  551. margin-bottom: 40rpx;
  552. }
  553. .location {
  554. display: flex;
  555. height: 32rpx;
  556. line-height: 32rpx;
  557. }
  558. }
  559. }
  560. .tips-wrap {
  561. width: 100%;
  562. height: 500px;
  563. position: relative;
  564. .tips-content {
  565. position: absolute;
  566. width: 100%;
  567. height: 100%;
  568. background: rgba(0, 0, 0, 0.6);
  569. top: 0;
  570. left: 0;
  571. padding: 40px 20px 20px;
  572. display: flex;
  573. align-items: center;
  574. flex-direction: column;
  575. .success-icon-wrap {
  576. background: #fff;
  577. width: 45px;
  578. height: 45px;
  579. border-radius: 50%;
  580. display: flex;
  581. align-items: center;
  582. justify-content: center;
  583. }
  584. .tit {
  585. font-size: 24px;
  586. color: #67c23a;
  587. margin: 20px 0;
  588. text-align: center;
  589. }
  590. .confirm {
  591. margin-top: 10px;
  592. width: 100px;
  593. }
  594. .content {
  595. display: flex;
  596. flex-direction: column;
  597. align-items: center;
  598. color: #fff;
  599. font-weight: bold;
  600. .mb20 {
  601. margin-bottom: 20px;
  602. }
  603. }
  604. }
  605. }
  606. }
  607. </style>