checkIn.vue 16 KB

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