tb-item-add.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <!-- 所有的 css js 资源 -->
  8. <link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
  9. <link rel="stylesheet" href="../../static/sa.css">
  10. <script src="../../static/kj/vue.min.js"></script>
  11. <script src="../../static/kj/element-ui/index.js"></script>
  12. <script src="../../static/kj/httpVueLoader.js"></script>
  13. <script src="../../static/kj/jquery.min.js"></script>
  14. <script src="../../static/kj/layer/layer.js"></script>
  15. <script src="../../static/sa.js"></script>
  16. <style type="text/css">
  17. .c-panel .el-form .c-label{width: 7em !important;}
  18. .c-panel .el-form .el-input, .c-panel .el-form .el-textarea__inner{width: 250px;}
  19. </style>
  20. </head>
  21. <body>
  22. <div class="vue-box" :class="{sbot: id}" style="display: none;" :style="'display: block;'">
  23. <!-- ------- 内容部分 ------- -->
  24. <div class="s-body">
  25. <div class="c-panel">
  26. <div class="c-title" v-if="id == 0">数据添加</div>
  27. <div class="c-title" v-else>数据修改</div>
  28. <el-form v-if="m">
  29. <sa-item type="text" name="项目编号" v-model="m.itemCode" br></sa-item>
  30. <sa-item type="text" name="项目名称" v-model="m.itemName" br></sa-item>
  31. <div class="c-item">
  32. <label class="c-label">项目类型:</label>
  33. <el-select v-model="m.typeId" style="width: 120px;" placeholder="请选择">
  34. <el-option
  35. v-for="type in itemTypeList"
  36. :key="type.id"
  37. :label="type.name"
  38. :value="type.id">
  39. </el-option>
  40. </el-select>
  41. </div>
  42. <sa-item type="num" name="项目金额(元)" v-model="m.price" br></sa-item>
  43. <sa-item type="text" name="单位" v-model="m.unit" br></sa-item>
  44. <!-- <sa-item type="enum" name="是否必须" v-model="m.need" :jv="{1: '否', 2: '是'}" jtype="3" br></sa-item>-->
  45. <!-- <sa-item type="text" name="创建时间" v-model="m.createTime" br></sa-item>-->
  46. <sa-item name="" class="s-ok" br>
  47. <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
  48. </sa-item>
  49. </el-form>
  50. </div>
  51. </div>
  52. <!-- ------- 底部按钮 ------- -->
  53. <div class="s-foot">
  54. <el-button type="primary" @click="ok()">确定</el-button>
  55. <el-button @click="sa.closeCurrIframe()">取消</el-button>
  56. </div>
  57. </div>
  58. <script>
  59. var app = new Vue({
  60. components: {
  61. "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue')
  62. },
  63. el: '.vue-box',
  64. data: {
  65. id: sa.p('id', 0), // 获取超链接中的id参数(0=添加,非0=修改)
  66. m: {
  67. id: '', // 主键
  68. typeId: '',
  69. typeName: '',
  70. itemName: '',
  71. itemCode: '',
  72. price: '',
  73. unit: '',
  74. }, // 实体对象
  75. itemTypeList: [],
  76. },
  77. methods: {
  78. // 创建一个 默认Model
  79. createModel: function() {
  80. return {
  81. id: '', // 主键
  82. typeId: '', //类型id
  83. typeName: '', //类型
  84. itemName: '', //项目名
  85. itemCode: '', //项目编号
  86. price: '', //费用
  87. unit: '', //单位
  88. }
  89. },
  90. // 提交数据
  91. ok: function(){
  92. // 表单校验
  93. let m = this.m;
  94. // sa.checkNull(m.id, '请输入 [主键]');
  95. sa.checkNull(m.itemCode, '请输入 [项目编号]');
  96. sa.checkNull(m.itemName, '请输入 [项目名称]');
  97. sa.checkNull(m.typeId, '请选择 [项目类型]');
  98. sa.checkNull(m.price, '请输入 [项目金额]');
  99. console.log(m.typeId);
  100. let typeList = this.itemTypeList;
  101. let typeId = m.typeId;
  102. let typeName = '';
  103. for (let i in typeList) {
  104. if(typeId == typeList[i].id){
  105. typeName = typeList[i].name;
  106. console.log("if:"+typeName);
  107. }
  108. }
  109. m.typeName = typeName;
  110. // 开始增加或修改
  111. if(this.id <= 0) { // 添加
  112. sa.ajax('/TbItem/add', m, function(res){
  113. sa.alert('增加成功', this.clean);
  114. }.bind(this));
  115. } else { // 修改
  116. sa.ajax('/TbItem/update', m, function(res){
  117. sa.alert('修改成功', this.clean);
  118. }.bind(this));
  119. }
  120. },
  121. // 添加/修改 完成后的动作
  122. clean: function() {
  123. if(this.id == 0) {
  124. this.m = this.createModel();
  125. } else {
  126. parent.app.f5(); // 刷新父页面列表
  127. sa.closeCurrIframe(); // 关闭本页
  128. }
  129. },
  130. getItemTypeList(){
  131. sa.ajax('/TbItemType/getList', function(resp) {
  132. this.itemTypeList = resp.data;
  133. }.bind(this));
  134. },
  135. },
  136. mounted: function(){
  137. this.getItemTypeList();
  138. // 初始化数据
  139. if(this.id <= 0) {
  140. this.m = this.createModel();
  141. } else {
  142. sa.ajax('/TbItem/getById?id=' + this.id, function(res) {
  143. this.m = res.data;
  144. if(res.data == null) {
  145. sa.alert('未能查找到 id=' + this.id + " 详细数据");
  146. }
  147. }.bind(this))
  148. }
  149. }
  150. })
  151. </script>
  152. </body>
  153. </html>