liyanqi
2022-11-01 e5b58707bae2d4e153560f51ed38859c530e9a66
src/views/operate/rectification/surveyList/components/createInterface/index.vue
@@ -2,49 +2,71 @@
    <div class="createmyInterface">
        <main>
            <div class="mainContent">
                <el-form ref="user" label-width="140px" autoComplete="on" :model="myInterface"
                    :rules="createmyInterfaceRules" label-position="right">
                    <!-- 应用名称 -->
                    <el-form-item label="应用名称:" prop="applicationName">
                        <el-input v-model="myInterface.applicationName" placeholder="填写应用名称"></el-input>
        <el-form
          ref="survey"
          label-width="140px"
          autoComplete="on"
          :model="myInterface"
          :rules="createSurvey"
          label-position="right"
        >
          <el-form-item class="optionItem" label="问题类型:" prop="type">
            <el-select v-model="myInterface.type" placeholder="请选择问题类型">
              <el-option label="问题类型一" value="shanghai"></el-option>
              <el-option label="问题类型二" value="beijing"></el-option>
            </el-select>
                    </el-form-item>
                    <!-- 应用图标 -->
                    <el-form-item label="应用图标:" prop="applicationIconUrl">
                        <div class="iconBox">
                            <div class="upload">
                                <img src="@/assets/imgs/user/default-avatar.jpg" alt="">
                            </div>
                            <div class="iconView">
                                <span>示意图</span>
                                <img src="@/assets/imgs/user/default-avatar.jpg" alt="">
                            </div>
                            <div class="tip">
                                <span>只允许上传jpg,jpeg,png,svg格式的图片,建议尺寸为105px*105px</span>
                            </div>
          <el-form-item class="optionItem" label="大类:" prop="bigclass">
            <el-select v-model="myInterface.bigclass" placeholder="请选择大类">
              <el-option label="大类一" value="shanghai"></el-option>
              <el-option label="大类二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="optionItem" label="小类:" prop="subclass">
            <el-select v-model="myInterface.subclass" placeholder="请选择小类">
              <el-option label="小类一" value="shanghai"></el-option>
              <el-option label="小类二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="optionItem" label="街道:" prop="street">
            <el-input
              v-model="myInterface.street"
              placeholder="请填写街道"
            ></el-input>
          </el-form-item>
          <el-form-item class="optionItem" label="社区:" prop="community">
            <el-input
              v-model="myInterface.community"
              placeholder="请填写社区"
            ></el-input>
          </el-form-item>
          <el-form-item class="optionItem" label="任务描述:" prop="task">
            <el-input
              v-model="myInterface.task"
              placeholder="请填写任务描述"
            ></el-input>
          </el-form-item>
          <el-form-item class="optionItem" label="上报时间:" prop="reportTime">
            <div class="block">
              <el-date-picker
                v-model="myInterface.reportTime"
                type="datetime"
                placeholder="选择日期时间"
              >
              </el-date-picker>
                        </div>
                    </el-form-item>
                    <!-- 应用类型 -->
                    <el-form-item label="应用类型:" prop="applicationType">
                        <div class="optionItem">
                            <el-radio-group v-model="myInterface.applicationType">
                                <el-radio :label="1">网页应用</el-radio>
                            </el-radio-group>
                        </div>
                    </el-form-item>
                    <!--网站url  -->
                    <el-form-item label="网站url:" prop="websiteUrl">
                        <el-input v-model="myInterface.websiteUrl"></el-input>
                    </el-form-item>
                    <!-- 应用描述 -->
                    <el-form-item label="应用描述:" prop="description">
                        <el-input v-model="myInterface.description" placeholder="请填写描述"></el-input>
                    </el-form-item>
                    <!-- 按钮 -->
                    <el-form-item>
                        <div class="optionBtn">
                            <el-button type="primary" class="btn submit" @click.native.prevent="handleUser">提交
              <el-button class="btn cancel" @click.native.prevent="handleCancel"
                >取消</el-button
              >
              <el-button
                type="primary"
                class="btn submit"
                @click.native.prevent="handleSave"
                >保存
                            </el-button>
                            <el-button class="btn reset">重置</el-button>
                        </div>
                    </el-form-item>
                </el-form>
@@ -55,85 +77,126 @@
<script>
export default {
    data() {
        const validateApplicationName = (rule, value, callback) => {
    const validateType = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写用户名称"));
        callback(new Error("请选择问题类型"));
            }
        };
        const validateApplicationIconUrl = (rule, value, callback) => {
    const validateBigClass = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写登录密码"));
            } else {
                const rep = /^\w+$/;
                if (!rep.test(value)) {
                    callback(new Error("密码只能是以数字、26个英文字母或者下划线组成的字符串"));
                }
        callback(new Error("请选择大类"));
            }
        };
        const validateApplicationType = (rule, value, callback) => {
    const validateSubClass = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写用户姓名"));
            } else {
                const rep = /^[\u4E00-\u9FA5]{2,4}$/;
                if (!rep.test(value)) {
                    callback("请输入正确的用户姓名");
                }
        callback(new Error("请选择小类"));
            }
        };
        const validatePhone = (rule, value, callback) => {
    const validateStreet = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写手机号码"));
            } else {
                const rep = /(^1[3|4|5|7|8|9]\d{9}$)|(^09\d{8}$)/
                if (!rep.test(value)) {
                    callback("请输入正确的手机号码");
                }
        callback(new Error("请填写街道"));
            }
        };
    const validateCommunity = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请填写社区"));
      }
    };
    const validateTask = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请填写任务描述"));
      }
    };
    const validateReportTime = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请选择任务上报时间"));
      }
    };
        return {
            myInterface: {
        num: "",
        type: "",
        bigclass: "",
        subclass: "",
        street: "",
        community: "",
        task: "",
        reportTime: "",
            },
            createmyInterfaceRules: {
                applicationName: [
                    { required: true, trigger: "blur", validator: validateApplicationName},
      createSurvey: {
        type: [
          {
            required: true,
            trigger: "blur",
            validator: validateType,
          },
                ],
                applicationIconUrl: [
                    { required: true, trigger: "blur", validator: validateApplicationIconUrl },
        bigclass: [
          {
            required: true,
            trigger: "blur",
            validator: validateBigClass,
          },
                ],
                applicationType: [
                    { required: true, trigger: "blur", validator: validateApplicationType },
        subclass: [
          {
            required: true,
            trigger: "blur",
            validator: validateSubClass,
          },
                ],
                websiteUrl: [
                    { required: true, trigger: "blur" },
        street: [
          { required: true, trigger: "blur", validator: validateStreet },
                ],
                description: [
                    { required: false, trigger: "blur" },
        community: [
          { required: true, trigger: "blur", validator: validateCommunity },
        ],
        task: [{ required: true, trigger: "blur", validator: validateTask }],
        reportTime: [
          { required: true, trigger: "blur", validator: validateReportTime },
                ],
            },
        }
    };
    },
    created() {
        const that = this;
    },
    methods: {
        handleUser() {
    // 关闭弹窗
    handleCancel() {
        console.log(1);
      this.$emit("closeDialog", { flag: false, index: 0 });
    },
    //保存
    handleSave() {
            const { myInterface } = this;
            this.$axios.post('sccg/system/portal/thirdApp/add', {
                websiteUrl:myInterface.websiteUrl,
                applicationIconUrl:myInterface.applicationIconUrl,
                applicationType:0,
                description:myInterface.description,
                applicationName:myInterface.applicationName
            }).then(res => {
                console.log(res);
                // if (res.code === 200) {
                //     this.refresh();
                // }
            })
        },
    },
    props: ['refresh']
        this.$refs.survey.validate((flag)=>{
            console.log(flag)
            if(flag){
            }else{
                return false
}
        })
    //   this.$axios
    //     .post("sccg/system/portal/thirdApp/add", {
    //       websiteUrl: myInterface.websiteUrl,
    //       applicationIconUrl: myInterface.applicationIconUrl,
    //       applicationType: 0,
    //       description: myInterface.description,
    //       applicationName: myInterface.applicationName,
    //     })
    //     .then((res) => {
    //       console.log(res);
    //       // if (res.code === 200) {
    //       //     this.refresh();
    //       // }
    //     });
    },
  },
  props: ['refresh','closeDialog'],
};
</script>
<style lang="scss" scoped>
.createmyInterface {
@@ -244,7 +307,6 @@
                    flex: 2;
                }
            }
        }
    }