index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <ContentWrap>
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="100px"
  10. >
  11. <el-form-item
  12. :label="visibleSelect ? '物资柜' : '绑定物资柜'"
  13. prop="materialsCabinetId"
  14. >
  15. <el-select
  16. v-model="queryParams.materialsCabinetId"
  17. :disabled="visibleSelect"
  18. @change="handleChangeCanbinet"
  19. placeholder="请选择物资柜"
  20. class="!w-240px"
  21. >
  22. <el-option
  23. v-for="dict in cabinets"
  24. :key="dict.value"
  25. :label="dict.label"
  26. :value="dict.value"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="物资名称" prop="materialsName">
  31. <el-input
  32. v-model="queryParams.materialsName"
  33. placeholder="请输入物资名称"
  34. clearable
  35. @keyup.enter="handleQuery"
  36. class="!w-240px"
  37. />
  38. </el-form-item>
  39. <el-form-item label="物资类型" prop="materialsTypeId">
  40. <el-tree-select
  41. v-model="queryParams.materialsTypeId"
  42. :data="machinerytypeOptions"
  43. :props="{ label: 'materialsTypeName', value: 'id' }"
  44. placeholder="请选择物资类型"
  45. class="!w-240px"
  46. />
  47. </el-form-item>
  48. <el-form-item label="物资规格种类" prop="propertyId">
  49. <el-select
  50. v-model="queryParams.propertyId"
  51. placeholder="请选择物资规格种类"
  52. @change="handlePropertyChange"
  53. class="!w-240px"
  54. >
  55. <el-option
  56. v-for="property in PropertyList"
  57. :key="property.id"
  58. :label="property.propertyName"
  59. :value="property.id"
  60. />
  61. </el-select>
  62. </el-form-item>
  63. <el-form-item label="物资规格" prop="recordId">
  64. <el-select
  65. v-model="queryParams.recordId"
  66. placeholder="请选择物资规格"
  67. :disabled="!queryParams.propertyId"
  68. class="!w-240px"
  69. >
  70. <el-option
  71. v-for="value in filteredPropertyValues"
  72. :key="value.id"
  73. :label="value.valueName"
  74. :value="value.id"
  75. />
  76. </el-select>
  77. </el-form-item>
  78. <el-form-item label="RFID" prop="materialsRfid">
  79. <el-input
  80. v-model="queryParams.materialsRfid"
  81. placeholder="请输入RFID"
  82. clearable
  83. @keyup.enter="handleQuery"
  84. class="!w-240px"
  85. />
  86. </el-form-item>
  87. <el-form-item label="供应商" prop="supplier">
  88. <el-input
  89. v-model="queryParams.supplier"
  90. placeholder="请输入供应商"
  91. clearable
  92. @keyup.enter="handleQuery"
  93. class="!w-240px"
  94. />
  95. </el-form-item>
  96. <el-form-item label="有效期截止" prop="expirationDate">
  97. <el-date-picker
  98. v-model="createTime"
  99. type="datetimerange"
  100. range-separator="-"
  101. value-format="YYYY-MM-DD HH:mm:ss"
  102. start-placeholder="开始日期"
  103. end-placeholder="结束日期"
  104. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  105. :picker-options="pickerOptions"
  106. class="!w-240px"
  107. />
  108. </el-form-item>
  109. <el-form-item label="是否在柜中" prop="loanState">
  110. <el-select
  111. v-model="queryParams.loanState"
  112. placeholder="是否在柜中"
  113. class="!w-240px"
  114. >
  115. <el-option
  116. v-for="dict in getIntDictOptions(DICT_TYPE.MATERIAL_STATUS)"
  117. :key="dict.value"
  118. :label="dict.label"
  119. :value="dict.value"
  120. />
  121. </el-select>
  122. </el-form-item>
  123. <el-form-item label="状态" prop="status">
  124. <el-select
  125. v-model="queryParams.status"
  126. placeholder="物资状态"
  127. class="!w-240px"
  128. >
  129. <el-option
  130. v-for="dict in getIntDictOptions(DICT_TYPE.MATERIAL_INFO_STATUS)"
  131. :key="dict.value"
  132. :label="dict.label"
  133. :value="dict.value"
  134. />
  135. </el-select>
  136. </el-form-item>
  137. <el-form-item>
  138. <el-button @click="handleQuery">
  139. <Icon icon="ep:search" class="mr-5px" /> 搜索
  140. </el-button>
  141. <el-button @click="resetQuery">
  142. <Icon icon="ep:refresh" class="mr-5px" /> 重置
  143. </el-button>
  144. <el-button
  145. type="primary"
  146. plain
  147. @click="openForm('create')"
  148. v-hasPermi="['iscs:materials:create']"
  149. >
  150. <Icon icon="ep:plus" class="mr-5px" /> 新增
  151. </el-button>
  152. <el-button
  153. type="primary"
  154. plain
  155. @click="handleImport"
  156. v-hasPermi="['iscs:materials:create']"
  157. >
  158. <Icon icon="ep:upload" class="mr-5px" /> 批量新增
  159. </el-button>
  160. <el-button
  161. v-if="cabinetId"
  162. type="primary"
  163. plain
  164. @click="handleBind"
  165. v-hasPermi="['iscs:materials:create']"
  166. >
  167. <Icon icon="ep:link" class="mr-5px" /> 绑定物资
  168. </el-button>
  169. <el-button
  170. type="danger"
  171. plain
  172. :disabled="multiple"
  173. @click="handleDelete"
  174. v-hasPermi="['iscs:materials:delete']"
  175. >
  176. <Icon icon="ep:delete" class="mr-5px" /> 批量删除
  177. </el-button>
  178. </el-form-item>
  179. </el-form>
  180. </ContentWrap>
  181. <!-- 列表 -->
  182. <ContentWrap>
  183. <el-table
  184. v-loading="loading"
  185. :data="materialsList"
  186. @selection-change="handleSelectionChange"
  187. >
  188. <el-table-column type="selection" width="55" align="center" />
  189. <el-table-column
  190. :label="visibleSelect ? '物资柜' : '绑定物资柜'"
  191. align="center"
  192. prop="cabinetName"
  193. >
  194. <template #default="scope">
  195. <span v-if="scope.row.cabinetName">{{ scope.row.cabinetName }}</span>
  196. <span v-else>-</span>
  197. </template>
  198. </el-table-column>
  199. <el-table-column label="物资编号" align="center" prop="id" />
  200. <el-table-column label="物资名称" align="center" prop="materialsName" />
  201. <el-table-column
  202. label="物资类型"
  203. align="center"
  204. prop="materialsTypeName"
  205. />
  206. <el-table-column
  207. label="物资规格种类"
  208. align="center"
  209. prop="propertiesProperty"
  210. />
  211. <el-table-column label="物资规格" align="center" prop="propertiesValue" />
  212. <el-table-column label="物资图片" prop="materialsTypePicture" width="90">
  213. <template #default="scope">
  214. <UploadImg
  215. v-if="scope.row.materialsTypePicture"
  216. v-model="scope.row.materialsTypePicture"
  217. :limit="1"
  218. height="50px"
  219. width="50px"
  220. />
  221. <span v-else>-</span>
  222. </template>
  223. </el-table-column>
  224. <el-table-column label="RFID" align="center" prop="materialsRfid">
  225. <template #default="scope">
  226. <span v-if="scope.row.materialsRfid">{{ scope.row.materialsRfid }}</span>
  227. <span v-else>-</span>
  228. </template>
  229. </el-table-column>
  230. <el-table-column label="供应商" align="center" prop="supplier" />
  231. <el-table-column label="有效期截止" align="center" prop="expirationDate" />
  232. <el-table-column label="是否在柜中" align="center" prop="loanState">
  233. <template #default="scope">
  234. <dict-tag
  235. :type="DICT_TYPE.MATERIAL_STATUS"
  236. :value="scope.row.loanState"
  237. />
  238. </template>
  239. </el-table-column>
  240. <el-table-column label="状态" align="center" prop="status">
  241. <template #default="scope">
  242. <dict-tag
  243. :type="DICT_TYPE.MATERIAL_INFO_STATUS"
  244. :value="scope.row.status"
  245. />
  246. </template>
  247. </el-table-column>
  248. <el-table-column label="操作" align="center">
  249. <template #default="scope">
  250. <el-button
  251. link
  252. type="primary"
  253. @click="openForm('update', scope.row.id)"
  254. v-hasPermi="['iscs:materials:update']"
  255. >
  256. 编辑
  257. </el-button>
  258. <el-button
  259. link
  260. type="danger"
  261. @click="handleDelete(scope.row.id)"
  262. v-hasPermi="['iscs:materials:delete']"
  263. >
  264. 删除
  265. </el-button>
  266. </template>
  267. </el-table-column>
  268. </el-table>
  269. <Pagination
  270. v-model:total="total"
  271. v-model:page="queryParams.pageNo"
  272. v-model:limit="queryParams.pageSize"
  273. @pagination="getList"
  274. />
  275. </ContentWrap>
  276. <!-- 表单弹窗 -->
  277. <MaterialForm ref="formRef" @success="getList" />
  278. <!-- 导入弹窗 -->
  279. <ImportDialog ref="importRef" @success="getList" />
  280. <!-- 绑定物资弹窗 -->
  281. <BindDialog ref="bindRef" :cabinet-id="cabinetId" @success="getList" />
  282. </template>
  283. <script lang="ts" setup>
  284. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  285. import { getDateRange} from '@/utils/formatTime'
  286. import { handleTree } from '@/utils/tree'
  287. import * as MaterialApi from '@/api/material/information'
  288. import * as CabinetApi from "@/api/material/lockers/index";
  289. import * as TypeApi from '@/api/material/type'
  290. import * as PropertyApi from '@/api/material/standard/index'
  291. import * as PropertyValueApi from "@/api/material/standard/propertyValue"
  292. import MaterialForm from './MaterialForm.vue'
  293. import ImportDialog from './ImportDialog.vue'
  294. import BindDialog from './BindDialog.vue'
  295. defineOptions({ name: 'MaterialInformation' })
  296. const props = defineProps({
  297. cabinetId: {
  298. type: [String, Number],
  299. default: null
  300. }
  301. })
  302. const message = useMessage() // 消息弹窗
  303. const { t } = useI18n() // 国际化
  304. // 列表数据
  305. const loading = ref(true) // 列表的加载中
  306. const total = ref(0) // 列表的总页数
  307. const materialsList = ref([]) // 列表的数据
  308. const ids = ref([]) // 选中的数据
  309. const single = ref(true) // 非单个禁用
  310. const multiple = ref(true) // 非多个禁用
  311. const visibleSelect = ref(false) // 是否显示选择物资柜
  312. // 查询参数
  313. const queryParams = reactive({
  314. pageNo: 1,
  315. pageSize: 10,
  316. materialsCode: undefined,
  317. materialsName: undefined,
  318. materialsRfid: undefined,
  319. loanState: undefined,
  320. materialsCabinetId: null as string | number | null,
  321. materialsTypeId: undefined,
  322. startExpirationDate: undefined,
  323. endExpirationDate: undefined,
  324. supplier: undefined,
  325. expirationDate: undefined,
  326. recordId: undefined,
  327. propertyId: undefined
  328. })
  329. // 日期选择器配置
  330. const createTime = ref([])
  331. const pickerOptions = {
  332. shortcuts: [
  333. {
  334. text: '最近一周',
  335. onClick(picker) {
  336. const end = new Date()
  337. const start = new Date()
  338. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  339. picker.$emit('pick', [start, end])
  340. }
  341. },
  342. {
  343. text: '最近一个月',
  344. onClick(picker) {
  345. const end = new Date()
  346. const start = new Date()
  347. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  348. picker.$emit('pick', [start, end])
  349. }
  350. },
  351. {
  352. text: '最近三个月',
  353. onClick(picker) {
  354. const end = new Date()
  355. const start = new Date()
  356. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  357. picker.$emit('pick', [start, end])
  358. }
  359. }
  360. ]
  361. }
  362. // 物资柜选项
  363. const cabinets = ref([])
  364. const queryParamsCabinets = reactive({
  365. pageNo: 1,
  366. pageSize: -1
  367. })
  368. // 物资类型选项
  369. const machinerytypeOptions = ref([])
  370. // 物资规格选项
  371. const PropertyList = ref([])
  372. const PropertyValueList = ref([])
  373. // 计算属性
  374. const filteredPropertyValues = computed(() => {
  375. if (!queryParams.propertyId) {
  376. return []
  377. }
  378. return PropertyValueList.value.filter(
  379. (value) => value.propertyId === queryParams.propertyId
  380. )
  381. })
  382. const route=useRoute()
  383. // 初始化
  384. onMounted(async () => {
  385. // 设置初始值
  386. setInitialCabinetId()
  387. await getList()
  388. await getTreeselect()
  389. await materialsCabinets()
  390. })
  391. // 设置初始物资柜ID
  392. const setInitialCabinetId = () => {
  393. if (props.cabinetId||route.query.cabinetId) {
  394. queryParams.materialsCabinetId = Number(props.cabinetId)
  395. queryParams.materialsCabinetId = Number(route.query.cabinetId)
  396. visibleSelect.value = true
  397. } else {
  398. queryParams.materialsCabinetId = 1
  399. }
  400. }
  401. // 查询物资柜
  402. const handleChangeCanbinet=(value)=>{
  403. console.log(value,'value')
  404. queryParams.materialsCabinetId = Number(value)
  405. }
  406. // 监听物资柜数据变化,确保值能正确回显
  407. watch(
  408. () => cabinets.value,
  409. (newCabinets) => {
  410. if (newCabinets && newCabinets.length > 0) {
  411. // 如果当前没有选中值,但有默认值,则设置
  412. if (!queryParams.materialsCabinetId) {
  413. setInitialCabinetId()
  414. }
  415. }
  416. },
  417. { immediate: true }
  418. )
  419. /** 查询物资列表 */
  420. const getList = async () => {
  421. loading.value = true
  422. try {
  423. if (Array.isArray(createTime.value) && createTime.value.length == 2) {
  424. const [startTime, endTime] = getDateRange(createTime.value[0], createTime.value[1])
  425. queryParams.startExpirationDate = startTime
  426. queryParams.endExpirationDate = endTime
  427. }
  428. console.log(queryParams,'queryParams')
  429. const data = await MaterialApi.listMaterials(queryParams)
  430. materialsList.value = data.list
  431. total.value = data.total
  432. } finally {
  433. loading.value = false
  434. }
  435. }
  436. /** 查询物资类型下拉树结构 */
  437. const getTreeselect = async () => {
  438. const data = await TypeApi.listType({ pageNo: 1, pageSize: -1 })
  439. machinerytypeOptions.value = handleTree(
  440. data.list,
  441. 'id',
  442. 'parentId',
  443. 'children'
  444. )
  445. // 获取物资属性名和属性值
  446. const propertyData = await PropertyApi.PropertyPage({ pageSize: -1, pageNo: 1 })
  447. PropertyList.value = propertyData.list
  448. const propertyValueData = await PropertyValueApi.PropertyValuePage({ pageSize: -1, pageNo: 1 })
  449. PropertyValueList.value = propertyValueData.list
  450. }
  451. /** 查询物资柜列表 */
  452. const materialsCabinets = async () => {
  453. const data = await CabinetApi.listMaterialsCabinet(queryParamsCabinets)
  454. if (data?.list) {
  455. cabinets.value = data.list.map((item) => ({
  456. value: item.id,
  457. label: item.cabinetName
  458. }))
  459. cabinets.value.push({ value: 0, label: '空' })
  460. }
  461. }
  462. /** 搜索按钮操作 */
  463. const handleQuery = () => {
  464. queryParams.pageNo = 1
  465. getList()
  466. }
  467. /** 重置按钮操作 */
  468. const resetQuery = () => {
  469. createTime.value = []
  470. queryParams.materialsCode = undefined
  471. queryParams.materialsName = undefined
  472. queryParams.loanState = undefined
  473. if(route.query.cabinetId) {
  474. queryParams.materialsCabinetId = Number(route.query.cabinetId)
  475. }else {
  476. queryParams.materialsCabinetId = undefined
  477. }
  478. queryParams.materialsTypeId = undefined
  479. queryParams.startExpirationDate = undefined
  480. queryParams.endExpirationDate = undefined
  481. queryParams.materialsRfid = undefined
  482. queryParams.supplier = undefined
  483. queryParams.propertyId = undefined
  484. queryParams.recordId = undefined
  485. handleQuery()
  486. }
  487. /** 多选框选中数据 */
  488. const handleSelectionChange = (selection: any[]) => {
  489. ids.value = selection.map((item) => item.id)
  490. single.value = selection.length !== 1
  491. multiple.value = !selection.length
  492. }
  493. /** 新增按钮操作 */
  494. const formRef = ref()
  495. const openForm = (type: string, id?: number) => {
  496. formRef.value.open(type, id)
  497. }
  498. /** 删除按钮操作 */
  499. const handleDelete = async (id?: number) => {
  500. const materialsIds = id || ids.value
  501. try {
  502. await message.delConfirm()
  503. await MaterialApi.deleteMaterials(materialsIds)
  504. message.success(t('common.delSuccess'))
  505. await getList()
  506. } catch {}
  507. }
  508. /** 导入按钮操作 */
  509. const importRef = ref()
  510. const handleImport = () => {
  511. importRef.value.open()
  512. }
  513. /** 绑定物资按钮操作 */
  514. const bindRef = ref()
  515. const handleBind = () => {
  516. bindRef.value.open()
  517. }
  518. /** 属性改变处理 */
  519. const handlePropertyChange = () => {
  520. queryParams.recordId = undefined
  521. }
  522. // /** 日期清空处理 */
  523. // const handleClearTime = (value: any) => {
  524. // if (value == null) {
  525. // queryParams.startExpirationDate = undefined
  526. // queryParams.endExpirationDate = undefined
  527. // }
  528. // }
  529. </script>