tb-fee-item-add.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>费项管理-添加/修改</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta name="viewport"
  7. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  8. <!-- 所有的 css js 资源 -->
  9. <link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
  10. <link rel="stylesheet" href="../../static/sa.css">
  11. <script src="../../static/kj/vue.min.js"></script>
  12. <script src="../../static/kj/element-ui/index.js"></script>
  13. <script src="../../static/kj/httpVueLoader.js"></script>
  14. <script src="../../static/kj/jquery.min.js"></script>
  15. <script src="../../static/kj/layer/layer.js"></script>
  16. <script src="../../static/sa.js"></script>
  17. <style type="text/css">
  18. .c-panel .el-form .c-label {
  19. width: 7em !important;
  20. }
  21. .c-panel .el-form .el-input,
  22. .c-panel .el-form .el-textarea__inner {
  23. width: 250px;
  24. }
  25. .rows {}
  26. .rows .row {
  27. float: left;
  28. width: 33.3333%;
  29. min-width: 25rem;
  30. }
  31. .rows .row .out {
  32. padding: 20px;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <div class="vue-box" :class="{sbot: id}" style="display: none;" :style="'display: block;'">
  38. <!-- ------- 内容部分 ------- -->
  39. <div class="s-body">
  40. <div class="c-panel">
  41. <div class="c-title" v-if="id == 0">数据添加</div>
  42. <div class="c-title" v-else>数据修改</div>
  43. <el-form v-if="m">
  44. <el-row>
  45. <el-col :span="12">
  46. <sa-item type="text" name="费项名称" v-model="m.name" br></sa-item>
  47. </el-col>
  48. <el-col :span="12">
  49. <div class="c-item br">
  50. <label class="c-label"><label style="color: red">*</label>收费企业:</label>
  51. <el-select v-model="m.companyId" placeholder="请选择" filterable size="mini">
  52. <el-option v-for="(item,index) in companyList" :key="index" :label="item.name"
  53. :value="item.id"> </el-option>
  54. </el-select>
  55. </div>
  56. </el-col>
  57. </el-row>
  58. <div>
  59. <div><el-button type="primary" icon="el-icon-plus" @click="addRules">收费规则</el-button></div>
  60. </div>
  61. <div class="rows">
  62. <el-form ref="dynamicValidateForm" :model="form" label-width="100px" class="demo-dynamic">
  63. <div v-for="(rule,index) in form.rules" class="row">
  64. <div class="out">
  65. <el-divider content-position="left">规则{{index+1}}
  66. <i class="el-icon-delete"
  67. style="color: red;margin-left: 20px;cursor: pointer;"
  68. @click="delRules(rule.index)"></i>
  69. </el-divider>
  70. <div class="c-item br">
  71. <el-form-item :prop="'rules.' + index + '.goodsCodes'" label="选择品目:" :rules="[
  72. { required: true, message: '请输入选择品目', trigger: 'blur' }
  73. ]">
  74. <el-select multiple v-model="rule.goodsCodes" placeholder="请选择"
  75. filterable size="mini">
  76. <el-option v-for="(item,index) in goodsList" :key="index"
  77. :label="item.name" :value="item.code"> </el-option>
  78. </el-select>
  79. <label @click="addAllGoods(rule)" v-if="rule.goodsCodes.length==0"
  80. style="font-size: 10px;cursor: pointer;padding: 5px 5px; color: white;background-color: #1890ff;border-radius: 2px;">全部</label>
  81. <label @click="rule.goodsCodes=[]" v-else
  82. style="font-size: 10px;cursor: pointer;padding: 5px 5px; color: white;background-color: red;border-radius: 2px;">清除</label>
  83. </el-form-item>
  84. </div>
  85. <sa-item type="enum" name="类型" v-model="rule.feeType"
  86. :jv="{2: '固定金额',1: '按交易额', 3:'按吨收费'}" jtype="3" br></sa-item>
  87. <sa-item type="num" v-if="rule.feeType==1||rule.feeType==3" name="百分比(%)"
  88. v-model="rule.percent" br></sa-item>
  89. <sa-item type="num" v-if="rule.feeType==2" name="金额(元)" v-model="rule.feeMoney"
  90. br></sa-item>
  91. </div>
  92. </div>
  93. </el-form>
  94. </div>
  95. </el-form>
  96. </div>
  97. </div>
  98. <!-- ------- 底部按钮 ------- -->
  99. <div class="s-foot">
  100. <el-button type="primary" @click="ok()">确定</el-button>
  101. <el-button @click="sa.closeCurrIframe()">取消</el-button>
  102. </div>
  103. </div>
  104. <script>
  105. var app = new Vue({
  106. components: {
  107. "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue')
  108. },
  109. el: '.vue-box',
  110. data: {
  111. id: sa.p('id', 0), // 获取超链接中的id参数(0=添加,非0=修改)
  112. m: null, // 实体对象
  113. form: {
  114. rules: [{
  115. index: 0,
  116. goodsCodes: [],
  117. feeType: 2,
  118. percent: 10,
  119. feeMoney: 30
  120. }],
  121. },
  122. companyList: [],
  123. goodsList: []
  124. },
  125. methods: {
  126. addRules() {
  127. let rule = {
  128. index: new Date().getTime(),
  129. goodsCodes: [],
  130. feeType: 2,
  131. percent: 10,
  132. feeMoney: 30
  133. }
  134. this.form.rules.push(rule);
  135. },
  136. delRules(index) {
  137. let rules = this.form.rules;
  138. if (rules.length == 1) {
  139. sa.error('只是保留一条规则')
  140. return;
  141. }
  142. let i = rules.map(obj => obj.index).indexOf(index);
  143. rules.splice(i, 1);
  144. },
  145. addAllGoods(rule) {
  146. rule.goodsCodes = this.goodsList.map(obj => obj.code);
  147. },
  148. getGoodsList: function() {
  149. sa.ajax('/level-one-server/TbGoods/getList', {
  150. pageSize: 100
  151. }, function(res) {
  152. this.goodsList = res.data; // 数据
  153. }.bind(this));
  154. },
  155. getCompanyList: function() {
  156. sa.ajax('/level-two-server/TbCompany/getList', {
  157. pageNo: 1,
  158. pageSize: 100
  159. }, function(res) {
  160. this.companyList = res.data; // 数据
  161. }.bind(this));
  162. },
  163. // 创建一个 默认Model
  164. createModel: function() {
  165. return {
  166. id: '', // 主键
  167. companyId: '', // 企业ID
  168. companyName: '', // 收费企业
  169. name: '', // 名称
  170. feeType: '2', // 类型(1=按交易额收取,2=按次收取)
  171. percent: '', // 百分比fee_type=1时生效
  172. goodsType: 'all',
  173. feeMoney: '', // 收费金额 fee_type=2时生效
  174. status: '1', // 状态(0=禁用,1=启用)
  175. }
  176. },
  177. // 提交数据
  178. ok: function() {
  179. // 表单校验
  180. let m = this.m;
  181. sa.checkNull(m.name, '请输入 [费项名称]');
  182. sa.checkNull(m.companyId, '请选择 [收费企业]');
  183. m.companyName = this.companyList.filter(obj => obj.id == m.companyId).pop().name;
  184. this.$refs.dynamicValidateForm.validate((valid) => {
  185. if (valid) {
  186. let rules = JSON.parse(JSON.stringify(this.form.rules));
  187. for (let i in rules) {
  188. let rule = rules[i];
  189. if (rule.feeType == 1 && !rule.percent) {
  190. sa.error('请输入百分比')
  191. return;
  192. }
  193. if (rule.feeType == 2 && !rule.feeMoney) {
  194. sa.error('请输入金额')
  195. return;
  196. }
  197. if (rule.feeType == 1) {
  198. rule.feeMoney = 0;
  199. }
  200. if (rule.feeType == 2) {
  201. rule.percent = 0;
  202. }
  203. rule.goodsCodes = rule.goodsCodes.join(',');
  204. }
  205. // 开始增加或修改
  206. m.rules = rules;
  207. console.log(m);
  208. if (this.id <= 0) { // 添加
  209. sa.ajaxJson('/level-two-server/TbFeeItem/add', sa.removeNull(m),
  210. function(res) {
  211. sa.alert('增加成功', this.clean);
  212. }.bind(this));
  213. } else { // 修改
  214. sa.ajaxJson('/level-two-server/TbFeeItem/update', sa.removeNull(m),
  215. function(res) {
  216. sa.alert('修改成功', this.clean);
  217. }.bind(this));
  218. }
  219. } else {
  220. return false;
  221. }
  222. });
  223. },
  224. // 添加/修改 完成后的动作
  225. clean: function() {
  226. if (this.id == 0) {
  227. this.m = this.createModel();
  228. } else {
  229. parent.app.f5(); // 刷新父页面列表
  230. sa.closeCurrIframe(); // 关闭本页
  231. }
  232. }
  233. },
  234. mounted: function() {
  235. this.getCompanyList();
  236. this.getGoodsList();
  237. // 初始化数据
  238. if (this.id <= 0) {
  239. this.m = this.createModel();
  240. } else {
  241. sa.ajax('/level-two-server/TbFeeItem/getById?id=' + this.id, function(res) {
  242. let data = res.data;
  243. let rules = data.rules;
  244. let list=[];
  245. for (let i in rules) {
  246. let rule = rules[i];
  247. let obj = {
  248. index: sa.randomString(),
  249. goodsCodes: rule.goodsCodes.split(','),
  250. feeType: rule.feeType,
  251. percent: rule.percent,
  252. feeMoney: rule.feeMoney
  253. }
  254. list.push(obj);
  255. }
  256. console.log(list);
  257. this.form.rules=list;
  258. this.m = res.data;
  259. if (res.data == null) {
  260. sa.alert('未能查找到 id=' + this.id + " 详细数据");
  261. }
  262. }.bind(this))
  263. }
  264. }
  265. })
  266. </script>
  267. </body>
  268. </html>