You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

490 lines
16 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <template>
  2. <div class="mod-config">
  3. <el-form :inline="true" label-position="top" :model="searchData">
  4. <!-- CompanyID 使用系统 customer:复用通用 Customer 权限选择器,允许不选,不选时查询所有客户财年数据 -->
  5. <com-po-order-customer-picker
  6. embedded
  7. allow-empty
  8. :site="$store.state.user.site"
  9. v-model="searchData.companyId"
  10. @change="onCustomerChange" />
  11. <el-form-item label="财年">
  12. <el-input v-model="searchData.years" clearable style="width: 120px"></el-input>
  13. </el-form-item>
  14. <el-form-item label=" ">
  15. <el-button v-if="authSearch" type="primary" @click="getDataList()">查询</el-button>
  16. <el-button v-if="authSave" type="primary" @click="addModal()">新增</el-button>
  17. <download-excel
  18. :fields="fields()"
  19. :data="exportData"
  20. type="xls"
  21. :name="exportName"
  22. :header="exportHeader"
  23. :footer="exportFooter"
  24. :fetch="createExportData"
  25. :before-generate="startDownload"
  26. :before-finish="finishDownload"
  27. worksheet="财年"
  28. class="el-button el-button--primary el-button--medium">
  29. {{ "导出" }}
  30. </download-excel>
  31. </el-form-item>
  32. </el-form>
  33. <el-table
  34. :height="height"
  35. :data="dataList"
  36. border
  37. v-loading="dataListLoading"
  38. style="width: 100%;">
  39. <el-table-column
  40. v-for="(item,index) in columnList" :key="index"
  41. :sortable="item.columnSortable"
  42. :prop="item.columnProp"
  43. :header-align="item.headerAlign"
  44. :show-overflow-tooltip="item.showOverflowTooltip"
  45. :align="item.align"
  46. :fixed="item.fixed == '' ? false : item.fixed"
  47. :min-width="item.columnWidth"
  48. :label="item.columnLabel">
  49. <template slot-scope="scope">
  50. <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column
  54. fixed="right"
  55. header-align="center"
  56. align="center"
  57. width="120"
  58. label="操作">
  59. <template slot-scope="scope">
  60. <el-link style="cursor: pointer" v-if="authUpdate" @click="updateModal(scope.row)">编辑 |</el-link>
  61. <el-link style="cursor: pointer" v-if="authDelete" @click="deleteRow(scope.row)">删除</el-link>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <!-- 分页栏 -->
  66. <el-pagination
  67. @size-change="sizeChangeHandle"
  68. @current-change="currentChangeHandle"
  69. :current-page="pageIndex"
  70. :page-sizes="[20, 50, 100, 200, 500]"
  71. :page-size="pageSize"
  72. :total="totalPage"
  73. layout="total, sizes, prev, pager, next, jumper">
  74. </el-pagination>
  75. <el-dialog title="财年管理" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="560px" class="period-modal">
  76. <el-form label-position="top" :model="modalData" style="margin-left: 7px; margin-right: 7px;" ref="modalForm">
  77. <el-row :gutter="24">
  78. <!-- Customer 即 CompanyID,新增必选;编辑时作为主键锁定不可改。财年/月份/是否关账不展示,保存时自动计算 -->
  79. <el-col :span="12">
  80. <com-po-order-customer-picker
  81. embedded
  82. :site="$store.state.user.site"
  83. :disabled="modalDisableFlag"
  84. v-model="modalData.companyId" />
  85. </el-col>
  86. </el-row>
  87. <el-row :gutter="24">
  88. <el-col :span="12">
  89. <el-form-item label="开始日期">
  90. <el-date-picker
  91. v-model="modalData.beginDate"
  92. type="date"
  93. value-format="yyyy-MM-dd"
  94. format="yyyy-MM-dd"
  95. style="width: 100%"
  96. placeholder="选择日期"
  97. @change="onBeginDateChange">
  98. </el-date-picker>
  99. </el-form-item>
  100. </el-col>
  101. <el-col :span="12">
  102. <el-form-item label="结束日期">
  103. <el-date-picker
  104. v-model="modalData.endDate"
  105. type="date"
  106. value-format="yyyy-MM-dd"
  107. format="yyyy-MM-dd"
  108. style="width: 100%"
  109. placeholder="选择日期">
  110. </el-date-picker>
  111. </el-form-item>
  112. </el-col>
  113. </el-row>
  114. </el-form>
  115. <el-footer style="height:40px;margin-top: 20px;text-align:center">
  116. <el-button type="primary" @click="saveData()">保存</el-button>
  117. <el-button type="primary" @click="modalFlag = false">关闭</el-button>
  118. </el-footer>
  119. </el-dialog>
  120. </div>
  121. </template>
  122. <script>
  123. import {
  124. getInventoryPeriodPage,
  125. saveInventoryPeriod,
  126. updateInventoryPeriod,
  127. deleteInventoryPeriod
  128. } from '@/api/baseInformation/srmInventoryPeriod.js'
  129. import ComPoOrderCustomerPicker from '@/views/modules/order/com_poOrder_CustomerPicker.vue'
  130. import dayjs from 'dayjs'
  131. export default {
  132. data () {
  133. return {
  134. // 导出 start
  135. exportData: [],
  136. exportName: '财年' + dayjs().format('YYYYMMDDHHmmss'),
  137. exportHeader: ['财年管理'],
  138. exportFooter: [],
  139. exportList: [],
  140. // 导出 end
  141. searchData: {
  142. companyId: '',
  143. years: ''
  144. },
  145. height: 200,
  146. pageIndex: 1,
  147. pageSize: 20,
  148. totalPage: 0,
  149. dataList: [],
  150. dataListLoading: false,
  151. modalFlag: false,
  152. modalDisableFlag: false,
  153. modalData: {
  154. companyId: '',
  155. years: '',
  156. months: '',
  157. beginDate: '',
  158. endDate: '',
  159. closed: 'N',
  160. flag: '1'
  161. },
  162. columnList: [
  163. {
  164. userId: this.$store.state.user.name,
  165. functionId: 'srmInventoryPeriod',
  166. serialNumber: 'srmInventoryPeriodTableYears',
  167. tableId: 'srmInventoryPeriodTable',
  168. tableName: '财年表',
  169. columnProp: 'years',
  170. headerAlign: 'center',
  171. align: 'center',
  172. columnLabel: '财年',
  173. columnHidden: false,
  174. columnImage: false,
  175. columnSortable: false,
  176. sortLv: 0,
  177. status: true,
  178. fixed: '',
  179. columnWidth: 100
  180. },
  181. {
  182. userId: this.$store.state.user.name,
  183. functionId: 'srmInventoryPeriod',
  184. serialNumber: 'srmInventoryPeriodTableCompanyId',
  185. tableId: 'srmInventoryPeriodTable',
  186. tableName: '财年表',
  187. columnProp: 'companyId',
  188. headerAlign: 'center',
  189. align: 'center',
  190. columnLabel: 'Customer',
  191. columnHidden: false,
  192. columnImage: false,
  193. columnSortable: false,
  194. sortLv: 0,
  195. status: true,
  196. fixed: '',
  197. columnWidth: 120
  198. },
  199. {
  200. userId: this.$store.state.user.name,
  201. functionId: 'srmInventoryPeriod',
  202. serialNumber: 'srmInventoryPeriodTableBeginDate',
  203. tableId: 'srmInventoryPeriodTable',
  204. tableName: '财年表',
  205. columnProp: 'beginDate',
  206. headerAlign: 'center',
  207. align: 'center',
  208. columnLabel: '开始日期',
  209. columnHidden: false,
  210. columnImage: false,
  211. columnSortable: false,
  212. sortLv: 0,
  213. status: true,
  214. fixed: '',
  215. columnWidth: 140
  216. },
  217. {
  218. userId: this.$store.state.user.name,
  219. functionId: 'srmInventoryPeriod',
  220. serialNumber: 'srmInventoryPeriodTableEndDate',
  221. tableId: 'srmInventoryPeriodTable',
  222. tableName: '财年表',
  223. columnProp: 'endDate',
  224. headerAlign: 'center',
  225. align: 'center',
  226. columnLabel: '结束日期',
  227. columnHidden: false,
  228. columnImage: false,
  229. columnSortable: false,
  230. sortLv: 0,
  231. status: true,
  232. fixed: '',
  233. columnWidth: 140
  234. }
  235. ],
  236. authSearch: false,
  237. authSave: false,
  238. authUpdate: false,
  239. authDelete: false,
  240. menuId: this.$route.meta.menuId || 'srmInventoryPeriod'
  241. }
  242. },
  243. components: {
  244. ComPoOrderCustomerPicker
  245. },
  246. mounted () {
  247. this.$nextTick(() => {
  248. this.height = window.innerHeight - 180
  249. })
  250. },
  251. created () {
  252. this.getButtonAuthData()
  253. // Customer 不再强制选择,默认不选即查询所有财年数据
  254. this.getDataList()
  255. },
  256. methods: {
  257. onBeginDateChange (val) {
  258. // 输入开始日期后,结束日期自动填为开始日期 +1 年 -1 天,如 2025-11-01 -> 2026-10-31
  259. if (!val) {
  260. return
  261. }
  262. this.modalData.endDate = dayjs(val).add(1, 'year').subtract(1, 'day').format('YYYY-MM-DD')
  263. },
  264. onCustomerChange (code) {
  265. this.searchData.companyId = code
  266. this.pageIndex = 1
  267. this.getDataList()
  268. },
  269. sizeChangeHandle (val) {
  270. this.pageSize = val
  271. this.pageIndex = 1
  272. this.getDataList()
  273. },
  274. currentChangeHandle (val) {
  275. this.pageIndex = val
  276. this.getDataList()
  277. },
  278. buildQueryParams (extra) {
  279. return Object.assign({
  280. site: this.$store.state.user.site,
  281. companyId: this.searchData.companyId || '',
  282. years: this.searchData.years || '',
  283. page: this.pageIndex,
  284. limit: this.pageSize
  285. }, extra || {})
  286. },
  287. async createExportData () {
  288. this.exportList = []
  289. await getInventoryPeriodPage(this.buildQueryParams({ page: 1, limit: 999999 })).then(({ data }) => {
  290. if (data && data.code === 0) {
  291. const pageData = data.data || data.page
  292. const rows = (pageData && pageData.list) ? pageData.list : (pageData || [])
  293. this.exportList = Array.isArray(rows) ? rows : []
  294. } else {
  295. this.$message.error((data && data.msg) || '导出失败')
  296. }
  297. }).catch(() => {
  298. this.$message.error('导出失败')
  299. })
  300. return this.exportList
  301. },
  302. startDownload () {
  303. this.dataListLoading = true
  304. },
  305. finishDownload () {
  306. this.dataListLoading = false
  307. },
  308. fields () {
  309. return this.columnList.reduce((acc, col) => {
  310. acc[col.columnLabel] = col.columnProp
  311. return acc
  312. }, {})
  313. },
  314. getDataList () {
  315. this.dataListLoading = true
  316. getInventoryPeriodPage(this.buildQueryParams()).then(({ data }) => {
  317. if (data && data.code === 0) {
  318. const pageData = data.data || data.page
  319. this.dataList = pageData && pageData.list ? pageData.list : (pageData || [])
  320. if (pageData && pageData.currPage) {
  321. this.pageIndex = pageData.currPage
  322. this.pageSize = pageData.pageSize
  323. this.totalPage = pageData.totalCount
  324. } else {
  325. this.totalPage = this.dataList ? this.dataList.length : 0
  326. }
  327. } else {
  328. this.$message.error(data.msg || '获取数据失败')
  329. }
  330. }).catch(error => {
  331. console.error('获取财年列表失败:', error)
  332. this.$message.error('获取数据失败: ' + (error.message || '网络错误'))
  333. }).finally(() => {
  334. this.dataListLoading = false
  335. })
  336. },
  337. addModal () {
  338. this.modalData = {
  339. // 默认为空,弹窗内必须选择 Customer;带入列表已选客户方便录入
  340. companyId: this.searchData.companyId || '',
  341. years: '',
  342. months: '',
  343. beginDate: '',
  344. endDate: '',
  345. closed: 'N',
  346. flag: '1'
  347. }
  348. this.modalDisableFlag = false
  349. this.modalFlag = true
  350. this.$nextTick(() => {
  351. if (this.$refs.modalForm) {
  352. this.$refs.modalForm.clearValidate()
  353. }
  354. })
  355. },
  356. updateModal (row) {
  357. this.modalData = {
  358. companyId: row.companyId,
  359. years: row.years,
  360. months: row.months,
  361. beginDate: row.beginDate || '',
  362. endDate: row.endDate || '',
  363. closed: row.closed || 'N',
  364. flag: '2'
  365. }
  366. // 财年/月份/客户为主键,编辑时锁定不可改
  367. this.modalDisableFlag = true
  368. this.modalFlag = true
  369. this.$nextTick(() => {
  370. if (this.$refs.modalForm) {
  371. this.$refs.modalForm.clearValidate()
  372. }
  373. })
  374. },
  375. deleteRow (row) {
  376. this.$confirm(`确定删除该财年记录吗?财年:${row.years},月份:${row.months}`, '提示', {
  377. confirmButtonText: '确定',
  378. cancelButtonText: '取消',
  379. type: 'warning'
  380. }).then(() => {
  381. deleteInventoryPeriod({
  382. site: this.$store.state.user.site,
  383. companyId: row.companyId,
  384. years: row.years,
  385. months: row.months
  386. }).then(({ data }) => {
  387. if (data && data.code === 0) {
  388. this.getDataList()
  389. this.$message({ message: data.msg || '删除成功', type: 'success', duration: 1500 })
  390. } else {
  391. this.$alert(data.msg || '删除失败', '错误', { confirmButtonText: '确定' })
  392. }
  393. }).catch(error => {
  394. console.error('删除财年失败:', error)
  395. this.$message.error('删除失败: ' + (error.message || '网络错误'))
  396. })
  397. }).catch(() => {
  398. this.$message.info('已取消删除')
  399. })
  400. },
  401. saveData () {
  402. if (!this.modalData.companyId) {
  403. this.$message.warning('请选择 Customer')
  404. return
  405. }
  406. const isAdd = this.modalData.flag === '1'
  407. if (isAdd && (!this.modalData.beginDate || !this.modalData.endDate)) {
  408. this.$message.warning('请选择开始日期和结束日期')
  409. return
  410. }
  411. if (this.modalData.beginDate && this.modalData.endDate &&
  412. new Date(this.modalData.beginDate) > new Date(this.modalData.endDate)) {
  413. this.$message.error('开始日期不能晚于结束日期')
  414. return
  415. }
  416. // 新增时财年/月份不展示,自动取结束日期的年份/月份;编辑时沿用原主键
  417. let years = this.modalData.years
  418. let months = this.modalData.months
  419. if (isAdd) {
  420. const end = dayjs(this.modalData.endDate)
  421. years = end.year()
  422. months = end.month() + 1
  423. }
  424. const payload = {
  425. site: this.$store.state.user.site,
  426. companyId: this.modalData.companyId,
  427. years: Number(years),
  428. months: Number(months),
  429. beginDate: this.modalData.beginDate || null,
  430. endDate: this.modalData.endDate || null,
  431. closed: this.modalData.closed || 'N'
  432. }
  433. const apiCall = isAdd ? saveInventoryPeriod(payload) : updateInventoryPeriod(payload)
  434. apiCall.then(({ data }) => {
  435. if (data && data.code === 0) {
  436. this.$message({ message: data.msg || '操作成功', type: 'success', duration: 1500 })
  437. this.getDataList()
  438. this.modalFlag = false
  439. } else {
  440. this.$alert(data.msg || '操作失败', '错误', { confirmButtonText: '确定' })
  441. }
  442. }).catch(error => {
  443. console.error('保存财年失败:', error)
  444. this.$message.error('保存失败: ' + (error.message || '网络错误'))
  445. })
  446. },
  447. getButtonAuthData () {
  448. let searchFlag = this.isAuth(this.menuId + ':search')
  449. let saveFlag = this.isAuth(this.menuId + ':save')
  450. let updateFlag = this.isAuth(this.menuId + ':update')
  451. let deleteFlag = this.isAuth(this.menuId + ':delete')
  452. this.authSearch = !searchFlag
  453. this.authSave = !saveFlag
  454. this.authUpdate = !updateFlag
  455. this.authDelete = !deleteFlag
  456. }
  457. }
  458. }
  459. </script>
  460. <style scoped lang="scss">
  461. .el-table /deep/ .cell {
  462. height: auto;
  463. line-height: 1.5;
  464. }
  465. /* 弹窗内 Customer 下拉撑满所在栅格,与下方日期列上下对齐 */
  466. .period-modal /deep/ .po-customer-picker .el-select {
  467. width: 100%;
  468. }
  469. </style>