add.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar title="新建外勤拜访">
  6. <!-- #ifndef MP-WEIXIN -->
  7. <button
  8. class="button white-btn"
  9. @click="handleSave">
  10. 保存
  11. </button>
  12. <!-- #endif -->
  13. </wk-nav-bar>
  14. <view class="container">
  15. <scroll-view :scroll-y="true" class="scroll-content">
  16. <map
  17. id="legworkMap"
  18. :style="{
  19. width: mapStyle.width
  20. }"
  21. :markers="markers"
  22. :longitude="centerPoint.longitude"
  23. :latitude="centerPoint.latitude"
  24. enable-scroll />
  25. <!-- show-location -->
  26. <!-- :markers="markers" -->
  27. <!-- #ifdef APP-PLUS | MP-WEIXIN -->
  28. <cover-view :class="{show: showCoverView}" class="cover-mask" />
  29. <!-- #endif -->
  30. <view class="address-box">
  31. <text class="wk wk-position icon" />
  32. <text class="address">
  33. {{ centerPoint.addr || '定位失败,请检查您的系统设置项' }}
  34. </text>
  35. <text class="re-location" @click="reLocation">
  36. 重新定位
  37. </text>
  38. </view>
  39. <!-- <view class="customer">
  40. <wk-field-revelance
  41. v-model="selectedCustomer"
  42. :config="customerConfig"
  43. :field="customerField" />
  44. </view> -->
  45. <!-- <textarea
  46. ref="core"
  47. v-model="formContent"
  48. :maxlength="500"
  49. placeholder="请输入外勤详细内容"
  50. placeholder-class="wk-placeholder placeholder"
  51. class="input-core" /> -->
  52. <view class="content">
  53. <wk-form
  54. ref="form"
  55. :fields="fieldArr" />
  56. <view class="image-cell">
  57. <view class="cell-title" @click.stop="handleSheet">
  58. <image :src="$static('images/icon/image.png')" class="pic" />
  59. <text class="text">
  60. 图片
  61. </text>
  62. <view class="add-icon">
  63. <text class="wk wk-plus" />
  64. </view>
  65. </view>
  66. <wk-image-content
  67. v-if="imgList.length > 0"
  68. :list="imgList"
  69. show-delete
  70. @delete="handleDeleteFile" />
  71. </view>
  72. </view>
  73. </scroll-view>
  74. </view>
  75. <!-- #ifdef MP-WEIXIN -->
  76. <view class="footer-btn-group">
  77. <button class="button" @click="handleSave">
  78. 保存
  79. </button>
  80. </view>
  81. <!-- #endif -->
  82. </view>
  83. <uni-popup
  84. ref="popup"
  85. type="actionsheet"
  86. radius="10rpx 10rpx 0 0"
  87. @change="handlePopupChange">
  88. <wk-action-sheet
  89. :list="popList"
  90. @select="handlePopSelect" />
  91. </uni-popup>
  92. </view>
  93. </template>
  94. <script>
  95. import { QueryById } from 'API/crm/customer'
  96. import { LegworkClock } from 'API/oa/legwork'
  97. import { FileDeleteById } from 'API/file'
  98. import Fields from '@/utils/fields.js'
  99. import {
  100. qqMapTransBMap,
  101. getLocation
  102. } from '@/utils/map.js'
  103. import WkFile from '@/utils/file.js'
  104. import { guid } from '@/utils/lib.js'
  105. export default {
  106. name: 'LegworkAdd',
  107. data() {
  108. return {
  109. fieldArr: [
  110. new Fields({
  111. name: '拜访客户',
  112. fieldName: 'activityTypeId',
  113. formType: 'customer',
  114. isNull: 1
  115. }),
  116. new Fields({
  117. name: '外勤详细内容',
  118. fieldName: 'content',
  119. formType: 'textarea',
  120. isNull: 1
  121. })
  122. ],
  123. customerConfig: {
  124. otherParams: {type: 2}
  125. },
  126. mapStyle: {
  127. width: 0
  128. },
  129. markers: [],
  130. centerPoint: {},
  131. selectedCustomer: [],
  132. imgList: [],
  133. batchId: guid(),
  134. formContent: '',
  135. showCoverView: false,
  136. popList: [
  137. '拍照',
  138. '从相册中选择'
  139. ],
  140. loading: false
  141. }
  142. },
  143. onLoad(options) {
  144. const id = options.customerId || null
  145. if (id) {
  146. this.getCustomerDetail(id)
  147. }
  148. },
  149. mounted() {
  150. this.mapStyle = {
  151. width: uni.upx2px(750) + 'px'
  152. }
  153. // #ifdef MP-WEIXIN
  154. this.getUserLocationAuth()
  155. // #endif
  156. // #ifndef MP-WEIXIN
  157. this.getLocation()
  158. // #endif
  159. this.$nextTick(function() {
  160. this.$refs.form.setConfig('activityTypeId', {
  161. optionsConfig: { showCreate: true }
  162. })
  163. })
  164. },
  165. methods: {
  166. getUserLocationAuth() {
  167. const that = this
  168. uni.getSetting({
  169. success: (data) => {
  170. console.log('setting: ', data)
  171. const flag = data.authSetting['scope.userLocation']
  172. if (!flag) {
  173. uni.authorize({
  174. scope: 'scope.userLocation',
  175. success: () => {
  176. that.getLocation()
  177. },
  178. fail: () => {
  179. that.$toast('定位失败')
  180. }
  181. })
  182. } else {
  183. that.getLocation()
  184. }
  185. },
  186. fail: () => {
  187. that.$toast('定位失败')
  188. }
  189. })
  190. },
  191. /**
  192. * 获取客户详情
  193. */
  194. getCustomerDetail(id) {
  195. QueryById({
  196. customerId: id
  197. }).then(res => {
  198. this.$nextTick(() => {
  199. this.$refs.form.setFormVal('activityTypeId', [res])
  200. })
  201. }).catch(() => {})
  202. },
  203. getLocation() {
  204. console.log('开始定位')
  205. getLocation().then(data => {
  206. this.centerPoint = data
  207. this.markers = [{
  208. ...data,
  209. width: 30,
  210. height: 30,
  211. iconPath: this.$static('images/map/location.png')
  212. }]
  213. console.log('定位:', this.centerPoint)
  214. }).catch(() => {
  215. // this.$toast(JSON.stringify(err))
  216. this.$toast('定位失败')
  217. })
  218. },
  219. reLocation() {
  220. uni.$once('choose-address', this.chooseAddress)
  221. this.$Router.navigateTo({
  222. url: '/pages_common/map/chooseAddress'
  223. })
  224. },
  225. chooseAddress(data) {
  226. this.centerPoint = {
  227. ...data,
  228. addr: data.address
  229. }
  230. this.markers = [{
  231. ...data,
  232. width: 30,
  233. height: 30,
  234. iconPath: this.$static('images/map/location.png')
  235. }]
  236. },
  237. handlePopupChange() {
  238. this.showCoverView = !this.showCoverView
  239. },
  240. handleDeleteFile(index) {
  241. let fileId = this.imgList[index].fileId || null
  242. this.imgList.splice(index, 1)
  243. FileDeleteById({
  244. id: fileId
  245. }).then().catch()
  246. },
  247. handleSheet() {
  248. // this.$refs.popup.open()
  249. const params = {type: 'img'}
  250. if (this.batchId) {
  251. params.batchId = this.batchId
  252. }
  253. const fileUpload = new WkFile(params)
  254. fileUpload.choose().then(data => {
  255. console.log('upload res: ', data)
  256. this.imgList = this.imgList.concat(data)
  257. })
  258. },
  259. handlePopSelect(index) {
  260. // this.$refs.popup.close()
  261. // const pop = this.popList[index]
  262. // if (pop === '拍照') {
  263. // } else {
  264. // }
  265. },
  266. handleSave() {
  267. if (this.loading) return
  268. this.loading = true
  269. this.$refs.form.getForm().then(form => {
  270. form = form.entity
  271. const p = this.centerPoint
  272. const point = qqMapTransBMap(p.longitude, p.latitude)
  273. form = {
  274. ...form,
  275. lng: point.longitude,
  276. lat: point.latitude,
  277. address: p.addr || p.address || '',
  278. activityType: 2
  279. }
  280. if (!form.lng || !form.lat) {
  281. this.$toast('定位失败!')
  282. this.loading = false
  283. return
  284. }
  285. // form.img = this.imgList
  286. if (this.imgList.length > 0) {
  287. form.batchId = this.imgList[0].batchId
  288. }
  289. console.log('save: ', form)
  290. LegworkClock(form).then(res => {
  291. this.loading = false
  292. this.$toast('签到成功')
  293. this.$refreshAndToPrev(this)
  294. }).catch(() => {
  295. this.loading = false
  296. })
  297. }).catch(() => {
  298. this.loading = false
  299. })
  300. },
  301. }
  302. }
  303. </script>
  304. <style scoped lang="scss">
  305. .main-container {
  306. .container {
  307. position: relative;
  308. flex: 1;
  309. width: 100%;
  310. display: flex;
  311. flex-direction: column;
  312. overflow: hidden;
  313. // padding-bottom: 150rpx;
  314. .scroll-content {
  315. width: 100%;
  316. height: 100%;
  317. overflow: hidden;
  318. }
  319. #legworkMap {
  320. width: 750rpx;
  321. height: 380rpx;
  322. }
  323. .cover-mask {
  324. position: absolute;
  325. top: 0;
  326. left: 0;
  327. z-index: 1024;
  328. width: 750rpx;
  329. height: 0;
  330. background-color: rgba(0,0,0,.4);
  331. &.show {
  332. height: 380rpx;
  333. }
  334. }
  335. .address-box {
  336. width: 100%;
  337. font-size: 28rpx;
  338. background-color: white;
  339. padding: 24rpx 20rpx;
  340. @include left;
  341. .icon {
  342. font-size: 36rpx;
  343. font-weight: 500;
  344. line-height: normal;
  345. color: #1C6CFF;
  346. margin-right: 15rpx;
  347. }
  348. .address {
  349. flex: 1;
  350. color: #999;
  351. margin-right: 15rpx;
  352. @include ellipsis;
  353. }
  354. .re-location {
  355. font-size: 24rpx;
  356. color: $theme-color;
  357. text-align: center;
  358. margin-right: 10rpx;
  359. }
  360. }
  361. .content {
  362. flex: 1;
  363. width: 100%;
  364. background-color: white;
  365. margin-top: 20rpx;
  366. padding: 20rpx 0;
  367. .image-cell {
  368. padding: 0 32rpx;
  369. .cell-title {
  370. padding: 15rpx 0;
  371. @include left;
  372. .pic {
  373. width: 36rpx;
  374. height: 36rpx;
  375. margin-right: 15rpx;
  376. }
  377. .text {
  378. flex: 1;
  379. }
  380. .add-icon {
  381. width: 38rpx;
  382. height: 38rpx;
  383. background-color: #E1E1E1;
  384. border-radius: 50%;
  385. @include center;
  386. .wk {
  387. font-size: $wk-font-mini;
  388. line-height: normal;
  389. color: white;
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. .save-btn {
  397. position: fixed;
  398. left: 3%;
  399. bottom: 24rpx;
  400. width: 94%;
  401. height: 100rpx;
  402. font-size: 36rpx;
  403. text-align: center;
  404. line-height: 100rpx;
  405. color: white;
  406. border-radius: 10rpx;
  407. background-color: $theme-color;
  408. }
  409. }
  410. </style>