index.vue 36 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 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item :label="$t('商品编码')" prop="productCode">
        <el-input
          v-model.trim="queryParams.productCode"
          :placeholder="$t('请输入商品编码')"
          clearable
          @keyup.enter.native="handleQuery"
          onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')"
        />
      </el-form-item>

      <el-form-item :label="$t('海关编码')" prop="customsCode">
        <el-input
          v-model.trim="queryParams.customsCode"
          :placeholder="$t('请输入海关编码')"
          clearable
          @keyup.enter.native="handleQuery"
          onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')"
        />
      </el-form-item>

      <el-form-item :label="$t('商品名称')" prop="titleZh">
        <el-input
          v-model="queryParams.titleZh"
          :placeholder="$t('请输入商品名称')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item :label="$t('商品类型')" prop="attrId">
        <el-select
          v-model="queryParams.typeId"
          multiple
          :placeholder="$t('选择商品类型')"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="types in typeList"
            :key="types.id"
            :label="$l(types, 'title')"
            :value="types.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item :label="$t('商品特性')" prop="attrId">
        <el-select
          v-model="queryParams.attrId"
          multiple
          :placeholder="$t('选择商品特性')"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="attr in attrList"
            :key="attr.id"
            :label="attr.attrName"
            :value="attr.id"
          />
        </el-select>
      </el-form-item>

      <!-- <el-form-item :label="$t('审核状态')" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" :placeholder="$t('选择审核状态')" clearable>
          <el-option v-for="auditStatusItem in auditStatusDictDatas" :key="auditStatusItem.id" :label="auditStatusItem.label" :value="auditStatusItem.value" />
        </el-select>
      </el-form-item>

      <el-form-item :label="$t('上架状态')" prop="status">
        <el-select v-model="queryParams.status" :placeholder="$t('选择上架状态')" clearable>
          <el-option v-for="statusItem in statusDictDatas" :key="statusItem.id" :label="statusItem.value == CommonStatusEnum.ENABLE ? '已上架' : '已下架'" :value="statusItem.value" />
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{
          $t("搜索")
        }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{
          $t("重置")
        }}</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ecw:product:create']"
          >{{ $t("新增") }}</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-setting"
          size="mini"
          @click="handleEdit"
          v-hasPermi="['ecw:product:attr']"
          >{{ $t("批量设置商品属性") }}</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ecw:product-price:export']"
          :loading="exportLoading"
          >{{ $t("导出") }}</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="list"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column :label="$t('商品编号')" align="center" prop="id" />
      <el-table-column :label="$t('商品类型')" align="center" prop="typeId">
        <template slot-scope="scope">
          <span>{{ getTypeName(scope.row.typeId) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('海关编码')"
        align="center"
        prop="customsCode"
      />
      <el-table-column :label="$t('中文标题')" align="center" prop="titleZh" />
      <el-table-column :label="$t('英文标题')" align="center" prop="titleEn" />
      <el-table-column :label="$t('商品属性')" align="center" prop="attrId">
        <template slot-scope="scope">
          <span>{{ getAttrName(scope.row.attrId) }}</span>
        </template>
      </el-table-column>
      <!--商品特性-->
      <el-table-column :label="$t('商品图片')" align="center" prop="attrId">
        <template slot-scope="scope">
          <el-image
            :src="firstImg(scope.row.imgs)"
            style="width: 50px; height: 50px"
            >{{ $t("") }}</el-image
          >
        </template>
      </el-table-column>

      <el-table-column
        prop="auditStatus"
        align="center"
        :label="$t('是否审核')"
        width="120"
      >
        <template slot-scope="scope">
          <el-select
            v-model="scope.row.auditStatus"
            @change="handleStatusChange(scope.row, 'auditStatus')"
          >
            <el-option
              v-for="auditStatusItem in auditStatusDictDatas"
              :key="auditStatusItem.id"
              :label="$l(auditStatusItem, 'label')"
              :value="parseInt(auditStatusItem.value)"
            />
          </el-select>
        </template>
      </el-table-column>

      <el-table-column
        :label="$t('添加人')"
        align="center"
        prop="creatorName"
      />

      <el-table-column :label="$t('添加时间')" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column
        :label="$t('修改人')"
        align="center"
        prop="updaterName"
      />

      <el-table-column :label="$t('修改时间')" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column prop="status" align="center" :label="$t('状态')" width="120">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
        </template>
      </el-table-column> -->

      <el-table-column
        :label="$t('操作')"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="toPriceManager(scope.row)"
            v-hasPermi="['ecw:product-price:query']"
            >{{ $t("路线价格") }}</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ecw:product:update']"
            >{{ $t("修改") }}</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ecw:product:delete']"
            >{{ $t("删除") }}</el-button
          >
          <!--要有价格复制权限 lanbm 2024-06-19 添加注释-->
          <el-button
            v-if="scope.row.auditStatus === 2"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="copyPrice(scope.row)"
            v-hasPermi="['ecw:product:copyPrice']"
            >{{ $t("复制价格") }}</el-button
          >

          <!-- <div v-else>
          <el-button  size="mini" type="text" @click="toPriceManager(scope.row)" v-hasPermi="['ecw:product-price:query']">{{$t('路线价格')}}</el-button>

          <el-button  size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['ecw:product:update']">{{$t('修改')}}</el-button>
          <el-button  size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['ecw:product:delete']">{{$t('删除')}}</el-button>
         </div> -->
          <!-- <el-button v-else size="mini" type="text" icon="el-icon-edit" @click="copyPrice(scope.row)" v-hasPermi="['ecw:product:copyPrice']">{{$t('复制价格')}}</el-button> -->
        </template>
        <!-- <template v-else>
          <el-button size="mini" type="text" @click="toPriceManager(scope.row)" v-hasPermi="['ecw:product-price:query']">{{$t('路线价格')}}</el-button>

          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['ecw:product:update']">{{$t('修改')}}</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['ecw:product:delete']">{{$t('删除')}}</el-button>

      
        </template> -->
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框(添加 / 修改) -->
    <el-dialog
      :modal="false"
      :modal-append-to-body="true"
      :title="title"
      :visible.sync="open"
      width="850px"
    >
      <el-form
        v-if="open"
        ref="form"
        :model="form"
        :rules="rules"
        label-width="110px"
      >
        <el-form-item :label="$t('商品类型')" prop="typeId">
          <el-select
            v-model="form.typeId"
            :placeholder="$t('选择商品类型')"
            clearable
          >
            <el-option
              v-for="types in typeList"
              :key="types.id"
              :label="types.titleZh"
              :value="types.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item :label="$t('中文标题')" prop="titleZh">
          <el-input
            v-model="form.titleZh"
            :placeholder="$t('请输入中文标题')"
          />
        </el-form-item>

        <el-form-item :label="$t('英文标题')" prop="titleEn">
          <el-input
            v-model="form.titleEn"
            :placeholder="$t('请输入英文标题')"
          />
        </el-form-item>

        <el-form-item :label="$t('商品图片')" prop="img">
          <image-upload v-model="form.imgs" />
        </el-form-item>

        <el-form-item prop="auditStatus" :label="$t('是否审核')">
          <template slot-scope="scope">
            <el-select v-model="form.auditStatus">
              <el-option
                v-for="auditStatusItem in auditStatusDictDatas"
                :key="auditStatusItem.id"
                :label="$l(auditStatusItem, 'label')"
                :value="parseInt(auditStatusItem.value)"
              />
            </el-select>
          </template>
        </el-form-item>
        <el-form-item :label="$t('商品编码')" prop="productCode">
          <el-input
            v-model="form.productCode"
            :placeholder="$t('请输入商品编码')"
          />
        </el-form-item>

        <el-form-item :label="$t('海关编码')" prop="customsCode">
          <el-input
            v-model="form.customsCode"
            :placeholder="$t('请输入海关编码')"
          />
        </el-form-item>

        <el-form-item :label="$t('商品特性')" prop="attrArray">
          <el-select
            v-model="form.attrArray"
            :placeholder="$t('选择商品特性')"
            clearable
            multiple
          >
            <el-option
              v-for="attr in attrList"
              :key="attr.id"
              :label="attr.attrName"
              :value="attr.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item :label="$t('商品材质')" prop="materialType">
          <el-select
            v-model="form.materialType"
            :placeholder="$t('选择商品材质')"
            clearable
          >
            <el-option
              v-for="materialItem in materialList"
              :key="materialItem.value"
              :label="materialItem.label"
              :value="materialItem.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item :label="$t('出运要求')" prop="requirements">
          <el-checkbox
            v-model="form.requirements"
            :checked="form.requirements === 1 ? true : false"
            :true-label="1"
            :false-label="0"
            >{{ $t("证书要求") }}({{ $t("支持多证书") }})</el-checkbox
          >
        </el-form-item>

        <el-form-item :label="$t('包装要求')" prop="packaging">
          <el-select
            v-model="form.packaging"
            :placeholder="$t('选择包装要求')"
            clearable
          >
            <el-option
              v-for="packageItem in packagingList"
              :key="packageItem.value"
              :label="packageItem.label"
              :value="packageItem.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item :label="$t('默认货柜位置')" prop="containerLocation">
          <el-select
            v-model="form.containerLocation"
            :placeholder="$t('选择货柜位置')"
            clearable
          >
            <el-option
              v-for="locationItem in locationList"
              :key="locationItem.value"
              :label="locationItem.label"
              :value="locationItem.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item :label="$t('订单方数上限')" prop="square">
          <el-input v-model.number="form.square" type="number">
            <!-- <template slot="append">{{$t('立方米')}}</template> -->
          </el-input>
        </el-form-item>

        <el-form-item :label="$t('是否预约入仓')" prop="needBook">
          <el-radio v-model.number="form.needBook" :label="1">{{
            $t("是")
          }}</el-radio>
          <el-radio v-model.number="form.needBook" :label="0">{{
            $t("否")
          }}</el-radio>
        </el-form-item>
        <!--        <el-form-item :label="$t('可参与优惠活动')" prop="you">
                  <el-select v-model="form.you" :placeholder="$t('可参与优惠活动')" clearable>
                    <el-option v-for="packageItem in packagingList" :key="packageItem.value" :label="packageItem.label" :value="packageItem.value" />
                  </el-select>
                </el-form-item> -->
        <el-form-item
          :label="$t('每日入仓上限')"
          prop="dayLimit"
          v-if="form.needBook == 1"
        >
          <el-input v-model.number="form.dayLimit" type="number">
            <template slot="append">{{ $t("立方米") }}</template>
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('可参与优惠')">
          <div
            style="
              width: 300px;
              height: 400px;
              border: 1px solid;
              overflow-y: auto;
            "
          >
            <div
              @click="selectMoveAbout(item)"
              style="
                display: flex;
                justify-content: space-between;
                align-items: center;
              "
              :style="{ cursor: item.mandatory ? 'no-drop' : 'pointer' }"
              v-for="item in preferentialList"
              :key="item.couponId"
            >
              <div>
                {{ $l(item, "title") }}
              </div>
              <i
                v-if="form.couponIds.includes(item.couponId)"
                style="margin-right: 20px"
                class="el-icon-check"
              ></i>
            </div>
          </div>
        </el-form-item>
        <!--        <el-form-item label-width="150px" label="空运订单重量上限kg">-->
        <!--          <el-input-number v-model="form.airWeightLimit"  controls-position="right"  ></el-input-number>-->

        <!--        </el-form-item>-->
        <!--        <packaging-type  key-arr="priceStepClearanceList" v-model="form">-->
        <!--          <el-button @click="visible =  true; open = false;" type="text">选择空运模板</el-button>-->
        <!--        </packaging-type>-->
        <!--         <p v-if="lineNum">-->
        <!--           <span>-->
        <!--             复制模板线路价格:{{lineNum}}个-->
        <!--           </span>-->
        <!--           <span @click="toPriceManager(formCopy, true)" style="color: #0a84ff;cursor: pointer;">-->
        <!--             查看《#{{$l(formCopy,'title')}}#》路线价格-->
        <!--           </span>-->
        <!--           <el-button style="font-size: 12px;margin-left: 15px;color: red;" type="text" @click="form.priceStepClearanceList = [];lineNum = 0"  >清除路线</el-button>-->
        <!--         </p>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{
          $t("确定")
        }}</el-button>
        <el-button @click="cancel">{{ $t("取消") }}</el-button>
      </div>
    </el-dialog>
    <el-dialog
      width="60%"
      :visible.sync="visible"
      @close="
        () => {
          open = true;
        }
      "
    >
      <product-dialog @copyLine="copyLine"></product-dialog>
    </el-dialog>
  </div>
</template>

<script>
import {
  createProduct,
  deleteProduct,
  exportProductExcel,
  getProduct,
  getProductPage,
  product_coupon_newProd,
  updateProduct,
} from "@/api/ecw/product";
import { getProductAttrList } from "@/api/ecw/productAttr";
import { getProductTypeList } from "@/api/ecw/productType";
import { DICT_TYPE, getDictDatas } from "@/utils/dict";
import { AuditStatusEnum, CommonStatusEnum } from "@/utils/constants";
import { uploadFile } from "@/api/infra/file";
import ImageUpload from "@/components/ImageUpload";
import PackagingType from "@/views/ecw/channel/componrnts/packaging-type.vue";
import ProductDialog from "@/views/ecw/product/product-dialog.vue";

export default {
  name: "EcwProductIndex",
  components: {
    ProductDialog,
    PackagingType,
    ImageUpload,
  },
  data() {
    return {
      visible: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //特性列表
      attrList: [],
      //类型列表
      typeList: [],
      //材质列表
      materialList: [],
      //包装列表
      packagingList: [],
      //货柜位置
      locationList: [],

      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        typeId: null,
        attrId: null,
        titleZh: null,
        titleEn: null,
        auditStatus: null,
        status: null,
      },
      // 表单参数
      form: {},
      formCopy: {},
      // 表单校验
      rules: {
        typeId: [
          {
            required: true,
            message: this.$t("商品类型不能为空"),
            trigger: "change",
          },
        ],
        attrArray: [
          {
            required: true,
            message: this.$t("商品特性不能为空"),
            trigger: "change",
          },
        ],
        titleZh: [
          {
            required: true,
            message: this.$t("中文标题不能为空"),
            trigger: "blur",
          },
        ],
        titleEn: [
          {
            required: true,
            message: this.$t("英文标题不能为空"),
            trigger: "blur",
          },
        ],
        // materialType: [{ required: true, message: this.$t("商品材质不能为空"), trigger: "blur" }],
        // packaging: [{ required: true, message: this.$t("包装要求不能为空"), trigger: "blur" }],
        // containerLocation: [{ required: true, message: this.$t("默认货柜位置不能为空"), trigger: "blur" }],
        // square: [{ required: true, message: this.$t("订单方数上线不能为空"), trigger: "blur" }],
        // needBook: [{ required: true, message: this.$t("是否预约入仓不能为空"), trigger: "blur" }],
      },

      CommonStatusEnum: CommonStatusEnum,
      AuditStatusEnum: AuditStatusEnum,
      statusDictDatas: getDictDatas(DICT_TYPE.COMMON_STATUS),
      auditStatusDictDatas: getDictDatas(DICT_TYPE.AUDIT_STATUS),
      materialList: getDictDatas(DICT_TYPE.ECW_PRODUCT_MATERIAL),
      packagingList: getDictDatas(DICT_TYPE.ECW_PACKAGING_TYPE),
      locationList: getDictDatas(DICT_TYPE.ECW_CONTAINER_LOCATION),
      preferentialList: [],
      exceptionProductId: 0, //新增商品异常传的id
      lineNum: 0,
    };
  },

  computed: {
    getTypeName() {
      return (typeId) => {
        for (let index in this.typeList) {
          let typeItem = this.typeList[index];
          if (typeItem.id == typeId) {
            return this.$l(typeItem, "title");
          }
        }
      };
    },

    getAttrName() {
      return (attrIds) => {
        let productAttrArray = [];
        let attrArray = attrIds.split(",");
        for (let attrIndex in attrArray) {
          let attrId = attrArray[attrIndex];
          for (let index in this.attrList) {
            let attrItem = this.attrList[index];
            if (attrItem.id == attrId) {
              productAttrArray.push(this.$l(attrItem, "attrName"));
            }
          }
        }
        return productAttrArray.join(",");
      };
    },
    firstImg() {
      return (imgString) => {
        if (!imgString || imgString == "") return imgString;
        let imgs = imgString.split(",");
        return imgs.length ? imgs[0] : null;
      };
    },
  },

  activated() {
    if (this.$route.query.typeId != this.queryParams.typeId) {
      this.queryParams.typeId = +this.$route.query.typeId || null;
    }
    //新增商品异常跳转商品修改
    if (this.$route.query.prodId) {
      this.exceptionProductId = this.$route.query.prodId;
      this.handleUpdate({ id: this.$route.query.prodId });
    }
    this.getList();
  },
  created() {
    //新增商品异常跳转商品修改
    if (this.$route.query.prodId) {
      this.exceptionProductId = this.$route.query.prodId;
      this.handleUpdate({ id: this.$route.query.prodId });
    }
    let typeId = this.$route.query.typeId;
    if (typeId) {
      this.queryParams.typeId = parseInt(typeId);
    }
    this.getAttrList();
    this.getTypeList();
    this.getList();
  },
  methods: {
    // copyLine(val , bol){
    //   this.formCopy = val;
    //   let copy = ()=>{
    //     if(val.priceStepClearanceList.length === 0) return  this.form.priceStepClearanceList = []
    //     this.form.airWeightLimit = val.airWeightLimit;
    //     val.priceStepClearanceList.forEach((item ,index) =>{
    //       if(this.form.priceStepClearanceList[index]){
    //         this.form.priceStepClearanceList[index].clearancePrice = item.clearancePrice
    //         this.form.priceStepClearanceList[index].clearancePriceUnit = item.clearancePriceUnit
    //         this.form.priceStepClearanceList[index].clearanceVolumeUnit = item.clearanceVolumeUnit
    //         this.form.priceStepClearanceList[index].endNum = item.endNum
    //         this.form.priceStepClearanceList[index].startNum = item.startNum
    //         this.form.priceStepClearanceList[index].weightUnit = item.weightUnit
    //       }else {
    //         let p = {
    //           "channelId":undefined,
    //           "clearancePrice":item.clearancePrice,
    //           "clearancePriceUnit":item.clearancePriceUnit,
    //           "clearanceVolumeUnit":item.clearanceVolumeUnit,
    //           "endNum":item.endNum,
    //           "packagingId":undefined,
    //           "startNum":item.startNum,
    //           "weightUnit":item.weightUnit
    //         }
    //         this.form.priceStepClearanceList.push(p)
    //       }
    //     })
    //   }
    //   this.visible = false;
    //   if(bol){
    //     let message = this.$l(this.form,'title') ? `请确认是否要将#${this.$l(val,'title')}#的所有路线价格复制到当前商品#${this.$l(this.form,'title')}#中?` : `请确认是否要将#${this.$l(val,'title')}#的所有路线价格复制到当前商品中?`
    //     this.$confirm(message, '提示', {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消',
    //       type: 'warning'
    //     }).then(() => {
    //       // this.form.priceLineCount = val.id;
    //       this.lineNum = val.priceLineCount;
    //       this.form.productTemplateId = val.id;
    //       this.form.isCopyProductPriceTemplate = true;
    //       copy()
    //       this.open = true;
    //     }).catch(() => {
    //       this.open = true;
    //     });
    //   }else {
    //     this.open = true;
    //     copy()
    //     this.lineNum = 0
    //     this.form.isCopyProductPriceTemplate = false;
    //   }
    //   this.$forceUpdate()
    // },
    /** 获取产品属性列表 */
    getAttrList() {
      getProductAttrList().then((response) => {
        this.attrList = response.data;
      });
    },

    /** 获取产品类型列表 */
    getTypeList() {
      getProductTypeList().then((response) => {
        this.typeList = response.data;
      });
    },

    /**跳转价格管理 */
    toPriceManager(row, flag = false) {
      /* localStorage.setItem('product', JSON.stringify(row));
      localStorage.setItem('typeList', JSON.stringify(this.typeList)); */
      let p;
      if (flag) {
        p = {
          product_id: row.id,
          product_type: row.typeId,
          transportType: 3,
        };
      } else {
        p = {
          product_id: row.id,
          product_type: row.typeId,
        };
      }
      this.$router.push({
        name: "ProductPrice",
        query: p,
      });
    },

    handleStatusChange(row, statusType) {
      updateProduct(row)
        .then(() => {
          this.$modal.msgSuccess(this.$t("修改成功"));
        })
        .catch(function () {
          if (statusType == "status") {
            row.status =
              row.status === CommonStatusEnum.ENABLE
                ? CommonStatusEnum.DISABLE
                : CommonStatusEnum.ENABLE;
          } else {
            row.auditStatus =
              row.auditStatus === AuditStatusEnum.PASS
                ? AuditStatusEnum.NOT_PASS
                : AuditStatusEnum.PASS;
          }
        });
    },
    //复制价格
    copyPrice(row) {
      this.$router.push({
        path: "/product/copyPrice",
        query: { titleZh: row.titleZh, id: row.id },
      });
    },

    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = { ...this.queryParams };
      params.filter = false;
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime");
      // 执行查询
      params.status = 0;
      getProductPage(params).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        typeId: undefined,
        attrArray: undefined,
        attrId: undefined,
        titleZh: undefined,
        titleEn: undefined,
        auditStatus: undefined,
        status: undefined,
        requirements: 0,
        needBook: 0,
        couponIds: [],
        airWeightLimit: undefined,
        priceStepClearanceList: [],
        isCopyProductPriceTemplate: false,
        productTemplateId: undefined,
      };
      this.lineNum = 0;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = this.$t("添加商品");
      product_coupon_newProd().then((r) => {
        this.preferentialList = r.data;
        this.form.couponIds = this.preferentialList
          .filter((i) => i.isDefault)
          .map((i) => i.couponId);
      });
      if (this.queryParams.typeId) {
        this.form.typeId = this.queryParams.typeId;
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      console.log(row);
      const id = row.id;
      getProduct(id).then((response) => {
        this.form = { ...response.data, couponIds: [] };
        this.form.channelPriceStepClearanceList =
          this.form.priceStepClearanceList;
        let attrArray = this.form.attrId ? this.form.attrId.split(",") : [];
        for (let index in attrArray) {
          let value = attrArray[index];
          attrArray[index] = parseInt(value);
        }
        this.$nextTick(() => {
          this.$set(this.form, "attrArray", attrArray);
        });
        this.open = true;
        this.title = this.$t("修改商品");
        product_coupon_newProd({ prodId: id }).then((r) => {
          this.preferentialList = r.data;
          this.form.couponIds = this.preferentialList
            .filter((i) => i.isDefault)
            .map((i) => i.couponId);
          // this.reset()
        });
      });
    },
    verify(row) {
      return (
        row.startNum !== "" &&
        row.endNum !== "" &&
        row.clearancePrice !== "" &&
        row.clearancePriceUnit !== "" &&
        row.clearanceVolumeUnit !== ""
      );
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return;
        }
        // if(!this.form.airWeightLimit){
        //   return this.$message.warning('请输入空运订单重量上限')
        // }
        // if(this.form.priceStepClearanceList.length === 0){
        //   return this.$message.warning('阶梯定价输入不完整!')
        // }else {
        //    let bol = this.form.priceStepClearanceList.every(this.verify)
        //   if(!bol){
        //     return this.$message.warning('阶梯定价输入不完整!')
        //   }
        //
        // }
        //商品特性转字符串
        this.form.attrId = this.form.attrArray.join(",");
        // 修改的提交
        if (this.form.id != null) {
          this.form.priceStepClearanceList.forEach((i) => {
            i.productId = this.form.id;
          });
          if (this.exceptionProductId) {
            this.form.productId = this.exceptionProductId;
            this.form.status = 0;
          } else {
            this.form.productId = this.form.id;
          }
          updateProduct(this.form).then((response) => {
            this.$modal.msgSuccess(this.$t("修改成功"));
            this.open = false;
            if (this.exceptionProductId) {
              this.exceptionProductId = null;
              this.$router.replace({ path: "/product/product-list" });
            }
            this.getList();
            this.lineNum = 0;
          });
          return;
        }
        // 添加的提交
        createProduct(this.form).then((response) => {
          this.$modal.msgSuccess(this.$t("新增成功"));
          this.open = false;
          this.getList();
          this.lineNum = 0;
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm(this.$t("是否确认删除商品编号为{id}的数据项?", { id }))
        .then(function () {
          return deleteProduct(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t("删除成功"));
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime");
      // 执行导出
      this.$modal
        .confirm(this.$t("是否确认导出所有商品数据项?"))
        .then(() => {
          this.exportLoading = true;
          return exportProductExcel(params);
        })
        .then((response) => {
          // this.$download.excel(response, '商品.xlsx');
          this.$message.success(
            this.$t("已加入导出队列,请稍后在下载日志中下载")
          );
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    // 上传预处理
    beforeUpload(file) {
      if (file.type.indexOf("image/") == -1) {
        this.$modal.msgError(
          this.$t("文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。")
        );
      } else {
        //上传
        let formData = new FormData();
        formData.append("file", file);
        // formData.append("path", this.uuid());
        uploadFile(formData).then((response) => {
          this.$set(this.form, "imgs", response.data);
          // this.form.img = response.data;
        });
      }
    },

    uuid() {
      var s = [];
      var hexDigits = "0123456789abcdef";
      for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
      }
      s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
      s[8] = s[13] = s[18] = s[23] = "-";

      var uuid = s.join("");
      return uuid;
    },
    // 表格多选
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 批量设置商品属性
    handleEdit() {
      this.$router.push({
        path: "product-attr/edit",
        query: {
          ids: this.ids,
        },
      });
    },
    selectMoveAbout(val) {
      if (!val.mandatory) {
        let index = this.form.couponIds.findIndex((i) => val.couponId == i);
        if (index >= 0) {
          this.$confirm(
            this.$t(
              `您确定要将商品从优惠活动${this.$l(val, "title")}中移出吗?`
            ),
            this.$t("提示"),
            {
              confirmButtonText: this.$t("确定"),
              cancelButtonText: this.$t("取消"),
              type: "warning",
            }
          )
            .then(() => {
              this.form.couponIds.splice(index, 1);
              this.$forceUpdate();
            })
            .catch(() => {});
        } else {
          this.$confirm(
            this.$t(
              `您确定要将商品加入到优惠活动${this.$l(val, "title")}中吗?`
            ),
            this.$t("提示"),
            {
              confirmButtonText: this.$t("确定"),
              cancelButtonText: this.$t("取消"),
              type: "warning",
            }
          )
            .then(() => {
              this.form.couponIds.push(val.couponId);
              this.$forceUpdate();
            })
            .catch(() => {});
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>