<template>
  <div class="question-wrap">
    <bread-crumb :curmbFirst="curmbFirst" :curmbSecond="curmbSecond">
    </bread-crumb>
    <div class="question-content screenSet" id="screenSet">
      <el-row :gutter="30" class="row" type="flex" style="margin-top: 10px;">
        <el-form
          ref="serchForm"
          :model="searchParam"
          label-width="75px"
          label-suffix=":"
          style="width:100%;"
        >
          <el-col :span="6">
            <el-form-item label="问卷名称">
              <el-input
                v-model="searchParam.name"
                size="mini"
                placeholder="请输入问卷名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="状态">
              <el-select
                clearable
                v-model="searchParam.status"
                size="mini"
                placeholder="请选择问卷状态"
              >
                <el-option
                  v-for="(item, index) in statuSelect"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" style="text-align:right;padding:0 30px 15px 0;">
            <el-button type="primary" size="small" @click="search(1)"
              >查询</el-button
            >
            <el-button type="default" size="small" @click="reset"
              >重置</el-button
            >
          </el-col>
        </el-form>
      </el-row>
      <el-button
        class="add-question"
        type="primary"
        size="small"
        @click="addQuestion"
        >新增问卷</el-button
      >
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column
          prop="id"
          label="问卷编号"
          min-width="50"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="name"
          label="问卷名称"
          min-width="100"
          align="center"
        ></el-table-column>
        <el-table-column label="最后修改人" min-width="50" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.modifiedId | modifyType(modifyArray) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="最后修改时间" min-width="100" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.modifiedTime | liveDateFilter }}</span>
          </template>
        </el-table-column>
        <el-table-column label="问卷状态" min-width="80" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.status | questionStatus }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          fixed="right"
          align="center"
          min-width="200"
        >
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="small"
              @click="editQuestion(scope.row)"
              >编辑</el-button
            >
            <el-button
              type="primary"
              v-show="scope.row.status == 1"
              size="small"
              @click="onAndDownLine(scope.row)"
              >上线
            </el-button>
            <el-button
              type="primary"
              v-show="scope.row.status == 2"
              size="small"
              @click="onAndDownLine(scope.row)"
              >下线
            </el-button>
            <el-button
              v-show="scope.row.showFlag == 1"
              type="primary"
              size="small"
              @click="gotoInfoList(scope.row.id)"
              >数据查看
            </el-button>
            <!-- <el-button type="primary" size="small" @click="reviewQuestion(scope.row)">查看题库</el-button> -->
          </template>
        </el-table-column>
        <div slot="empty">
          <div class="table-empty">
            <img src="../../assets/image/no-content1.png" />
            <p>没有查询到相关结果</p>
          </div>
        </div>
      </el-table>
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="searchParam.pageNo"
          :page-sizes="[15, 30, 50, 100, 200, 500, 700, 1000, 1500, 2000]"
          :page-size="searchParam.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalRows"
        >
        </el-pagination>
      </div>
    </div>
    <!-- 问卷新增(编辑) -->
    <el-dialog
      class="img-edit"
      :title="questionTitle"
      :visible.sync="discussEditVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form
        ref="questionForm"
        :rules="rules"
        :model="questionEditList"
        label-width="220px"
        label-suffix=":"
        size="mini"
      >
        <el-form-item>
          <el-radio-group
            v-model="questionEditList.showType"
            style="margin-left: -65px;"
            :disabled="formStatus != 'create'"
          >
            <el-radio :label="1">单题显示</el-radio>
            <el-radio :label="2">平铺显示</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="问卷标题" prop="name">
          <el-input
            v-model="questionEditList.name"
            maxlength="30"
            placeholder="标题最多30字符"
            style="width: 300px;"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="题库导入" prop="fileName">
          <el-col :span="12">
            <el-input
              class="form-input"
              :placeholder="excelFileName"
              v-model="fileName"
              disabled
              style="width: 99%;"
            />
          </el-col>
          <el-col :span="10">
            <el-upload
              class="upload-demo"
              style="display: inline-block;width: 80px;"
              action="#"
              accept=".xlsx"
              :before-upload="beforeImport"
              :limit="1"
            >
              <el-button type="primary" size="mini">导入题库</el-button>
            </el-upload>
            <el-button type="default" size="mini" @click="uploadTemplate"
              >模板下载</el-button
            >
          </el-col>
        </el-form-item>
        <el-form-item
          label="下一题按钮"
          v-show="questionEditList.showType == 1"
        >
          <div class="submit-btn" style="margin-right:20px;">
            <p>置灰不可点</p>
            <el-upload
              v-model="questionEditList.nextDisableClickUrl"
              class="avatar-uploader"
              action="#"
              :show-file-list="false"
              :before-upload="beforeAvatarUpload_1"
            >
              <el-button size="mini" type="primary">上传</el-button>
            </el-upload>
            <div class="uploat-content">
              <img
                v-show="questionEditList.nextDisableClickUrl"
                :src="questionEditList.nextDisableClickUrl"
                class="bg-img"
              />
              <img
                v-show="!questionEditList.nextDisableClickUrl"
                class="bg-img"
                src="https://files.yunqueyi.com/image/png/common/20190408164003674.png"
              />
            </div>
          </div>
          <div class="submit-btn">
            <p>点亮可点</p>
            <el-upload
              v-model="questionEditList.nextClickUrl"
              class="avatar-uploader"
              action="#"
              :show-file-list="false"
              :before-upload="beforeAvatarUpload_2"
            >
              <el-button size="mini" type="primary">上传</el-button>
            </el-upload>
            <div class="uploat-content">
              <img
                v-show="questionEditList.nextClickUrl"
                :src="questionEditList.nextClickUrl"
                class="bg-img"
              />
              <img
                v-show="!questionEditList.nextClickUrl"
                class="bg-img"
                src="https://files.yunqueyi.com/image/png/common/20190408164015812.png"
              />
            </div>
          </div>
        </el-form-item>
        <el-form-item label="问卷导言" v-show="questionEditList.showType == 2">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3 }"
            v-model="questionEditList.questionIntro"
            maxlength="210"
            placeholder="最多210字符"

          ></el-input>
        </el-form-item>
        <el-form-item
          label="业务类型"
          v-show="questionEditList.showType == 2"
          prop="bizType"
        >
          <el-radio-group
            v-model="questionEditList.bizType"
            :disabled="formStatus != 'create'"
          >
            <el-radio :label="0">普通问卷</el-radio>
            <el-radio :label="1">招募问卷</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="是否需要审核"
          v-show="questionEditList.showType == 2"
          prop="bizType"
        >
          <el-radio-group
            v-model="questionEditList.auditFlag"
            :disabled="formStatus != 'create'"
            @change="addAuditFlag"
          >
            <el-radio :label="2">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="填写完是否需要提示用户分享"
          v-show="questionEditList.showType == 2"
        >
          <el-radio-group
            v-model="questionEditList.shareFlag"
            :disabled="formStatus != 'create'"
          >
            <el-radio :label="2">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="分享地址" class="spe-label-require" v-show="questionEditList.showType == 2 && questionEditList.shareFlag == 1">
          <el-input
            v-model="questionEditList.shareUrl"
            style="width: 300px;">
          </el-input>
        </el-form-item>
        <el-form-item label="分享的标题" class="spe-label-require" v-show="questionEditList.showType == 2 && questionEditList.shareFlag == 1">
          <el-input
            v-model="questionEditList.shareTitle"
            style="width: 300px;">
          </el-input>
        </el-form-item>
        <el-form-item label="分享的描述" class="spe-label-require" v-show="questionEditList.showType == 2 && questionEditList.shareFlag == 1">
          <el-input
            v-model="questionEditList.shareIntro"
            style="width: 300px;">
          </el-input>
        </el-form-item>
        <el-form-item label="基本信息" v-show="questionEditList.showType == 2">
          <el-checkbox v-model="userBase.name" label="true">姓名</el-checkbox>
          <el-checkbox v-model="userBase.mobile" label="true"
            >手机号</el-checkbox
          >
          <el-checkbox v-model="userBase.address" label="true"
            >地址</el-checkbox
          >
        </el-form-item>
        <div v-show="questionEditList.showType == 2">
          <el-form-item class="submit-btn" label="头图">
            <el-upload
              v-model="questionEditList.headDiagramUrl"
              class="avatar-uploader"
              action="#"
              :show-file-list="false"
              :before-upload="beforeAvatarUpload_4"
            >
              <el-button class="head-btn" size="mini" type="primary"
                >上传</el-button
              >
            </el-upload>
            <div class="uploat-content">
              <img
                v-show="questionEditList.headDiagramUrl"
                :src="questionEditList.headDiagramUrl"
                class="head-bg-img"
              />
              <img
                v-show="!questionEditList.headDiagramUrl"
                class="head-bg-img"
                src="../../assets/image/default.png"
              />
            </div>
          </el-form-item>
        </div>
        <el-form-item class="submit-btn" label="提交按钮">
          <el-upload
            v-model="questionEditList.submitButtomUrl"
            class="avatar-uploader"
            action="#"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload_3"
          >
            <el-button size="mini" type="primary">上传</el-button>
          </el-upload>
          <div class="uploat-content">
            <img
              v-show="questionEditList.submitButtomUrl"
              :src="questionEditList.submitButtomUrl"
              class="bg-img"
            />
            <img
              v-show="!questionEditList.submitButtomUrl"
              class="bg-img"
              src="https://files.yunqueyi.com/image/png/common/20190408164026451.png"
            />
          </div>
        </el-form-item>
        <el-form-item label="问卷填写完毕提示文案" prop="promptCopy">
          <el-input
            v-model="questionEditList.promptCopy"
            maxlength="40"
            style="width: 300px;"
          ></el-input>
          <span style="font-size:12px;">限40字符</span>
        </el-form-item>

        <el-form-item
          label="登录权限控制"
          v-show="questionEditList.showType == 2"
        >
          <el-checkbox-group v-model="loginAuthList" class="login-auth" >
            <el-checkbox label="1" :disabled="questionEditList.auditFlag==1">云鹊医APP</el-checkbox>
            <el-checkbox label="2" :disabled="questionEditList.auditFlag==1">云鹊医H5</el-checkbox>
          </el-checkbox-group>
           <p style="color:red;">注意：如不勾选登录权限则用户信息记录为游客</p>
        </el-form-item>
        <el-form-item
          label="问卷填写次数"
          v-show="questionEditList.showType == 2"
          prop="limitNum"
        >
          <el-radio v-model="questionEditList.limitNumFlag" label="0" :disabled="questionEditList.auditFlag==1">
            <el-input
              v-model="questionEditList.limitNum"
              controls-position="right"
              :min="1"
              style="width: 100px;"
              @blur="checkLimitNum"
              @focus="beforeInputLimitNum"
              :disabled="questionEditList.auditFlag==1"
            ></el-input>
          </el-radio>
          <el-radio v-model="questionEditList.limitNumFlag" label="1" :disabled="questionEditList.auditFlag==1"
            >不限制填写次数</el-radio
          >
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <el-button
          type="primary"
          size="small"
          @click="submitQuestion"
          style="width:120px;"
          >提交</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import BreadCrumb from "../../components/breadcrumb.vue";
import * as commonUtil from "../../utils/utils";
import { getFilePath, doUpload } from "../../utils/qiniu-util";
import { QUESTION_UPLOAD_TEMPLATE } from "../../utils/constants";
let vm = null;
export default {
  components: {
    BreadCrumb
  },
  data() {
    return {
      curmbFirst: "组件",
      curmbSecond: "问卷管理",
      questionTitle: "问卷新增/编辑",
      discussEditVisible: false,
      excelFileName: "",
      fileName: "",
      fileArray: [],
      tableData: [],
      totalRows: 0,
      loading: false,
      searchParam: {
        name: "",
        status: "",
        pageSize: 15,
        pageNo: 1
      },
      modifyArray: [],
      questionEditList: {
        id: "",
        showType: 1,
        name: "",
        nextDisableClickUrl: "",
        nextClickUrl: "",
        submitButtomUrl: "",
        promptCopy: "",
        headDiagramUrl: "",
        questionIntro: "",
        bizType: 0, //业务类型  0普通 ，1 招募
        limitNumFlag: "0", //填写次数flag
        limitNum: 1, //填写次数
        auditFlag: 2,
        shareFlag: 2,
        shareUrl: '',
        shareTitle: '',
        shareIntro: '',
      },
      formStatus: "create",
      loginAuthList: [], //登录权限控制
      userBase: {}, //基本信息
      rules: {
        name: [
          {
            required: true,
            message: "请输入问卷标题",
            trigger: "blur"
          }
        ],
        promptCopy: [
          {
            required: true,
            message: "请输入问卷填写完毕提示文案",
            trigger: "blur"
          }
        ],
        bizType: [
          {
            required: true,
            message: "请选择业务类型",
            trigger: "blur"
          }
        ],
        limitNum: [
          {
            required: true
          }
        ]
      },
      statuSelect: [
        {
          label: "下线",
          value: 1
        },
        {
          label: "上线",
          value: 2
        }
      ]
    };
  },
  created() {
    vm = this;
    vm.search();
    vm.getAllModify();
  },
  // 挂载到Dom完成时
  mounted: function() {
    commonUtil.resizeHeight();
  },
  methods: {
    addAuditFlag() {
      if(this.questionEditList.auditFlag == 1) {
        vm.loginAuthList = ["1","2"];
        vm.questionEditList.limitNumFla = '1';
        vm.questionEditList.limitNum = 1;
      } else {

      }
    },
    // 查询
    search(flag) {
      if (flag) vm.searchParam.pageNo = 1;
      vm.GET("/campaign/adminQuestionnaire/queryList", vm.searchParam).then(
        res => {
          if (res.code == "000000") {
            vm.tableData = res.data.questionnaireList;
            vm.totalRows = res.data.total;
          }
        }
      );
    },
    handleSizeChange(value) {
      vm.searchParam.pageSize = value;
      vm.search();
    },
    handleCurrentChange(value) {
      vm.searchParam.pageNo = value;
      vm.search();
    },
    reset() {
      vm.searchParam.name = "";
      vm.searchParam.status = "";
      vm.search();
    },
    // 获取所有修改人
    getAllModify() {
      vm.GET("/campaign/adminQuestionnaire/getAllUser").then(res => {
        if (res.code == "000000") {
          vm.modifyArray = res.data;
        }
      });
    },
    // 新增问卷
    addQuestion() {
      vm.discussEditVisible = true;
      vm.formStatus = "create";
      if (vm.$refs.questionForm !== undefined) {
        vm.$refs.questionForm.resetFields();
      }
      vm.questionEditList = Object.assign(
        {},
        {
          id: "",
          showType: 1,
          name: "",
          nextDisableClickUrl: "",
          nextClickUrl: "",
          submitButtomUrl: "",
          promptCopy: "您已成功提交问卷，感谢您的参与！",
          headDiagramUrl: "",
          questionIntro: "",
          bizType: 0,
          limitNumFlag: "0",
          limitNum: 1,
          auditFlag: 2,
          shareFlag: 2,
          shareUrl: '',
          shareTitle: '',
          shareIntro: '',
        }
      );
      vm.loginAuthList = ["1"];
      vm.userBase = Object.assign(
        {},
        {
          address: false,
          mobile: false,
          name: false
        }
      );
      vm.fileName = "";
      vm.fileArray = [];
      vm.excelFileName = "";
    },
    // 编辑
    editQuestion(row) {
      if (vm.$refs.questionForm !== undefined) {
        vm.$refs.questionForm.resetFields();
      }
      vm.discussEditVisible = true;
      vm.formStatus = "edit";
      vm.excelFileName = "";
      vm.fileName = "";
      vm.fileArray = [];

      vm.GET("/campaign/adminQuestionnaire/getQuestionnaireById", {
        id: row.id
      }).then(res => {
        if (res.code == "000000") {
          // console.log(res.data);
          let { questionnaireInfo, loginAuthInfo } = res.data.data;
          vm.questionEditList = Object.assign({}, questionnaireInfo);

          vm.questionEditList = Object.assign({}, vm.questionEditList, {
            questionIntro: questionnaireInfo.questionIntro.replace(
              /<br>/g,
              "\n"
            ),
            limitNumFlag: questionnaireInfo.limitNum < 1 ? "1" : "0",
            limitNum:
              questionnaireInfo.limitNum < 1 ? 1 : questionnaireInfo.limitNum
          });

          const userBaseData = JSON.parse(questionnaireInfo.userBase);
          vm.userBase = Object.assign({}, vm.userBase, {
            address: Boolean(userBaseData.address),
            mobile: Boolean(userBaseData.mobile),
            name: Boolean(userBaseData.name)
          });

          vm.loginAuthList = loginAuthInfo;
        }
      });
    },
    // 上线/下线
    onAndDownLine(row) {
      let req = null;
      if (row.status == 1) {
        req = {
          id: row.id,
          status: 2
        };
      } else {
        req = {
          id: row.id,
          status: 1
        };
      }
      vm.GET("/campaign/adminQuestionnaire/upperOrLowerShip", req).then(res => {
        if (res.code == "000000") {
          vm.search();
        }
      });
    },
    gotoInfoList(infoId) {
      this.$router.push({path: '/discuss-info-list',query:{id:infoId}})
    },
    // 导入题库
    beforeImport(file) {
      if (commonUtil.isEmptyUtils(file)) return;
      let arr = file.type.split("/");
      let ext = "." + arr[1];
      let reader = new FileReader();
      reader.onload = function(e) {
        let fileJson = {
          fileName: file.name,
          file: e.target.result.substr(e.target.result.indexOf("base64,") + 7),
          ext: ext
        };
        vm.fileArray = [
          {
            base64: fileJson
          }
        ];
        vm.fileName = file.name;
        vm.excelFileName = file.name;
        vm.$message.info("读取完毕");
      };
      reader.readAsDataURL(file);
      return false;
    },
    // 模板下载
    uploadTemplate() {
      window.location.href = QUESTION_UPLOAD_TEMPLATE;
    },
    // 置灰不可点图片上传
    beforeAvatarUpload_1(file) {
      if (commonUtil.isEmptyUtils(file)) return;
      vm.imgDoUpload(file, 1, 50, 750, 100);
      return false;
    },
    // 点亮图片上传
    beforeAvatarUpload_2(file) {
      if (commonUtil.isEmptyUtils(file)) return;
      vm.imgDoUpload(file, 2, 50, 750, 100);
      return false;
    },
    // 提交图片上传
    beforeAvatarUpload_3(file) {
      if (commonUtil.isEmptyUtils(file)) return;
      vm.imgDoUpload(file, 3, 50, 690, 88);
      return false;
    },
    // 头图图片上传
    beforeAvatarUpload_4(file) {
      if (commonUtil.isEmptyUtils(file)) return;
      vm.imgDoUpload(file, 4, 100, 750, -1);
      return false;
    },
    imgDoUpload(file, urlType, size, w, h) {
      const isSize = file.size / 1024 < size;
      if (!isSize) {
        vm.$message.info("上传图片要小于" + size + "k");
        return;
      }
      var _img = new FileReader();
      _img.readAsDataURL(file);
      _img.onload = function(theFile) {
        let image = new Image();
        image.src = theFile.target.result;
        image.onload = function() {
          let _this = this;
          let uploadFlag = false;
          if (h == -1) {
            if (_this.width != w) {
              vm.$message.info("上传图片宽度应为" + w + "，请重新上传");
            } else {
              uploadFlag = true;
            }
          } else {
            if (_this.width != w || _this.height != h) {
              vm.$message.info(
                "上传图片尺寸应为" + w + "*" + h + "，请重新上传"
              );
            } else {
              uploadFlag = true;
            }
          }
          if (uploadFlag) {
            vm.$message.info("开始上传");
            doUpload(
              vm,
              file,
              getFilePath(file, null),
              "preview4",
              "progress1",
              1
            ).then(function(path) {
              if (urlType == 1) {
                vm.questionEditList.nextDisableClickUrl = path.fullPath;
              } else if (urlType == 2) {
                vm.questionEditList.nextClickUrl = path.fullPath;
              } else if (urlType == 3) {
                vm.questionEditList.submitButtomUrl = path.fullPath;
              } else {
                vm.questionEditList.headDiagramUrl = path.fullPath;
              }
              vm.$message.success("上传成功");
            });
          }
        };
      };
    },
    // 提交
    submitQuestion() {
       if (vm.questionEditList.showType == 1) {
        // 单题显示
        vm.questionEditList.questionIntro = "";
        vm.questionEditList.headDiagramUrl = "";
      } else {
        vm.questionEditList.nextDisableClickUrl = "";
        vm.questionEditList.nextClickUrl = "";
      }
      if (!vm.questionEditList.id) {
        if (commonUtil.isEmptyList(vm.fileArray)) {
          vm.$message.info("请导入题库");
          return;
        }
      }
      if (vm.questionEditList.showType == 2) {
         if (vm.questionEditList.shareFlag == 1) {
           if (vm.questionEditList.shareUrl == '') {
             vm.$message.info("请填写分享地址");
             return;
           }
           if (vm.questionEditList.shareTitle == '') {
             vm.$message.info("请填写分享标题");
             return;
           }
           if (vm.questionEditList.shareIntro == '') {
             vm.$message.info("请填写分享描述");
             return;
           }
         }else {
           vm.questionEditList.shareUrl = '';
           vm.questionEditList.shareTitle = '';
           vm.questionEditList.shareIntro = '';
         }
      }
      let req = {
        model: JSON.parse(JSON.stringify(vm.questionEditList)),
        fileArray: vm.fileArray,
        loginAuth: []
      };
      if (vm.questionEditList.limitNumFlag == 1) {
        req.model.limitNum = -1;
      }
      let reqUserBase = Object.assign({}, vm.userBase, {
        address: Number(vm.userBase.address),
        mobile: Number(vm.userBase.mobile),
        name: Number(vm.userBase.name)
      });
      req.model.userBase = JSON.stringify(reqUserBase);
      vm.loginAuthList.map(u => {
        req.loginAuth.push({
          value: u
        });
      });
      req.model.questionIntro = vm.questionEditList.questionIntro.replace(
        /\n/g,
        "<br>"
      );
      // console.log(req);


      vm.$refs.questionForm.validate(valid => {
        //console.log(this.discussEditVisible)
        if (valid) {
          if (vm.formStatus === 'create' && vm.questionEditList.showType == 2) {
            vm.$confirm('业务类型提交后无法再次修改, 请确认是否提交?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            })
              .then(() => {
                commonUtil.openLoading(vm)
                vm.POST(
                  '/campaign/adminQuestionnaire/insertOrUpdateQuestionnaire',
                  req
                ).then(res => {
                  commonUtil.closeLoading(vm)
                  if (res.code == '000000') {
                    vm.discussEditVisible = false
                    vm.$message({
                      type: 'success',
                      message: '操作成功'
                    })
                    vm.search()
                  } else {
                    vm.$message.info(res.message)
                  }
                })
              })
              .catch(() => {
                vm.$message({
                  type: 'info',
                  message: '已取消提交'
                })
              })
          } else {
            commonUtil.openLoading(vm)
            vm.POST(
              '/campaign/adminQuestionnaire/insertOrUpdateQuestionnaire',
              req
            ).then(res => {
              commonUtil.closeLoading(vm)
              if (res.code == '000000') {
                vm.discussEditVisible = false
                vm.$message({
                  type: 'success',
                  message: '操作成功'
                })
                vm.search()
              } else {
                vm.$message.info(res.message)
              }
            })
          }
        }
      })
    },
    // 校验输入数字为正整数
    checkLimitNum() {
      const regexp = /^[1-9]\d*$/;
      if (!regexp.test(vm.questionEditList.limitNum)) {
        vm.questionEditList = Object.assign({}, vm.questionEditList, {
          limitNum: 1
        });
      }
    },
    // foucs选中则改变radio
    beforeInputLimitNum() {
      vm.questionEditList = Object.assign({}, vm.questionEditList, {
        limitNumFlag: "0"
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.question-wrap {
  .question-content {
    background: #fff;

    .add-question {
      float: right;
      margin: 10px;
    }

    .table-empty {
      img {
        width: 100px;
      }

      p {
        margin-top: -50px;
      }
    }
  }

  .submit-btn {
    display: inline-block;
    overflow: hidden;

    p {
      font-size: 12px;
    }

    .avatar-uploader {
      float: right;

      .el-button {
        margin-left: 10px;
      }

      .head-btn {
        margin-top: 48px !important;
      }
    }

    .uploat-content {
      float: left;

      .bg-img {
        width: 150px;
        height: 30px;
      }

      .head-bg-img {
        width: 80px;
        height: 80px;
      }
    }
  }

  .login-auth {
    width: 400px;

    .el-checkbox {
      display: inline-block;
      width: 150px;
      text-align: left;
    }
  }
}
</style>
<style>
  .spe-label-require .el-form-item__label:before{
    content: '*';
    color: #F56C6C;
    margin-right: 4px;
  }
</style>
