tabbar.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <script setup lang="ts">
  2. import TabbarEvo from '@/components/tabbar-evo.vue'
  3. import { currRoute } from '../utils'
  4. import { defaultThemeVars } from '../core/themes/default'
  5. import DataForm from '@/components/data-form.vue'
  6. import { addUnit } from 'wot-design-uni/components/common/util'
  7. import { useUserStore } from '../store'
  8. import { storeToRefs } from 'pinia'
  9. import {
  10. addBlue,
  11. channelTabbarHome,
  12. channelTabbarHomeActive,
  13. channelTabbarMine,
  14. channelTabbarMineActive,
  15. } from '@designer-hub/assets/src/assets/svgs'
  16. import { ComponentExposed } from 'vue-component-type-helpers'
  17. import { getDesignerList } from '../core/libs/requests'
  18. import { requestToast } from '@designer-hub/app/src/core/utils/common'
  19. import { createFollowUp, getDesigners } from '../core/libs/agent-requests'
  20. import { useFollowUp } from '../composables/followUp'
  21. import AMapWX from '@/pages/common/amap-wx.130'
  22. const action = ref(`${import.meta.env.VITE_SERVER_BASEURL}/app-api/infra/file/upload`)
  23. const fileList = ref<string[]>([])
  24. const userStore = useUserStore()
  25. const { userInfo, isAgent, isMerchant } = storeToRefs(userStore)
  26. const { schema, rules, schemaTypeOnline } = useFollowUp()
  27. const publishState = ref(false)
  28. const designerList = ref<any[]>([])
  29. const dataForm = ref({
  30. stylistId: '',
  31. followType: '1',
  32. followTime: new Date().getTime(),
  33. address: {
  34. latitude: 0,
  35. longitude: 0,
  36. address: '',
  37. },
  38. imgUrl: '',
  39. })
  40. const currentAddress = ref<any>([])
  41. const dataFormRef = ref<ComponentExposed<typeof DataForm>>()
  42. const schemaTypeOnlineRef = ref<ComponentExposed<typeof DataForm>>()
  43. // 地图实例化
  44. const AmapFun = new AMapWX.AMapWX({ key: 'efde483f8801a09d3c5db032556e6593' })
  45. const wxGetAddress = (longitude: number, latitude: number) => {
  46. return new Promise((resolve, reject) => {
  47. AmapFun.getRegeo({
  48. location: `${longitude},${latitude}`,
  49. success: (res: any) => {
  50. resolve(res)
  51. },
  52. fail: (err: any) => {
  53. reject(err)
  54. },
  55. })
  56. })
  57. }
  58. const items = computed(() => {
  59. if (isAgent.value) {
  60. return [
  61. {
  62. title: '首页',
  63. iconPath: channelTabbarHome,
  64. selectedIconPath: channelTabbarHomeActive,
  65. path: '/pages/home/index',
  66. },
  67. {
  68. title: '跟进',
  69. iconPath: addBlue,
  70. selectedIconPath: addBlue,
  71. path: '/pages/publish/index',
  72. // hiddenTitle: true,
  73. main: true,
  74. },
  75. {
  76. title: '我的',
  77. iconPath: channelTabbarMine,
  78. selectedIconPath: channelTabbarMineActive,
  79. path: '/pages/mine/index',
  80. },
  81. ]
  82. }
  83. return [
  84. {
  85. title: '首页',
  86. iconPath: channelTabbarHome,
  87. selectedIconPath: channelTabbarHomeActive,
  88. path: '/pages/home/index',
  89. },
  90. {
  91. title: '我的',
  92. iconPath: channelTabbarMine,
  93. selectedIconPath: channelTabbarMineActive,
  94. path: '/pages/mine/index',
  95. },
  96. ]
  97. })
  98. const handleTabbarItemClick = (path: string) => {
  99. if (path === '/pages/publish/index') {
  100. if (schema.value.stylistId.props.columns.length > 0) {
  101. const { value } = designerList.value[0]
  102. dataForm.value.stylistId = value
  103. }
  104. dataForm.value.address.address = ''
  105. dataForm.value.address.latitude = 0
  106. dataForm.value.address.longitude = 0
  107. dataForm.value.imgUrl = ''
  108. publishState.value = true
  109. return
  110. }
  111. uni.switchTab({ url: path })
  112. }
  113. const handleAdd = async (e) => {
  114. console.log(e)
  115. publishState.value = true
  116. }
  117. const handleSubmit = async () => {
  118. const { valid } = await dataFormRef.value.validate()
  119. if (!valid) {
  120. return
  121. }
  122. if (fileList.value.length) {
  123. const temp: string[] = []
  124. fileList.value.forEach((each: any) => {
  125. temp.push(JSON.parse(each.response).data)
  126. })
  127. dataForm.value.imgUrl = temp.join(',')
  128. }
  129. console.log(dataForm.value)
  130. if (!dataForm.value.imgUrl) {
  131. uni.showToast({ icon: 'none', title: '请上传图片' })
  132. return false
  133. }
  134. if (!dataForm.value.address && dataForm.value.followType === '1') {
  135. uni.showToast({ icon: 'none', title: '请刷新定位' })
  136. return false
  137. }
  138. const { code } = await requestToast(() => createFollowUp(dataForm.value), {
  139. success: true,
  140. successTitle: '跟进成功',
  141. })
  142. if (code === 0) {
  143. publishState.value = false
  144. dataForm.value = {
  145. stylistId: '',
  146. followType: '1',
  147. followTime: new Date().getTime(),
  148. address: {
  149. latitude: 0,
  150. longitude: 0,
  151. address: '',
  152. },
  153. imgUrl: '',
  154. }
  155. fileList.value = []
  156. uni.$emit('refresh')
  157. }
  158. }
  159. const handleChange = ({ fileList: files }) => {
  160. fileList.value = files
  161. console.log(fileList.value)
  162. }
  163. const getCurrentLocation = () => {
  164. uni.showToast({ icon: 'loading', title: '正在获取位置...' })
  165. uni.getLocation({
  166. type: 'gcj02',
  167. success: async (success: any) => {
  168. currentAddress.value = await wxGetAddress(success?.longitude, success?.latitude)
  169. const { name, latitude, longitude } = currentAddress.value[0]
  170. dataForm.value.address.address = name
  171. dataForm.value.address.latitude = latitude
  172. dataForm.value.address.longitude = longitude
  173. uni.hideToast()
  174. },
  175. fail: (err) => {
  176. console.log('获取地址失败', err)
  177. if (err.errCode === 1005 || err.errCode === 10001) {
  178. console.log('位置权限未授权')
  179. uni.authorize({
  180. scope: 'scope.userLocation',
  181. success: () => {
  182. uni.getLocation({
  183. type: 'gcj02',
  184. success: async (success) => {
  185. console.log('授权后,获取地址', success)
  186. currentAddress.value = await wxGetAddress(success?.longitude, success?.latitude)
  187. const { name, latitude, longitude } = currentAddress.value[0]
  188. dataForm.value.address.address = name
  189. dataForm.value.address.latitude = latitude
  190. dataForm.value.address.longitude = longitude
  191. uni.hideToast()
  192. },
  193. fail: function (err) {
  194. console.log('获取位置失败:', err)
  195. uni.hideToast()
  196. },
  197. })
  198. },
  199. fail: function () {
  200. uni.hideToast()
  201. // 用户拒绝授权,可以选择记录下来,不再提示
  202. uni.showToast({
  203. title: '您拒绝了位置授权',
  204. icon: 'none',
  205. duration: 2000,
  206. })
  207. // 可以引导用户去设置中授权
  208. uni.showModal({
  209. title: '提示',
  210. content: '请在系统设置中打开定位服务权限',
  211. success: function (modalRes) {
  212. if (modalRes.confirm) {
  213. uni.openSetting()
  214. }
  215. },
  216. })
  217. },
  218. })
  219. }
  220. },
  221. })
  222. }
  223. onMounted(async () => {
  224. const {
  225. data: { list },
  226. } = await getDesigners({
  227. brokerId: userInfo.value?.userId.toString(),
  228. pageNo: 1,
  229. pageSize: -1,
  230. })
  231. schema.value.stylistId.props.columns = list.map((item) => ({
  232. value: item.id,
  233. label: item.name,
  234. }))
  235. designerList.value = schema.value.stylistId.props.columns
  236. console.log('dataForm.value', designerList.value)
  237. })
  238. </script>
  239. <template>
  240. <wd-config-provider :themeVars="defaultThemeVars" custom-class="flex-grow flex flex-col">
  241. <view class="bg-[#F2F3F6] pb-20 flex-grow">
  242. <slot />
  243. </view>
  244. <TabbarEvo
  245. :items="items"
  246. fixed
  247. safeAreaInsetBottom
  248. :current-path="currRoute().path"
  249. @click="handleTabbarItemClick"
  250. />
  251. <wd-action-sheet v-model="publishState" title="创建跟进" @close="publishState = false">
  252. <view class="flex flex-col p-4 h-[calc(65vh)]! overflow-y-auto">
  253. <div>
  254. <DataForm
  255. ref="dataFormRef"
  256. :schema="schema"
  257. :rules="rules"
  258. direction="horizontal"
  259. v-model="dataForm"
  260. ></DataForm>
  261. <!-- 根据 followType 值 区分 线下 线上 -->
  262. <template v-if="dataForm.followType === '1'">
  263. <div
  264. class="grid mb-4 items-start"
  265. :style="{ 'grid-template-columns': `${addUnit(64)} auto` }"
  266. >
  267. <label
  268. class="text-sm font-normal leading-relaxed text-black/60 h-10 flex items-center"
  269. >
  270. <span
  271. class="text-[#ef4343] text-base font-normal font-['PingFang_SC'] leading-normal visible"
  272. >
  273. *
  274. </span>
  275. 地址
  276. </label>
  277. <div
  278. class="wd-input h-[40px] lh-[40px] flex justify-between px-[20px]"
  279. @click="getCurrentLocation"
  280. >
  281. <div>
  282. {{ !dataForm.address.address ? '点击获取当前位置' : dataForm.address.address }}
  283. </div>
  284. <wd-icon name="refresh" size="14px"></wd-icon>
  285. </div>
  286. </div>
  287. </template>
  288. <div
  289. class="grid mb-4 items-start"
  290. :style="{ 'grid-template-columns': `${addUnit(64)} auto` }"
  291. >
  292. <label class="text-sm font-normal leading-relaxed text-black/60 h-10 flex items-center">
  293. <span
  294. class="text-[#ef4343] text-base font-normal font-['PingFang_SC'] leading-normal visible"
  295. >
  296. *
  297. </span>
  298. 图片
  299. </label>
  300. <wd-upload
  301. :file-list="fileList"
  302. image-mode="aspectFill"
  303. accept="media"
  304. :action="action"
  305. :multiple="true"
  306. :limit="9"
  307. @change="handleChange"
  308. ></wd-upload>
  309. </div>
  310. </div>
  311. <div><wd-button block :round="false" @click="handleSubmit">提交</wd-button></div>
  312. </view>
  313. </wd-action-sheet>
  314. <wd-toast />
  315. <wd-message-box />
  316. </wd-config-provider>
  317. </template>
  318. <style lang="scss">
  319. /* stylelint-disable-next-line selector-type-no-unknown */
  320. layout-tabbar-uni {
  321. display: flex;
  322. flex-direction: column;
  323. flex-grow: 1;
  324. }
  325. </style>