index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. hasTaskTypeTemplate: boolean
  78. signDate: string
  79. submitting?: boolean
  80. }>(),
  81. {
  82. target: undefined,
  83. packageItem: undefined,
  84. submitting: false,
  85. }
  86. )
  87. const emit = defineEmits<{
  88. (event: 'confirm', detail: VisitSignDetail): void
  89. }>()
  90. const visible = defineModel<boolean>('visible', { default: false })
  91. const supportedTemplateRoutes: TemplateRouteKey[] = [
  92. 'hospital:default',
  93. 'hospital:TEMPLATE1',
  94. 'hospital:TEMPLATE2',
  95. 'company:TEMPLATE1',
  96. 'company:TEMPLATE2',
  97. 'pharmacy:TEMPLATE1',
  98. 'pharmacy:TEMPLATE2',
  99. 'pharmacy:TEMPLATE3',
  100. ]
  101. const purposeDictTypeMap: Record<VisitTargetType, string> = {
  102. hospital: 'user_sign_detail_purpose',
  103. company: 'user_sign_detail_distribution_purpose',
  104. pharmacy: 'user_sign_detail_pharmacy_purpose',
  105. }
  106. const targetNameMap: Record<VisitTargetType, string> = {
  107. hospital: '医院名称',
  108. company: '商业公司名称',
  109. pharmacy: '药店名称',
  110. }
  111. const loading = ref(false)
  112. const templateType = ref<VisitTemplateType>('')
  113. const scenePhotoMinCount = ref(1)
  114. const drugOptions = ref<PickerOption[]>([])
  115. const purposeOptions = ref<PickerOption[]>([])
  116. const resultOptions = ref<PickerOption[]>([])
  117. const visitorOptions = ref<PickerOption[]>([])
  118. const templateFormRef = ref<VisitTemplateFormExpose>()
  119. const targetNameLabel = computed(() => {
  120. return props.target ? targetNameMap[props.target.type] : '拜访对象'
  121. })
  122. const templateRouteKey = computed<TemplateRouteKey | ''>(() => {
  123. const targetType = props.target?.type
  124. if (!targetType) return ''
  125. if (targetType === 'hospital' && !templateType.value) return 'hospital:default'
  126. const routeKey = `${targetType}:${templateType.value}` as TemplateRouteKey
  127. return supportedTemplateRoutes.includes(routeKey) ? routeKey : ''
  128. })
  129. watch(visible, (isVisible) => {
  130. if (isVisible) void loadTemplate()
  131. })
  132. const loadTemplate = async () => {
  133. if (
  134. !props.target ||
  135. !props.packageItem ||
  136. !props.taskTypeId ||
  137. (props.hasTaskTypeTemplate && !props.deptId)
  138. ) {
  139. visible.value = false
  140. return
  141. }
  142. resetTemplateState()
  143. if (!props.hasTaskTypeTemplate) return
  144. loading.value = true
  145. try {
  146. const templateRes = await getTemplateApi({
  147. deptId: props.deptId,
  148. taskTypeId: props.taskTypeId,
  149. })
  150. if (!visible.value) return
  151. templateType.value = templateRes.data?.template || ''
  152. scenePhotoMinCount.value = Math.max(Number(templateRes.data?.detail?.numberLimit) || 1, 1)
  153. if (templateRouteKey.value === 'hospital:default') return
  154. const purposeDictType =
  155. templateRouteKey.value === 'hospital:TEMPLATE2'
  156. ? 'user_sign_detail_template2_purpose'
  157. : purposeDictTypeMap[props.target.type]
  158. const [drugRes, purposeRes, resultRes, visitorRes] = await Promise.all([
  159. getListDrugTableApi(String(props.packageItem.value)),
  160. getDictTypeApi(purposeDictType),
  161. getDictTypeApi('user_sign_detail_result'),
  162. needsVisitorOptions(templateRouteKey.value)
  163. ? getDictTypeApi('user_sign_detail_pharmacy_person')
  164. : Promise.resolve(null),
  165. ])
  166. if (!visible.value) return
  167. drugOptions.value = (Array.isArray(drugRes.data) ? drugRes.data : []).map((item) => ({
  168. label: String(item),
  169. value: String(item),
  170. }))
  171. purposeOptions.value = toDictOptions(purposeRes.data)
  172. resultOptions.value = toDictOptions(resultRes.data)
  173. visitorOptions.value = toDictOptions(visitorRes?.data)
  174. } catch {
  175. visible.value = false
  176. } finally {
  177. loading.value = false
  178. }
  179. }
  180. const needsVisitorOptions = (routeKey: TemplateRouteKey | '') => {
  181. return routeKey === 'pharmacy:TEMPLATE2' || routeKey === 'pharmacy:TEMPLATE3'
  182. }
  183. const toDictOptions = (list: DictItem[] | null | undefined): PickerOption[] => {
  184. return (Array.isArray(list) ? list : []).map((item) => ({
  185. label: item.label,
  186. value: item.value,
  187. }))
  188. }
  189. const handleConfirm = () => {
  190. if (props.submitting || loading.value) return
  191. const detail = templateFormRef.value?.submit()
  192. if (detail) emit('confirm', detail)
  193. }
  194. const resetTemplate = () => {
  195. resetTemplateState()
  196. loading.value = false
  197. }
  198. const resetTemplateState = () => {
  199. templateType.value = ''
  200. scenePhotoMinCount.value = 1
  201. drugOptions.value = []
  202. purposeOptions.value = []
  203. resultOptions.value = []
  204. visitorOptions.value = []
  205. templateFormRef.value = undefined
  206. }
  207. </script>
  208. <style lang="scss" scoped>
  209. .visit-template {
  210. display: flex;
  211. flex-direction: column;
  212. height: 94vh;
  213. max-height: 94vh;
  214. background: #f5f7fa;
  215. }
  216. .visit-template__header {
  217. display: flex;
  218. flex-shrink: 0;
  219. align-items: center;
  220. justify-content: space-between;
  221. padding: 28rpx 30rpx;
  222. background: #ffffff;
  223. border-bottom: 2rpx solid #edf1f5;
  224. }
  225. .visit-template__heading {
  226. min-width: 0;
  227. }
  228. .visit-template__title {
  229. color: #172033;
  230. font-size: 32rpx;
  231. font-weight: 700;
  232. line-height: 44rpx;
  233. }
  234. .visit-template__subtitle {
  235. max-width: 560rpx;
  236. margin-top: 4rpx;
  237. overflow: hidden;
  238. color: #8491a2;
  239. font-size: 22rpx;
  240. line-height: 32rpx;
  241. text-overflow: ellipsis;
  242. white-space: nowrap;
  243. }
  244. .visit-template__close {
  245. display: flex;
  246. flex-shrink: 0;
  247. align-items: center;
  248. justify-content: center;
  249. width: 60rpx;
  250. height: 60rpx;
  251. background: #f4f7fa;
  252. border-radius: 50%;
  253. }
  254. .visit-template__loading {
  255. display: flex;
  256. flex: 1;
  257. align-items: center;
  258. justify-content: center;
  259. }
  260. .visit-template__loading-text {
  261. margin-left: 16rpx;
  262. color: #8491a2;
  263. font-size: 26rpx;
  264. }
  265. .visit-template__scroll {
  266. flex: 1;
  267. min-height: 0;
  268. }
  269. .visit-template__content {
  270. padding: 18rpx 0 28rpx;
  271. }
  272. .visit-template__unsupported {
  273. padding: 120rpx 30rpx;
  274. color: #8491a2;
  275. font-size: 26rpx;
  276. text-align: center;
  277. }
  278. .visit-template__actions {
  279. display: flex;
  280. flex-shrink: 0;
  281. gap: 18rpx;
  282. padding: 20rpx 28rpx calc(20rpx + env(safe-area-inset-bottom));
  283. background: #ffffff;
  284. box-shadow: 0 -8rpx 24rpx rgba(31, 51, 73, 0.08);
  285. box-sizing: border-box;
  286. }
  287. .visit-template__button {
  288. display: flex;
  289. flex: 1;
  290. align-items: center;
  291. justify-content: center;
  292. height: 88rpx;
  293. border-radius: 18rpx;
  294. font-size: 28rpx;
  295. font-weight: 600;
  296. box-sizing: border-box;
  297. }
  298. .visit-template__button--cancel {
  299. color: #53657a;
  300. background: #eef2f6;
  301. }
  302. .visit-template__button--confirm {
  303. color: #ffffff;
  304. background: linear-gradient(135deg, #50b5ff 0%, #2f8cf7 100%);
  305. box-shadow: 0 10rpx 22rpx rgba(47, 140, 247, 0.22);
  306. }
  307. .visit-template__button--disabled {
  308. opacity: 0.55;
  309. pointer-events: none;
  310. }
  311. </style>