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.

353 lines
11 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
  1. <template>
  2. <div class="mod-config">
  3. <!-- 查询条件 -->
  4. <el-form :inline="true" label-position="top" :model="searchData">
  5. <el-form-item label="货币代码">
  6. <el-input v-model="searchData.currency" clearable style="width: 120px" placeholder="货币代码"></el-input>
  7. </el-form-item>
  8. <el-form-item label="货币描述">
  9. <el-input v-model="searchData.currencyDesc" clearable style="width: 160px" placeholder="货币描述"></el-input>
  10. </el-form-item>
  11. <el-form-item label="状态">
  12. <el-select v-model="searchData.active" clearable placeholder="状态" style="width: 120px">
  13. <el-option label="启用" value="Y"></el-option>
  14. <el-option label="禁用" value="N"></el-option>
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label=" ">
  18. <el-button type="primary" @click="getDataList()">查询</el-button>
  19. <el-button type="primary" @click="addModal()">新增</el-button>
  20. </el-form-item>
  21. </el-form>
  22. <!-- 主表 -->
  23. <el-table
  24. :height="height"
  25. :data="dataList"
  26. border
  27. v-loading="dataListLoading"
  28. style="width: 100%;">
  29. <el-table-column
  30. prop="currency"
  31. header-align="center"
  32. align="left"
  33. width="120"
  34. label="货币代码">
  35. </el-table-column>
  36. <el-table-column
  37. prop="currencyDesc"
  38. header-align="center"
  39. align="left"
  40. min-width="150"
  41. label="货币描述"
  42. show-overflow-tooltip>
  43. </el-table-column>
  44. <el-table-column
  45. prop="site"
  46. header-align="center"
  47. align="center"
  48. width="120"
  49. label="站点">
  50. </el-table-column>
  51. <el-table-column
  52. prop="active"
  53. header-align="center"
  54. align="center"
  55. width="100"
  56. label="状态">
  57. <template slot-scope="scope">
  58. <span>{{ scope.row.active === 'Y' ? '启用' : '禁用' }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column
  62. prop="baseCurrency"
  63. header-align="center"
  64. align="center"
  65. width="120"
  66. label="基础货币">
  67. <template slot-scope="scope">
  68. <span>{{ scope.row.baseCurrency === 'Y' ? '是' : '否' }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column
  72. fixed="right"
  73. header-align="center"
  74. align="center"
  75. width="120"
  76. label="操作">
  77. <template slot-scope="scope">
  78. <el-link style="cursor: pointer" @click="updateModal(scope.row)">编辑 |</el-link>
  79. <el-link style="cursor: pointer" @click="deleteHandle(scope.row)">删除</el-link>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <!-- 分页 -->
  84. <el-pagination
  85. @size-change="sizeChangeHandle"
  86. @current-change="currentChangeHandle"
  87. :current-page="pageIndex"
  88. :page-sizes="[10, 20, 50, 100]"
  89. :page-size="pageSize"
  90. :total="totalPage"
  91. layout="total, sizes, prev, pager, next, jumper">
  92. </el-pagination>
  93. <!-- 新增/修改对话框 -->
  94. <el-dialog :title="modalTitle" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="415px">
  95. <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" ref="modalForm" style="margin-left: 7px;">
  96. <el-form-item label="货币代码" prop="currency" :rules="rules.currency">
  97. <el-input v-model="modalData.currency" :disabled="modalDisableFlag" style="width: 100px"></el-input>
  98. </el-form-item>
  99. <el-form-item label="状态" prop="active">
  100. <el-select v-model="modalData.active" style="width: 100px">
  101. <el-option label="启用" value="Y"></el-option>
  102. <el-option label="禁用" value="N"></el-option>
  103. </el-select>
  104. </el-form-item>
  105. <el-form-item label="基础货币" prop="baseCurrency">
  106. <el-select v-model="modalData.baseCurrency" style="width: 100px">
  107. <el-option label="是" value="Y"></el-option>
  108. <el-option label="否" value="N"></el-option>
  109. </el-select>
  110. </el-form-item>
  111. </el-form>
  112. <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;">
  113. <el-form-item label="货币描述" prop="currencyDesc" :rules="rules.currencyDesc">
  114. <el-input v-model="modalData.currencyDesc" style="width: 325px"></el-input>
  115. </el-form-item>
  116. <el-form-item label="站点" prop="site" :rules="rules.site" v-if="modalData.flag === '2'">
  117. <el-input v-model="modalData.site" disabled style="width: 325px"></el-input>
  118. </el-form-item>
  119. </el-form>
  120. <el-footer style="height:40px;margin-top: 20px;text-align:center">
  121. <el-button type="primary" @click="saveData()">保存</el-button>
  122. <el-button type="primary" @click="modalFlag = false">关闭</el-button>
  123. </el-footer>
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <script>
  128. import { getCurrencyListWithPaging,
  129. addCurrency,
  130. updateCurrency,
  131. deleteCurrency } from '@/api/baseInformation/srmCurrency.js'
  132. export default {
  133. name: "srmSupplierCurrency",
  134. data() {
  135. return {
  136. height: 300,
  137. dataList:[],
  138. dataListLoading: false,
  139. pageIndex: 1,
  140. pageSize: 20,
  141. totalPage: 0,
  142. searchData: {
  143. currency: '',
  144. currencyDesc: '',
  145. active: '',
  146. baseCurrency: '',
  147. site: this.$store.state.user.site
  148. },
  149. modalFlag: false,
  150. modalTitle: '',
  151. modalDisableFlag: false,
  152. isEdit: false,
  153. modalData: {
  154. currency: '',
  155. currencyDesc: '',
  156. site: this.$store.state.user.site,
  157. active: 'Y',
  158. baseCurrency: 'N'
  159. },
  160. rules: {
  161. currency: [
  162. { required: true, message: '请输入货币代码', trigger: 'blur' }
  163. ],
  164. currencyDesc: [
  165. { required: true, message: '请输入货币描述', trigger: 'blur' }
  166. ],
  167. site: [
  168. { required: true, message: '请输入站点', trigger: 'blur' }
  169. ],
  170. active: [
  171. { required: true, message: '请选择状态', trigger: 'change' }
  172. ],
  173. baseCurrency: [
  174. { required: true, message: '请选择是否基础货币', trigger: 'change' }
  175. ]
  176. },
  177. }
  178. },
  179. mounted() {
  180. this.$nextTick(() => {
  181. this.height = window.innerHeight - 240;
  182. })
  183. // 初始化数据
  184. this.getDataList()
  185. },
  186. methods: {
  187. // 获取数据列表
  188. getDataList() {
  189. this.dataListLoading = true
  190. const params = {
  191. ...this.searchData,
  192. page: this.pageIndex,
  193. limit: this.pageSize
  194. }
  195. getCurrencyListWithPaging(params).then(({data}) => {
  196. if (data && data.code === 0) {
  197. const pageData = data.data || data.page
  198. this.dataList = pageData && pageData.list ? pageData.list : pageData
  199. if(pageData && pageData.currPage) {
  200. this.pageIndex = pageData.currPage
  201. this.pageSize = pageData.pageSize
  202. this.totalPage = pageData.totalCount
  203. } else {
  204. this.totalPage = this.dataList ? this.dataList.length : 0
  205. }
  206. } else {
  207. this.$message.error(data.msg || '获取数据失败')
  208. }
  209. }).catch(error => {
  210. console.error('获取货币列表失败:', error)
  211. this.$message.error('获取数据失败: ' + (error.message || '网络错误'))
  212. }).finally(() => {
  213. this.dataListLoading = false
  214. })
  215. },
  216. // 每页数
  217. sizeChangeHandle(val) {
  218. this.pageSize = val
  219. this.pageIndex = 1
  220. this.getDataList()
  221. },
  222. // 当前页
  223. currentChangeHandle(val) {
  224. this.pageIndex = val
  225. this.getDataList()
  226. },
  227. // 新增
  228. addModal() {
  229. this.modalTitle = '新增货币'
  230. this.isEdit = false
  231. this.modalDisableFlag = false
  232. this.modalData = {
  233. currency: '',
  234. currencyDesc: '',
  235. site: this.$store.state.user.site || this.$store.state.user.currentSite || '', // 设置默认值但不显示在界面上
  236. active: 'Y',
  237. baseCurrency: 'N',
  238. flag: '1'
  239. }
  240. this.$nextTick(() => {
  241. if (this.$refs.modalForm) {
  242. this.$refs.modalForm.clearValidate()
  243. }
  244. })
  245. this.modalFlag = true
  246. },
  247. // 修改
  248. updateModal(row) {
  249. this.modalTitle = '修改货币'
  250. this.isEdit = true
  251. this.modalDisableFlag = true
  252. this.modalData = {
  253. currency: row.currency,
  254. currencyDesc: row.currencyDesc,
  255. site: row.site,
  256. active: row.active,
  257. baseCurrency: row.baseCurrency
  258. }
  259. this.$nextTick(() => {
  260. if (this.$refs.modalForm) {
  261. this.$refs.modalForm.clearValidate()
  262. }
  263. })
  264. this.modalFlag = true
  265. },
  266. // 保存数据
  267. saveData() {
  268. this.$refs.modalForm.validate((valid) => {
  269. if (valid) {
  270. const saveData = { ...this.modalData }
  271. let apiCall
  272. if (this.modalData.flag === '1') {
  273. apiCall = addCurrency(saveData)
  274. } else {
  275. apiCall = updateCurrency(saveData)
  276. }
  277. apiCall.then(({data}) => {
  278. if (data && data.code === 0) {
  279. this.$message({
  280. message: '操作成功',
  281. type: 'success',
  282. duration: 1500
  283. })
  284. // 立即关闭弹窗并刷新数据,不依赖 onclose 回调
  285. this.modalFlag = false
  286. this.getDataList()
  287. } else {
  288. this.$message.error(data.msg || '操作失败')
  289. }
  290. }).catch(error => {
  291. console.error('保存货币失败:', error)
  292. this.$message.error('保存失败: ' + (error.message || '网络错误'))
  293. })
  294. } else {
  295. return false
  296. }
  297. })
  298. },
  299. // 删除
  300. deleteHandle(row) {
  301. this.$confirm(`确定删除此货币吗?货币代码:${row.currency}`, '提示', {
  302. confirmButtonText: '确定',
  303. cancelButtonText: '取消',
  304. type: 'warning'
  305. }).then(() => {
  306. const params = {
  307. currency: row.currency,
  308. site: row.site
  309. }
  310. deleteCurrency(params).then(({data}) => {
  311. if (data && data.code === 0) {
  312. this.$message({
  313. message: '删除成功',
  314. type: 'success',
  315. duration: 1500
  316. })
  317. // 立即刷新数据,不依赖 onclose 回调
  318. this.getDataList()
  319. } else {
  320. this.$message.error(data.msg || '删除失败')
  321. }
  322. }).catch(error => {
  323. console.error('删除货币失败:', error)
  324. this.$message.error('删除失败: ' + (error.message || '网络错误'))
  325. })
  326. }).catch(() => {
  327. this.$message.info('已取消删除')
  328. })
  329. }
  330. }
  331. }
  332. </script>
  333. <style scoped>
  334. .mod-config {
  335. padding: 20px;
  336. }
  337. </style>