<template>
  <el-dialog
    title="保存条件"
    :visible.sync="visible"
    @close="handleClose"
    v-dialogDrag
    custom-class="common-dialog"
    :close-on-click-modal="false">
    <el-form :model="paramForm" @submit.native.prevent :rules="rules"
      ref="formRef" label-width="80px" size="mini"   label-position="left">
      <el-row :gutter="50">
        <el-col :span="24">
         <el-form-item  label="条件名称"  prop="collectName">
           <el-input
                v-model="paramForm.collectName"
                v-inputFilter:trim
                @keyup.native.enter="submitForm"
                placeholder="请输入">
           </el-input>
         </el-form-item>
        </el-col >
      </el-row>
      <el-form-item style="margin-bottom: 0;text-align: center" label-width="0px">
        <el-button  @click="submitForm"   type="warning">保存</el-button>
        <el-button   @click="handleClose"  type="info" plain>取消</el-button>
      </el-form-item>
    </el-form>

  </el-dialog>
</template>

<script>

export default {
    name: "dig-save",
    mounted:function(){

    },
    methods: {

      submitForm() {

        this.$refs['formRef'].validate((valid) => {
          if(!valid){return;}
          let dictData = this.$parent.queryParam || {};
          let nullValues = Object.values(dictData).every( item => item==='');
          if(nullValues) {
            this.$message.warning('筛选条件为空');
            return;
          }
          let param = {
            moduleId: '3110', //模块id
            moduleName: 'CUSTOMER', //模块名称
            collectName: this.paramForm.collectName, //条件名称
            collectData: JSON.stringify(dictData), //字典保存内容，将条件转换成JSON格式
            isDefault: 0,
            status: 1,
          };
          this.$ajax.post({
            domain: 'crmCmUrl',
            url: 'collect.saveCollect',
            data: JSON.stringify(param),
            requestType: 'body',
            showLoad: true,
            success: function (res) {
              if (res.errorCode === 200) {
                this.$message.success('保存成功');
                this.visible = false;
              }
            }.bind(this),
            error: function (res) {
              this.$message.error( res.body.msg || res.msg);
            }.bind(this)
          })
       });
      },
      //关闭弹窗
      handleClose() {
        this.$refs.formRef.resetFields();
        this.paramForm.collectName = '';
        this.visible = false;
      },
    },
    data() {
      return {
        visible: false,
        paramForm: {
          collectName: '',
        },
        // 表单具体校验
        rules: {
          collectName: [  {required: true, message: '请输入条件名称', trigger: 'blur'} ],
        },
      }
    },


}
</script>

<style type="text/css"  lang="scss">

</style>
