AdwebSiteBlackIpForm.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form :form="form" slot="detail">
  5. <a-row>
  6. <a-col :span="24">
  7. <a-form-item label="站点" :labelCol="labelCol" :wrapperCol="wrapperCol">
  8. <a-select placeholder="请选择站点" v-decorator="['siteId',validatorRules.siteId]" showSearch :filterOption="filterOption">
  9. <a-select-option v-for="option in siteOptions" :key="option.id" :value="option.id">{{option.name}}</a-select-option>
  10. </a-select>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :span="24">
  14. <a-form-item label="ip" :labelCol="labelCol" :wrapperCol="wrapperCol">
  15. <a-input v-decorator="['ip',validatorRules.ip]" placeholder="请输入ip" ></a-input>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :span="24">
  19. <a-form-item label="黑白名单" :labelCol="labelCol" :wrapperCol="wrapperCol">
  20. <a-select v-decorator="['blackOrWhite',validatorRules.blackOrWhite]" placeholder="请选择黑白名单">
  21. <a-select-option :value="0">黑名单</a-select-option>
  22. <a-select-option :value="1">白名单</a-select-option>
  23. </a-select>
  24. </a-form-item>
  25. </a-col>
  26. <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
  27. <a-button @click="submitForm">提 交</a-button>
  28. </a-col>
  29. </a-row>
  30. </a-form>
  31. </j-form-container>
  32. </a-spin>
  33. </template>
  34. <script>
  35. import { httpAction, getAction } from '/@/api/manage/manage'
  36. import pick from 'lodash.pick'
  37. import JFormContainer from '/@/components/Form/src/container/JFormContainer.vue';
  38. export default {
  39. name: 'AdwebSiteBlackIpForm',
  40. components: {
  41. JFormContainer,
  42. },
  43. props: {
  44. //流程表单data
  45. formData: {
  46. type: Object,
  47. default: ()=>{},
  48. required: false
  49. },
  50. //表单模式:true流程表单 false普通表单
  51. formBpm: {
  52. type: Boolean,
  53. default: false,
  54. required: false
  55. },
  56. //表单禁用
  57. disabled: {
  58. type: Boolean,
  59. default: false,
  60. required: false
  61. }
  62. },
  63. data () {
  64. return {
  65. form: this.$form.createForm(this),
  66. model: {},
  67. labelCol: {
  68. xs: { span: 24 },
  69. sm: { span: 5 },
  70. },
  71. wrapperCol: {
  72. xs: { span: 24 },
  73. sm: { span: 16 },
  74. },
  75. confirmLoading: false,
  76. validatorRules: {
  77. siteId: {
  78. rules: [
  79. { required: true, message: '请选择站点'}
  80. ]
  81. },
  82. ip: {
  83. rules: [
  84. { required: true, message: 'ip不能为空', trigger: 'blur' }
  85. ]
  86. },
  87. blackOrWhite: {
  88. rules: [
  89. { required: true, message: '请选择黑白名单'}
  90. ],
  91. }
  92. },
  93. url: {
  94. add: "/adweb/adwebSiteBlackIp/add",
  95. edit: "/adweb/adwebSiteBlackIp/edit",
  96. queryById: "/adweb/adwebSiteBlackIp/queryById"
  97. },
  98. siteOptions:[],
  99. }
  100. },
  101. computed: {
  102. formDisabled(){
  103. if(this.formBpm===true){
  104. if(this.formData.disabled===false){
  105. return false
  106. }
  107. return true
  108. }
  109. return this.disabled
  110. },
  111. showFlowSubmitButton(){
  112. if(this.formBpm===true){
  113. if(this.formData.disabled===false){
  114. return true
  115. }
  116. }
  117. return false
  118. }
  119. },
  120. created () {
  121. //如果是流程中表单,则需要加载流程表单data
  122. this.showFlowData();
  123. this.getSiteList();
  124. },
  125. methods: {
  126. add () {
  127. this.edit({});
  128. },
  129. edit (record) {
  130. this.form.resetFields();
  131. this.model = Object.assign({}, record);
  132. this.visible = true;
  133. this.$nextTick(() => {
  134. this.form.setFieldsValue(pick(this.model,'siteId','siteCode','status','ip','blackOrWhite','createTime'))
  135. })
  136. },
  137. //渲染流程表单数据
  138. showFlowData(){
  139. if(this.formBpm === true){
  140. let params = {id:this.formData.dataId};
  141. getAction(this.url.queryById,params).then((res)=>{
  142. if(res.success){
  143. this.edit (res.result);
  144. }
  145. });
  146. }
  147. },
  148. submitForm () {
  149. const that = this;
  150. // 触发表单验证
  151. this.form.validateFields((err, values) => {
  152. if (!err) {
  153. that.confirmLoading = true;
  154. let httpurl = '';
  155. let method = '';
  156. if(!this.model.id){
  157. httpurl+=this.url.add;
  158. method = 'post';
  159. }else{
  160. httpurl+=this.url.edit;
  161. method = 'put';
  162. }
  163. let formData = Object.assign(this.model, values);
  164. for(let j = 0; j < that.siteOptions.length; j++){
  165. if(formData.siteId == that.siteOptions[j].id){
  166. formData.siteCode = that.siteOptions[j].code;
  167. }
  168. }
  169. console.log("表单提交数据",formData)
  170. httpAction(httpurl,formData,method).then((res)=>{
  171. if(res.success){
  172. that.$message.success(res.message);
  173. that.$emit('ok');
  174. }else{
  175. that.$message.warning(res.message);
  176. }
  177. }).finally(() => {
  178. that.confirmLoading = false;
  179. })
  180. }
  181. })
  182. },
  183. popupCallback(row){
  184. this.form.setFieldsValue(pick(row,'siteId','siteCode','status','ip','blackOrWhite','createTime'))
  185. },
  186. filterOption(input, option) {
  187. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  188. },
  189. //获取站点列表
  190. getSiteList() {
  191. let that = this
  192. getAction('/sys/api/getSiteListByUid').then(function (res) {
  193. if (res.code == 0) {
  194. that.siteOptions = res.data;
  195. } else {
  196. that.$message.error('获取站点失败!')
  197. }
  198. }).catch(function (err) {
  199. console.log(err)
  200. })
  201. },
  202. }
  203. }
  204. </script>