index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <wd-popup
  3. v-model="visible"
  4. position="bottom"
  5. root-portal
  6. lock-scroll
  7. :close-on-click-modal="false"
  8. custom-style="border-radius: 32rpx 32rpx 0 0; overflow: hidden;"
  9. @close="resetTemplate"
  10. >
  11. <view class="visit-template">
  12. <view class="visit-template__header">
  13. <view class="visit-template__heading">
  14. <view class="visit-template__title">拜访明细</view>
  15. <view class="visit-template__subtitle">{{ target?.name }}</view>
  16. </view>
  17. <view class="visit-template__close" @click="visible = false">
  18. <wd-icon name="close" size="32rpx" color="#8b98a8" />
  19. </view>
  20. </view>
  21. <view v-if="loading" class="visit-template__loading">
  22. <wd-loading color="#2f8cf7" />
  23. <text class="visit-template__loading-text">正在加载拜访模板</text>
  24. </view>
  25. <scroll-view v-else class="visit-template__scroll" scroll-y>
  26. <view class="visit-template__content">
  27. <wd-cell :title="targetNameLabel" :value="target?.name" />
  28. <wd-cell title="拜访时间" :value="signDate" />
  29. <TemplateContent
  30. v-if="templateRouteKey"
  31. ref="templateFormRef"
  32. :route-key="templateRouteKey"
  33. :drug-options="drugOptions"
  34. :purpose-options="purposeOptions"
  35. :result-options="resultOptions"
  36. :visitor-options="visitorOptions"
  37. :scene-photo-min-count="scenePhotoMinCount"
  38. />
  39. <view v-else class="visit-template__unsupported">暂不支持当前拜访模板</view>
  40. </view>
  41. </scroll-view>
  42. <view class="visit-template__actions">
  43. <view
  44. class="visit-template__button visit-template__button--cancel"
  45. @click="visible = false"
  46. >
  47. 取消
  48. </view>
  49. <view
  50. class="visit-template__button visit-template__button--confirm"
  51. :class="{ 'visit-template__button--disabled': submitting || loading }"
  52. @click="handleConfirm"
  53. >
  54. {{ submitting ? '确定中' : '确定' }}
  55. </view>
  56. </view>
  57. </view>
  58. </wd-popup>
  59. </template>
  60. <script setup lang="ts">
  61. import { computed, ref, watch } from 'vue'
  62. import { getDictTypeApi } from '@/services/modules/common'
  63. import type { DictItem } from '@/services/modules/common/type'
  64. import type { SharePackageItem } from '@/services/modules/information/type'
  65. import { getListDrugTableApi } from '@/services/modules/task/taskFrom'
  66. import { getTemplateApi } from '@/services/modules/task/taskVisit'
  67. import type { VisitSignDetail, VisitTemplateType } from '@/services/modules/task/taskVisit/type'
  68. import type { VisitTarget, VisitTargetType } from '../../types'
  69. import TemplateContent from './TemplateContent.vue'
  70. import type { PickerOption, TemplateRouteKey, VisitTemplateFormExpose } from './types'
  71. const props = withDefaults(
  72. defineProps<{
  73. target?: VisitTarget
  74. packageItem?: SharePackageItem
  75. deptId: string
  76. taskTypeId: string
  77. signDate: string
  78. submitting?: boolean
  79. }>(),
  80. {
  81. target: undefined,
  82. packageItem: undefined,
  83. submitting: false,
  84. }
  85. )
  86. const emit = defineEmits<{
  87. (event: 'confirm', detail: VisitSignDetail): void
  88. }>()
  89. const visible = defineModel<boolean>('visible', { default: false })
  90. const supportedTemplateRoutes: TemplateRouteKey[] = [
  91. 'hospital:default',
  92. 'hospital:TEMPLATE1',
  93. 'hospital:TEMPLATE2',
  94. 'company:TEMPLATE1',
  95. 'company:TEMPLATE2',
  96. 'pharmacy:TEMPLATE1',
  97. 'pharmacy:TEMPLATE2',
  98. 'pharmacy:TEMPLATE3',
  99. ]
  100. const purposeDictTypeMap: Record<VisitTargetType, string> = {
  101. hospital: 'user_sign_detail_purpose',
  102. company: 'user_sign_detail_distribution_purpose',
  103. pharmacy: 'user_sign_detail_pharmacy_purpose',
  104. }
  105. const targetNameMap: Record<VisitTargetType, string> = {
  106. hospital: '医院名称',
  107. company: '商业公司名称',
  108. pharmacy: '药店名称',
  109. }
  110. const loading = ref(false)
  111. const templateType = ref<VisitTemplateType>('')
  112. const scenePhotoMinCount = ref(1)
  113. const drugOptions = ref<PickerOption[]>([])
  114. const purposeOptions = ref<PickerOption[]>([])
  115. const resultOptions = ref<PickerOption[]>([])
  116. const visitorOptions = ref<PickerOption[]>([])
  117. const templateFormRef = ref<VisitTemplateFormExpose>()
  118. const targetNameLabel = computed(() => {
  119. return props.target ? targetNameMap[props.target.type] : '拜访对象'
  120. })
  121. const templateRouteKey = computed<TemplateRouteKey | ''>(() => {
  122. const targetType = props.target?.type
  123. if (!targetType) return ''
  124. if (targetType === 'hospital' && !templateType.value) return 'hospital:default'
  125. const routeKey = `${targetType}:${templateType.value}` as TemplateRouteKey
  126. return supportedTemplateRoutes.includes(routeKey) ? routeKey : ''
  127. })
  128. watch(visible, (isVisible) => {
  129. if (isVisible) void loadTemplate()
  130. })
  131. const loadTemplate = async () => {
  132. if (!props.target || !props.packageItem || !props.deptId || !props.taskTypeId) {
  133. visible.value = false
  134. return
  135. }
  136. resetTemplateState()
  137. loading.value = true
  138. try {
  139. const templateRes = await getTemplateApi({
  140. deptId: props.deptId,
  141. taskTypeId: props.taskTypeId,
  142. })
  143. if (!visible.value) return
  144. templateType.value = templateRes.data?.template || ''
  145. scenePhotoMinCount.value = Math.max(Number(templateRes.data?.detail?.numberLimit) || 1, 1)
  146. if (templateRouteKey.value === 'hospital:default') return
  147. const purposeDictType =
  148. templateRouteKey.value === 'hospital:TEMPLATE2'
  149. ? 'user_sign_detail_template2_purpose'
  150. : purposeDictTypeMap[props.target.type]
  151. const [drugRes, purposeRes, resultRes, visitorRes] = await Promise.all([
  152. getListDrugTableApi(String(props.packageItem.value)),
  153. getDictTypeApi(purposeDictType),
  154. getDictTypeApi('user_sign_detail_result'),
  155. needsVisitorOptions(templateRouteKey.value)
  156. ? getDictTypeApi('user_sign_detail_pharmacy_person')
  157. : Promise.resolve(null),
  158. ])
  159. if (!visible.value) return
  160. drugOptions.value = (Array.isArray(drugRes.data) ? drugRes.data : []).map((item) => ({
  161. label: String(item),
  162. value: String(item),
  163. }))
  164. purposeOptions.value = toDictOptions(purposeRes.data)
  165. resultOptions.value = toDictOptions(resultRes.data)
  166. visitorOptions.value = toDictOptions(visitorRes?.data)
  167. } catch {
  168. visible.value = false
  169. } finally {
  170. loading.value = false
  171. }
  172. }
  173. const needsVisitorOptions = (routeKey: TemplateRouteKey | '') => {
  174. return routeKey === 'pharmacy:TEMPLATE2' || routeKey === 'pharmacy:TEMPLATE3'
  175. }
  176. const toDictOptions = (list: DictItem[] | null | undefined): PickerOption[] => {
  177. return (Array.isArray(list) ? list : []).map((item) => ({
  178. label: item.label,
  179. value: item.value,
  180. }))
  181. }
  182. const handleConfirm = () => {
  183. if (props.submitting || loading.value) return
  184. const detail = templateFormRef.value?.submit()
  185. if (detail) emit('confirm', detail)
  186. }
  187. const resetTemplate = () => {
  188. resetTemplateState()
  189. loading.value = false
  190. }
  191. const resetTemplateState = () => {
  192. templateType.value = ''
  193. scenePhotoMinCount.value = 1
  194. drugOptions.value = []
  195. purposeOptions.value = []
  196. resultOptions.value = []
  197. visitorOptions.value = []
  198. templateFormRef.value = undefined
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .visit-template {
  203. display: flex;
  204. flex-direction: column;
  205. height: 94vh;
  206. max-height: 94vh;
  207. background: #f5f7fa;
  208. }
  209. .visit-template__header {
  210. display: flex;
  211. flex-shrink: 0;
  212. align-items: center;
  213. justify-content: space-between;
  214. padding: 28rpx 30rpx;
  215. background: #ffffff;
  216. border-bottom: 2rpx solid #edf1f5;
  217. }
  218. .visit-template__heading {
  219. min-width: 0;
  220. }
  221. .visit-template__title {
  222. color: #172033;
  223. font-size: 32rpx;
  224. font-weight: 700;
  225. line-height: 44rpx;
  226. }
  227. .visit-template__subtitle {
  228. max-width: 560rpx;
  229. margin-top: 4rpx;
  230. overflow: hidden;
  231. color: #8491a2;
  232. font-size: 22rpx;
  233. line-height: 32rpx;
  234. text-overflow: ellipsis;
  235. white-space: nowrap;
  236. }
  237. .visit-template__close {
  238. display: flex;
  239. flex-shrink: 0;
  240. align-items: center;
  241. justify-content: center;
  242. width: 60rpx;
  243. height: 60rpx;
  244. background: #f4f7fa;
  245. border-radius: 50%;
  246. }
  247. .visit-template__loading {
  248. display: flex;
  249. flex: 1;
  250. align-items: center;
  251. justify-content: center;
  252. }
  253. .visit-template__loading-text {
  254. margin-left: 16rpx;
  255. color: #8491a2;
  256. font-size: 26rpx;
  257. }
  258. .visit-template__scroll {
  259. flex: 1;
  260. min-height: 0;
  261. }
  262. .visit-template__content {
  263. padding: 18rpx 0 28rpx;
  264. }
  265. .visit-template__unsupported {
  266. padding: 120rpx 30rpx;
  267. color: #8491a2;
  268. font-size: 26rpx;
  269. text-align: center;
  270. }
  271. .visit-template__actions {
  272. display: flex;
  273. flex-shrink: 0;
  274. gap: 18rpx;
  275. padding: 20rpx 28rpx calc(20rpx + env(safe-area-inset-bottom));
  276. background: #ffffff;
  277. box-shadow: 0 -8rpx 24rpx rgba(31, 51, 73, 0.08);
  278. box-sizing: border-box;
  279. }
  280. .visit-template__button {
  281. display: flex;
  282. flex: 1;
  283. align-items: center;
  284. justify-content: center;
  285. height: 88rpx;
  286. border-radius: 18rpx;
  287. font-size: 28rpx;
  288. font-weight: 600;
  289. box-sizing: border-box;
  290. }
  291. .visit-template__button--cancel {
  292. color: #53657a;
  293. background: #eef2f6;
  294. }
  295. .visit-template__button--confirm {
  296. color: #ffffff;
  297. background: linear-gradient(135deg, #50b5ff 0%, #2f8cf7 100%);
  298. box-shadow: 0 10rpx 22rpx rgba(47, 140, 247, 0.22);
  299. }
  300. .visit-template__button--disabled {
  301. opacity: 0.55;
  302. pointer-events: none;
  303. }
  304. </style>