list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <a-card size="small" :bordered="false" class="expenseManagementList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="费用单号">
  10. <a-input id="expenseManagementList-accountExpensesNo" v-model.trim="queryParam.accountExpensesNo" allowClear placeholder="请输入费用单号"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="创建时间">
  15. <rangeDate ref="rangeDate" @change="dateChange" />
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="费用类型">
  20. <a-cascader
  21. @change="changeCostType"
  22. change-on-select
  23. v-model="costType"
  24. expand-trigger="hover"
  25. :options="costTypeList"
  26. :fieldNames="{ label: 'name', value: 'costTypeSn', children: 'children' }"
  27. id="productInfoList-costType"
  28. placeholder="请选择费用类型"
  29. allowClear />
  30. </a-form-item>
  31. </a-col>
  32. <template v-if="advanced">
  33. <a-col :md="6" :sm="24">
  34. <a-form-item label="单据状态">
  35. <v-select
  36. v-model="queryParam.state"
  37. ref="state"
  38. id="expenseManagementList-state"
  39. code="EXPENSE_AUDIT_TYPE"
  40. placeholder="请选择单据状态"
  41. allowClear></v-select>
  42. </a-form-item>
  43. </a-col>
  44. </template>
  45. <a-col :md="6" :sm="24">
  46. <span class="table-page-search-submitButtons">
  47. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="expenseManagementList-refresh">查询</a-button>
  48. <a-button style="margin-left: 8px" @click="resetSearchForm()" :disabled="disabled" id="expenseManagementList-reset">重置</a-button>
  49. <a @click="advanced=!advanced" style="margin-left: 8px">
  50. {{ advanced ? '收起' : '展开' }}
  51. <a-icon :type="advanced ? 'up' : 'down'"/>
  52. </a>
  53. </span>
  54. </a-col>
  55. </a-row>
  56. </a-form>
  57. </div>
  58. <!-- 操作按钮 -->
  59. <div class="table-operator">
  60. <a-button v-if="$hasPermissions('B_expenseNew')" id="expenseManagementList-add" type="primary" class="button-error" @click="handleEdit()">新增</a-button>
  61. </div>
  62. <!-- alert -->
  63. <a-alert type="info" style="margin-bottom:10px">
  64. <div slot="message">
  65. 共 <strong>{{ totalData&&(totalData.count || totalData.count==0) ? totalData.count : '--' }}</strong> 条记录,
  66. 金额共计 <strong>{{ totalData&&(totalData.totalAmount || totalData.totalAmount==0) ? '¥'+totalData.totalAmount : '--' }}</strong>
  67. </div>
  68. </a-alert>
  69. <!-- 列表 -->
  70. <s-table
  71. class="sTable fixPagination"
  72. ref="table"
  73. :style="{ height: tableHeight+84.5+'px' }"
  74. size="small"
  75. :rowKey="(record) => record.id"
  76. :columns="columns"
  77. :data="loadData"
  78. :scroll="{ y: tableHeight }"
  79. :defaultLoadData="false"
  80. bordered>
  81. <!-- 费用类别 -->
  82. <template slot="expensesType" slot-scope="text, record">
  83. {{ record.expensesTypeName1 }} <span v-if="record.expensesTypeName2">>{{ record.expensesTypeName2 }}</span> <span v-if="record.expensesTypeName3">>{{ record.expensesTypeName3 }}</span>
  84. </template>
  85. <!-- 状态 -->
  86. <template slot="accountExpensesNo" slot-scope="text, record">
  87. <span :class="$hasPermissions('B_expenseDetail')?'active':'common'" @click="handleDetail(record)">{{ text }}</span>
  88. </template>
  89. <!-- 操作 -->
  90. <template slot="action" slot-scope="text, record">
  91. <a-button
  92. size="small"
  93. type="link"
  94. v-if="record.state == 'WAIT_AUDIT' && $hasPermissions('B_expenseAudit')"
  95. class="button-warning"
  96. @click="handleAudit(record)"
  97. id="expenseManagement-audit-btn">审核</a-button>
  98. <a-button
  99. size="small"
  100. type="link"
  101. v-if="record.state == 'WAIT_AUDIT' && $hasPermissions('B_expenseEdit')"
  102. class="button-info"
  103. @click="handleEdit(record)"
  104. id="expenseManagement-edit-btn">编辑</a-button>
  105. <a-button
  106. size="small"
  107. type="link"
  108. v-if="record.state == 'WAIT_AUDIT' && $hasPermissions('B_expenseDel')"
  109. class="button-error"
  110. @click="handleDel(record)"
  111. id="expenseManagement-del-btn">删除</a-button>
  112. <span v-if="record.state != 'WAIT_AUDIT'||( !$hasPermissions('B_expenseAudit')&& !$hasPermissions('B_expenseEdit') && !$hasPermissions('B_expenseDel'))">--</span>
  113. </template>
  114. </s-table>
  115. </a-spin>
  116. <!-- 详情 -->
  117. <expense-management-detail-modal :openModal="openModal" :itemId="itemId" @close="closeDetail" />
  118. </a-card>
  119. </template>
  120. <script>
  121. import { commonMixin } from '@/utils/mixin'
  122. import { STable, VSelect } from '@/components'
  123. import rangeDate from '@/views/common/rangeDate.vue'
  124. import { settleExpenseQuery, delExpense, settleExpenseQuerySum, auditExpense } from '@/api/settleExpense'
  125. import { costTypeAllQuery } from '@/api/costType'
  126. import expenseManagementDetailModal from './detailModal.vue'
  127. export default {
  128. name: 'ExpenseManagementList',
  129. components: { STable, VSelect, expenseManagementDetailModal, rangeDate },
  130. mixins: [commonMixin],
  131. data () {
  132. return {
  133. spinning: false,
  134. tableHeight: 0,
  135. disabled: false, // 查询、重置按钮是否可操作
  136. advanced: true, // 高级搜索 展开/关闭
  137. costTypeList: [], // 费用类型
  138. costType: [],
  139. // 查询参数
  140. queryParam: {
  141. beginDate: '',
  142. endDate: '',
  143. accountExpensesNo: '',
  144. expensesTypeSn1: '',
  145. expensesTypeSn2: '',
  146. expensesTypeSn3: '',
  147. state: '',
  148. settleState: ''
  149. },
  150. // 汇总
  151. totalData: {
  152. count: 0,
  153. totalAmount: 0
  154. },
  155. // 表头
  156. columns: [
  157. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  158. { title: '费用单号', dataIndex: 'accountExpensesNo', width: '20%', align: 'center', scopedSlots: { customRender: 'accountExpensesNo' } },
  159. { title: '创建时间', dataIndex: 'createDate', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  160. { title: '费用类型', scopedSlots: { customRender: 'expensesType' }, width: '20%', align: 'center' },
  161. { title: '金额', dataIndex: 'settleAmount', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? ('¥' + text) : '--') } },
  162. { title: '单据状态', dataIndex: 'stateDictValue', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  163. { title: '操作', scopedSlots: { customRender: 'action' }, width: '15%', align: 'center' }
  164. ],
  165. // 加载数据方法 必须为 Promise 对象
  166. loadData: parameter => {
  167. this.disabled = true
  168. this.spinning = true
  169. return settleExpenseQuery(Object.assign(parameter, this.queryParam)).then(res => {
  170. let data
  171. if (res.status == 200) {
  172. data = res.data
  173. const no = (data.pageNo - 1) * data.pageSize
  174. for (var i = 0; i < data.list.length; i++) {
  175. data.list[i].no = no + i + 1
  176. }
  177. this.disabled = false
  178. // 费用类型
  179. if (this.costTypeList.length == 0) {
  180. this.getCostTypeList()
  181. }
  182. // 汇总
  183. this.totalData.count = data.count
  184. this.settleExpenseQuerySum(Object.assign(parameter, this.queryParam))
  185. }
  186. this.spinning = false
  187. return data
  188. })
  189. },
  190. openModal: false, // 查看详情 弹框
  191. itemId: '' // 当前id
  192. }
  193. },
  194. methods: {
  195. // 时间 change
  196. dateChange (date) {
  197. this.queryParam.beginDate = date[0]
  198. this.queryParam.endDate = date[1]
  199. },
  200. // 递归函数
  201. recursionFun (data) {
  202. if (data) {
  203. data.map((item, index) => {
  204. if (item.children && item.children.length == 0) {
  205. delete item.children
  206. } else {
  207. this.recursionFun(item.children)
  208. }
  209. })
  210. }
  211. },
  212. // 获取费用类型数据
  213. getCostTypeList () {
  214. costTypeAllQuery({}).then(res => {
  215. // 递归去除空children
  216. this.recursionFun(res.data)
  217. this.costTypeList = res.data
  218. })
  219. },
  220. closeDetail () {
  221. this.openModal = false
  222. this.itemId = null
  223. },
  224. // 费用类型 change
  225. changeCostType (val, opt) {
  226. this.queryParam.expensesTypeSn1 = val[0] ? val[0] : ''
  227. this.queryParam.expensesTypeSn2 = val[1] ? val[1] : ''
  228. this.queryParam.expensesTypeSn3 = val[2] ? val[2] : ''
  229. },
  230. // 新增/编辑
  231. handleEdit (row) {
  232. if (row) {
  233. this.$router.push({ name: 'expenseManagementEdit', params: { id: row.id } })
  234. } else {
  235. this.$router.push({ name: 'expenseManagementAdd' })
  236. }
  237. },
  238. // 详情
  239. handleDetail (row) {
  240. if (this.$hasPermissions('B_expenseDetail')) {
  241. this.itemId = row.id
  242. this.openModal = true
  243. }
  244. },
  245. // 审核
  246. handleAudit (row) {
  247. const _this = this
  248. this.$confirm({
  249. title: '提示',
  250. content: '确定要审核吗?',
  251. centered: true,
  252. onOk () {
  253. _this.spinning = true
  254. auditExpense({
  255. id: row.id
  256. }).then(res => {
  257. if (res.status == 200) {
  258. _this.$message.success(res.message)
  259. _this.$refs.table.refresh()
  260. _this.spinning = false
  261. } else {
  262. _this.spinning = false
  263. }
  264. })
  265. }
  266. })
  267. },
  268. // 删除
  269. handleDel (row) {
  270. const _this = this
  271. _this.itemId = row.id
  272. _this.$confirm({
  273. title: '提示',
  274. content: '删除后原数据不可恢复,是否删除?',
  275. centered: true,
  276. onOk () {
  277. _this.spinning = true
  278. delExpense({ id: _this.itemId }).then(res => {
  279. if (res.status == 200) {
  280. _this.$message.success(res.message)
  281. _this.$refs.table.refresh()
  282. _this.spinning = false
  283. } else {
  284. _this.spinning = false
  285. }
  286. })
  287. }
  288. })
  289. },
  290. // 汇总
  291. settleExpenseQuerySum (params) {
  292. settleExpenseQuerySum(params).then(res => {
  293. this.totalData.totalAmount = res.data && res.data.settleAmount || 0
  294. })
  295. },
  296. // 重置
  297. resetSearchForm () {
  298. this.$refs.rangeDate.resetDate()
  299. this.queryParam.beginDate = ''
  300. this.queryParam.endDate = ''
  301. this.queryParam.accountExpensesNo = ''
  302. this.queryParam.expensesTypeSn1 = ''
  303. this.queryParam.expensesTypeSn2 = ''
  304. this.queryParam.expensesTypeSn3 = ''
  305. this.queryParam.state = ''
  306. this.queryParam.settleState = ''
  307. this.queryParam.beginDate = ''
  308. this.queryParam.endDate = ''
  309. this.costType = []
  310. this.$refs.table.refresh(true)
  311. },
  312. pageInit () {
  313. const _this = this
  314. this.$nextTick(() => { // 页面渲染完成后的回调
  315. _this.setTableH()
  316. })
  317. },
  318. setTableH () {
  319. const tableSearchH = this.$refs.tableSearch.offsetHeight
  320. this.tableHeight = window.innerHeight - tableSearchH - 270
  321. }
  322. },
  323. watch: {
  324. advanced (newValue, oldValue) {
  325. const _this = this
  326. this.$nextTick(() => { // 页面渲染完成后的回调
  327. _this.setTableH()
  328. })
  329. },
  330. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  331. this.setTableH()
  332. }
  333. },
  334. mounted () {
  335. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  336. this.pageInit()
  337. this.resetSearchForm()
  338. }
  339. },
  340. activated () {
  341. // 如果是新页签打开,则重置当前页面
  342. if (this.$store.state.app.isNewTab) {
  343. this.pageInit()
  344. this.resetSearchForm()
  345. }
  346. // 仅刷新列表,不重置页面
  347. if (this.$store.state.app.updateList) {
  348. this.pageInit()
  349. this.$refs.table.refresh()
  350. }
  351. },
  352. beforeRouteEnter (to, from, next) {
  353. next(vm => {})
  354. }
  355. }
  356. </script>
  357. <style lang="less">
  358. .expenseManagementList-wrap{
  359. .sTable{
  360. margin-top: 10px;
  361. }
  362. .active{
  363. color: #ed1c24;
  364. cursor: pointer;
  365. }
  366. .common{
  367. color: rgba(0, 0, 0);
  368. }
  369. }
  370. </style>