SopContentAdd.vue 32.1 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 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
<!-- 规则配置 -->
<template>
  <d2-container class="edit-content">
    <div class="content-form" v-loading="loading">
      <div class="content-info">
        <div class="title">
          <div class="line"></div>
          <span>内容信息</span>
        </div>
        <div class="info-form-main">
          <el-form :model="formData" :rules="rules" ref="ruleForm">
            <el-form-item
              prop="title"
              label="标题:"
              label-width="120px"
              class="dis-in-block"
              :style="{ 'margin-bottom': '22px' }"
            >
              <el-input
                v-model.trim="formData.title"
                placeholder="请输入标题"
                maxlength="20"
                :style="{ width: '432px' }"
                clearable
              >
              </el-input>
            </el-form-item>
            <el-form-item label-width="120px" label="类型:" prop="type">
              <el-radio-group
                v-model="formData.contentType"
                @change="changeFileType()"
              >
                <!-- <el-radio :label="0">图片</el-radio> -->
                <el-radio :label="1">图文</el-radio>
                <el-radio :label="2">视频</el-radio>
                <el-radio :label="3">pdf</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label-width="120px" label="封面:" prop="coverImgUrl">
              <glsx-preview
                :pic-options="coverOptions"
                :image-url-arr="formData.coverImgUrl"
                limit="1"
              ></glsx-preview>
            </el-form-item>
            <el-form-item
              prop="subtitle"
              label="副标题:"
              label-width="120px"
              class="dis-in-block"
              :style="{ 'margin-bottom': '22px' }"
            >
              <el-input
                type="textarea"
                v-model.trim="formData.subtitle"
                placeholder="200个字符以内"
                maxlength="200"
                :style="{ width: '580px' }"
                clearable
                show-word-limit
              >
              </el-input>
            </el-form-item>
            <el-form-item
              v-if="formData.contentType == 1"
              label-width="120px"
              label="内容:"
              prop="content"
            >
              <!-- <div v-if="formData.type == 0"> -->
              <!-- 图文编辑器 -->
              <textBox
                ref="TextBox"
                :excludeMenus="['code', 'video']"
                @change="(e) => handleTextBoxChange(e)"
                @focus="handleTextBoxFocus"
                :boxHeight="240"
              ></textBox>
              <!-- </div> -->
            </el-form-item>
            <el-form-item
              v-if="formData.contentType != 1"
              label-width="120px"
              label="内容:"
              prop="imageList"
            >
              <div v-if="formData.contentType == 2">
                <glsx-preview
                  :pic-options="videoOptions"
                  @beforeUpload="beforeUpload"
                  @afterUpload="afterUpload"
                  :image-url-arr="formData.imageList"
                  limit="1"
                ></glsx-preview>
                <p class="photo-top-tips">支持 .mp4,大小不超过200M</p>
              </div>
              <div v-if="formData.contentType == 3">
                <uploadPdf
                  :pic-options="pdfOptions"
                  :image-url-arr="formData.imageList"
                  @beforeUpload="beforeUpload"
                  @afterUpload="afterUpload"
                  limit="1"
                ></uploadPdf>
                <p class="photo-top-tips">支持 .pdf,大小不超过50M</p>
              </div>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="publish-channel-form">
        <div class="title">
          <div class="line"></div>
          <span>员工设置</span>
        </div>
        <div class="publish-info">
          <el-form :model="formData" :rules="rules" ref="channelForm">
            <el-form-item
              label-width="120px"
              label="员工对象:"
              prop="customerDataList"
            >
              <el-button
                v-show="
                  formData.customerDataList.length == 0 ||
                  formData.customerDataList.every(
                    (item) => item.labelList.length == 0
                  )
                "
                class="screeningCustomers default-blue-btn el-icon-plus m-t-10"
                size="small"
                @click="viewMembers()"
              >
                去选择
              </el-button>
              <div
                v-show="
                  formData.customerDataList.length != 0 &&
                  formData.customerDataList.some(
                    (item) => item.labelList.length !== 0
                  )
                "
              >
                <div class="customer-box m-t-10">
                  <div class="el-input-tag input-tag-wrapper">
                    <div class="customer-title">
                      发送员工:预估
                      <el-button
                        type="text"
                        :loading="customerLoading"
                        @click="handlePopStaff"
                      >
                        <span v-if="!customerLoading">{{
                          estimatedNumberOfPeople
                        }}</span>
                      </el-button>
                      人
                    </div>
                    <div>
                      <div
                        v-for="(subItem, subIdx) in formData.customerDataList"
                        :key="subIdx"
                      >
                        <el-tag
                          v-for="(k, n) in subItem.labelList"
                          :key="n"
                          class="customer-tag"
                          size="small"
                          type="info"
                          :closable="true"
                          :disable-transitions="false"
                          @close="handleDeleteCustomer(n, subIdx)"
                        >
                          <span
                            >{{ subItem.labelGroup.name }}:{{ k.name }}</span
                          >
                        </el-tag>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="m-t-10 screeningCustomers">
                  <el-button type="text" @click="handleSelectCustomer()"
                    >编辑</el-button
                  >
                  <el-button type="text" @click="handleResetCustomer()"
                    >重置</el-button
                  >
                </div>
              </div>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="publish-channel-form">
        <div class="title">
          <div class="line"></div>
          <span>群送设置</span>
        </div>
        <div class="publish-info">
          <el-form :model="formData" :rules="rules" ref="sendTypeForm">
            <el-form-item
              label-width="120px"
              label="群发方式:"
              prop="sendType"
            >
              <el-radio-group v-model="formData.sendType">
                <el-radio :label="1">即时推送</el-radio>
                <el-radio :label="2">定时推送</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              v-if="formData.sendType == 2"
              label-width="120px"
              label="群发时间:"
              prop="sendTime"
            >
              <!--   :picker-options="expireTimeOPtion" -->
              <el-date-picker
                type="datetime"
                v-model="formData.sendTime"
                placeholder="选择日期时间"
                :picker-options="pickerOptions"
                format="yyyy-MM-dd HH:mm:ss"
                default-time="00:00:00"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div style="margin-top: 40px; text-align: center">
        <el-button
          type="primary"
          class="width_100"
          @click="checkValidData(1)"
          :disabled="Boolean($store.state.d2admin.loading.value && !type)"
          :loading="Boolean($store.state.d2admin.loading.value && type)"
          >保存并使用</el-button
        >
        <el-button
          type="primary"
          plain
          class="width_100"
          @click="checkValidData(0)"
          v-if="!routeInfo.status"
          :disabled="Boolean($store.state.d2admin.loading.value && type)"
          :loading="Boolean($store.state.d2admin.loading.value && !type)"
          >存草稿</el-button
        >
        <el-button class="width_100 cancel-btn" @click="handleCancel"
          >取消</el-button
        >
      </div>
    </div>
    <tableDialog
      v-if="relateStoreVisible"
      ref="formRelateStore"
      :relate-store-visible="relateStoreVisible"
      :store-api="getList"
      :store-search-form="storeSearchForm"
      @handleRelateStoreConfirm="handleRelateStoreClose"
      @handleRelateStoreClose="handleRelateStoreClose"
    >
      <el-row slot>
        <el-form :model="storeSearchForm" ref="relate" :inline="true">
          <el-form-item label="关键字:">
            <el-input
              v-model.trim="storeSearchForm.staffNameOrPhone"
              placeholder="请输入员工名称/手机号进行搜索"
              @keydown.native="handleStoreInput"
              clearable
            />
          </el-form-item>
          <el-button type="primary" @click="handleSearchStore">搜索</el-button>
        </el-form>
      </el-row>
    </tableDialog>
    <previewEffectDialog
      v-if="showImageView"
      :visible="showImageView"
      :list="formData.imageList"
      @closeDialog="closeDialog"
    ></previewEffectDialog>
    <el-dialog :visible.sync="lookImgVisible">
      <img width="100%" :src="dialogObj.url" alt="图片" />
    </el-dialog>
    <select-tag
      ref="selectTagForm"
      @tagSelected="handleDialogConfirm"
      :dialogVisible="isTagVisible"
      :labelTypesStr="'企业标签'"
    ></select-tag>
  </d2-container>
</template>

<script>
// import dayjs from "dayjs"
import { Util, deepClone } from "@/common/util"
import selectTag from "./components/selectTag"
import preview from "./components/preview"
import uploadPdf from "./components/uploadPdf"
import tableDialog from "./components/tableDialog"
import previewEffectDialog from "./components/previewEffectDialog"
import { getList, getAccountMerchantList } from "@/api/merchant"
import textBox from "@/components/glsx-combi-form/textBox"
import {
  insertOrUpdate,
  contentManagerTaskById,
  getListLabelStaffPage
} from "@api/contentManager"
export default {
  name: "SopContentAdd",
  components: {
    glsxPreview: preview,
    uploadPdf,
    tableDialog,
    previewEffectDialog,
    textBox,
    selectTag: selectTag
  },
  data() {
    return {
      loading: false,
      type: 1,
      estimatedNumberOfPeople: "",
      customerDataList: [],
      isTagVisible: false,
      pickerOptions: {
        // 限制今天当前时间之前的时间(包含小时数)
        disabledDate: (time) => {
          return time.getTime() < Date.now() - 8.64e7
        },
        // selectableRange: this.getSelectableRange
        // () => {
        //   const currentDate = new Date()
        //   currentDate.setMinutes(currentDate.getMinutes() + 30)
        //   console.log(currentDate.getHours(), currentDate.getMinutes())
        //   return `${currentDate.getHours()}:${currentDate.getMinutes()}:${currentDate.getSeconds()} - 23:59:59`
        //   // new Date().getHours() + 1 + ":00:00 - 23:59:59"
        // }
        selectableRange: this.getSelectableRange()
        // new Date().getHours() +
        // ":" +
        // (new Date().getMinutes() + 1) +
        // ":00" +
        // " - 23:59:59"
      },
      getList: getListLabelStaffPage,
      getAccountMerchantList,
      expireTimeOPtion: {},
      currentDate: new Date(),
      showImageView: false,
      relateStoreVisible: false,
      uploading: false,
      storeSearchForm: {
        staffNameOrPhone: ""
      },
      storeSelected: [],
      merchantVisible: false,
      brandVisible: false,
      tableData: [],
      coverOptions: {
        width: "88px",
        height: "88px",
        isClose: true,
        limitSize: 1
      },
      picOptions: {
        width: "88px",
        height: "88px",
        isClose: true,
        limitSize: 10,
        type: "img",
        isDrag: true
      },
      videoOptions: {
        width: "88px",
        height: "88px",
        isClose: true,
        limitSize: 200,
        type: "video"
      },
      pdfOptions: {
        width: "104px",
        height: "104px",
        isClose: true,
        limitSize: 50
      },
      formData: {
        title: "",
        contentType: 1,
        coverImgUrl: [],
        subtitle: "",
        imageList: [],
        sendType: 1,
        sendTime: "",
        formData: [],
        customerDataList: [],
        content: ""
      },
      rules: {
        title: [{ required: true, message: "请输入标题", trigger: "change" }],
        contentType: [
          { required: true, message: "请选择类型", trigger: "change" }
        ],
        sendTime: [
          { required: true, message: "请选择时间", trigger: "change" }
        ],
        content: [{ required: true, message: "请输入内容", trigger: "change" }],
        sendType: [
          { required: true, message: "请选择群发方式", trigger: "change" }
        ],
        // coverImgUrl: {
        //   required: true,
        //   validator: (rule, value, callback) => {
        //     if (value && value[0]) {
        //       callback()
        //     } else {
        //       callback("请上传封面")
        //     }
        //   },
        //   trigger: "change"
        // },
        imageList: {
          required: true,
          validator: (rule, value, callback) => {
            if (value && value.length) {
              callback()
            } else {
              callback("请上传内容文件")
            }
          },
          trigger: "change"
        },
        sendTime: {
          required: true,
          validator: (rule, value, callback) => {
            if (value) {
              const currentTime = new Date()
              const inputTime = new Date(value)
              if (inputTime > currentTime) {
                callback()
              } else {
                callback("选中时间需要大于当前时间")
              }
            } else {
              callback("请选中发送时间")
            }
          },
          trigger: "change"
        },
        customerDataList: {
          required: true,
          validator: (rule, value, callback) => {
            // console.log(
            //   this.formData.customerDataList,
            //   this.formData.customerDataList.length
            // )
            let params = this.getParams()
            if (value && params.labelList.length) {
              callback()
            } else {
              callback("请选择员工对象")
            }
          },
          trigger: "change"
        }
      },
      dialogObj: {},
      lookImgVisible: false,
      tableSearchForm: {},
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableOption: true,
        tableColumns: [
          {
            label: "门店名称",
            prop: "merchantName"
          },
          {
            label: "门店商户号",
            prop: "merchantId"
          }
        ]
      },
      brandTableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "brandList",
        tableOption: true,
        tableColumns: [
          {
            label: "品牌名称",
            prop: "label"
          }
        ]
      },
      routeInfo: {},
      customerLoading: false
    }
  },
  watch: {
    "formData.sendTime"(selectTime) {
      const selectedDate = new Date(selectTime)
      const selectedDateWithoutTime = new Date(
        selectedDate.getFullYear(),
        selectedDate.getMonth(),
        selectedDate.getDate(),
        0,
        0,
        0,
        0
      ).getTime()
      const todayWithoutTime = new Date(
        new Date().getFullYear(),
        new Date().getMonth(),
        new Date().getDate(),
        0,
        0,
        0,
        0
      ).getTime()

      if (selectedDateWithoutTime === todayWithoutTime) {
        // 当选择的日期就是当天的时候,这个时候就要限制时间应当大于此时此刻的时分秒
        const currentDate = new Date()
        currentDate.setMinutes(currentDate.getMinutes() + 30)
        console.log(currentDate.getHours(), currentDate.getMinutes())
        this.pickerOptions.selectableRange = `${currentDate.getHours()}:${currentDate.getMinutes()}:${currentDate.getSeconds()} - 23:59:59`
      } else {
        // 当选择的日期大于当天的时候,这时需要把时分秒的限制放开,否则不能选择
        this.pickerOptions.selectableRange = "00:00:00 - 23:59:59"
      }
    },
    "formData.content"() {
      this.$refs.ruleForm.validateField("content")
    },
    "formData.imageList"() {
      this.$refs.ruleForm.validateField("imageList")
    }
    // 开始时间 的 小时限制
    // "formData.sendTime"(selectTime) {
    //   const date = new Date(new Date(selectTime).setHours(0, 0, 0, 0)).getTime()
    //   const today = new Date(new Date().setHours(0, 0, 0, 0)).getTime()
    //   if (date <= today) {
    //     // 当选择的日期就是当天的时候,这个时候就要限制时间应当大于此时此刻的时分秒
    //     this.pickerOptions.selectableRange =
    //       new Date().getHours() +
    //       ":" +
    //       (new Date().getMinutes() + 1) +
    //       ":00" +
    //       "- 23:59:59"
    //   } else {
    //     // 当选择的日期大于当天的时候,这时需要把时分秒的限制放开,否则不能选择
    //     this.pickerOptions.selectableRange = "00:00:00 - 23:59:59"
    //   }
    // }
    // 结束时间
    // "saveForm.endTime"(selectTime) {
    //   const date = new Date(new Date(selectTime).setHours(0, 0, 0, 0)).getTime()
    //   const today = new Date(new Date().setHours(0, 0, 0, 0)).getTime()
    //   if (date <= today) {
    //     // 当选择的日期就是当天的时候,这个时候就要限制时间应当大于此时此刻的时分秒
    //     this.pickerOptions.selectableRange =
    //       new Date().getHours() +
    //       ":" +
    //       (new Date().getMinutes() + 1) +
    //       ":00" +
    //       "- 23:59:59"
    //   } else {
    //     // 当选择的日期大于当天的时候,这时需要把时分秒的限制放开,否则不能选择
    //     this.pickerOptions.selectableRange = "00:00:00 - 23:59:59"
    //   }
    // }
  },

  mounted() {
    const { id } = this.$route.query
    this.routeInfo = this.$route.query
    if (id) this.getDetail()
    // console.log(this.pickerOptions)
    // console.log(this.getSelectableRange())
  },

  methods: {
    getSelectableRange() {
      const currentDate = new Date()
      currentDate.setMinutes(currentDate.getMinutes() + 30)
      return `${currentDate.getHours()}:${currentDate.getMinutes()}:00 - 23:59:59`
    },
    handleDeleteCustomer(idx, pIdx) {
      this.formData.customerDataList[pIdx].labelList.splice(idx, 1)
      this.customerLoading = true
      this.getCustomerByTagList("filtrate")
    },
    handlePopStaff() {
      this.relateStoreVisible = true
    },
    getCustomerByTagList(type) {
      let params = {}
      if (type == "filtrate") {
        params = {
          labelInfoList: [],
          pageSize: 99999999,
          pageNum: 1
        }
        this.formData.customerDataList &&
          this.formData.customerDataList.forEach((item) => {
            item.labelList.length &&
              item.labelList.forEach((subItem) => {
                params.labelInfoList.push({
                  groupId: item.labelGroup.id,
                  // groupId: 4,
                  groupName: item.labelGroup.name,
                  groupType: item.labelType,
                  labelId: subItem.id,
                  // labelId: 16,
                  labelName: subItem.name
                })
              })
          })
      }
      // params.labelInfoList = params.labelInfoList || []
      this.storeSearchForm.labelInfoList = params.labelInfoList || []

      console.log(params, "params")
      params.labelInfoList.length &&
        getListLabelStaffPage(params)
          .then((res) => {
            this.estimatedNumberOfPeople = res?.total || 0
            this.customerLoading = false
          })
          .catch((err) => {
            this.viewLoading = false
            this.groupNumber = 0
          })
    },
    handleDialogConfirm(val) {
      this.formData.customerDataList = val
      this.customerLoading = true

      this.getCustomerByTagList("filtrate")
    },
    // 查看群发人数
    viewMembers() {
      this.handleSelectCustomer()
    },
    handleResetCustomer() {
      this.formData.customerDataList = []
      this.customerLoading = false
      this.estimatedNumberOfPeople = ""
      this.$refs.selectTagForm.labelTreeRetSelect = []
    },
    handleSelectCustomer() {
      this.isTagVisible = !this.isTagVisible
      this.$refs.selectTagForm.init(
        JSON.parse(JSON.stringify(this.formData.customerDataList))
      )
    },
    // 获取富文本框内容
    handleTextBoxChange(val, targetItem) {
      // this.formObj[targetItem.name] = val
      this.formData.content = val
      console.log(this.$refs.formData)

      // this.$refs.formData
    },
    handleTextBoxFocus() {
      this.$refs.TextBox.setEdit(this.formData.content)
    },
    disabledDate(time) {
      // 禁用过去的日期
      return time.getTime() < Date.now() - 8.64e7 // 8.64e7 毫秒数代表一天
    },
    disabledHours() {
      const hours = []
      const currentHour = this.currentDate.getHours()
      for (let i = 0; i < currentHour; i++) {
        hours.push(i)
      }
      return hours
    },
    // 切换文件类型
    changeFileType(e) {
      this.formData.imageList = []
      this.formData.content = ""
      this.uploading = false
    },
    getDetail() {
      contentManagerTaskById({ id: this.$route.query.id }).then((res) => {
        if (res) {
          console.log(res, "res")
          for (const key in this.formData) {
            if (key == "coverImgUrl") {
              this.formData[key] = res[key] ? [res[key]] : []
            } else if (key == "content") {
              if (res.contentType == 1) {
                // type = 1 是文本,文本的imageList数据结构为[image: '',imageName: '']
                this.formData[key] = res.content
              }
              if (res.contentType == 2) {
                // type = 2 是pdf,pdf的imageList数据结构为['url','url']
                this.formData["imageList"] = [...JSON.parse(res.content)]
                // res.detailInfos?.map((item) => item.image)
              }
              if (res.contentType == 3) {
                // type = 2 是pdf,pdf的imageList数据结构为[image: '',imageName: '']
                //  let urlObj = JSON.parse(res.content)
                this.formData["imageList"] = JSON.parse(res.content)
                //  res.detailInfos
              }
            } else if (key == "sendTime" && res.sendTime) {
              this.formData.sendTime = Util.dateFormate(
                res.sendTime,
                "YYYY-MM-DD HH:mm:ss"
              )
            } else {
              // if (key == "content") {
              //   // this.currentDate = new Date(res[key])
              //   console.log(res[key])
              // }
              this.formData[key] = res[key]
            }
          }
          this.formData.customerDataList = this.transformLabelList(
            res.labelList
          )

          // 初始化 富文本内容
          this.formData.contentType == 1 && this.handleTextBoxFocus()
          this.getCustomerByTagList("filtrate")
        }
      })
    },
    transformLabelList(labelList) {
      // debugger
      const customerDataList = []

      // Group labels by labelGroupId
      const labelGroups = {}
      for (const label of labelList) {
        if (!labelGroups[label.labelGroupId]) {
          labelGroups[label.labelGroupId] = {
            labelGroup: {
              id: label.labelGroupId,
              name: label.labelGroupName
            },
            labelList: [],
            labelType: label.labelType
          }
        }
        labelGroups[label.labelGroupId].labelList.push({
          id: label.labelId,
          name: label.labelName
        })
      }

      // Convert the grouped labels to the desired structure
      for (const groupId in labelGroups) {
        customerDataList.push(labelGroups[groupId])
      }
      console.log(labelGroups, customerDataList, "customerDataList")
      return customerDataList
    },
    // 切换业务场景并且是指定门店  或者  切换可见门店   就清空已选的
    // clearTableFn(type) {
    //   if ((type == 1 && this.formData.showMerchant == 2) || type == 2) {
    //     this.storeSelected = []
    //     this.tableData = []
    //   }
    // },
    getParams(type) {
      const params = deepClone(this.formData)
      params.coverImgUrl = params.coverImgUrl[0]
      params.labelList = params.customerDataList.reduce((pre, item) => {
        item.labelList.forEach((subItem) => {
          pre.push({
            labelGroupId: item.labelGroup.id,
            labelGroupName: item.labelGroup.name,
            labelGroupType: item.labelType,
            labelId: subItem.id,
            labelName: subItem.name
          })
        })
        return pre
      }, [])
      if (params.contentType != 1) {
        params.content = JSON.stringify(params.imageList)
      }
      // params.status = type
      delete params.customerDataList
      if (this.$route.query.id) params.id = this.$route.query.id
      console.log(params, "params")
      return params
    },
    // 草稿和保存都先检验
    checkValidData(type) {
      this.type = type
      if (this.uploading) {
        return this.$message.error(`文件上传中,请耐心等待文件上传完成`)
      }
      this.$refs.ruleForm.validate((valid) => {
        this.$refs.channelForm.validate((valid1) => {
          this.$refs.sendTypeForm.validate((valid2) => {
            if (valid && valid1 && valid2) {
              if (type) {
                this.confirmAdd(type)
              } else {
                this.commitFn(type)
              }
            }
          })
        })
      })
    },
    beforeUpload() {
      this.uploading = true
    },
    afterUpload() {
      this.uploading = false
    },
    // 保存需要二次弹窗
    confirmAdd(type) {
      this.$confirm("是否确认保存", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then((end) => {
        if (end == "confirm") {
          this.commitFn(type)
        }
      })
    },
    //
    commitFn(type) {
      const params = this.getParams(type)
      params.saveDraft = !Boolean(type)
      // const _api = params.id ? updateContent : addContent
      this.loading = true
      insertOrUpdate(params).then((res) => {
        if (res) {
          this.$message.success(
            `${!type ? "保存草稿" : params.id ? "修改" : "新增"}成功`
          )
          this.handleCancel()
        }
        this.loading = false
      })
    },
    // 取消按钮返回列表页
    handleCancel() {
      this.$router.push({
        name: "staffMassSending"
      })
    },
    // 关闭员工弹窗
    handleRelateStoreClose() {
      this.relateStoreVisible = false
    },
    // 门店弹窗按回车查询
    handleStoreInput(e) {
      e.keyCode === 13 && this.handleSearchStore()
    },
    // 门店弹窗点击查询
    handleSearchStore() {
      this.$refs.formRelateStore.handleCurrentChange(1)
    },
    // 删除table 门店或者品牌
    // delMerchant(row, idx) {
    //   this.tableData.splice(idx, 1)
    // },
    // 关闭查看效果
    closeDialog() {
      this.showImageView = false
    },
    // 点击查看效果 图片预览
    showEffect() {
      this.showImageView = true
    }
  }
}
</script>
<style scoped lang="scss">
.content-form {
  .title {
    height: 50px;
    line-height: 50px;
    padding: 0 20px;
    border-bottom: 1px solid #e5e5e5;
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    display: flex;
    align-items: center;
    .line {
      width: 4px;
      height: 16px;
      background: #185efe;
      border-radius: 2px;
      margin-right: 8px;
    }
  }
}
.content-info {
  background: #fff;

  .info-form-main {
    padding: 16px 20px;
    .dis-in-block {
      display: inline-block;
    }
    .photo-top-tips {
      margin: 0 0;
      color: #999999;
      .tip-btn {
        color: #185efe;
        cursor: pointer;
      }
    }
    .activity-img {
      position: relative;
      cursor: pointer;
      background: #f4f4f4;
    }
    .wrap {
      width: 88px;
      height: 88px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    .img-w-h {
      width: 88px;
      height: 88px;
    }
    .add {
      font-size: 24px;
      height: 24px;
      color: #999999;
    }
    .number {
      font-weight: 400;
      font-size: 12px;
      color: #999999;
    }
    .muti-imgs {
      display: inline-block;
      position: relative;
    }
    .muti-imgs:hover .img-btns {
      display: block;
    }
    .img-btns {
      display: none;
      height: 100%;
      position: absolute;
      width: 88px;
      height: 88px;
      left: 0;
      top: 0;
      z-index: 2;
      color: #fff;
      background: rgba(0, 0, 0, 0.5);
    }
    .btn-item {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      display: flex;
      width: 70%;
      justify-content: space-around;
    }
    .el-icon-delete,
    .el-icon-zoom-in {
      cursor: pointer;
    }
    .pdf_box {
      width: 98px;
      height: 32px;
      background: #f8f8f8;
      border: 1px solid #e6e6e6;
      border-radius: 4px;
      position: relative;
      cursor: pointer;
      .pdf_wrap {
        width: 98px;
        height: 32px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        align-items: center;
        justify-content: center;
        .add {
          font-size: 24px;
          color: #999999;
        }
        .number {
          font-weight: 400;
          font-size: 12px;
          color: #999999;
        }
      }
    }
  }
}
.publish-channel-form {
  background: white;
  margin-top: 16px;
  .publish-info {
    padding: 16px 20px;
  }
  .btn-class {
    background: #f8f8f8;
  }
}
.customer-box {
  width: 567px;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;

  .customer-title {
    box-sizing: border-box;
    height: 39px;
    line-height: 39px;
    padding: 0 10px;
    // border-bottom: 1px solid #dcdfe6;
  }

  .input-tag-wrapper {
    max-height: 227px;
    overflow: auto;
    position: relative;
    font-size: 14px;
    padding: 0 10px 10px;
    box-sizing: border-box;
    color: #666;
    display: inline-block;
    outline: none;
    flex-wrap: wrap;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    display: flex;
    align-items: center;
    font-size: 14px;

    .el-tag.el-tag--info .el-tag__close {
      color: #909399 !important;
      background: transparent !important;
    }

    .customer-tag {
      margin: 4px;
    }

    i {
      color: #75acff;
      margin-right: 3px;
      font-size: 14px;
    }
  }
}
</style>