friendGroupAdd.vue 12.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
<template>
  <div>
    <div class="container">
      <div class="title">
        编辑朋友圈
      </div>
      <!-- <input type="file" @change="uploadFile" /> -->
      <div class="info-box">
        <div class="info-content gl-form-page">
          <el-form class="basic-form" :model="basicForm" label-width="154px" :rules="basicRules" ref="groupForm">
            <el-form-item prop="taskName" label="群发名称:" size="small">
              <el-input v-model="basicForm.taskName" placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item prop="taskMerchantId" label="选择门店:" size="small">
              <el-select filterable v-model="basicForm.taskMerchantId" placeholder="请选择">
                <el-option v-for="item in optionsMe" :key="item.msgMerchantId" :label="item.msgMerchantName" :value="item.msgMerchantId"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="userList">
              <label slot="label" class="required">选择员工:</label>
              <el-button size="small" @click="openMembers">
                <i class="el-icon-plus"></i>
                选择员工
              </el-button>
              <div class="sale-select" v-show="basicForm.userList && basicForm.userList.length != 0">
                <div :key="key" class="el-input-tag input-tag-wrapper">
                  <el-tag effect="plain" type="info" v-for="(tag, idx) in basicForm.userList" :key="idx" closable :disable-transitions="false" @close="remove(tag, idx)">
                    <i class="el-icon-user-solid"></i>
                    {{ tag.staffName }}
                  </el-tag>
                </div>
              </div>
              <div v-show="empErrorShow" class="el-form-item__error">请选择员工</div>
            </el-form-item>
            <el-form-item prop="attachmentList">
              <label slot="label" class="required">朋友圈内容:</label>
              <GLEditor ref="welcome" :form="'customer'" :btnList="btnList" @previewWord="previewForm"></GLEditor>
              <div v-show="attachmentShow" class="el-form-item__error">{{ attachmentText }}</div>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <GLDialog bigTitle="选择成员" mode="big" :visible.sync="membersVisible" @onOk="handleConfirm" @onCancel="membersVisible = !membersVisible">
        <SelectMember ref="membersForm" v-if="membersVisible" :selectData="selectData"></SelectMember>
      </GLDialog>
    </div>
    <GLFooter>
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" v-loading="addLoading" @click="handleSubmit">提交</el-button>
    </GLFooter>
  </div>
</template>

<script>
const ATT_TYPE = {
  TEXT: 1,
  IMAGE: 2,
  VEDIO: 3,
  URL: 4,
  MINIPROGRAM: 5,
  FILE: 6,
  ACTIVITY: 7
}
import { utils } from 'glsx-common'
import department from '@/mixins/department'
import SelectMember from './components/selectMember.vue'
import * as dayjs from 'dayjs'
export default {
  mixins: [department],
  components: {
    SelectMember
  },
  data() {
    return {
      optionsMe: [],
      addLoading: false,
      taggingList: [],
      previewView: [],
      btnList: [
        {
          name: '表情',
          funcName: '',
          type: 'expression',
          limitSize: 10
        },
        {
          name: '图片',
          funcName: '',
          type: 'img',
          togetherItem: [ATT_TYPE.TEXT], //只允许文本和图片
          limitSize: 10, //限制图片大小
          limitNum: 9, //限制图片数量
          // limitWidth: 10000, //限制单张图片宽度
          // limitHeight: 10000,//限制单张图片高度
          Isdraggable: true, //图片拖拽
          uploadApi: this.$apis.common.pictureUpload
        },
        {
          name: '视频',
          funcName: '',
          type: 'video',
          limitSize: 10, //限制视频大小
          togetherItem: [ATT_TYPE.TEXT], //只允许文本和图片
          limitNum: 1, //限制视频数量
          limitWidth: 1280, //限制视频宽度
          limitHeight: 720, //限制视频高度
          limitTime: 30, //限制视频时长
          uploadApi: this.$apis.common.pictureUpload
        }
        // {
        //   name: '模板',
        //   type: 'message',
        //   funName: 'message',
        //   getSearchApi: this.$apis.welcomeword.createdNameList,
        //   templateApi: this.$apis.welcomeword.templatePage,
        //   templateUpdateApi: this.$apis.welcomeword.templateUpdate,
        //   templateSaveApi: this.$apis.welcomeword.templateSave,
        //   templateDetailApi: this.$apis.welcomeword.templateDetail
        // }
      ],
      basicForm: {
        userList: [],
        taskName: '',
        taskMerchantId: ''
      },
      attachmentShow: false,
      empErrorShow: false,
      attachmentText: '请输入朋友圈内容',
      basicRules: {
        taskMerchantId: [{ required: true, message: '请选择门店', trigger: 'change' }],
        taskName: [{ required: true, message: '请输入群发名称', trigger: 'blur' }]
      },
      membersVisible: false,
      groupList: [],
      key: new Date(),
      dialogVisible: false,
      previewFlag: false,
      selectData: [],
      // 是否有修改筛选成员
      isUpdate: true,
      tagging: [],
      groupNumber: 0,
      dateOptions: {
        disabledDate(time) {
          let now = new Date()
          now.setTime(now.getTime() - 3600 * 1000 * 24)
          return time.getTime() < now
        }
      },
      timeOptions: {
        selectableRange: '00:00:00 - 23:59:59'
      },
      editStatus: false,
      firstFlag: true,
      footerLeft: 40,
      footerWidth: 500,
      viewLoading: false
    }
  },
  watch: {
    basicForm: {
      handler(val) {
        if (this.firstFlag) {
          this.firstFlag = false
        } else {
          this.editStatus = true
        }
      },
      deep: true
    },
    'basicForm.userList'() {
      this.empErrorShow = false
    }
  },
  async mounted() {
    const merchantList = await this.merchantList()
    this.optionsMe = merchantList ? merchantList.data : []
  },
  methods: {
    // uploadFile(e) {
    //   const files = e.target.files
    //   var formData = new FormData()
    //   formData.append('file', files[0])
    //   formData.append('pic', files[0].name)
    //   formData.append('picWidth', 1080)
    //   formData.append('picHeight', 1920)
    //   fetch('http://192.168.1.170:8086/rpc-scrm-entmicro-container/picture/compression/upload', {
    //     method: 'post',
    //     body: formData
    //   })
    // },
    previewForm(val) {
      this.previewView = val
      this.attachmentShow = false
    },
    openMembers() {
      this.membersVisible = !this.membersVisible
    },
    handleCancel() {
      if (this.editStatus || this.$refs.welcome.previewList.length > 0) {
        this.$confirm('当前有内容信息未保存,是否继续返回?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.$router.push('/friendGroup/index')
          })
          .catch(() => {})
      } else {
        this.$router.push('/friendGroup/index')
      }
    },
    // 成员弹窗
    handleConfirm() {
      console.log(this.$refs.membersForm.innerTags)
      if (this.$refs.membersForm.innerTags.length) {
        // this.basicForm.userList = this.$refs.membersForm.innerTags
        this.$set(this.basicForm, 'userList', this.$refs.membersForm.innerTags)
        this.selectData = this.basicForm.userList
        this.openMembers()
        this.isUpdate = true
        this.editStatus = true
      } else {
        this.$message({
          type: 'error',
          message: '请选择成员'
        })
      }
    },
    remove(val, idx) {
      if (this.$refs.membersForm) {
        this.$refs.membersForm.remove(val)
        this.$set(this.basicForm, 'userList', this.$refs.membersForm.innerTags)
        this.key = new Date()
      } else {
        this.basicForm.userList.splice(idx, 1)
        this.selectData = this.basicForm.userList
        this.key = new Date()
      }
      this.isUpdate = true
    },
    handleSubmit: utils.debounce(function() {
      this.$refs.groupForm.validate(valid => {
        if (valid) {
          if (this.basicForm.userList.length == 0) {
            this.empErrorShow = true
            return
          }
          const previewList = this.$refs.welcome.previewList
          if (previewList.length == 0) {
            this.attachmentShow = true
            return
          }

          if (previewList.length != 0) {
            this.basicForm.attachmentList = previewList
          }
          let staffIds = this.basicForm.userList.map(item => {
            return item.staffId
          })
          let attachmentList = this.$refs.welcome.previewList
          const material = previewList.filter(item => item.attType != ATT_TYPE.TEXT)
          let materialType = 0
          if (material && material.length > 0) {
            switch (material[0].attType) {
              case ATT_TYPE.IMAGE:
                materialType = 1
                break
              case ATT_TYPE.VEDIO:
                materialType = 3
                break
              case ATT_TYPE.ACTIVITY:
                materialType = 4
                break
            }
          }
          if (material.length > 1) {
            materialType = 2
          }
          const { taskName, taskMerchantId } = this.basicForm
          const taskMerchantName = this.optionsMe.find(item => item.msgMerchantId == taskMerchantId).msgMerchantName
          let params = {
            materialType,
            attachmentList,
            staffIds,
            taskName,
            taskMerchantName,
            taskMerchantId
          }
          this.addLoading = true
          this.$apis.friendGroup.batchmomentSave(params).then(res => {
            this.addLoading = false
            if (res) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.$router.push('/friendGroup/index')
            }
          })
        }
      })
    }, 300)
  }
}
</script>

<style lang="scss" scoped>
.container {
  margin-bottom: 16px;
  background: #ffffff;
  box-shadow: 0 10px 20px 0 rgba(88, 80, 255, 0.1);
  // padding: 20px;
  .title {
    padding: 20px 0 17px 20px;
    font-size: 16px;
    color: #333;
    font-weight: 600;
    border-bottom: 1px solid #d8d8d8;
    > span {
      font-size: 14px;
      color: #999999;
      margin-left: 10px;
      font-weight: 100;
    }
  }
  .tips-text {
    display: flex;
    // align-items: center;
    justify-self: center;
    color: #000;
    font-size: 14px;
    padding: 6px 16px;
    margin-top: 10px;
    background-color: rgba(230, 233, 255, 0.49);
    border: 1px solid rgba(88, 80, 255, 0.49);
    border-radius: 4px;
    line-height: 24px;
    min-width: 488px;
    max-width: 844px;
    width: auto;
    box-sizing: border-box;
    .tips-icon {
      width: 14px;
      height: 14px;
      margin: 6px 8px 0 0;
    }
  }
  .info-box {
    .basic-form {
      padding: 32px 0 20px 20px;
    }
  }

  .form-tips {
    font-size: 12px;
    color: #999;
  }
  .preview {
    margin-right: 24px;
    margin-bottom: 100px;
  }
}
.label-text {
  margin-left: 10px;
  font-size: 14px;
  span {
    color: #5850ff;
  }
}
.sale-select {
  display: flex;
  align-items: center;
}
.input-tag-wrapper {
  max-height: 75px;
  overflow: auto;
  position: relative;
  font-size: 14px;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #666;
  display: inline-block;
  outline: none;
  padding: 5px 5px 0px 5px;
  flex-wrap: wrap;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 450px;
  display: flex;
  align-items: center;
  margin-top: 6px;
  font-size: 14px;
  i {
    color: #75acff;
    margin-right: 3px;
    font-size: 14px;
  }
}
.el-tag {
  margin-right: 4px;
  height: 26px;
  line-height: 24px;
  margin-bottom: 5px;
  // background: #fff !important;
}
.tag-input {
  background: transparent;
  border: none !important;
  font-size: 14px;
  height: 32px;
  outline: none;
  padding-left: 0;
  width: 100px;
}
.form-error {
  color: #f56c6c;
  font-size: 12px;
  margin-left: 186px;
  margin-top: 10px;
}
/deep/ {
  .el-form-item .el-form-item {
    margin-bottom: 22px;
  }
  .required {
    display: inline-block;
    line-height: 40px;
  }
  .required::before {
    content: '*';
    color: #f56c6c;
    margin-right: 4 px;
  }
  .el-loading-spinner {
    transform: translateY(8px);
  }
  .el-scrollbar {
    padding-bottom: 10px;
  }
  .welcome-box {
    min-width: 488px;
    max-width: 844px;
    width: auto !important;
  }
}
.group-content {
  padding: 22px 0 20px;
}
</style>