Purchase.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <script setup lang="ts">
  2. import {defineAsyncComponent, nextTick, onMounted, reactive, ref} from 'vue'
  3. import {ElMessage, ElMessageBox} from 'element-plus'
  4. import {Delete, Edit, Finished, View} from '@element-plus/icons-vue'
  5. import TableBase from '@/components/TableBase/index.vue'
  6. import {useTablePublic} from '@/hooks/useTablePublic'
  7. import {ColumnProps} from '@/components/TableBase/interface/index'
  8. import {
  9. Purchase_Apply_User_List,
  10. Purchase_Del,
  11. Purchase_Excel,
  12. Purchase_List,
  13. Purchase_Stat_Excel
  14. } from '@/api/purchase/index'
  15. import { deptOptions } from '@/hooks/useTablePublic'
  16. import {stockInexcel, Storehouse_VerifyContract_Recover_User_List} from "@/api/storehouse";
  17. interface UserInfoIn {
  18. T_name: string
  19. T_type_name: string
  20. T_text: string
  21. T_uuid: string
  22. T_dept_name: string
  23. T_post_name: string
  24. }
  25. const columns: ColumnProps[] = [
  26. {type: 'index', label: '序号', width: 80},
  27. {prop: 'T_date', label: '申请时间'},
  28. {prop: 'T_dept', label: '申请部门'},
  29. {prop: 'T_uuid_name', label: '申请人'},
  30. {prop: 'T_State', label: '状态', name: 'T_State'},
  31. {prop: 'T_submit_name', label: '提交人'},
  32. {prop: 'T_approver_name', label: '审批人'},
  33. {prop: 'T_remark', label: '备注', width: 125},
  34. {prop: 'operation', label: '操作', width: 260, fixed: 'right'}
  35. ]
  36. // 搜索
  37. const options = reactive([
  38. {name: '待采购', id: 1},
  39. {name: '已采购', id: 2},
  40. ])
  41. const TableRef = ref<InstanceType<typeof TableBase> | null>(null)
  42. const {globalStore, updateOnTableList} = useTablePublic()
  43. const openPurchaseDrawer = (type: string, row?: any) => purchaseFormRef.value?.purchaseFromOpen(type, row)
  44. const purchaseFormRef = ref<InstanceType<typeof PurchaseForm> | null>(null)
  45. const PurchaseForm = defineAsyncComponent(() => import(/*webpackChunkName: 'PurchaseForm'*/ './PurchaseForm.vue'))
  46. const T_date = ref<string[]>([])
  47. const initParam = reactive({
  48. User_tokey: globalStore.GET_User_tokey,
  49. T_uuid: '',
  50. T_dept: '',
  51. T_state: '',
  52. T_end_date: '',
  53. T_start_date: ''
  54. })
  55. const searchHandle = () => {
  56. initParam.T_end_date = T_date.value ? T_date.value[1] : ''
  57. initParam.T_start_date = T_date.value ? T_date.value[0] : ''
  58. TableRef.value?.searchTable()
  59. }
  60. const DeletePurchase = (Id: number) => {
  61. ElMessageBox.confirm('您确定要删除采购申请吗?', '警告', {
  62. confirmButtonText: '确定',
  63. cancelButtonText: '取消',
  64. type: 'warning'
  65. })
  66. .then(async () => {
  67. const res: any = await Purchase_Del({User_tokey: globalStore.GET_User_tokey, T_id: Id})
  68. if (res.Code === 200) {
  69. ElMessage.success('删除成功!')
  70. nextTick(() => updateOnTableList(TableRef.value))
  71. }
  72. })
  73. .catch(() => {
  74. ElMessage.warning('取消成功!')
  75. })
  76. }
  77. const exportExcel = async (Id: number) => {
  78. const result:any = await Purchase_Excel({
  79. User_tokey: globalStore.GET_User_tokey,
  80. T_id: Id,
  81. })
  82. if (result.Code === 200) {
  83. window.open(result.Data)
  84. }
  85. }
  86. const exportStatExcel = async () => {
  87. const result:any = await Purchase_Stat_Excel({
  88. User_tokey: globalStore.GET_User_tokey,
  89. T_uuid: initParam.T_uuid,
  90. T_dept: initParam.T_dept,
  91. T_state: initParam.T_state,
  92. T_end_date: initParam.T_end_date,
  93. T_start_date: initParam.T_start_date
  94. })
  95. if (result.Code === 200) {
  96. window.open(result.Data)
  97. }
  98. }
  99. interface ListItem {
  100. value: string
  101. label: string
  102. }
  103. const loading = ref(false)
  104. const list = ref<ListItem[]>([])
  105. const optionsData = ref<ListItem[]>([])
  106. const remoteMethod = async (query: string) => {
  107. if (query) {
  108. loading.value = true
  109. setTimeout(() => {
  110. loading.value = false
  111. optionsData.value = list.value.filter((item: any) => {
  112. return item.label.toLowerCase().includes(query.toLowerCase())
  113. })
  114. }, 200)
  115. } else {
  116. optionsData.value = list.value
  117. }
  118. }
  119. const click2 = async () => { optionsData.value = list.value }
  120. onMounted(async () => {
  121. const result: any = await Purchase_Apply_User_List({})
  122. let arr = []
  123. if (result?.Data !== null) {
  124. arr = result.Data.Data
  125. }
  126. list.value = arr.map((item: any) => {
  127. return { value: item.T_uuid, label: item.T_name }
  128. })
  129. })
  130. </script>
  131. <template>
  132. <div class="purchase">
  133. <TableBase
  134. ref="TableRef"
  135. :columns="columns"
  136. :requestApi="Purchase_List"
  137. :initParam="initParam"
  138. >
  139. <template #table-header>
  140. <div class="input-suffix">
  141. <el-row :gutter="20" style="margin-bottom: 0">
  142. <el-col :xl="6" :lg="6" :md="6" style="display: flex">
  143. <span class="inline-flex items-center">申请日期:</span>
  144. <el-date-picker
  145. v-model="T_date"
  146. type="daterange"
  147. range-separator="~"
  148. start-placeholder="开始时间"
  149. end-placeholder="结束时间"
  150. format="YYYY-MM-DD"
  151. value-format="YYYY-MM-DD"
  152. />
  153. </el-col>
  154. <el-col :xl="6" :md="6">
  155. <span class="inline-flex items-center">部门:</span>
  156. <el-select v-model="initParam.T_dept" class="w-50 m-2" clearable placeholder="请选择部门~">
  157. <el-option v-for="item in deptOptions" :key="item.id" :label="item.name" :value="item.id"/>
  158. </el-select>
  159. </el-col>
  160. <el-col :xl="6" :lg="6" :md="6" class="d-flex">
  161. <span class="inline-flex items-center">申请人:</span>
  162. <el-select v-model="initParam.T_uuid" filterable remote reserve-keyword placeholder="申请人"
  163. :remote-method="remoteMethod" :loading="loading" @click="click2" clearable style="width: 150px;">
  164. <el-option v-for="item in optionsData" :key="item.value" :label="item.label" :value="item.value" />
  165. </el-select>
  166. </el-col>
  167. <el-col :xl="6" :md="6">
  168. <span class="inline-flex items-center">状态:</span>
  169. <el-select v-model="initParam.T_state" class="w-50 m-2" clearable placeholder="请选择状态~">
  170. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id"/>
  171. </el-select>
  172. <el-button type="primary" @click="searchHandle">搜索</el-button>
  173. <el-button type="success" @click="exportStatExcel">导出</el-button>
  174. </el-col>
  175. </el-row>
  176. </div>
  177. </template>
  178. <template #T_State="{ row }">
  179. <el-tag v-if="row.T_State === 1" type="primary" effect="dark">待采购</el-tag>
  180. <el-tag v-else-if="row.T_State === 2" type="success" effect="dark">已采购</el-tag>
  181. <el-tag v-else-if="row.T_State === 3" type="warning" effect="dark">待审批</el-tag>
  182. <el-tag v-else type="danger" effect="dark">未通过</el-tag>
  183. </template>
  184. <template #right="{ row }">
  185. <el-button link type="success" size="small" :icon="View" @click="openPurchaseDrawer('view', row)">详情
  186. </el-button>
  187. <el-button
  188. link
  189. type="success"
  190. size="small"
  191. :icon="Finished"
  192. @click="exportExcel(row.Id)"
  193. >导出
  194. </el-button>
  195. <el-button
  196. link
  197. type="primary"
  198. size="small"
  199. :icon="Edit"
  200. @click="openPurchaseDrawer('edit', row)"
  201. >编辑
  202. </el-button>
  203. <el-button
  204. link
  205. type="danger"
  206. size="small"
  207. :icon="Delete"
  208. :disabled="[2].includes(row.T_State)"
  209. @click="DeletePurchase(row.Id)"
  210. >删除
  211. </el-button
  212. >
  213. </template>
  214. </TableBase>
  215. <PurchaseForm ref="purchaseFormRef" purchaseName="purchase" @onTableList="updateOnTableList(TableRef)"/>
  216. </div>
  217. </template>
  218. <style scoped lang="scss">
  219. @import '@/styles/var.scss';
  220. .purchase {
  221. height: 100%;
  222. display: flex;
  223. overflow: hidden;
  224. @include f-direction;
  225. :deep(.table-header),
  226. :deep(.card) {
  227. margin: 0;
  228. border-radius: 8px;
  229. }
  230. :deep(.el-table .cell) {
  231. white-space: normal !important;
  232. }
  233. .input-suffix {
  234. width: 100%;
  235. .inline-flex {
  236. white-space: nowrap;
  237. }
  238. .btn {
  239. display: flex;
  240. justify-content: end;
  241. }
  242. .w-50 {
  243. width: 12.5rem;
  244. }
  245. }
  246. }
  247. </style>