checkIn.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. },
  204. }
  205. },
  206. computed: {
  207. ...mapGetters(['nickName', 'postName']),
  208. },
  209. created() {
  210. this.getLocation()
  211. const navData = uni.getMenuButtonBoundingClientRect()
  212. this.height = navData.height + 'px'
  213. this.paddingTop = navData.top + 'px'
  214. },
  215. watch: {
  216. 'form.punchType'(val) {
  217. this.form.targetId = undefined
  218. this.form.targetName = undefined
  219. },
  220. },
  221. methods: {
  222. selectLable(type) {
  223. if (type) {
  224. const findItem = this.checkTypeColumns.find((item) => item.key == type)
  225. return findItem.value
  226. }
  227. },
  228. // 选择打卡类型
  229. pickCheckType(e) {
  230. this.form.punchType = e.value[0].key
  231. this.form.punchVal = e.value[0].value
  232. this.showCheckType = false
  233. },
  234. // 经销商
  235. closeDealer(dealer) {
  236. if (dealer) {
  237. this.form.targetId = dealer.id
  238. this.form.targetName = dealer.name
  239. }
  240. },
  241. // 关闭选择客户
  242. closeCust(user) {
  243. if (user) {
  244. this.form.targetId = user.id
  245. this.form.targetName = user.name
  246. }
  247. },
  248. closePartners(partners) {
  249. if (partners) {
  250. this.form.targetId = partners.id
  251. this.form.targetName = partners.name
  252. }
  253. },
  254. closePartnersConcat(concat) {
  255. if (concat) {
  256. this.form.partnerContactId = concat.id
  257. this.form.partnerContactName = concat.name
  258. }
  259. },
  260. openSelectUser() {
  261. if (this.form.punchType == '20') {
  262. this.$refs.cust.open()
  263. } else if (this.form.punchType == '30' || this.form.punchType == '40') {
  264. this.$refs.dealer.open()
  265. } else if (this.form.punchType == '50') {
  266. this.$refs.partners.open()
  267. }
  268. },
  269. openPartnersConcat() {
  270. this.$refs.partnersConcat.open()
  271. },
  272. getLocation() {
  273. this.show = true
  274. const _this = this
  275. uni.getLocation({
  276. type: 'wgs84',
  277. success: function (res) {
  278. const latitude = res.latitude.toString()
  279. const longitude = res.longitude.toString()
  280. uni.request({
  281. header: {
  282. 'Content-Type': 'application/text',
  283. },
  284. url:
  285. process.uniEnv.VUE_APP_PROTOCOL +
  286. 'apis.map.qq.com/ws/geocoder/v1/?location=' +
  287. latitude +
  288. ',' +
  289. longitude +
  290. '&key=6REBZ-BRN6J-BMAFY-FIRI3-SMK43-G3FXU',
  291. success(re) {
  292. if (re.statusCode === 200) {
  293. _this.address = re.data.result.address
  294. _this.form.punchLat = latitude
  295. _this.form.punchLng = longitude
  296. _this.form.punchLocation = re.data.result.address
  297. _this.show = false
  298. } else {
  299. _this.address = '点击重试'
  300. this.$refs.uToast.show({
  301. type: 'error',
  302. message: '定位失败,请重试',
  303. })
  304. }
  305. },
  306. fail: (err) => (_this.show = false),
  307. })
  308. },
  309. fail: (err) => (_this.show = false),
  310. })
  311. },
  312. async checkIn() {
  313. const [fail, resp] = await to(this.$refs.form.validate())
  314. if (fail && fail.length > 0) {
  315. this.$refs.uNotify.show({
  316. top: this.height + this.paddingTop + 10,
  317. type: 'warning',
  318. message: fail[0].message,
  319. duration: 1000 * 3,
  320. })
  321. return
  322. }
  323. if (!this.form.punchLat || !this.form.punchLng) {
  324. this.address = '点击重试'
  325. return this.$refs.uToast.show({
  326. type: 'error',
  327. message: '定位失败,请重试',
  328. })
  329. }
  330. const [err, res] = await uni.chooseImage({
  331. count: 1, //默认9
  332. sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
  333. sourceType: ['camera'],
  334. })
  335. if (err) return
  336. this.select(res)
  337. res.tempFiles[0].name = new Date().getTime() + ''
  338. res.tempFiles[0].type = ''
  339. },
  340. // // 选择上传触发函数
  341. select(e) {
  342. let url = process.uniEnv.VUE_APP_UPLOAD_WEED
  343. uni.request({
  344. url, //仅为示例,并非真实接口地址。
  345. success: (res) => {
  346. this.uploadFiles(e, res.data)
  347. },
  348. })
  349. },
  350. // 上传函数
  351. async uploadFiles(e, res) {
  352. let action = process.uniEnv.VUE_APP_PROTOCOL + res.publicUrl + '/' + res.fid
  353. uni.uploadFile({
  354. url: action,
  355. filePath: e.tempFilePaths[0],
  356. name: 'file',
  357. formData: {
  358. file: e.tempFiles[0],
  359. },
  360. success: (res) => {
  361. this.form.punchImg = action
  362. api.checkIn(this.form).then((res) => {
  363. this.$refs.uToast.show({
  364. type: 'success',
  365. message: '打卡成功',
  366. })
  367. })
  368. },
  369. fail: () => {
  370. console.log('err')
  371. },
  372. })
  373. },
  374. showCheckList() {
  375. if (!this.showList) {
  376. this.queryForm.pageNum = 1
  377. this.checkList = []
  378. this.loadCheckList()
  379. }
  380. this.showList = !this.showList
  381. },
  382. async loadCheckList() {
  383. this.loadStatus = 'loading'
  384. const [err, res] = await to(api.getCheckList(this.queryForm))
  385. if (err) {
  386. this.loadStatus = 'nomore'
  387. return
  388. }
  389. if (res && res.code == 200) {
  390. this.checkList = [...this.checkList, ...(res.data.list || [])]
  391. // this.checkList = res.data.list
  392. this.total = res.data.total
  393. this.loadStatus = this.checkList.length == this.total ? 'nomore' : 'loadmore'
  394. } else {
  395. this.loadStatus = 'nomore'
  396. }
  397. },
  398. scrolltolower() {
  399. if (this.checkList.length < this.total && this.loadStatus != 'loading') {
  400. this.queryForm.pageNum++
  401. this.$u.throttle(this.loadCheckList(), 2000, false)
  402. }
  403. },
  404. goBack() {
  405. uni.navigateBack({
  406. //关闭当前页面,返回上一页面或多级页面。
  407. delta: 1,
  408. })
  409. },
  410. },
  411. }
  412. </script>
  413. <style lang="scss" scoped>
  414. /deep/ .uni-file-picker {
  415. display: none;
  416. }
  417. .home {
  418. padding-top: 188rpx;
  419. height: 100%;
  420. .nav {
  421. position: absolute;
  422. left: 0;
  423. top: 0;
  424. width: 100%;
  425. height: 284rpx;
  426. background: #3e7ef8;
  427. .title {
  428. position: relative;
  429. text-align: center;
  430. font-size: 32rpx;
  431. font-weight: bold;
  432. color: #ffffff;
  433. .back {
  434. position: absolute;
  435. top: 0;
  436. bottom: 0;
  437. margin: auto;
  438. left: 70rpx;
  439. display: flex;
  440. }
  441. }
  442. }
  443. .main {
  444. display: flex;
  445. flex-direction: column;
  446. position: absolute;
  447. width: 100%;
  448. height: calc(100vh - 188rpx);
  449. background: #ffffff;
  450. box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
  451. border-radius: 31rpx 31rpx 0 0;
  452. padding: 0 32rpx;
  453. overflow: hidden;
  454. padding-bottom: 64rpx;
  455. .main-header {
  456. padding: 20rpx 40rpx;
  457. display: flex;
  458. justify-content: space-between;
  459. .user-info {
  460. display: flex;
  461. .user-img {
  462. width: 116rpx;
  463. height: 116rpx;
  464. border-radius: 50%;
  465. margin-right: 32rpx;
  466. }
  467. .info {
  468. height: 116rpx;
  469. margin-right: 32rpx;
  470. }
  471. }
  472. .more {
  473. display: flex;
  474. flex-direction: column;
  475. align-items: center;
  476. }
  477. }
  478. .main-container {
  479. flex: 1;
  480. display: flex;
  481. flex-direction: column;
  482. align-items: center;
  483. justify-content: center;
  484. .btn {
  485. width: 300rpx;
  486. height: 300rpx;
  487. border-radius: 50%;
  488. background: linear-gradient(70deg, #3e7ef8, #1d66dc);
  489. display: flex;
  490. justify-content: center;
  491. align-items: center;
  492. color: #fff;
  493. font-size: 48rpx;
  494. font-weight: bold;
  495. box-shadow: 0 6rpx 19rpx 2rpx rgba(29, 102, 220, 0.2);
  496. margin-bottom: 40rpx;
  497. }
  498. .location {
  499. display: flex;
  500. height: 32rpx;
  501. line-height: 32rpx;
  502. }
  503. }
  504. }
  505. }
  506. </style>