linkAssociation.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <hc-new-dialog v-model="isShow" is-footer-center is-table title="关联委托单" widths="80%" @close="linkSamplingClose">
  3. <hc-body split padding="10px">
  4. <template #left>
  5. <hc-new-card scrollbar>
  6. <TestTree
  7. :auto-expand-keys="treeAutoExpandKeys" :project-id="projectId" :tenant-id="userInfo?.tenant_id"
  8. :wbs-temp-id="projectInfo?.referenceWbsTemplateIdTrial" :wbs-type="2" :entrust="1"
  9. @node-tap="wbsElTreeClick"
  10. />
  11. </hc-new-card>
  12. </template>
  13. <hc-new-card>
  14. <template #header>
  15. <div class="w-50">
  16. <el-select v-model="searchForm.contractId" placeholder="选择合同段" filterable block>
  17. <el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id" />
  18. </el-select>
  19. </div>
  20. <div class="ml-2">
  21. <el-button type="primary" @click="searchClick">
  22. <hc-icon name="search-2" />
  23. <span>搜索</span>
  24. </el-button>
  25. </div>
  26. </template>
  27. <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" :index-style="{ width: 60 }">
  28. <template #status="{ row }">
  29. <el-tag v-if="row.status === 1" type="info" effect="dark">未上报</el-tag>
  30. <el-tag v-if="row.status === 2" type="warning" effect="dark">已上报-待审批</el-tag>
  31. <el-tag v-if="row.status === 3" type="primary" effect="dark">待试验</el-tag>
  32. <el-tag v-if="row.status === 4" type="success" effect="dark">委托完成</el-tag>
  33. </template>
  34. <template #action="{ row }">
  35. <el-link v-if="row.id === curId && isSelected" type="success" @click="rowCancel(row)">取消选择</el-link>
  36. <!-- el-link v-else type="primary" :disabled="row.status !== 4" @click="rowSelect(row)">选择</el-link -->
  37. <el-link v-if="row.id !== curId || !isSelected" type="primary" :disabled="!row.testId" @click="rowSelect(row)">选择</el-link>
  38. </template>
  39. </hc-table>
  40. <template #action>
  41. <hc-pages :pages="searchForm" @change="pageChange" />
  42. </template>
  43. </hc-new-card>
  44. </hc-body>
  45. <template #footer>
  46. <el-button @click="linkSamplingClose">取消</el-button>
  47. <el-button hc-btn type="primary" @click="linkSamplingClick">确定</el-button>
  48. </template>
  49. </hc-new-dialog>
  50. <!-- 关联更换 -->
  51. <hc-new-dialog v-model="isCountShow" is-footer-center title="关联更换" widths="30rem" @close="linkCountClose">
  52. <el-form ref="formRef" :model="formModel" :rules="formRules" label-position="top" label-width="auto">
  53. <el-form-item label="试验数量:" prop="expCount">
  54. <el-input v-model="formModel.expCount" placeholder="试验数量" />
  55. </el-form-item>
  56. </el-form>
  57. <template #footer>
  58. <el-button @click="linkCountClose">取消</el-button>
  59. <el-button hc-btn type="primary" @click="linkCountClick">确定</el-button>
  60. </template>
  61. </hc-new-dialog>
  62. </template>
  63. <script setup>
  64. import { ref, watch } from 'vue'
  65. import { useAppStore } from '~src/store'
  66. import { formValidate, getArrValue, getObjValue, isNullES } from 'js-fast-way'
  67. import mainApi from '~api/tentative/detect/commission'
  68. import samplingApi from '~api/tentative/material/sampling'
  69. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  70. import TestTree from '~src/views/tentative/material/components/TestTree.vue'
  71. const props = defineProps({
  72. ids: {
  73. type: [String, Number],
  74. default: '',
  75. },
  76. cid: {
  77. type: [String, Number],
  78. default: '',
  79. },
  80. })
  81. const emit = defineEmits(['change', 'close'])
  82. //变量
  83. const useAppState = useAppStore()
  84. const userInfo = ref(useAppState.getUserInfo)
  85. const projectId = ref(useAppState.getProjectId)
  86. const contractId = ref(useAppState.getContractId)
  87. const projectInfo = ref(useAppState.getProjectInfo)
  88. const isShow = defineModel('modelValue', {
  89. default: false,
  90. })
  91. //深度监听数据
  92. const curId = ref(props.ids)
  93. watch(() => props.ids, (id) => {
  94. curId.value = id
  95. })
  96. //监听
  97. watch(() => isShow.value, (show) => {
  98. if (show) getContractData()
  99. })
  100. //搜索表单
  101. const searchForm = ref({ current: 1, size: 20, total: 0 })
  102. //获取合同段信息
  103. const contractData = ref([])
  104. const getContractData = async () => {
  105. const { data } = await samplingApi.getErtractInfo({
  106. projectId: projectId.value,
  107. contractId: contractId.value,
  108. })
  109. const res = getArrValue(data)
  110. contractData.value = res
  111. if (!isNullES(props.cid)) {
  112. searchForm.value.contractId = props.cid
  113. }
  114. if (isNullES(props.cid) && res.length > 0) {
  115. searchForm.value.contractId = res[0].id
  116. }
  117. }
  118. //自动展开缓存
  119. const treeAutoExpandKeys = ref(getStoreValue('testTreeExpandKeys') || [])
  120. //树被点击
  121. const nodeDataInfo = ref({})
  122. const nodeErTreeId = ref('')
  123. const wbsElTreeClick = ({ data, keys }) => {
  124. nodeDataInfo.value = data
  125. searchForm.value.nodeId = data['primaryKeyId']
  126. nodeErTreeId.value = data['erTreeId'] || ''
  127. //缓存自动展开
  128. treeAutoExpandKeys.value = keys
  129. setStoreValue('testTreeExpandKeys', keys)
  130. //获取表格
  131. searchClick()
  132. }
  133. //搜索
  134. const searchClick = () => {
  135. searchForm.value.current = 1
  136. getTableData()
  137. }
  138. //分页被点击
  139. const pageChange = ({ current, size }) => {
  140. searchForm.value.current = current
  141. searchForm.value.size = size
  142. getTableData()
  143. }
  144. //表格数据
  145. const tableData = ref([])
  146. const tableColumn = ref([
  147. { key: 'entrustInfo', name: '委托单位' },
  148. { key: 'entrustNo', name: '委托单编号' },
  149. { key: 'entrustName', name: '委托单名称' },
  150. { key: 'status', name: '委托单状态', width: 120, align: 'center' },
  151. { key: 'action', name: '操作', width: 120, align: 'center', fixed: 'right' },
  152. ])
  153. //获取数据
  154. const tableLoading = ref(false)
  155. const getTableData = async () => {
  156. tableLoading.value = true
  157. const { error, code, data } = await mainApi.page(searchForm.value)
  158. //处理数据
  159. tableLoading.value = false
  160. if (!error && code === 200) {
  161. tableData.value = getArrValue(data['records'])
  162. searchForm.value.total = data.total || 0
  163. } else {
  164. tableData.value = []
  165. searchForm.value.total = 0
  166. }
  167. }
  168. //选择
  169. const currentId = ref(null)
  170. const entrustNoVal = ref('')
  171. const rowSelect = async ({ id, entrustNo }) => {
  172. isCountShow.value = true
  173. formModel.value = {}
  174. currentId.value = id
  175. entrustNoVal.value = entrustNo
  176. const { data } = await mainApi.detail(id)
  177. formModel.value = getObjValue(data)
  178. isSelected.value = true // 设置选中状态
  179. }
  180. //取消选择
  181. const rowCancel = () => {
  182. currentId.value = null
  183. entrustNoVal.value = ''
  184. formModel.value = {}
  185. isSelected.value = false // 清除选中状态
  186. }
  187. const isSelected = ref(false) // 新增状态变量
  188. //确认关联取样材料
  189. const linkSamplingClick = () => {
  190. emit('change', curId.value, formModel.value, entrustNoVal.value)
  191. linkSamplingClose()
  192. }
  193. //取消关联取样材料
  194. const linkSamplingClose = () => {
  195. isShow.value = false
  196. formModel.value = {}
  197. entrustNoVal.value = ''
  198. emit('close')
  199. }
  200. //表单数据
  201. const formRef = ref(null)
  202. const formModel = ref({})
  203. const formRules = {
  204. expCount: {
  205. required: true,
  206. trigger: 'blur',
  207. message: '请填写试验数量',
  208. },
  209. }
  210. //确定
  211. const isCountShow = ref(false)
  212. const linkCountClick = async () => {
  213. const isForm = await formValidate(formRef.value)
  214. if (!isForm) return
  215. const { id, expCount } = formModel.value
  216. const { error, code, msg } = await mainApi.update({ id, expCount })
  217. if (!error && code === 200) {
  218. window.$message.success('选择成功')
  219. curId.value = currentId.value
  220. linkCountClose()
  221. } else {
  222. window.$message.error(msg || '选择失败')
  223. }
  224. }
  225. //取消
  226. const linkCountClose = () => {
  227. isCountShow.value = false
  228. // formModel.value = {}
  229. }
  230. </script>