appoint.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <!--
  2. * @Author: wanglj wanglijie@dashoo.cn
  3. * @Date: 2025-03-24 09:17:15
  4. * @LastEditors: wanglj wanglijie@dashoo.cn
  5. * @LastEditTime: 2025-03-26 16:39:21
  6. * @FilePath: \labsop_h5\src\view\instr\detail.vue
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. -->
  9. <template>
  10. <div class="container">
  11. <van-form ref="formRef" required="auto">
  12. <van-cell-group>
  13. <van-field label="预约仪器" v-model="state.form.instName" readonly :rules="[{ required: true }]" />
  14. </van-cell-group>
  15. <h4>预约时间</h4>
  16. <van-cell-group class="mt10">
  17. <van-field
  18. v-model="state.form.startTime"
  19. is-link
  20. readonly
  21. label="开始时间"
  22. placeholder="开始时间"
  23. @click="onRouterPush('/instr-calendar', { id: state.form.instId })"
  24. :rules="[{ required: true, message: '开始时间不能为空' }]"
  25. />
  26. <van-field
  27. v-model="state.form.endTime"
  28. is-link
  29. readonly
  30. label="结束时间"
  31. placeholder="结束时间"
  32. @click="onRouterPush('/instr-calendar', { id: state.form.instId })"
  33. :rules="[{ required: true, message: '结束时间不能为空' }]"
  34. />
  35. </van-cell-group>
  36. <h4>申请明细</h4>
  37. <template v-if="state.appointId == 0">
  38. <van-cell-group class="mt10" v-if="state.isActiveService">
  39. <!-- <van-field name="radio" label="课题/服务" :rules="[{ required: true }]">
  40. <template #input>
  41. <van-radio-group v-model="state.form.projectType" direction="horizontal" @change="changeProjectType">
  42. <van-radio style="margin-right: 20px" name="project">课题</van-radio>
  43. <van-radio name="service">服务</van-radio>
  44. </van-radio-group>
  45. </template>
  46. </van-field> -->
  47. <van-field
  48. v-if="state.form.projectType == 'project'"
  49. label="课题组"
  50. placeholder="课题组"
  51. @click="state.showProject = true"
  52. v-model="state.form.projectName"
  53. :rules="[{ required: true, message: '课题不能为空' }]"
  54. >
  55. </van-field>
  56. <van-field
  57. v-if="state.form.projectType == 'service'"
  58. label="服务"
  59. placeholder="服务"
  60. @click="state.shwoService = true"
  61. v-model="state.form.serviceName"
  62. :rules="[{ required: true, message: '服务不能为空' }]"
  63. >
  64. </van-field>
  65. <!-- <van-field
  66. v-if="state.form.projectType == 'project'"
  67. label="经费卡"
  68. placeholder="经费卡"
  69. is-link
  70. readonly
  71. @click="state.showExpenseCard = true"
  72. v-model="state.form.expenseCardName"
  73. ></van-field> -->
  74. <van-field
  75. label="预约人"
  76. placeholder="预约人"
  77. is-link
  78. readonly
  79. @click="openSelectUser"
  80. v-model="state.form.nickName"
  81. :rules="[{ required: true, message: '预约人不能为空' }]"
  82. ></van-field>
  83. <van-field
  84. label="联系电话"
  85. placeholder="联系电话"
  86. v-model="state.form.userContact"
  87. :rules="[{ required: true, message: '联系电话不能为空' }]"
  88. ></van-field>
  89. <van-field label="备注" placeholder="备注" v-model="state.form.remark" rows="2" autosize type="textarea" maxlength="300" show-word-limit></van-field>
  90. </van-cell-group>
  91. </template>
  92. <CustomForm ref="customFormRef" :formData="state.form.createForm"></CustomForm>
  93. </van-form>
  94. </div>
  95. <van-action-bar>
  96. <van-action-bar-button class="w100" type="primary" text="提交" @click="onClickButton" />
  97. </van-action-bar>
  98. <!-- 选择服务 -->
  99. <van-popup v-model:show="state.shwoService" position="bottom">
  100. <van-picker :columns="serviceList" :columns-field-names="{ text: 'name', value: 'id' }" @confirm="pickService" @cancel="state.shwoService = false" />
  101. </van-popup>
  102. <!-- 选择课题 -->
  103. <van-popup v-model:show="state.showProject" position="bottom">
  104. <van-picker
  105. :columns="projectList"
  106. :columns-field-names="{ text: 'projectName', value: 'projectId' }"
  107. @confirm="pickProject"
  108. @cancel="state.showProject = false"
  109. />
  110. </van-popup>
  111. <!-- 选择经费卡 -->
  112. <van-popup v-model:show="state.showExpenseCard" position="bottom">
  113. <van-picker
  114. :columns="fundsList"
  115. :columns-field-names="{ text: 'finAccount', value: 'id' }"
  116. @confirm="pickExpenseCard"
  117. @cancel="state.showExpenseCard = false"
  118. />
  119. </van-popup>
  120. <!-- 选择预约人 -->
  121. <van-popup v-model:show="state.showAppointUser" position="bottom">
  122. <van-picker
  123. :columns="userList"
  124. :columns-field-names="{ text: 'nickName', value: 'id' }"
  125. @confirm="pickAppointUser"
  126. @cancel="state.showAppointUser = false"
  127. />
  128. </van-popup>
  129. <AppointDialog ref="appointDialogRef" />
  130. </template>
  131. <script lang="ts" setup>
  132. import to from 'await-to-js'
  133. import { useRoute, useRouter } from 'vue-router'
  134. import { useInstrApi } from '/@/api/instr'
  135. import { useInstDocApi } from '/@/api/instr/document'
  136. import { defineAsyncComponent, onMounted, reactive, ref } from 'vue'
  137. import { formatDate } from '/@/utils/formatTime'
  138. import { showNotify } from 'vant'
  139. import download from 'downloadjs'
  140. import { useNoticeApi } from '/@/api/instr/notice'
  141. import { useProApi } from '/@/api/project'
  142. import technicalApi from '/@/api/technical/index'
  143. import { Local } from '/@/utils/storage'
  144. import { useUserApi } from '/@/api/system/user'
  145. import { useUserInfo } from '/@/stores/userInfo'
  146. import { storeToRefs } from 'pinia'
  147. import instAppoint from '/@/api/instr/instAppoint'
  148. import { useConfigApi } from '/@/api/system/config'
  149. const CustomForm = defineAsyncComponent(() => import('/@/components/CustomForm.vue'))
  150. const storesUseUserInfo = useUserInfo()
  151. const { userInfos } = storeToRefs(storesUseUserInfo)
  152. const route = useRoute()
  153. const router = useRouter()
  154. const projApi = useProApi()
  155. const instApi = useInstrApi()
  156. const userApi = useUserApi()
  157. const configApi = useConfigApi()
  158. const serviceList = ref([])
  159. const projectList = ref([])
  160. const fundsList = ref([])
  161. const userList = ref([])
  162. const appointDialogRef = ref()
  163. const formRef = ref()
  164. const customFormRef = ref()
  165. const state = reactive({
  166. loading: false,
  167. appointId: 0,
  168. isActiveService: false,
  169. showProject: false,
  170. shwoService: false,
  171. showExpenseCard: false,
  172. showAppointUser: false,
  173. isInstrHead: false,
  174. instDetail: {} as any,
  175. form: {
  176. instId: 0,
  177. instName: '',
  178. startTime: '',
  179. endTime: null,
  180. projectName: null,
  181. projectId: null,
  182. serviceId: null,
  183. serviceName: null,
  184. expenseCardId: 0,
  185. expenseCardName: '',
  186. userContact: '',
  187. userId: 0,
  188. nickName: '',
  189. projectType: '',
  190. assistEnable: false,
  191. createForm: [],
  192. remark: ''
  193. }
  194. })
  195. // 选择课题还是服务
  196. const changeProjectType = () => {
  197. state.form.serviceId = 0
  198. state.form.serviceName = ''
  199. state.form.projectId = 0
  200. state.form.projectName = ''
  201. state.form.expenseCardId = 0
  202. state.form.expenseCardName = ''
  203. fundsList.value = []
  204. }
  205. const pickProject = ({ selectedOptions }) => {
  206. state.form.projectId = selectedOptions[0].projectId
  207. state.form.projectName = selectedOptions[0].projectName
  208. state.showProject = false
  209. getFundsData()
  210. }
  211. // 选择服务
  212. const pickService = ({ selectedOptions }) => {
  213. state.form.serviceId = selectedOptions[0].id
  214. state.form.serviceName = selectedOptions[0].name
  215. state.shwoService = false
  216. }
  217. // 经费卡选择
  218. const pickExpenseCard = ({ selectedOptions }) => {
  219. state.form.expenseCardId = selectedOptions[0].id
  220. state.form.expenseCardName = selectedOptions[0].finAccount
  221. state.showExpenseCard = false
  222. }
  223. const getFundsData = async () => {
  224. const [err, res]: ToResponse = await to(projApi.getFinanceAccountList({ projId: state.form.projectId }))
  225. if (err) return
  226. fundsList.value = res?.data.list ? [res?.data.list] : []
  227. // if (fundsList.value && fundsList.value.length > 0 && fundsList.value[0].length > 0) {
  228. // state.form.expenseCardId = fundsList.value[0][0].id
  229. // state.form.expenseCardName = fundsList.value[0][0].finAccount
  230. // }
  231. }
  232. // 预约人选择
  233. const pickAppointUser = ({ selectedOptions }) => {
  234. state.form.nickName = selectedOptions[0].nickName
  235. state.form.userId = selectedOptions[0].id
  236. state.form.userContact = selectedOptions[0].phone
  237. state.showAppointUser = false
  238. state.form.serviceId = 0
  239. state.form.serviceName = ''
  240. state.form.projectId = 0
  241. state.form.projectName = ''
  242. state.form.expenseCardId = 0
  243. state.form.expenseCardName = ''
  244. fundsList.value = []
  245. getMyProjectInfo(state.form.userId)
  246. }
  247. // 选择预约人
  248. const openSelectUser = () => {
  249. if (!state.isInstrHead) return
  250. state.showAppointUser = true
  251. }
  252. const init = async () => {
  253. //延长预约会传一个预约id 有预约id 获取预约详情
  254. const [err, res]: ToResponse = await to(configApi.getEntityMapByKey({ configKey: 'instr_is_activate_service' }))
  255. if (err) return
  256. state.isActiveService = res.data?.configValue == '10' ? true : false
  257. state.form.projectType = 'project'
  258. state.form.userId = userInfos.value.id || 0
  259. state.form.nickName = userInfos.value.nickName || ''
  260. state.form.userContact = userInfos.value.phone || ''
  261. getMyProjectInfo()
  262. getUserService()
  263. getUserList()
  264. getInstrDetails()
  265. getAppointConfig()
  266. }
  267. const getInstrDetails = async () => {
  268. const [err, res]: ToResponse = await to(instApi.getDetail({ id: state.form.instId }))
  269. if (err) return
  270. if (res?.code === 200) {
  271. state.instDetail = res.data
  272. state.form.instName = state.instDetail.instName
  273. const userInfo = storesUseUserInfo.userInfos
  274. state.isInstrHead = userInfo.id ? res.data.instHeadId.split(',').includes('' + userInfo?.id) : false
  275. }
  276. }
  277. // 获取用户下的服务
  278. const getUserService = async () => {
  279. const [err, res]: ToResponse = await to(technicalApi.getList({ noPage: true }))
  280. if (err) return
  281. serviceList.value = [res?.data.list]
  282. if (state.form.projectType == 'service') {
  283. state.form.serviceId = res?.data.list[0].id || 0
  284. state.form.serviceName = res?.data.list[0].name || ''
  285. }
  286. }
  287. // 获取用户相关的课题组
  288. const getMyProjectInfo = async (id?: number) => {
  289. let params = {}
  290. if (id) {
  291. params = { id }
  292. } else {
  293. params = {}
  294. }
  295. const [err, res]: ToResponse = await to(projApi.getMySelfProjectGroup(params))
  296. if (err) return
  297. // state.form.projectName = res?.data.pgName || ''
  298. // state.form.projectId = res?.data.id || null
  299. projectList.value = [{ projectName: res?.data.pgName || '', projectId: res?.data.id || null }]
  300. if (state.form.projectType == 'project') {
  301. state.form.projectId = res?.data.id || null
  302. state.form.projectName = res?.data.pgName || ''
  303. getFundsData()
  304. }
  305. }
  306. const getUserList = async () => {
  307. const [err, res]: ToResponse = await to(userApi.getUserList({ noPage: true }))
  308. if (err) return
  309. userList.value = [res?.data.list]
  310. }
  311. // 预约配置信息
  312. const getAppointConfig = async () => {
  313. const params = {
  314. instId: state.form.instId,
  315. code: 'InstCfgAppoint'
  316. }
  317. const [err, res]: ToResponse = await to(instApi.getSettingDetail({ ...params }))
  318. if (err) return
  319. state.form.createForm = res?.data?.config.createForm ? JSON.parse(res.data.config.createForm) : []
  320. }
  321. const onRouterPush = (val: string, params?: any) => {
  322. router.push({
  323. path: val,
  324. query: { ...params }
  325. })
  326. }
  327. const onClickButton = async () => {
  328. state.loading = true
  329. const [errValid] = await to(formRef.value.validate())
  330. const customForm = customFormRef.value.getFormData()
  331. if (errValid || (state.form.createForm.length && !customForm)) {
  332. state.loading = false
  333. return
  334. }
  335. const params = JSON.parse(JSON.stringify(state.form))
  336. params.userName = params.nickName
  337. params.sampleForm = JSON.stringify(customForm)
  338. delete params.createForm
  339. const [err]: ToResponse = await to(instAppoint.add(params))
  340. if (err) {
  341. state.loading = false
  342. return
  343. }
  344. showNotify({
  345. type: 'success',
  346. message: '预约成功'
  347. })
  348. router.push({
  349. path: '/instr-detail',
  350. query: {
  351. id: params.instId
  352. }
  353. })
  354. }
  355. onMounted(() => {
  356. const id = route.query.id ? +route.query.id : 0
  357. const startTime = route.query.startTime ? formatDate(new Date(+route.query.startTime), 'YYYY-mm-dd HH:MM') : ''
  358. const endTime = route.query.endTime ? formatDate(new Date(+route.query.endTime), 'YYYY-mm-dd HH:MM') : ''
  359. state.form.instId = id
  360. state.form.startTime = startTime
  361. state.form.endTime = endTime
  362. init()
  363. })
  364. </script>
  365. <style lang="scss" scoped>
  366. .container {
  367. height: calc(100% - 70px);
  368. padding: 10px;
  369. background-color: #f9f9f9;
  370. overflow-y: auto;
  371. h4 {
  372. height: 18px;
  373. line-height: 18px;
  374. display: flex;
  375. margin: 10px 0;
  376. span {
  377. font-weight: normal;
  378. margin-left: auto;
  379. }
  380. &::before {
  381. display: inline-block;
  382. content: '';
  383. width: 3px;
  384. height: 18px;
  385. background-color: #1c9bfd;
  386. margin-right: 4px;
  387. vertical-align: middle;
  388. }
  389. }
  390. }
  391. </style>