relateProDialog.vue 13.7 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
<!-- 编辑商品弹窗 -->
<template>
  <d2-dialog
    title="添加绑定升级商品"
    :isVisible.sync="relateProVisible"
    btnOkLabel="关联"
    width="950px"
    @confirmDialog="handleRelateProConfirm"
    @closeDialog="handleRelateProClose"
    class="relatePro"
  >
    <div class="relateProDialog flex">
      <img
        v-show="proInfo.thumbUrl"
        :src="proInfo.thumbUrl"
      />
      <img
        v-show="!proInfo.thumbUrl"
        src="./image/no-choice.png"
      />
      <el-form
        :model="proInfo"
        :rules="rules"
        label-width="110px"
        ref="proRuleForm1"
        style="width: calc(100% - 180px);"
      >
        <div class="w-50">
          <el-form-item
            label="选择产品"
            prop="goodsCode"
          >
            <el-select
              style="width: 98%;"
              v-model="proInfo.goodsCode"
              placeholder="请选择一款作为升级商品"
              value-key="goodsCode"
              filterable="true"
              @change="handleChangeGood"
            >
              <el-option
                v-for="item in proList"
                :key="item.goodsCode"
                :label="item.goodsName"
                :value="item.goodsCode"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="w-50">
          <el-form-item label="分类">
            <el-input
              disabled
              placeholder="分类"
              :value="proInfo.goodsTypeName"
              class="dis-in-block"
            ></el-input>
          </el-form-item>
        </div>
        <div class="w-50">
        </div>
        <div class="w-50">
          <el-form-item label="编号">
            <el-input
              disabled
              placeholder="编号"
              :value="proInfo.goodsCode"
              class="dis-in-block"
            ></el-input>
          </el-form-item>
        </div>
        <div class="w-50">
          <el-form-item
            label="到店价格"
            prop="shopPrice"
          >
            <el-input
              v-model="proInfo.shopPrice"
              placeholder="请输入建议到店价格"
              class="dis-in-block"
              @input="handleShopPrice"
              @blur="handleShopPriceBlur"
            >
              <i
                slot="suffix"
                class="suffix"
              >元</i>
            </el-input>
          </el-form-item>
        </div>
        <div class="w-50">
          <el-form-item
            label="建议升级价格"
            prop="upgradePrice"
          >
            <el-input
              v-model="proInfo.upgradePrice"
              placeholder="请输入建议升级价格"
              class="dis-in-block"
              @input="handleUpgradePrice"
            >
              <i
                slot="suffix"
                class="suffix"
              >元</i>
            </el-input>
          </el-form-item>
        </div>
        <div class="w-50">
          <el-form-item
            label="额外成本"
            prop="extraCost"
          >
            <el-input
              v-model="proInfo.extraCost"
              placeholder="请输入额外成本"
              class="dis-in-block"
              @input="handleExtraCost"
            >
              <i
                slot="suffix"
                class="suffix"
              >元</i>
            </el-input>
          </el-form-item>
        </div>
        <div class="w-50">
          <el-form-item label="零售折扣">
            <el-input
              v-model="proInfo.maxUpgradeDiscount"
              placeholder="仅支持输入1.0~9.9的数值"
              clearable
              class="dis-in-block"
              @input="handleMaxUpgradeDiscount"
            >
              <i
                slot="suffix"
                class="suffix"
              >折</i>
            </el-input>
          </el-form-item>
        </div>
        <div class="w-50">
          <el-form-item label="零售价格">
            <el-input
              v-model="proInfo.retailPrice"
              placeholder="请输入零售价格"
              clearable
              class="dis-in-block"
              @input="handleRetailPrice"
            >
              <i
                slot="suffix"
                class="suffix"
              >元</i>
            </el-input>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <!-- <div class="relateProDialog flex">
      <span class="sub-title">分配给导流方 (4S门店)</span>
      <el-form
        :model="proInfo"
        :rules="rules"
        label-width="110px"
        ref="proRuleForm2"
        style="width: calc(100% - 185px)"
      >
        <div class="w-50">
          <el-form-item
            label="分润规则"
            prop="profitType"
          >
            <el-select
              style="width: 98%;"
              v-model="proInfo.profitType"
              placeholder="请选择分润规则"
            >
              <el-option
                v-for="x in separateOpt"
                :key="x.confId"
                :value="x.confId"
                :label="x.confLabel"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="w-50">
          <el-form-item
            label="分润比例"
            title="每笔订单分配给4s店的金额结算比例。"
            prop="profitValue"
          >
            <el-input
              v-model="proInfo.profitValue"
              @input="handleProfitInput"
              placeholder="请输入0~100整数"
              class="dis-in-block"
            >
              <i
                slot="suffix"
                class="suffix"
              >%</i>
            </el-input>
          </el-form-item>
        </div>
      </el-form>
    </div> -->
    <!-- <div class="relateProDialog flex">
      <span class="sub-title" style="margin-right: 42px;">分配给合伙人 (合作商)</span>
      <el-form
        :model="proInfo"
        :rules="rules"
        label-width="110px"
        ref="proRuleForm3"
        style="width: calc(100% - 185px)"
      >
        <div class="w-50">
          <el-form-item
            label="阳光激励费"
            title="每笔订单分配给合作商的金额结算比例。"
            prop="incentiveCost"
          >
            <el-input
              v-model="proInfo.incentiveCost"
              @input="handleIncentiveCost"
              placeholder="请输入阳光激励费"
              class="input-with-select"
            >
              <el-select
                slot="prepend"
                style="width: 75px;"
                v-model="proInfo.incentiveType"
                @change="handleChangeType"
              >
                <el-option
                  v-for="(item, index) in incentiveTypeList"
                  :key="index"
                  :value="item.confId"
                  :label="item.confLabel"
                ></el-option>
              </el-select>
              <i
                slot="suffix"
                class="suffix"
              >{{proInfo.incentiveType === 1 ? '%' : '元'}}</i>
            </el-input>
          </el-form-item>
        </div>
        <div class="w-50">
          <el-form-item
            label="分润比例"
            title="每笔订单分配给合作商的金额结算比例。"
            prop="partnerProfitPer"
          >
            <el-input
              v-model="proInfo.partnerProfitPer"
              @input="handlePartnerProfitPer"
              placeholder="请输入0~100整数"
              class="dis-in-block"
            >
              <i
                slot="suffix"
                class="suffix"
              >%</i>
            </el-input>
          </el-form-item>
        </div>
      </el-form>
    </div> -->
    <!-- <span
      class="btn-txt"
      slot="btn-start"
    >提示:配置的分润规则和比例将优先根据门店打款方式结算。</span> -->
  </d2-dialog>
</template>

<script>
import _ from 'lodash'
import { limitPrice } from '@/common/constants'
export default {
  name: 'relateProDialog',
  data() {
    return {
      goodVal: {},
      proInfo: {
        // thumbUrl: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1244233290,1050095100&fm=26&gp=0.jpg',
        thumbUrl: '',
        goodsCode: '',
        goodsName: '',
        goodsTypeName: '',
        type: '',
        upgradePrice: '',
        shopPrice: '',
        // profitType: '',
        // profitValue: '',
        extraCost: '',
        // partnerProfitPer: '',
        maxUpgradeDiscount: '',
        incentiveType: 1
        // incentiveCost: ''
      },
      rules: {
        goodsCode: [{ required: true, message: '请选择关联升级商品', trigger: 'change' }],
        upgradePrice: [
          { required: true, message: '请输入建议升级价', trigger: 'blur' },
          { required: true,
            trigger: 'blur',
            validator: (rule, value, callback) => {
              (+value < +this.proInfo.shopPrice) ? callback(new Error('建议升级价需要大于或等于到店价格')) : callback()
            }
          }],
        shopPrice: [{ required: true, message: '请输入到店价', trigger: 'blur' }]
        // profitType: [{ required: true, message: '请输入分润规则', trigger: 'change' }],
        // profitValue: [{ required: true, message: '请输入分润比例', trigger: 'blur' }],
        // incentiveCost: [{ required: true, message: '请输入阳光激励费', trigger: 'change' }],
        // partnerProfitPer: [{ required: true, message: '请输入分润比例', trigger: 'blur' }]
      },
      oldVal: {
        upgradePrice: '',
        shopPrice: '',
        maxUpgradeDiscount: ''
      },
      separateOpt: [{
        confId: 1,
        confLabel: '毛利'
      }, {
        confId: 2,
        confLabel: '收入'
      }],
      incentiveTypeList: [{
        confId: 1,
        confLabel: '比例'
      }, {
        confId: 2,
        confLabel: '金额'
      }]
    }
  },

  props: {
    relateProVisible: {
      type: Boolean,
      default: false
    },
    proList: {
      type: Array,
      default: () => []
    },
    originProInfo: {
      type: Object,
      default: () => { }
    }
  },

  mounted() {
    this.proInfo = this.originProInfo ? _.cloneDeep(this.originProInfo) : _.cloneDeep(this.proInfo)
    !this.proInfo.incentiveType && (this.proInfo.incentiveType = 1)
  },

  methods: {
    handleChangeGood(value) {
      var targetItem = this.proList.find(item => item.goodsCode === value)
      this.proInfo.goodsName = targetItem.goodsName
      this.proInfo.goodsCode = targetItem.goodsCode
      this.proInfo.thumbUrl = targetItem.thumbUrl
      this.proInfo.goodsTypeName = targetItem.goodsTypeName
    },
    handleRelateProConfirm() {
      this.$refs.proRuleForm1.validate(valid1 => {
        // this.$refs.proRuleForm2.validate(valid2 => {
        // this.$refs.proRuleForm3.validate(valid3 => {
        if (valid1) {
          this.$emit('handleRelateProConfirm', this.proInfo)
        }
        // })
        // })
      })
    },
    handleRelateProClose() {
      this.$emit('handleRelateProClose')
    },
    handleUpgradePrice(newVal) {
      this.proInfo.upgradePrice = limitPrice(newVal, this.oldVal.upgradePrice, 8, 2)
      this.oldVal.upgradePrice = this.proInfo.upgradePrice
    },
    handleShopPrice(newVal) {
      this.proInfo.shopPrice = limitPrice(newVal, this.oldVal.shopPrice, 6, 2)
      this.oldVal.shopPrice = this.proInfo.shopPrice
    },
    handleShopPriceBlur() {
      if (this.proInfo.upgradePrice) {
        var validateObj = (this.proInfo.shopPrice <= this.proInfo.upgradePrice) ? 'clearValidate' : 'validateField'
        this.$refs.proRuleForm1[validateObj]('upgradePrice')
      }
    },
    handleMaxUpgradeDiscount(newVal) {
      this.proInfo.maxUpgradeDiscount = limitPrice(newVal, this.oldVal.maxUpgradeDiscount, 1, 1, 1)
      this.oldVal.maxUpgradeDiscount = this.proInfo.maxUpgradeDiscount
    },
    // handleProfitInput(newVal) {
    //   this.proInfo.profitValue = limitPrice(newVal, this.oldVal.profitValue, 3, 0, 0, 100)
    //   this.oldVal.profitValue = this.proInfo.profitValue
    // },
    // handlePartnerProfitPer(newVal) {
    //   this.proInfo.partnerProfitPer = limitPrice(newVal, this.oldVal.partnerProfitPer, 3, 0, 0, 100)
    //   this.oldVal.partnerProfitPer = this.proInfo.partnerProfitPer
    // },
    handleExtraCost(newVal) {
      this.proInfo.extraCost = limitPrice(newVal, this.oldVal.extraCost, 8, 2)
      this.oldVal.extraCost = this.proInfo.extraCost
    },
    handleRetailPrice(newVal) {
      this.proInfo.retailPrice = limitPrice(newVal, this.oldVal.retailPrice, 6, 2)
      this.oldVal.retailPrice = this.proInfo.retailPrice
    }
    // handleIncentiveCost(newVal) {
    //   this.proInfo.incentiveCost = this.proInfo.incentiveType === 1 ? limitPrice(newVal, this.oldVal.incentiveCost, 3, 0, 0, 100) : limitPrice(newVal, this.oldVal.incentiveCost, 6, 2)
    //   this.oldVal.incentiveCost = this.proInfo.incentiveCost
    // },
    // handleChangeType() {
    //   this.proInfo.incentiveCost = ''
    //   this.oldVal.incentiveCost = ''
    // }
  }
}

</script>
<style scoped>
.relateProDialog.flex {
  display: flex;
}
.relateProDialog .sub-title {
  display: inline-block;
  height: 52px;
  line-height: 36px;
  margin-right: 40px;
}
.relateProDialog .w-50 {
  display: inline-block;
  width: 50%;
}
.relateProDialog img {
  width: 160px;
  height: 160px;
  margin-right: 20px;
}
.relateProDialog .dis-in-block {
  /* display: inline-block; */
  width: 98%;
  /* margin-right: 6px; */
}
.relatePro .btn-txt {
  display: inline-block;
  font-size: 14px;
  margin-right: 209px;
  color: #606266;
}
</style>