index.vue 8.0 KB

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