index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar title="附近的客户" />
  6. <view class="list-view">
  7. <view class="list-wrapper">
  8. <view class="filter-group">
  9. <wk-base-filter :tabs="options" @filter="handleFilter" />
  10. </view>
  11. <wk-scroll-view
  12. :status="listStatus"
  13. class="list-scroll"
  14. @refresh="getList({}, true)">
  15. <nearby-customer-item
  16. v-for="(item, index) in listData"
  17. :key="item.customerId"
  18. :index="index"
  19. :item-data="item" />
  20. </wk-scroll-view>
  21. </view>
  22. </view>
  23. </view>
  24. <uni-popup ref="popup" type="dialog">
  25. <uni-popup-dialog
  26. v-model="userRadius"
  27. :check-func="inputCheckFunc"
  28. required-text="请输入数字"
  29. title="自定义距离(千米)"
  30. placeholder="'请输入距离'"
  31. mode="input"
  32. @confirm="handleDialogConfirm" />
  33. </uni-popup>
  34. </view>
  35. </template>
  36. <script>
  37. import { NearbyCustomer } from 'API/crm/customer'
  38. import { AdminQueryUserList } from 'API/admin'
  39. import NearbyCustomerItem from './components/nearbyCustomerItem'
  40. // import NearbyMap from './components/nearbyMap.vue'
  41. import { mapGetters } from 'vuex'
  42. import {
  43. bMapTransQQMap,
  44. qqMapTransBMap,
  45. getLocation
  46. } from '@/utils/map.js'
  47. export default {
  48. name: 'NearbyCustomerIndex',
  49. components: {
  50. // OptionsFilter,
  51. NearbyCustomerItem
  52. },
  53. data() {
  54. return {
  55. GetListFn: NearbyCustomer, // 获取列表数据接口
  56. options: [
  57. {
  58. label: '距离',
  59. field: 'radius',
  60. value: 3000,
  61. valueData: 1,
  62. options: [
  63. {label: '1公里以内', value: 1000},
  64. {label: '3公里以内', value: 3 * 1000},
  65. {label: '5公里以内', value: 5 * 1000},
  66. {label: '10公里以内', value: 10 * 1000},
  67. {label: '20公里以内', value: 20 * 1000},
  68. {label: '30公里以内', value: 30 * 1000},
  69. {label: '50公里以内', value: 50 * 1000},
  70. {label: '自定义', value: '__defined__'},
  71. ]
  72. },
  73. // {
  74. // label: '负责人',
  75. // field: 'ownerUserId',
  76. // options: []
  77. // },
  78. {
  79. label: '所属模块',
  80. field: 'type',
  81. value: '',
  82. valueData: 0,
  83. options: [
  84. {label: '全部', value: ''},
  85. {label: '客户', value: 2},
  86. {label: '公海', value: 9}
  87. ]
  88. },
  89. ],
  90. filterData: {
  91. radius: 3000,
  92. type: ''
  93. },
  94. userRadius: 3,
  95. listData: [],
  96. listStatus: 'noMore',
  97. devicePoint: {
  98. // lat: 34.762279,
  99. // lng: 113.77765
  100. }
  101. }
  102. },
  103. computed: {
  104. ...mapGetters({
  105. userInfo: 'user/userInfo'
  106. })
  107. },
  108. onBackPress(evt) {
  109. if (this.showMap) {
  110. this.showMap = !this.showMap
  111. return true // 返回值为 true 时,表示不执行默认的返回
  112. }
  113. return false
  114. },
  115. mounted() {
  116. // this.getUserList()
  117. // this.getLocation()
  118. // this.devicePoint = {
  119. // latitude: 34.762279,
  120. // longitude: 113.77765
  121. // }
  122. // this.getList()
  123. // #ifdef MP-WEIXIN
  124. this.getUserLocationAuth()
  125. // #endif
  126. // #ifndef MP-WEIXIN
  127. this.getLocation()
  128. // #endif
  129. },
  130. methods: {
  131. getUserList() {
  132. AdminQueryUserList({
  133. pageType: 0
  134. }).then(res => {
  135. this.options[1].options = res.list.map(item => {
  136. return {
  137. label: item.realname,
  138. value: item.userId
  139. }
  140. })
  141. this.$set(this.options, 1, this.options[1])
  142. }).catch()
  143. },
  144. getUserLocationAuth() {
  145. const that = this
  146. uni.getSetting({
  147. success: (data) => {
  148. console.log('setting: ', data)
  149. const flag = data.authSetting['scope.userLocation']
  150. if (!flag) {
  151. uni.authorize({
  152. scope: 'scope.userLocation',
  153. success: () => {
  154. that.getLocation()
  155. },
  156. fail: () => {
  157. that.$toast('定位失败')
  158. }
  159. })
  160. } else {
  161. that.getLocation()
  162. }
  163. },
  164. fail: () => {
  165. that.$toast('定位失败')
  166. }
  167. })
  168. },
  169. getLocation() {
  170. getLocation(false).then(res => {
  171. this.devicePoint = qqMapTransBMap(res.longitude, res.latitude)
  172. this.getList()
  173. }).then().catch(() => {
  174. this.$toast('定位失败')
  175. })
  176. },
  177. /**
  178. * 获取附近的客户
  179. */
  180. getList() {
  181. if (this.listStatus === 'loading') return
  182. this.showMap = false
  183. if (!this.devicePoint.longitude || !this.devicePoint.latitude) {
  184. this.$toast('定位失败')
  185. return
  186. }
  187. this.listStatus = 'loading'
  188. NearbyCustomer({
  189. lng: this.devicePoint.longitude,
  190. lat: this.devicePoint.latitude,
  191. type: this.filterData.type || '',
  192. radius: this.filterData.radius === '__defined__' ? Number((this.userRadius * 1000).toFixed()) : this.filterData.radius,
  193. ownerUserId: this.filterData.ownerUserId || ''
  194. }).then(res => {
  195. console.log('NearbyCustomer list:', res)
  196. this.listData = res || []
  197. this.listStatus = 'noMore'
  198. }).catch(() => {
  199. this.listStatus = 'noMore'
  200. })
  201. },
  202. handleDropdownChange(index) {
  203. // 记录点击的是第几个tab
  204. this.activeTabIndex = index
  205. },
  206. handleFilter(item) {
  207. console.log('item: ', item)
  208. this.filterData[item.field] = item.value
  209. if (item.field === 'radius' && item.value === '__defined__') {
  210. // delete this.filterData.status
  211. this.$refs.popup.open()
  212. } else {
  213. this.getList()
  214. }
  215. },
  216. inputCheckFunc(val) {
  217. return !isNaN(Number(val))
  218. },
  219. handleDialogConfirm(next, val) {
  220. this.userRadius = val
  221. this.getList()
  222. next()
  223. },
  224. handleToSearch() {},
  225. handleToggleMap() {
  226. this.showMap = !this.showMap
  227. }
  228. }
  229. }
  230. </script>
  231. <style scoped lang="scss">
  232. .main-container {
  233. display: flex;
  234. flex-direction: column;
  235. // padding-bottom: $tabbar-height;
  236. overflow-y: hidden;
  237. .search-btn {
  238. margin-right: 28rpx;
  239. .icon {
  240. font-weight: 400;
  241. font-size: 40rpx;
  242. color: white;
  243. }
  244. }
  245. .img-icon__map {
  246. width: 44rpx;
  247. height: 44rpx;
  248. vertical-align: middle;
  249. }
  250. .list-view {
  251. flex: 1;
  252. overflow-y: hidden;
  253. .list-wrapper {
  254. width: 100%;
  255. height: 100%;
  256. display: flex;
  257. flex-direction: column;
  258. overflow: hidden;
  259. .list-scroll {
  260. flex: 1;
  261. overflow: hidden;
  262. }
  263. }
  264. }
  265. .map-view {
  266. flex: 1;
  267. overflow: hidden;
  268. }
  269. }
  270. </style>