|
@@ -0,0 +1,236 @@
|
|
|
+<template>
|
|
|
+ <div v-loading="loading" class="hc-uni-app-table-form" :class="[editType]">
|
|
|
+ <hc-table-form ref="tableFormRef" :form="tableFormInfo" :html="excelHtml" :scroll="false" :pkey="appItem.excelId" @render="tableFormRender" />
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { onMounted, ref, watch } from 'vue'
|
|
|
+import wbsApi from '~api/data-fill/wbs'
|
|
|
+import { useAppStore } from '~src/store'
|
|
|
+import queryApi from '~api/ledger/query'
|
|
|
+import { getArrValue, getObjVal, getObjValue, isString } from 'js-fast-way'
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ option: {
|
|
|
+ type: Object,
|
|
|
+ default: () => ({}),
|
|
|
+ },
|
|
|
+})
|
|
|
+
|
|
|
+//初始变量
|
|
|
+const useAppState = useAppStore()
|
|
|
+
|
|
|
+//基础变量
|
|
|
+const appItem = ref(props.option)
|
|
|
+const tableFormRef = ref(null)
|
|
|
+const editType = ref('form')
|
|
|
+const loading = ref(false)
|
|
|
+
|
|
|
+//深度监听
|
|
|
+watch(() => [
|
|
|
+ props.option,
|
|
|
+], ([option]) => {
|
|
|
+ appItem.value = getObjValue(option)
|
|
|
+ getDataApi()
|
|
|
+}, { deep: true })
|
|
|
+
|
|
|
+//渲染完成
|
|
|
+onMounted(() => {
|
|
|
+ //设置主题
|
|
|
+ useAppState.setTheme('light')
|
|
|
+ useAppState.setThemeVal('light')
|
|
|
+ if (getObjVal(appItem.value)) {
|
|
|
+ getDataApi()
|
|
|
+ }
|
|
|
+ editTypeClick('form')
|
|
|
+ //接受app传递过来的消息
|
|
|
+ window.addEventListener('message', (event) => {
|
|
|
+ if (event.data.source === 'app') {
|
|
|
+ setMessage(event.data)
|
|
|
+ }
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+//设置消息
|
|
|
+const setMessage = ({ data, type }) => {
|
|
|
+ if (type === 'editTypeClick') {
|
|
|
+ editTypeClick(data)
|
|
|
+ } else if (type === 'formSave') {
|
|
|
+ toSaveClick()
|
|
|
+ } else if (type === 'pageTap') {
|
|
|
+ console.log(data)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const getDataApi = async () => {
|
|
|
+ const { excelId } = appItem.value
|
|
|
+ console.log('appItem', appItem.value)
|
|
|
+ if (excelId) {
|
|
|
+ loading.value = true
|
|
|
+ await getTableFormInfo()
|
|
|
+ await getExcelHtml()
|
|
|
+ loading.value = false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//获取表单初始数据
|
|
|
+const getFormDataInit = (data = {}) => {
|
|
|
+ const { projectId, contractId, excelId, date } = appItem.value
|
|
|
+ return {
|
|
|
+ linkTabIds: [],
|
|
|
+ ...data,
|
|
|
+ projectId: projectId,
|
|
|
+ contractId: contractId,
|
|
|
+ recordTime: date,
|
|
|
+ pkeyId: excelId,
|
|
|
+ isTheLog: '1',
|
|
|
+ theLogId: '',
|
|
|
+ classify: 1,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//获取已填写的数据
|
|
|
+const formLogDataList = ref([])
|
|
|
+const getTableFormInfo = async () => {
|
|
|
+ const { contractId, excelId, pkeyId, date } = appItem.value
|
|
|
+ const { data } = await queryApi.getTheLogBusinessData({
|
|
|
+ contractId: contractId,
|
|
|
+ pkeyId: excelId,
|
|
|
+ nodePrimaryKeyId: pkeyId,
|
|
|
+ recordTime: date,
|
|
|
+ theLogId: '',
|
|
|
+ }, false)
|
|
|
+ let res = getArrValue(data), formArrData = []
|
|
|
+ window?.postMessage({
|
|
|
+ type: 'formLength',
|
|
|
+ source: 'web',
|
|
|
+ data: res.length,
|
|
|
+ })
|
|
|
+ if (res.length > 0) {
|
|
|
+ for (let i = 0; i < res.length; i++) {
|
|
|
+ formArrData.push(getFormDataInit(res[i]))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ formArrData.push(getFormDataInit())
|
|
|
+ }
|
|
|
+ formLogDataList.value = formArrData
|
|
|
+ getBussDataInfo()
|
|
|
+}
|
|
|
+
|
|
|
+//获取表单初始数据
|
|
|
+const formLogIndex = ref(0)
|
|
|
+const tableFormInfo = ref({})
|
|
|
+const getBussDataInfo = (index = 0) => {
|
|
|
+ const formLog = formLogDataList.value
|
|
|
+ const info = getObjValue(formLog[index])
|
|
|
+ formLogIndex.value = index
|
|
|
+ if (getObjVal(info)) {
|
|
|
+ tableFormInfo.value = info
|
|
|
+ } else {
|
|
|
+ tableFormInfo.value = {}
|
|
|
+ }
|
|
|
+ window?.postMessage({
|
|
|
+ type: 'formIndex',
|
|
|
+ source: 'web',
|
|
|
+ data: {
|
|
|
+ id: info?.id ?? '',
|
|
|
+ page: index + 1,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ //tableFormRef.value?.setExcelHtml()
|
|
|
+ //queryCurrentLogSelectProcessList(info?.id ?? '')
|
|
|
+}
|
|
|
+
|
|
|
+//获取当前日志资料关联的工序节点信息
|
|
|
+const queryCurrentLogSelectProcessList = async (bid) => {
|
|
|
+ const index = formLogIndex.value
|
|
|
+ if (bid) {
|
|
|
+ const { contractId } = appItem.value
|
|
|
+ const { data } = await queryApi.queryCurrentLogSelectProcessList({
|
|
|
+ contractId: contractId,
|
|
|
+ businessId: bid ?? '',
|
|
|
+ }, false)
|
|
|
+ //处理数据
|
|
|
+ formLogDataList.value[index]['linkTabIds'] = getArrValue(data)
|
|
|
+ } else {
|
|
|
+ //const formData = formLogDataList.value[index]
|
|
|
+ //processDataList.value = getArrValue(formData?.linkTabIds)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//获取模板标签数据
|
|
|
+const excelHtml = ref('')
|
|
|
+const isTableForm = ref(false)
|
|
|
+const getExcelHtml = async () => {
|
|
|
+ const { contractId, excelId } = appItem.value
|
|
|
+ if (excelId) {
|
|
|
+ //获取数据
|
|
|
+ const { error, code, data } = await queryApi.getExcelHtml({
|
|
|
+ contractId: contractId,
|
|
|
+ pkeyId: excelId,
|
|
|
+ }, false)
|
|
|
+ //处理数据
|
|
|
+ const resData = isString(data) ? data || '' : ''
|
|
|
+ if (!error && code === 200 && resData) {
|
|
|
+ excelHtml.value = resData
|
|
|
+ isTableForm.value = true
|
|
|
+ } else {
|
|
|
+ excelHtml.value = ''
|
|
|
+ isTableForm.value = false
|
|
|
+ window?.$message?.warning('暂无表单')
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isTableForm.value = false
|
|
|
+ window?.$message?.error(`excelId: ${excelId || '-1 或 空'}`)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//渲染完成
|
|
|
+const tableFormRender = (form) => {
|
|
|
+ tableFormInfo.value = form
|
|
|
+}
|
|
|
+
|
|
|
+//切换显示模式
|
|
|
+const tableWidth = ref(0)
|
|
|
+const editTypeClick = (type) => {
|
|
|
+ let metaEle = document.getElementsByName('viewport')[0]
|
|
|
+ if (type === 'form') {
|
|
|
+ metaEle.setAttribute('content', 'width=device-width,user-scalable=no,initial-scale=1.0')
|
|
|
+ tableWidth.value = 0
|
|
|
+ } else if (type === 'table') {
|
|
|
+ metaEle.setAttribute('content', 'width=1080, initial-scale=0.5,user-scalable=yes')
|
|
|
+ tableWidth.value = document.body.offsetWidth
|
|
|
+ }
|
|
|
+ editType.value = type
|
|
|
+}
|
|
|
+
|
|
|
+//保存表单
|
|
|
+const toSaveClick = async () => {
|
|
|
+ const { pkeyId, status } = appItem.value
|
|
|
+ if (!pkeyId) {
|
|
|
+ window?.$message?.warning('pkeyId为空')
|
|
|
+ return
|
|
|
+ } else if (status === '3') {
|
|
|
+ window?.$message?.warning('已上报的资料,不允许保存。')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const formData = tableFormRef.value?.getFormData()
|
|
|
+ const { error, code, msg } = await wbsApi.saveExcelBussData(formData, false)
|
|
|
+ if (!error && code === 200) {
|
|
|
+ window?.$message?.success('保存成功')
|
|
|
+ window?.postMessage({
|
|
|
+ type: 'saveSuccess',
|
|
|
+ source: 'web',
|
|
|
+ data: {},
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ window?.$message?.error(msg)
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+@import "~src/styles/uni-app/table-form.scss";
|
|
|
+</style>
|