常见的手写功能

168 阅读1分钟

01行内三元表达式

<el-input :disabled="enterId ? true : false"/>
**<text :style="{'color':status === true ? 'blue':'red'}">按钮</text>**
{{scope.row.state == 0?“已完成”:scope.row.state == 1?“未完成”:‘处理中’}}
**deleteData({
          enterId: item.enterId,
          status: (item.status == 1 ? 0 : 1)
        })**
        // 这个不是三元表达式但是都加了小括号
        res.result.contact.forEach((item) => {
              item.contactMobile && (item.contactMobile = aesDt(item.contactMobile));
            });

02删除添加联系人

<el-form-item class="form-item-style2" v-for="(item, index) in form.contact" :key="index">
        <el-form-item :label="'企业联系人'+ (index + 1)" label-width="140px" >
          <el-input v-model="item.contactName" :maxlength="20" placeholder="请输入" />
        </el-form-item>
        <el-form-item :label="'企业联系人电话'+ (index + 1)" label-width="140px" >
          <el-input v-model="item.contactMobile" :maxlength="11" placeholder="请输入" />
        </el-form-item>
        <span class="icon-delete" v-if="index > 0" @click="deleteLiaisonMan(index)" />
      </el-form-item>

      <el-form-item v-show="form.contact.length < 3" label="" label-width="140px" class="form-item-style2">
        <div class="item-style-wrapper" @click="addLiaisonMan">
          <span class="icon-add" /><span>新增联系人</span>
        </div>
      </el-form-item>
// 删除企业联系人
    deleteLiaisonMan(index) {
      this.form.contact.splice(index, 1);
    },
addLiaisonMan() {
      this.form.contact.push({
        contactId: '',
        contactName: '',
        contactMobile: '',
      });
    },

03自定义点确定上传文件

<el-form-item style="margin-bottom: 0" label="上传文件">
          <el-upload
            ref="upload"
            action
            :on-change="fileChange"
            accept=".xls,.xlsx"
            :file-list="fileList"
            :show-file-list="false"
            :auto-upload="false"
          >
            <el-button slot="trigger" plain size="small"
              ><i class="el-icon-upload2 el-icon--left"></i>上传文件</el-button
            >
            <el-button
              style="margin-left: 16px"
              type="text"
              @click="downloadTem"
              >下载文件模版</el-button
            >
          </el-upload>
        </el-form-item>
fileChange(file,filelist){
      console.log(file,filelist);
      this.tempData = file.raw
      this.disable = false
uploadSectionFile() {
const form = new FormData();
      // 文件对象
      console.log(this.tempData);
      form.append('file',this.tempData)
      
      // console.log(form);
      serviceApi.importEnterprise(form)
        .then((res) => {
          //自行处理各种情况
          console.log(res);
          const code = res && parseInt(res.code, 10);
          if (code === 200) {
            this.$message({
              message: "导入成功!",
              type: "success",
            });
            this.showExportData = false
          } else {
            this.$message({
            message: res.message,
            type: "warning",
          });
          }
        })
        .catch((err) => {
          console.log("err", err);
        });
    },