综合办公系统
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.

siteExpenses.vue 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" style="padding: 20px 100px 0">
  4. <el-form-item label="现场开支:">
  5. <div style="color:#F56C6C">现场开支与借款挂钩,请慎重填写</div>
  6. <table border="1">
  7. <tr>
  8. <td colspan="5" class="head">现场开支表</td>
  9. </tr>
  10. <tr>
  11. <td>序号</td>
  12. <td>名称</td>
  13. <td>金额</td>
  14. <td>备注</td>
  15. <td>操作</td>
  16. </tr>
  17. <tr v-for="item, index in expensesList">
  18. <td>{{ index + 1 }}</td>
  19. <td>
  20. <el-select v-model="item.name" placeholder="请选择开支项" clearable @change="handleExpenseChange"
  21. style="width: 100%;">
  22. <el-option v-for="dict in dict.type.cmc_borrow_expense" clearable :key="dict.value" :label="dict.label"
  23. :value="dict.value" />
  24. <el-option label="+新增更多开支项..." value="new_expense" />
  25. </el-select>
  26. </td>
  27. <td>
  28. <el-input-number style="width: 100%;" :controls="false" v-model="item.amount"
  29. placeholder="请输入金额"></el-input-number>
  30. </td>
  31. <td>
  32. <el-input type="textarea" v-model="item.remark"></el-input>
  33. </td>
  34. <td>
  35. <el-button icon="el-icon-delete" type="text" style="color:#F56C6C"
  36. @click="deletExpensesList(index)">删除</el-button>
  37. </td>
  38. </tr>
  39. <tr>
  40. <td colspan="2" style="text-align: right; font-weight: bold;">现场开支总计:</td>
  41. <td style="font-weight: bold;">{{ totalAmount }}</td>
  42. <td colspan="2"></td>
  43. </tr>
  44. </table>
  45. <el-button type="primary" plain icon="el-icon-plus" @click="addExpensesList" size="mini"></el-button>
  46. </el-form-item>
  47. </el-form>
  48. <el-dialog title="新增开支项" :visible.sync="open" width="400px" append-to-body>
  49. <el-form ref="newExpenseForm" :model="newExpenseForm" :rules="newExpenseRules" label-width="120px">
  50. <el-form-item label="开支项名称" prop="name">
  51. <el-input v-model="newExpenseForm.name" placeholder="请输入开支项名称" />
  52. </el-form-item>
  53. </el-form>
  54. <div slot="footer" class="dialog-footer">
  55. <el-button type="primary" @click="submitNewExpense">确 定</el-button>
  56. <el-button @click="open = false">取 消</el-button>
  57. </div>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import { addData, getDicts } from "@/api/system/dict/data";
  63. import { listSite, delSite } from "@/api/oa/budget/budgetSite.js";
  64. export default {
  65. dicts: ['cmc_borrow_expense', 'cmc_unit'],
  66. props: {
  67. outerUsers: {
  68. type: Array,
  69. default: () => []
  70. },
  71. budgetId: {
  72. type: String,
  73. default: ''
  74. },
  75. },
  76. watch: {
  77. expensesList: {
  78. handler(newVal) {
  79. this.$emit('expensesList', [...newVal])
  80. },
  81. },
  82. budgetId() {
  83. this.initTable()
  84. },
  85. },
  86. data() {
  87. return {
  88. open: false,
  89. form: {},
  90. expensesList: [{
  91. name: '',
  92. amount: 0,
  93. remark: '',
  94. }],
  95. newExpenseForm: {
  96. name: ''
  97. },
  98. newExpenseRules: {
  99. name: [
  100. { required: true, message: "开支项不能为空", trigger: "blur" }
  101. ],
  102. }
  103. }
  104. },
  105. computed: {
  106. totalAmount() {
  107. let sum = this.expensesList.reduce((sum, item) => sum + (Number(item.amount) || 0), 0);
  108. this.$emit('siteSum', sum.toFixed(2))
  109. return sum.toFixed(2);
  110. }
  111. },
  112. created() {
  113. },
  114. methods: {
  115. initTable() {
  116. if (this.budgetId != '') {
  117. listSite({ pageSize: 100, budgetId: this.budgetId }).then(res => {
  118. if (res.rows.length > 0) {
  119. this.expensesList = res.rows;
  120. } else {
  121. this.expensesList = [{
  122. name: '',
  123. amount: 0,
  124. remark: '',
  125. }];
  126. }
  127. })
  128. }
  129. },
  130. addExpensesList() {
  131. this.expensesList.push({
  132. name: '',
  133. amount: 0,
  134. });
  135. },
  136. deletExpensesList(index) {
  137. let arr = this.expensesList;
  138. if (arr.length == 1) {
  139. return;
  140. }
  141. if (index >= 0 && index < arr.length) {
  142. const item = arr[index];
  143. if (item.id) {
  144. // If the item has an ID, it exists in the database, so delete it
  145. delSite(item.id).then(response => {
  146. this.$modal.msgSuccess("删除成功");
  147. arr.splice(index, 1);
  148. }).catch(() => {
  149. this.$modal.msgError("删除失败");
  150. });
  151. } else {
  152. // If the item doesn't have an ID, just remove it from the array
  153. arr.splice(index, 1);
  154. }
  155. }
  156. },
  157. handleExpenseChange(value) {
  158. if (value === 'new_expense') {
  159. this.open = true;
  160. } else if (value === '食宿') {
  161. const currentIndex = this.expensesList.findIndex(item => item.name === value);
  162. if (currentIndex !== -1) {
  163. const totalDays = this.outerUsers.reduce((sum, user) => sum + (user.days || 0), 0);
  164. this.expensesList[currentIndex].amount = 130 * totalDays;
  165. this.expensesList[currentIndex].remark = '130元/人天,共计' + totalDays + '人天';
  166. }
  167. }
  168. },
  169. submitNewExpense() {
  170. this.$refs["newExpenseForm"].validate(valid => {
  171. if (valid) {
  172. let length = this.dict.type.cmc_borrow_expense.length;
  173. this.newExpenseForm.dictType = 'cmc_borrow_expense';
  174. this.newExpenseForm.dictLabel = this.newExpenseForm.name;
  175. this.newExpenseForm.dictValue = this.newExpenseForm.name;
  176. this.newExpenseForm.listClass = 'default';
  177. this.newExpenseForm.dictSort = length;
  178. addData(this.newExpenseForm).then(response => {
  179. this.$modal.msgSuccess("新增成功");
  180. this.open = false;
  181. this.newExpenseForm.name = '';
  182. // 刷新字典数据
  183. getDicts("cmc_borrow_expense").then(res => {
  184. let arr = [];
  185. for (let i = 0; i < res.data.length; i++) {
  186. arr.push({
  187. label: res.data[i].dictLabel,
  188. value: res.data[i].dictValue,
  189. raw: res.data[i]
  190. })
  191. }
  192. this.dict.type.cmc_borrow_expense = arr;
  193. })
  194. });
  195. }
  196. })
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. table {
  203. width: 100%;
  204. /*居中*/
  205. // margin: 0 auto;
  206. /*边框*/
  207. /* border: 1px solid black; */
  208. text-align: center;
  209. border-collapse: collapse;
  210. border: 1px solid #DCDFE6;
  211. /*设置背景颜色*/
  212. /* background-color: #bfa; */
  213. td {
  214. padding: 1px;
  215. }
  216. .head {
  217. background-color: #e7f6f3;
  218. font-family: '微软雅黑';
  219. font-size: 18;
  220. font-weight: bold;
  221. }
  222. }
  223. </style>