index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <HcCard>
  3. <template #header>
  4. <div class="w-36">
  5. <el-select v-model="searchForm.purType" block clearable placeholder="采购类型" size="large">
  6. <el-option v-for="item in purTypeData" :label="item.dictName" :value="item.dictValue" />
  7. </el-select>
  8. </div>
  9. <div class="w-72 ml-2">
  10. <!-- <el-select v-model="searchForm.useOrgName" block clearable placeholder="使用单位" size="large">
  11. <el-option label="暂无接口1" value="1"/>
  12. <el-option label="暂无接口2" value="2"/>
  13. </el-select> -->
  14. <el-select v-model="searchForm.useOrgName" block clearable placeholder="采购类型" size="large">
  15. <el-option v-for="item in useOrgNameData" :label="item.dictName" :value="item.dictValue" />
  16. </el-select>
  17. </div>
  18. <div class="ml-4">
  19. <el-button type="primary" size="large" @click="searchClick">
  20. <HcIcon name="search-2" />
  21. <span>搜索</span>
  22. </el-button>
  23. </div>
  24. <div class="ml-2">
  25. <el-button size="large" @click="resetClick">
  26. <HcIcon name="close-circle" />
  27. <span>重置</span>
  28. </el-button>
  29. </div>
  30. </template>
  31. <template #extra>
  32. <el-button size="large" type="warning" hc-btn @click="draftsClick">
  33. <HcIcon name="draft" />
  34. <span>草稿箱{{ draftNum > 0 ? `(${draftNum})` : '' }}</span>
  35. </el-button>
  36. <el-button size="large" type="primary" hc-btn @click="addRowClick">
  37. <HcIcon name="add" />
  38. <span>新增采购申请</span>
  39. </el-button>
  40. </template>
  41. <HcTable :column="tableColumn" :datas="tableData" :loading="tableLoading">
  42. <template #action="{ row, index }">
  43. <el-popconfirm title="是否确认撤销?" hide-icon @confirm="rowCancel(row)">
  44. <template #reference>
  45. <el-button
  46. size="small" type="primary"
  47. :disabled="row.status !== 1"
  48. :loading="row.isCancelLoading"
  49. >
  50. 撤销
  51. </el-button>
  52. </template>
  53. </el-popconfirm>
  54. </template>
  55. </HcTable>
  56. <template #action>
  57. <HcPages :pages="searchForm" @change="pageChange" />
  58. </template>
  59. <!-- 草稿箱 -->
  60. <HcDialog
  61. is-to-body is-table bg-color="#ffffff" widths="62rem" :footer="false" :show="draftsModal"
  62. :title="draftNum > 0 ? `草稿箱(${draftNum})` : '草稿箱'" @close="draftsCloseClick"
  63. >
  64. <el-alert title="3个月内未更新的草稿将被自动删除" type="warning" show-icon />
  65. <div style="position: relative;height: calc(100% - 44px);">
  66. <HcTable :is-index="false" :column="tableDraftsColumn" :datas="tableDraftsData">
  67. <template #action="{ row, index }">
  68. <el-button size="small" type="primary" @click="editDraftClick(row)">
  69. 继续编辑
  70. </el-button>
  71. <el-button size="small" type="danger" @click="delDraftClick(row)">
  72. 删除
  73. </el-button>
  74. </template>
  75. </HcTable>
  76. </div>
  77. </HcDialog>
  78. </HcCard>
  79. </template>
  80. <script setup>
  81. import { onActivated, ref } from 'vue'
  82. import { useRouter } from 'vue-router'
  83. import { getDictInfo } from '~api/other'
  84. import mainApi from '~api/expense/purchaseRequest'
  85. import { getArrValue } from 'js-fast-way'
  86. import { delMessage } from '~uti/tools'
  87. const router = useRouter()
  88. onActivated(() => {
  89. getApi()
  90. })
  91. const getApi = () => {
  92. getPurType()
  93. getUseOrgNameData()
  94. getTableData()
  95. getDraftNum()
  96. }
  97. //采购类型字典
  98. const purTypeData = ref([])
  99. const getPurType = async () => {
  100. const { error, code, data } = await getDictInfo('purchase_type')
  101. //判断状态
  102. if (!error && code === 200) {
  103. purTypeData.value = getArrValue(data)
  104. } else {
  105. purTypeData.value = []
  106. }
  107. }
  108. //采购使用单位
  109. const useOrgNameData = ref([])
  110. const getUseOrgNameData = async () => {
  111. const { error, code, data } = await mainApi.getUseOrgNameList()
  112. //判断状态
  113. if (!error && code === 200) {
  114. useOrgNameData.value = getArrValue(data)
  115. } else {
  116. useOrgNameData.value = []
  117. }
  118. }
  119. //搜索表单
  120. const searchForm = ref({ purType: null, useOrgName: null, current: 1, size: 20, total: 0 })
  121. //搜索
  122. const searchClick = () => {
  123. searchForm.value.current = 1
  124. getTableData()
  125. }
  126. //重置搜索表单
  127. const resetClick = () => {
  128. searchForm.value = { current: 1, size: 20, total: 0 }
  129. }
  130. //分页被点击
  131. const pageChange = ({ current, size }) => {
  132. searchForm.value.current = current
  133. searchForm.value.size = size
  134. getTableData()
  135. }
  136. //获取数据
  137. const tableLoading = ref(false)
  138. const tableColumn = [
  139. { key: 'purDesc', name: '申请事由', minWidth: '200' },
  140. { key: 'purTypeName', name: '采购类型', width: '200', align: 'center' },
  141. { key: 'useOrgName', name: '使用单位', minWidth: '200' },
  142. { key: 'expectedDeliveryDate', name: '期望交付日期', width: '160', align: 'center' },
  143. { key: 'purPrice', name: '总采购资金', width: '160', align: 'center' },
  144. { key: 'approvalResultName', name: '审批结果', width: '140', align: 'center' },
  145. { key: 'approvalStatusName', name: '审批状态', width: '160', align: 'center' },
  146. { key: 'createName', name: '创建人', width: '140', align: 'center' },
  147. { key: 'createTime', name: '创建时间', width: '160', align: 'center' },
  148. { key: 'action', name: '操作', width: '90', align: 'center', fixed: 'right' },
  149. ]
  150. const tableData = ref([])
  151. const getTableData = async () => {
  152. tableLoading.value = true
  153. const { error, code, data } = await mainApi.page(searchForm.value)
  154. //判断状态
  155. tableLoading.value = false
  156. if (!error && code === 200) {
  157. tableData.value = getArrValue(data['records'])
  158. searchForm.value.total = data['total'] || 0
  159. } else {
  160. tableData.value = []
  161. searchForm.value.total = 0
  162. }
  163. }
  164. //撤销
  165. const rowCancel = async (row) => {
  166. row.isCancelLoading = true
  167. const { error, code, msg } = await mainApi.cancel({ id: row.id })
  168. //判断状态
  169. row.isCancelLoading = false
  170. if (!error && code === 200) {
  171. window.$message?.success(msg)
  172. getTableData().then()
  173. } else {
  174. window.$message?.error(msg)
  175. }
  176. }
  177. //新增
  178. const addRowClick = () => {
  179. router.push({
  180. name: 'expense-purchaseRequest-record',
  181. })
  182. }
  183. //草稿箱
  184. const draftsModal = ref(false)
  185. const draftsClick = () => {
  186. draftsModal.value = true
  187. }
  188. const draftsCloseClick = () => {
  189. draftsModal.value = false
  190. }
  191. //草稿箱数据
  192. const draftNum = ref(0)
  193. const tableDraftsColumn = [
  194. { key: 'title', name: '标题' },
  195. { key: 'updateTime', name: '更新时间', width: '200' },
  196. { key: 'action', name: '操作', width: '170', align: 'center' },
  197. ]
  198. const tableDraftsData = ref([])
  199. //获取草稿数量
  200. const getDraftNum = async () => {
  201. const { error, code, data } = await mainApi.draft()
  202. //判断状态
  203. if (!error && code === 200) {
  204. const res = getArrValue(data)
  205. tableDraftsData.value = res
  206. draftNum.value = res.length
  207. } else {
  208. tableDraftsData.value = []
  209. draftNum.value = 0
  210. }
  211. }
  212. //继续编辑
  213. const editDraftClick = ({ emdraftIds }) => {
  214. draftsModal.value = false
  215. router.push({
  216. name: 'expense-purchaseRequest-record',
  217. query: { id: emdraftIds },
  218. })
  219. }
  220. //删除草稿
  221. const delDraftClick = ({ groupId }) => {
  222. delMessage(async () => {
  223. const { error, code, msg } = await mainApi.remove({ groupId })
  224. //判断状态
  225. if (!error && code === 200) {
  226. window.$message?.success(msg)
  227. getDraftNum().then()
  228. } else {
  229. window.$message?.error(msg)
  230. }
  231. })
  232. }
  233. </script>