checkIn.vue 16 KB

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