add.vue 27.9 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
<template>
  <div class="goods-ctnr">
    <div class="global-title">{{ !routeInfo.id ? '新增' : disabled ? '查看' : '编辑' }}商品</div>
    <div class="container">
      <glsx-combi-form :isInline="false" class="glsx-combi-form" ref="baseInfoRef" labelWidth="154px"
                       defaultWidth="432px" :formObj.sync="formObj" :formData="formData" :formRules="myRule">
        <div slot="selectGoodsSlot">
          <el-button :class="['el-icon-plus', {'disabled-class':disabled}]" size="small" @click="openGoodsDialog">
            {{ formObj.smartcarlifeInfoId ? '重新选择' : '选择商品' }}
          </el-button>
        </div>
        <div slot="goodsInfoSlot" class="goods-wrap">
          <glsx-combi-form :isInline="false" ref="goodsInfoRef" labelWidth="154px" defaultWidth="432px"
                           :formObj.sync="formObj" :formData="goodsFormData" :formRules="goodsRule">
            <div slot="uploadSlot" class="upload-calss">
              <glsx-preview :picOptions="posterOptions" :imageUrlArr="formObj.coverList"></glsx-preview>
              <span class="tip">建议尺寸750*750,图片格式为jpg,jpeg,png,大小2M以内</span>
            </div>
          </glsx-combi-form>
        </div>
        <div slot="propagateCoverSlot" class="propagate-cover-class">
          <div class="upload-wrap">
            <glsx-preview :picOptions="posterOptions" :imageUrlArr="formObj.styleBImgList"></glsx-preview>
            <span class="preview" @click="showPreviewDialog=true">预览</span>
          </div>
          <span class="tip">分类布局选择种草样式B时商品宣传大图,建议720*540,大小2M以内</span>
        </div>
        <div slot="paymentSlot">
          <el-radio-group :disabled="disabled" v-model="formObj.paymentType">
            <el-radio :label="1">全款</el-radio>
            <el-radio :label="2">定金+尾款</el-radio>
          </el-radio-group>
          <div class="money-wrap" v-if="formObj.paymentType == 2">
            <label class="label" for="">定金金额/元:</label>
            <format-input :disabled="disabled" :intDigit="4" :precise="2" v-model="formObj.depositPrice"></format-input>
          </div>
        </div>
        <div slot="saleStoreSlot">
          <el-button v-if="!disabled" class="el-icon-plus" size="small" @click="closeDialog">选择门店</el-button>
          <template v-if="saleMerchantList && saleMerchantList.length">
            <GLTable class="selected-table" :hasPage="false" ref="selectedRef" :tableParams="selectedtableParams"
                     :tableData="saleMerchantList">
              <div slot="activityPriceSlot" slot-scope="scope">
                <format-input :disabled="disabled" :intDigit="6" :precise="2" placeholder="请输入"
                              v-model="scope.scope.activityPrice"></format-input>
              </div>
              <div slot="originalPriceSlot" slot-scope="scope">
                <format-input :disabled="disabled" :intDigit="6" :precise="2" placeholder="请输入"
                              v-model="scope.scope.originalPrice"></format-input>
              </div>
              <div slot="retainagePriceSlot" slot-scope="scope">
                {{ retainagePriceFn(scope.scope.activityPrice) }}
              </div>
              <div slot="auth-button" slot-scope="scope">
                <el-button v-if="!disabled" type="text" @click="handleDel(scope.scope)">删除</el-button>
              </div>
            </GLTable>
          </template>
        </div>

        <div slot="productVideoSlot">
          <el-form-item label="">
            <template v-if="!formObj.goodsVideo">
              <div class="upload-img">
                <i class="el-icon-plus avatar-uploader-desc-icon"></i>
                <div class="avatar-uploader-desc-word">上传视频</div>
                <input type="file" class="upload-video" style="opacity: 0" accept=".mp4"
                       @change="e => handleVideoChange(e)"/>
              </div>
            </template>
            <template v-else>
              <div class="video-box">
                <video id="video" width="100%" height="100%" preload loop muted>
                  <source :src="formObj.goodsVideo" type="video/mp4"/>
                </video>
                <div class="mask">
                  <div class="video-pane-close" @click="handleEnlarge(formObj.goodsVideo, 'video')">
                    <img src="../../assets/channel/view.png" alt=""/>
                  </div>
                  <div class="video-pane-close" @click="close('radio')" v-if="!disabled">
                    <img src="../../assets/channel/dele.png" alt=""/>
                  </div>
                </div>
              </div>
            </template>
            <div class="text-tip2">作为商品详情页顶部展示和详情展示,格式建议mp4,大小不超过20M</div>
          </el-form-item>
        </div>
        <div slot="carSeriesSlot">
          <el-radio-group :disabled="disabled" v-model="formObj.vehicleSeriesType">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">部分</el-radio>
          </el-radio-group>
          <div v-if="formObj.vehicleSeriesType == 2">
            <el-button type="default" v-if="!disabled" class="el-icon-plus" @click="handleCarSeriesClose">选择车系
            </el-button>
            <div class="car-series-wrap" v-if="vehicleSeriesRequestList && vehicleSeriesRequestList.length">
              <div class="car-series-item" v-for="item in vehicleSeriesRequestList" :key="item.vehicleSeriesId">
                {{ item.vehicleSeriesName }}
              </div>
            </div>
          </div>
        </div>
      </glsx-combi-form>
    </div>
    <GLFooter style="margin-top: 16px;">
      <el-button @click="handleCancel">取消</el-button>
      <el-button v-if="!disabled" type="primary" @click="handleSave">确定</el-button>
    </GLFooter>
    <selectCarDialog v-if="carDialogVisible" :echoData="vehicleSeriesRequestList" @handleClose="handleCarSeriesClose"
                     @handleConfirm="handleConfirm" :dialogVisible="carDialogVisible"></selectCarDialog>
    <selectGoods v-if="goodsVisible" :routeInfo="routeInfo" :dialogVisible="goodsVisible" :goodsInfo="{goodsSource:1}"
                 @handleGoodsConfirm="handleGoodsConfirm" @handleGoodsClose="handleGoodsClose"></selectGoods>
    <selectMerchantDialog @confirmDialog="confirmDialog" @closeDialog="closeDialog"
                          :goodsId="formObj.smartcarlifeInfoId" :selectedList="saleMerchantList"
                          v-if="merchantDialogVisible" :isVisible="merchantDialogVisible"></selectMerchantDialog>
    <el-dialog class="image-dialog" :visible.sync="dialogVisibleImg" width="50%">
      <img :src="dialogSrc" width="100%" v-if="dialogType == 'img'" />
      <video width="100%" autoplay controls :src="dialogSrc" v-else></video>
    </el-dialog>
    <div v-if="showPreviewDialog" class="preview-dialog" @click="showPreviewDialog = false">
      <img class="preview-img" src="@/assets/preview.png" alt=""/>
    </div>
  </div>
</template>
<script>
const MerchantColumns = [
  {
    label: '门店名称',
    prop: 'merchantName',
  },
  {
    label: '门店原价(元)',
    width: 220,
    addHtml: 'originalPriceSlot'
  },
  {
    label: '门店活动价(元)',
    width: 220,
    addHtml: 'activityPriceSlot'
  },
  {
    label: '尾款金额(元)',
    width: 150,
    addHtml: 'retainagePriceSlot'
  }
]

const notPriceColumns = [
  {
    label: '门店名称',
    prop: 'merchantName',
  },
  {
    label: '门店原价(元)',
    addHtml: 'originalPriceSlot'
  },
  {
    label: '门店活动价(元)',
    addHtml: 'activityPriceSlot'
  }
]
import glsxCombiForm from '@/components/glsx-combi-form'
import selectGoods from './components/selectGoods'
import selectCarDialog from '@/views/store/components/selectCarDialog'
import selectMerchantDialog from './components/selectMerchantDialog'

export default {
  name: 'add',
  components: {
    glsxCombiForm,
    selectGoods,
    selectCarDialog,
    selectMerchantDialog
  },
  watch: {
    'formObj.paymentType': {
      handler(nVal, oVal) {
        if (nVal == 1) {
          this.selectedtableParams.tableColumns = notPriceColumns
        } else {
          this.selectedtableParams.tableColumns = MerchantColumns
        }
      },
      deep: true
    }
  },
  data() {
    return {
      showPreviewDialog: false,
      dialogVisibleImg:false,
      goodsVisible: false,
      carDialogVisible: false,
      merchantDialogVisible: false,
      disabled: false,
      dialogSrc:'',
      routeInfo: {},
      defaultProps: {
        children: 'categoryName',
        label: 'childs'
      },
      posterOptions: {
        width: '104px',
        height: '104px',
        key: 'posterImg',
        isClose: true
      },
      goodsFormData: [
        {
          label: '商品图',
          addHtml: 'uploadSlot',
          isDisabled: false
        },
        {
          label: '商品名称',
          name: 'goodsName',
          maxlength: 20,
          showLimit: true,
          type: 'input',
          isDisabled: false
        },
        {
          label: '售价(元)',
          name: 'retailPrice',
          type: 'showTxt'
        },
        {
          label: '最低售价(元)',
          name: 'minSellPrice',
          type: 'showTxt'
        },
      ],
      formObj: {
        smartcarlifeInfoId: '',
        goodsName: '',
        goodsType: '1',
        goodsImage: '',
        minSellPrice: '',
        retailPrice: '',
        coverList: [],
        styleBImgList: [],
        styleBImg: '',
        paymentType: 1,
        depositPrice: '',
        vehicleSeriesType: 1,
        goodsVideo: '',
        associationClassifyFirstId: ''
      },
      saleMerchantList: [],
      vehicleSeriesRequestList: [],
      myRule: {
        selectGoodsName: [
          {
            required: true,
            validator: (rule, value, callback) => {
              if (!this.formObj.smartcarlifeInfoId) {
                callback(new Error('请选择商品'))
              } else {
                callback()
              }
            },
            trigger: 'change'
          }
        ],
        goodsInfoName: [{
          required: true,
          validator: (rule, value, callback) => {
            if (!this.formObj.coverList && !this.formObj.coverList[0]) {
              callback(new Error('请上传商品图'))
            } else if (!this.formObj.goodsName) {
              callback(new Error('请输入商品名称'))
            } else {
              callback()
            }
          },
          trigger: 'change'
        }],
        paymentType: [{
          required: true,
          validator: (rule, value, callback) => {
            if (this.formObj.paymentType == 2 && !this.formObj.depositPrice) {
              callback(new Error('请输入定金金额'))
            } else {
              callback()
            }
            this.validateField('saleStore')
          },
          trigger: 'change'
        }],
        saleStore: [{
          required: true,
          validator: (rule, value, callback) => {
            const target = this.saleMerchantList.find(item => !item.activityPrice || !item.originalPrice)
            const hasNegTarget = this.saleMerchantList.find(item => {
              let activityPrice = item.activityPrice || 0
              let depositPrice = this.formObj.depositPrice || 0
              return +activityPrice < +depositPrice
            })
            const hasTarget = this.saleMerchantList.find(item => {
              let originalPrice = item.originalPrice || 0
              let activityPrice = item.activityPrice || 0
              let minSellPrice = this.formObj.minSellPrice || 0
              return (+activityPrice > +originalPrice || +originalPrice < minSellPrice)
            })
            if (!this.saleMerchantList.length) {
              callback(new Error('请选择门店'))
            } else if (target) {
              callback(new Error('门店活动价和原价不能为空'))
            } else if (this.formObj.paymentType == 2 && hasNegTarget) {
              callback(new Error('活动价不能小于定金'))
            } else if (hasTarget) {
              callback(new Error('原价不能小于最低售价和活动价'))
            } else {
              callback()
            }
          },
          trigger: 'change'
        }],
        carSeriesName: [{
          required: true,
          validator: (rule, value, callback) => {
            if (this.formObj.vehicleSeriesType == 2 && !this.vehicleSeriesRequestList.length) {
              callback(new Error('请选择适用车系'))
            } else {
              callback()
            }
          },
          trigger: 'change'
        }],
        associationClassifyFirstId: [{required: true, message: '请选择关联商品分类', trigger: 'change'}],
      },
      formData: [
        {
          label: '选择商品',
          name: 'selectGoodsName',
          addHtml: 'selectGoodsSlot',
          type: 'input',
          isDisabled: false
        },
        {
          label: '商品信息',
          name: 'goodsInfoName',
          addHtml: 'goodsInfoSlot',
          type: 'input',
          isDisabled: false
        },
        {
          label: '种草样式B宣传图',
          name: 'propagateCover',
          addHtml: 'propagateCoverSlot'
        },
        {
          label: '收款方式',
          name: 'paymentType',
          addHtml: 'paymentSlot'
        },
        {
          label: '销售门店',
          name: 'saleStore',
          addHtml: 'saleStoreSlot'
        },
        {
          label: '产品视频',
          name: 'productVideo',
          addHtml: 'productVideoSlot'
        },
        // {
        //   label: '产品视频',
        //   name: 'activityVideoList',
        //   type: 'upload',
        //   uploadType: 'video',
        //   suffixSlot: 'activityVideos',
        //   // tips: '大图下可以展示视频,不上传则不显示',
        //   limitSize: 20,
        //   maxPhotoNum: 1,
        //   handleDelete: idx => {
        //     this.formObj.activityVideoList = ''
        //   },
        //   handleUpload: (e, file, targetItem) => {
        //     const imgFile = e.target.result
        //     const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
        //     const fileSuffix = file.name.split('.')[file.name.split('.').length - 1]
        //     if (fileSuffix.toLowerCase() != 'mp4') {
        //       this.$message.error('上传视频不是MP4的格式!')
        //       return true
        //     }
        //     this.loading = true
        //     this.$apis.common
        //         .uploadVideoApi({ file: base64 })
        //         .then(res => {
        //           this.formObj.activityVideoList = res
        //         })
        //         .finally(() => {
        //           this.loading = false
        //         })
        //   }
        // },
        {
          label: '适用车系',
          name: 'carSeriesName',
          addHtml: 'carSeriesSlot',
        },
        // {
        //   label: '关联商品分类',
        //   name: 'categoryName',
        //   addHtml: 'categorySlot'
        // },
        {
          label: '关联商品分类',
          name: 'associationClassifyFirstId',
          type: 'select',
          optionList: [],
          optionId: 'id',
          optionLabel: 'categoryName',
          isDisabled: false
        },
      ],
      selectedtableParams: {
        listName: 'list',
        tableOption: {
          width: 100
        },
        tableColumns: notPriceColumns
      }
    }
  },
  created() {
    this.getCategory()
    const urlParam = this.$route.params
    this.routeInfo = JSON.parse(decodeURIComponent(urlParam.id))
    const {id, type} = this.routeInfo
    if (type == 1) {
      this.disabled = true
      this.posterOptions.isClose = false
      const _target = this.goodsFormData.find(item => item.name == 'goodsName')
      _target.isDisabled = true
      const _classifyTarget = this.formData.find(item => item.name == 'associationClassifyFirstId')
      _classifyTarget.isDisabled = true
      this.selectedtableParams.tableOption = null
    }
    if (id) {
      this.getDetail()
    }
  },
  methods: {
    getCategory() {
      const params = {
        pageSize: 10000,
        pageNum: 1,
        categoryType: 1
      }
      this.$apis.category.getCategoryListApi(params).then(res => {
        if (res?.list?.length) {
          const _target = this.formData.find(item => item.name == 'associationClassifyFirstId')
          _target.optionList = res.list
        }
      })
    },
    // 上传视频
    handleVideoChange(e) {
      let file = e.srcElement.files[0]
      var reader = new FileReader()
      // 默认30MB
      const limitSize = 20
      const isLt = file.size / 1024 / 1024 < limitSize
      if (!isLt) {
        this.$message.error('上传视频大小不能超过' + limitSize + 'MB!')
        this.loading = false
        return
      }
      this.$notify({
        title: '提示',
        message: '视频上传中,请稍后'
      })
      document.querySelector('.upload-video').value = ''
      reader.readAsDataURL(file)
      reader.onload = e => {
        const videoFile = e.target.result
        const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + videoFile.split(',')[1]
        this.$apis.common.uploadVideoApi({file: base64}).then(res => {
          if (res) {
            this.$notify({
              title: '提示',
              message: '视频上传成功',
              type: 'success'
            })
            this.loading = false
            this.formObj.goodsVideo = res
          } else {
            this.loading = false
          }
        })
      }
    },
    // 预览图文
    handleEnlarge(src, type) {
      this.dialogVisibleImg = true
      this.dialogSrc = src
      this.dialogType = type ? type : 'img'
    },
    // 删除图片/视频
    close(type, index) {
      switch (type) {
        case 'radio':
          this.formObj.goodsVideo = ''
          break
        default:
          this.formObj.goodsVideo = ''
      }
    },
    validateField(field) {
      if (Array.isArray(field)) {
        field.forEach(item => {
          this.$refs.baseInfoRef.$refs.formRef.validateField(item)
        })
      } else {
        this.$refs.baseInfoRef.$refs.formRef.validateField(field)
      }
    }
    ,
    retainagePriceFn(price) {
      let depositPrice = this.formObj.paymentType == 1 ? 0 : this.formObj.depositPrice
      if (this.formObj.paymentType == 1) return '--'
      if (!price) {
        return '待计算'
      } else {
        return Number((price - depositPrice).toFixed(2))
      }
    }
    ,
    openGoodsDialog() {
      if (this.disabled) return
      this.goodsVisible = true
    }
    ,
    handleGoodsClose() {
      this.goodsVisible = false
    }
    ,
    handleGoodsConfirm(e) {

      if (this.formObj.smartcarlifeInfoId != e?.id) this.saleMerchantList = []
      let {id: smartcarlifeInfoId, goodsName, goodsImage, minSellPrice, retailPrice,goodsVideo} = e || {}
      minSellPrice = minSellPrice ? Number(Number(minSellPrice / 100).toFixed(2)) : 0
      retailPrice = retailPrice ? Number(Number(retailPrice / 100).toFixed(2)) : 0

      // 若选择的商品素材包含了视频,则带入对应的视频文件
      if (goodsVideo) this.formObj.goodsVideo = goodsVideo
      this.formObj = {
        ...this.formObj,
        smartcarlifeInfoId,
        goodsName,
        goodsImage,
        coverList: [goodsImage],
        minSellPrice,
        retailPrice
      }
      this.handleGoodsClose()
      this.validateField(['selectGoodsName', 'goodsInfoName'])
    }
    ,
    handleCarSeriesClose() {
      this.carDialogVisible = !this.carDialogVisible
    }
    ,
    handleConfirm(e = {}) {
      let carList = []
      for (const key in e) {
        for (const sonKey in e[key]) {
          carList = [...carList, ...e[key][sonKey]]
        }
      }
      this.vehicleSeriesRequestList = carList.map(item => {
        const {id, name, parentId, parentName, rootId, rootName} = item
        return {
          brandId: rootId,
          brandName: rootName,
          childBrandId: parentId,
          childBrandName: parentName,
          vehicleSeriesId: id,
          vehicleSeriesName: name
        }
      })
      this.handleCarSeriesClose()
      this.validateField('carSeriesName')
    }
    ,
    confirmDialog(e) {
      this.saleMerchantList = e || []
      this.closeDialog()
      this.validateField('saleStore')
    }
    ,
    closeDialog() {
      if (!this.merchantDialogVisible && !this.formObj.smartcarlifeInfoId) {
        return  this.$message({
          message: '请选择商品',
          type: 'error',
          customClass: 'message-Z-zinde'
        })
      }
      this.merchantDialogVisible = !this.merchantDialogVisible
    }
    ,
    handleDel(row) {
      const idx = this.saleMerchantList.findIndex(item => item.merchantId == row.merchantId)
      if (idx > -1) this.saleMerchantList.splice(idx, 1)
    }
    ,
    selectCategory(e) {
      this.formObj.associationClassifyFirstId = e?.parent?.id
      this.formObj.associationClassifySecondId = e?.data?.id
      this.validateField('categoryName')
    }
    ,
    getParams() {
      let obj = JSON.parse(JSON.stringify(this.formObj))
      obj.goodsImage = obj.coverList[0]
      obj.styleBImg = obj.styleBImgList[0]
      obj.depositPrice = obj.depositPrice ? Number(Number(obj.depositPrice * 10 * 10).toFixed(0)) : 0
      if (obj.paymentType == 1) delete obj.depositPrice
      delete obj.minSellPrice
      delete obj.retailPrice
      delete obj.coverList
      delete obj.styleBImgList

      let saleMerchantList = this.saleMerchantList.map(item => {
        let {merchantId, merchantName, activityPrice, originalPrice} = item
        let price = this.formObj.paymentType == 1 ? 0 : this.formObj.depositPrice
        let retainagePrice = activityPrice - price
        activityPrice = activityPrice ? Number(Number(activityPrice * 10 * 10).toFixed(0)) : 0
        retainagePrice = retainagePrice ? Number(Number(retainagePrice * 10 * 10).toFixed(0)) : 0
        originalPrice = originalPrice ? Number(Number(originalPrice * 10 * 10).toFixed(0)) : 0
        if (obj.paymentType == 1) {
          return {merchantId, merchantName, activityPrice, originalPrice}
        } else {
          return {merchantId, merchantName, activityPrice, retainagePrice, originalPrice}
        }
      })
      const params = {
        saleMerchantList: saleMerchantList,
        vehicleSeriesRequestList: this.vehicleSeriesRequestList,
        ...obj
      }
      if (this.routeInfo.id) params.id = this.routeInfo.id
      return params
    },
    handleSave() {
      this.$refs.baseInfoRef.$refs.formRef.validate(valid => {
        if (valid) {
          const params = this.getParams()
          this.$apis.goods.addGoodsApi(params).then(res => {
            if (res) {
              this.$message.success('操作成功')
              this.handleCancel()
            }
          })
        }
      })
    }
    ,
    handleCancel() {
      this.$router.back()
    }
    ,
    getDetail() {
      const params = {
        id: this.routeInfo.id
      }
      if (this.routeInfo.merchantId) params.merchantId = this.routeInfo.merchantId
      this.$apis.goods.getGoodsDetail(params).then(res => {
        if (res) {
          for (const key in this.formObj) {
            const formatAttr = ['depositPrice', 'minSellPrice', 'retailPrice']
            if (formatAttr.includes(key)) {
              this.formObj[key] = res[key] ? Number(Number(res[key] / 100).toFixed(2)) : 0
            } else {
              this.formObj[key] = res[key]
            }
          }
          this.formObj.goodsType = '1'
          this.formObj.coverList = [res.goodsImage]
          this.formObj.styleBImgList = res.styleBImg ?  [res.styleBImg] : []
          this.saleMerchantList = res.saleMerchantList?.map(item => {
            let activityPrice = item.activityPrice ? Number(Number(item.activityPrice / 100).toFixed(2)) : 0
            let originalPrice = item.originalPrice ? Number(Number(item.originalPrice / 100).toFixed(2)) : 0
            return {...item, activityPrice, originalPrice}
          }) || []
          this.vehicleSeriesRequestList = res?.vehicleSeriesList?.map(item => {
            const {brandId, brandName, childBrandId, childBrandName, vehicleSeriesId, vehicleSeriesName} = item
            return {brandId, brandName, childBrandId, childBrandName, vehicleSeriesId, vehicleSeriesName}
          }) || []
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">
.container {
  .glsx-combi-form {
    /deep/ .el-radio-group {
      .el-radio__label {
        padding-left: 8px;
      }
    }
  }

  background-color: #fff;

  .disabled-class {
    cursor: not-allowed;
    color: #666666;
  }


  .propagate-cover-class{
    .preview{
      color: #5850ff;
      font-weight: 400;
      font-size: 14px;
      line-height: 20px;
      align-self: self-end;
      margin-left: 10px;
      cursor: pointer;
    }
    .upload-wrap{
      display: flex;
    }
    .tip{
      height: 20px;
      line-height: 20px;
      align-self: flex-end;
      font-weight: 400;
      font-size: 14px;
      color: #999999;
    }
  }

  .goods-wrap {
    padding: 20px 20px 1px;
    width: 1000px;
    background: #F9F9F9;
    border-radius: 4px;

    .upload-calss {
      display: flex;

      .tip {
        height: 20px;
        line-height: 20px;
        align-self: flex-end;
        font-weight: 400;
        font-size: 14px;
        color: #999999;
        margin-left: 10px;
      }
    }
  }

  .category-class {
    width: 432px;
  }

  .money-wrap {
    .label {
      width: 92px;
      height: 20px;
      line-height: 20px;
      font-weight: 400;
      font-size: 14px;
      color: #333333;
      text-align: right;
    }

    .el-input {
      width: 432px;
    }
  }

  .selected-table {
    margin-top: 10px;
    width: 100%;
    max-width: 1000px;

    .el-button--text {
      padding: 0;
    }
  }

  .car-series-wrap {
    margin-top: 8px;
    width: 580px;
    height: 80px;
    background: #FFFFFF;
    border: 1px solid #E8E8EA;
    border-radius: 4px;
    padding: 6px 8px;
    overflow-y: auto;

    .car-series-item {
      display: inline-block;
      padding: 0 8px;
      height: 24px;
      color: #666666;
      line-height: 24px;
      background: #FAFBFE;
      border: 1px solid #E5E5E5;
      border-radius: 4px;
      margin-right: 4px;
    }
  }
}


.upload-img {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 104px;
  height: 104px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px dashed rgba(0, 0, 0, 0.15);
  border-radius: 4px;

  input {
    position: absolute;
    // top: 0;
    // left: 0;
    width: 104px;
    height: 104px;
  }
}



.avatar-uploader-desc-word {
  font-weight: 400;
  font-size: 28 rpx;
  color: #666666;
}

.video-box {
  position: relative;
  width: 104px;
  height: 104px;
  border-radius: 4px;
  margin-right: 8px;

  &:hover .mask {
    opacity: 1;
  }

  .video {
    position: absolute;
    object-fit: fill;
  }

  .photo-activity {
    position: absolute;
    width: 104px;
    height: 104px;
  }

  .mask {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    background: rgba(0, 0, 0, 0.5);
    color: #ffffff;
    opacity: 0;
    top: 0;
    right: 0;
    width: 104px;
    height: 104px;
    z-index: 999;

    .video-pane-close {
      width: 14px;
      height: 14px;
      cursor: pointer;
      margin-right: 8px;
    }
  }
}

.activity-img-box {
  display: flex;
}

.text-tip2 {
  font-family: PingFangSC-Regular;
  font-weight: 400;
  font-size: 14 rpx;
  color: #999999;
  margin-bottom: -35px;
}

.preview-dialog{
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 99;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  .preview-img{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 390px;
    height: 720px;
  }
}
</style>