fromDrawer.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <hc-drawer v-model="isShow" to-id="node-card-plan" is-close @close="goBack">
  3. <hc-card>
  4. <template #header>
  5. <el-link type="primary" @click="goBack">返回</el-link>
  6. </template>
  7. <template #extra>
  8. <HcTooltip keys="system-service-plan-save-btn">
  9. <el-button
  10. v-if="status === 2 || status === 3 || status === 4"
  11. :disabled="!isWriteUserAuthorized"
  12. class="ml-6"
  13. hc-btn
  14. keys="system-service-plan-save-btn"
  15. type="primary"
  16. :loading="saveLoading"
  17. @click="savePlan"
  18. >
  19. <HcIcon name="save" />
  20. 保存数据
  21. </el-button>
  22. <el-button
  23. v-else
  24. class="ml-6"
  25. hc-btn
  26. keys="system-service-plan-save-btn"
  27. type="primary"
  28. :loading="saveLoading"
  29. @click="savePlan"
  30. >
  31. <HcIcon name="save" />
  32. 保存数据
  33. </el-button>
  34. </HcTooltip>
  35. <HcTooltip keys="system-service-plan-preview-btn">
  36. <el-button
  37. class="node-card-plan-btn ml-6"
  38. hc-btn
  39. keys="system-service-plan-preview-btn"
  40. color="#3F9EFF"
  41. :loading="preViewLoad"
  42. :disabled="dataId.length === 0 "
  43. @click="previewPlan"
  44. >
  45. <HcIcon name="eye" />
  46. 预览
  47. </el-button>
  48. </HcTooltip>
  49. <HcTooltip keys="system-service-plan-send-btn">
  50. <el-button
  51. v-if="status === 1"
  52. class="node-card-plan-btn ml-6"
  53. hc-btn
  54. keys="system-service-plan-send-btn"
  55. type="warning"
  56. :loading="sendPlanLoad"
  57. :disabled="!isWriteUserAuthorized || dataId.length === 0 "
  58. @click="sendPlan"
  59. >
  60. <HcIcon name="send-plane" />
  61. 发送计划
  62. </el-button>
  63. </HcTooltip>
  64. <HcTooltip keys="system-service-plan-back-btn">
  65. <el-button
  66. v-if="status === 2"
  67. class="node-card-plan-btn ml-6"
  68. hc-btn
  69. keys="system-service-plan-back-btn"
  70. type="warning"
  71. :disabled="!isSendUserAuthorized"
  72. :loading="backPlanLoad"
  73. @click="backPlan"
  74. >
  75. <HcIcon name="arrow-go-back" />
  76. 计划回退
  77. </el-button>
  78. </HcTooltip>
  79. <HcTooltip keys="system-service-plan-comfirm-btn">
  80. <el-button
  81. v-if="status === 2"
  82. :loading="confirmPlanLoad"
  83. class="node-card-plan-btn ml-6"
  84. hc-btn
  85. keys="system-service-plan-comfirm-btn"
  86. type="success"
  87. :disabled="!isSendUserAuthorized"
  88. @click="confirmPlan"
  89. >
  90. <HcIcon name="check" />
  91. 确认计划
  92. </el-button>
  93. </HcTooltip>
  94. </template>
  95. <div class="hc-table-form-box">
  96. <HcTableForm
  97. ref="tableFormRef"
  98. :form="tableFormData"
  99. :html="excelHtmlData"
  100. :loading="loading"
  101. :pkey="excelIdVal"
  102. :disabled="!isTableForm"
  103. @render="tableFormRender"
  104. />
  105. </div>
  106. </hc-card>
  107. <!-- 选择任务人 -->
  108. <HcUserModal v-model="isUserModalShow" :data="userData" :datas="dataInfo" @finish="fixedUserFinish" />
  109. </hc-drawer>
  110. </template>
  111. <script setup>
  112. import { computed, ref, watch } from 'vue'
  113. import { arrToKey, deepClone, getObjVal, isString } from 'js-fast-way'
  114. import HcUserModal from './hc-tasks-user/user-modal.vue'
  115. import { useAppStore } from '~src/store'
  116. import dataApi from '~api/systemService/service'
  117. import { toPdfPage } from '~uti/btn-auth'
  118. //参数
  119. const props = defineProps({
  120. type: {
  121. type:[String, Number],
  122. default:'',
  123. },
  124. dataId: {
  125. type:[String, Number],
  126. default:'',
  127. },
  128. })
  129. const emit = defineEmits(['close'])
  130. const type = ref(props.type)
  131. const dataId = ref(props.dataId)
  132. const isShow = defineModel('modelValue', {
  133. default: false,
  134. })
  135. const tableFormRef = ref(null)
  136. const tableFormData = ref({})
  137. const excelHtmlData = ref('')
  138. const loading = ref(false)
  139. const excelIdVal = ref('')
  140. const isTableForm = ref(false)
  141. const useAppState = useAppStore()
  142. const projectId = ref(useAppState.getProjectId)
  143. const contractId = ref(useAppState.getContractId)
  144. const user_id = ref(useAppState.getUserInfo.user_id ?? '')
  145. const status = ref()
  146. watch(isShow, (val) => {
  147. if (val) {
  148. if (val) getExcelHtml()
  149. tableFormData.value = {}
  150. excelHtmlData.value = ''
  151. isTableForm.value = false
  152. if (dataId.value) {
  153. getDetailData()
  154. getAddLogBusinessData()
  155. }
  156. }
  157. })
  158. //监听
  159. watch(() => [
  160. props.type,
  161. props.dataId,
  162. ], ([val, id]) => {
  163. type.value = val
  164. dataId.value = id
  165. if (val === 1) {
  166. excelIdVal.value = '1937773223861026820'
  167. } else {
  168. excelIdVal.value = '1937773223861026822'
  169. }
  170. }, { immediate: true })
  171. //获取模板标签数据
  172. const getExcelHtml = async () => {
  173. loading.value = true
  174. //获取数据
  175. const { error, code, data } = await dataApi.getServiceHtml({
  176. contractId: contractId.value || '',
  177. pkeyId: excelIdVal.value,
  178. projectId: projectId.value || '',
  179. }, false)
  180. loading.value = false
  181. //处理数据
  182. const resData = isString(data) ? data || '' : ''
  183. if (!error && code === 200 && resData) {
  184. excelHtmlData.value = resData
  185. } else {
  186. excelHtmlData.value = ''
  187. isTableForm.value = false
  188. }
  189. }
  190. //获取填写数据
  191. const getAddLogBusinessData = async () => {
  192. const { data } = await dataApi.getServiceBussData({
  193. id: dataId.value,
  194. pkeyId: excelIdVal.value,
  195. }, false)
  196. //设置默认数据
  197. let formArrData = getObjVal(data)
  198. const defaultData = setFormDefaultData(formArrData)
  199. // tableFormData.value = defaultData
  200. if (getObjVal(defaultData)) {
  201. tableFormData.value = defaultData
  202. } else {
  203. tableFormData.value = {}
  204. }
  205. tableFormRef.value?.setExcelHtml()
  206. }
  207. //设置表单默认数据
  208. const setFormDefaultData = (formInfo = {}) => {
  209. return {
  210. ...formInfo,
  211. projectId: projectId.value,
  212. contractId: contractId.value,
  213. pkeyId: excelIdVal.value,
  214. }
  215. }
  216. //渲染表单完成
  217. const tableFormRender = (form) => {
  218. isTableForm.value = form.isRenderForm
  219. }
  220. const goBack = () => {
  221. isShow.value = false
  222. emit('close')
  223. }
  224. const sendPlan = ()=>{
  225. userData.value = []
  226. isUserModalShow.value = true
  227. }
  228. // 计算属性:判断 writeUser 是否包含 user_id
  229. const isWriteUserAuthorized = computed(() => {
  230. const writeUserStr = writeUser.value
  231. const writeUserArray = writeUserStr.split(',')
  232. const cleanedArray = writeUserArray.filter(item => item.trim() !== '')
  233. console.log(cleanedArray, 'cleanedArray')
  234. console.log(user_id.value, 'user_id.value')
  235. return cleanedArray.includes(user_id.value)
  236. })
  237. // 计算属性:判断 sendUser 是否包含 user_id
  238. const isSendUserAuthorized = computed(() => {
  239. const writeUserStr = sendUser.value
  240. const writeUserArray = writeUserStr.split(',')
  241. const cleanedArray = writeUserArray.filter(item => item.trim() !== '')
  242. return cleanedArray.includes(user_id.value)
  243. })
  244. const isUserModalShow = ref(false)
  245. const userData = ref([])
  246. const dataInfo = ref({
  247. projectId:projectId.value,
  248. contractId:contractId.value,
  249. })
  250. const userIds = ref('')
  251. const fixedUserFinish = async (data) => {
  252. const res = deepClone(data)
  253. userData.value = res
  254. userIds.value = arrToKey(res, 'userId', ',')
  255. console.log(userIds, 'userIds')
  256. sendPlanClick(2)
  257. }
  258. const sendPlanLoad = ref(false)
  259. const sendPlanClick = async (type)=>{
  260. sendPlanLoad.value = true
  261. const { error, code, msg, data } = await dataApi.sendServicePlan(
  262. {
  263. id: dataId.value,
  264. sendUser: userIds.value,
  265. }
  266. , false)
  267. sendPlanLoad.value = false
  268. if (!error && code === 200) {
  269. window?.$message?.success(msg)
  270. getDetailData()
  271. } else {
  272. sendPlanLoad.value = false
  273. }
  274. }
  275. //回退计划
  276. const backPlanLoad = ref(false)
  277. const backPlan = async ()=>{
  278. backPlanLoad.value = true
  279. const { error, code, msg, data } = await dataApi.cancelServicePlan(
  280. {
  281. id: dataId.value,
  282. }
  283. , false)
  284. backPlanLoad.value = false
  285. if (!error && code === 200) {
  286. window?.$message?.success(msg)
  287. getDetailData()
  288. }
  289. }
  290. //确认计划
  291. const confirmPlanLoad = ref(false)
  292. const confirmPlan = async ()=>{
  293. confirmPlanLoad.value = true
  294. const { error, code, msg, data } = await dataApi.confirmServicePlan(
  295. {
  296. id: dataId.value,
  297. }
  298. , false)
  299. confirmPlanLoad.value = false
  300. if (!error && code === 200) {
  301. window?.$message?.success(msg)
  302. getDetailData()
  303. }
  304. }
  305. //保存数据
  306. const saveLoading = ref(false)
  307. const savePlan = async ()=>{
  308. console.log( tableFormData.value, 'tableFormData.value')
  309. let objres = {
  310. ...tableFormData.value,
  311. projectId: projectId.value,
  312. contractId: contractId.value,
  313. pkeyId: excelIdVal.value,
  314. group_id: dataId.value,
  315. }
  316. saveLoading.value = true
  317. const { error, code, msg, data } = await dataApi.saveServiceData(
  318. objres
  319. , false)
  320. saveLoading.value = false
  321. if (!error && code === 200) {
  322. dataId.value = data
  323. window?.$message?.success(msg)
  324. getDetailData()
  325. } else {
  326. saveLoading.value = false
  327. }
  328. }
  329. //预览
  330. const preViewLoad = ref(false)
  331. const previewPlan = async ()=>{
  332. preViewLoad.value = true
  333. const { error, code, data } = await dataApi.getDetail({
  334. id: dataId.value,
  335. }, false)
  336. preViewLoad.value = false
  337. if (!error && code === 200) {
  338. const res = getObjVal(data)
  339. const { pdfUrl } = res
  340. if (pdfUrl) {
  341. toPdfPage(pdfUrl)
  342. } else {
  343. window?.$message?.error('暂无预览文件')
  344. }
  345. } else {
  346. window?.$message?.error('暂无预览文件')
  347. }
  348. }
  349. const sendUser = ref('')
  350. const writeUser = ref('')
  351. const getDetailData = async ()=>{
  352. const { error, code, data } = await dataApi.getDetail({
  353. id: dataId.value,
  354. }, false)
  355. if (!error && code === 200) {
  356. const res = getObjVal(data)
  357. status.value = res.status
  358. console.log( status.value, ' status.value')
  359. console.log(user_id, ' user_id.value')
  360. sendUser.value = res.sendUser
  361. writeUser.value = res.writeUser
  362. } else {
  363. status.value = ''
  364. sendUser.value = ''
  365. writeUser.value = ''
  366. }
  367. }
  368. </script>
  369. <style scoped lang="scss">
  370. .node-card-plan-btn{
  371. color:white;
  372. }
  373. .hc-table-form-box{
  374. height: 100%;
  375. overflow-y: auto;
  376. overflow-x: auto;
  377. }
  378. </style>