tabbar.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 } from '../core/libs/agent-requests'
  20. import { useFollowUp } from '../composables/followUp'
  21. import { success } from '@/core/libs/svgs'
  22. const userStore = useUserStore()
  23. const { userInfo, isAgent, isMerchant } = storeToRefs(userStore)
  24. const { schema, rules, schemaTypeOnline, schemaTypeOffline } = useFollowUp()
  25. const publishState = ref(false)
  26. const designerList = ref<any[]>([])
  27. const dataForm = ref({
  28. stylistId: '',
  29. followType: '1',
  30. })
  31. const dataFormRef = ref<ComponentExposed<typeof DataForm>>()
  32. const schemaTypeOfflineRef = ref<ComponentExposed<typeof DataForm>>()
  33. const schemaTypeOnlineRef = ref<ComponentExposed<typeof DataForm>>()
  34. const items = computed(() => {
  35. if (isAgent.value) {
  36. return [
  37. {
  38. title: '首页',
  39. iconPath: channelTabbarHome,
  40. selectedIconPath: channelTabbarHomeActive,
  41. path: '/pages/home/index',
  42. },
  43. {
  44. title: '跟进',
  45. iconPath: addBlue,
  46. selectedIconPath: addBlue,
  47. path: '/pages/publish/index',
  48. // hiddenTitle: true,
  49. main: true,
  50. },
  51. {
  52. title: '我的',
  53. iconPath: channelTabbarMine,
  54. selectedIconPath: channelTabbarMineActive,
  55. path: '/pages/mine/index',
  56. },
  57. ]
  58. }
  59. return [
  60. {
  61. title: '首页',
  62. iconPath: channelTabbarHome,
  63. selectedIconPath: channelTabbarHomeActive,
  64. path: '/pages/home/index',
  65. },
  66. {
  67. title: '我的',
  68. iconPath: channelTabbarMine,
  69. selectedIconPath: channelTabbarMineActive,
  70. path: '/pages/mine/index',
  71. },
  72. ]
  73. })
  74. const handleTabbarItemClick = (path: string) => {
  75. if (path === '/pages/publish/index') {
  76. if (schema.value.stylistId.props.columns.length > 0) {
  77. const { value } = designerList.value[0]
  78. dataForm.value.stylistId = value
  79. }
  80. publishState.value = true
  81. return
  82. }
  83. uni.switchTab({ url: path })
  84. }
  85. const handleAdd = async (e) => {
  86. console.log(e)
  87. publishState.value = true
  88. }
  89. const handleSubmit = async () => {
  90. const { valid } = await dataFormRef.value.validate()
  91. if (!valid) {
  92. return
  93. }
  94. console.log(dataForm.value)
  95. const { code } = await requestToast(
  96. () =>
  97. createFollowUp({ ...dataForm.value, address: { address: '', latitude: '', longitude: '' } }),
  98. {
  99. success: true,
  100. successTitle: '跟进成功',
  101. },
  102. )
  103. if (code === 0) {
  104. publishState.value = false
  105. }
  106. }
  107. const getCurrentLocation = () => {
  108. console.log('点击地址')
  109. uni.chooseAddress({
  110. success: (success) => {
  111. console.log('地理位置 成功', success)
  112. },
  113. fail: (fail) => {
  114. console.log('获取地址失败', fail)
  115. },
  116. })
  117. }
  118. onMounted(async () => {
  119. const {
  120. data: { list },
  121. } = await getDesignerList({
  122. brokerId: userInfo.value?.userId.toString(),
  123. pageNo: 1,
  124. pageSize: -1,
  125. })
  126. schema.value.stylistId.props.columns = list.map((item) => ({
  127. value: item.id,
  128. label: item.name,
  129. }))
  130. designerList.value = schema.value.stylistId.props.columns
  131. console.log('dataForm.value', designerList.value)
  132. })
  133. </script>
  134. <template>
  135. <wd-config-provider :themeVars="defaultThemeVars" custom-class="flex-grow flex flex-col">
  136. <view class="bg-[#F2F3F6] pb-20 flex-grow">
  137. <slot />
  138. </view>
  139. <TabbarEvo
  140. :items="items"
  141. fixed
  142. safeAreaInsetBottom
  143. :current-path="currRoute().path"
  144. @click="handleTabbarItemClick"
  145. />
  146. <wd-action-sheet v-model="publishState" title="创建跟进" @close="publishState = false">
  147. <view class="flex flex-col p-4">
  148. <div>
  149. <DataForm
  150. ref="dataFormRef"
  151. :schema="schema"
  152. :rules="rules"
  153. direction="horizontal"
  154. v-model="dataForm"
  155. ></DataForm>
  156. <!-- 根据 followType 值 区分 线下 线上 -->
  157. <template v-if="dataForm.followType === '1'">
  158. <div
  159. class="grid mb-4 items-start"
  160. :style="{ 'grid-template-columns': `${addUnit(64)} auto` }"
  161. >
  162. <label
  163. class="text-sm font-normal leading-relaxed text-black/60 h-10 flex items-center"
  164. >
  165. 地址
  166. </label>
  167. <div
  168. class="wd-input h-[40px] lh-[40px] flex justify-between px-[20px]"
  169. @click="getCurrentLocation"
  170. >
  171. <div>点击获取当前位置</div>
  172. <wd-icon name="refresh" size="14px"></wd-icon>
  173. </div>
  174. </div>
  175. </template>
  176. <DataForm
  177. ref="schemaTypeOnlineRef"
  178. :schema="schemaTypeOnline"
  179. :rules="rules"
  180. direction="horizontal"
  181. v-model="dataForm"
  182. ></DataForm>
  183. </div>
  184. <div><wd-button block :round="false" @click="handleSubmit">提交</wd-button></div>
  185. </view>
  186. </wd-action-sheet>
  187. <wd-toast />
  188. <wd-message-box />
  189. </wd-config-provider>
  190. </template>
  191. <style lang="scss">
  192. /* stylelint-disable-next-line selector-type-no-unknown */
  193. layout-tabbar-uni {
  194. display: flex;
  195. flex-direction: column;
  196. flex-grow: 1;
  197. }
  198. </style>