tb-trade-area-add.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. </style>
  26. </head>
  27. <body>
  28. <div class="vue-box" :class="{sbot: id}" style="display: none;" :style="'display: block;'">
  29. <!-- ------- 内容部分 ------- -->
  30. <div class="s-body">
  31. <div class="c-panel">
  32. <div class="c-title" v-if="id == 0">数据添加</div>
  33. <div class="c-title" v-else>数据修改</div>
  34. <el-form size="mini" v-if="m">
  35. <div class="c-item br">
  36. <label class="c-label"><label style="color: red">*</label>名称:</label>
  37. <el-input size="mini" v-model="m.name"></el-input>
  38. </div>
  39. <div class="c-item br">
  40. <label class="c-label"><label style="color: red">*</label>地址:</label>
  41. <el-cascader size="mini" placeholder="请选择" v-model="m.address_arry" :options="options"
  42. :props={value:'id',label:'district'}></el-cascader>
  43. </div>
  44. <div class="c-item br">
  45. <label class="c-label"><label style="color: red">*</label>详细地址:</label>
  46. <el-input size="mini" v-model="m.detailAddress"></el-input>
  47. </div>
  48. <div class="c-item br s-ok">
  49. <label class="c-label"></label>
  50. <el-button size="mini" type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
  51. </div>
  52. </el-form>
  53. </div>
  54. </div>
  55. <!-- ------- 底部按钮 ------- -->
  56. <div class="s-foot">
  57. <el-button size="mini" type="primary" @click="ok()">确定</el-button>
  58. <el-button size="mini" @click="sa.closeCurrIframe()">取消</el-button>
  59. </div>
  60. </div>
  61. <script>
  62. var app = new Vue({
  63. el: '.vue-box',
  64. data: {
  65. id: sa.p('id', 0), // 获取超链接中的id参数(0=添加,非0=修改)
  66. platformList: [],
  67. options: [],
  68. m: null, // 实体对象
  69. },
  70. methods: {
  71. getAddress() {
  72. sa.ajax('/sp-admin/TbDistrict/getTreeData', function(resp) {
  73. this.options = resp.data;
  74. }.bind(this));
  75. },
  76. // 创建一个 默认Model
  77. createModel: function() {
  78. return {
  79. id: '', // 主键
  80. name: '', // 名称
  81. detailAddress: '', // 名称
  82. address_arry: [], // 名称
  83. status: '1', // 状态(0=禁用,1=启用)
  84. addressIds: '', //
  85. address: '', //
  86. createTime: '', //
  87. }
  88. },
  89. // 表单验证
  90. submitCheck: function() {
  91. try {
  92. var m = this.m; // 获取 m对象
  93. sa.checkNull(m.name, '请输入 [名称]');
  94. sa.checkEmptyArray(m.address_arry, '请选择 [地址]');
  95. sa.checkNull(m.detailAddress, '请输入 [详细地址]');
  96. return 'ok'; // 全部通过验证,返回ok 表示正确
  97. } catch (e) {
  98. sa.error(e.msg);
  99. }
  100. },
  101. // 提交数据
  102. ok: function() {
  103. // 验证
  104. if (this.submitCheck() != 'ok') {
  105. return;
  106. }
  107. this.m.addressIds = this.m.address_arry.join(',');
  108. // 开始增加或修改
  109. if (this.id <= 0) { // 添加
  110. sa.ajax('/level-one-server/TbTradeArea/add', this.m, function(res) {
  111. sa.alert('增加成功', this.clean);
  112. }.bind(this));
  113. } else { // 修改
  114. sa.ajax('/level-one-server/TbTradeArea/update', this.m, function(res) {
  115. sa.alert('修改成功', this.clean);
  116. }.bind(this));
  117. }
  118. },
  119. // 添加/修改 完成后的动作
  120. clean: function() {
  121. if (this.id == 0) {
  122. this.m = this.createModel();
  123. } else {
  124. parent.app.f5(); // 刷新父页面列表
  125. sa.closeCurrIframe(); // 关闭本页
  126. }
  127. }
  128. },
  129. mounted: function() {
  130. // 初始化数据
  131. if (this.id <= 0) {
  132. this.m = this.createModel();
  133. } else {
  134. sa.ajax('/level-one-server/TbTradeArea/getById?id=' + this.id, function(res) {
  135. this.m = res.data;
  136. if (res.data == null) {
  137. sa.alert('未能查找到 id=' + this.id + " 详细数据");
  138. }
  139. this.m.address_arry = this.m.addressIds.split(',');
  140. }.bind(this))
  141. }
  142. this.getAddress();
  143. }
  144. })
  145. </script>
  146. </body>
  147. </html>