FirstStep.js 13.2 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
// packageEquity/pages/carEquity/components/FirstStep/FirstStep.js
import data from '../constant/stepData'
import fn from '../constant/ruleFn'
import carLifeApi from '~/packageEquity/carEquityApi'
import commonApi from '~/api/api'
const defaultLabelWidth = 'var(--fontSize140)'
import Util from '~/utils/util'
import { validateVin, formatVinInput } from '~/utils/vinVaildate'
// import api from '~/api/api'
Component({
  options: {
    styleIsolation: 'apply-shared'
  },
  /**
   * 组件的属性列表
   */
  properties: {
    serviceInfo: {
      type: Object,
      observer: function (n) {
        this.setData({
          formData: n
        })
      }
    },
    orderInfo: {
      type: Object,
      observer: function (n) {
        if (n?.modifyEquityQuotation) {
          this.setData({
            // activeNames: ['3'],
            disable: true
          })
        } else {
          this.setData({
            disable: false
          })
        }
      }
    },
    // 页面存放表单对象的对象名
    dataAttrName: {
      type: String,
      value: null
    },
    subBtnShow: {
      type: Boolean,
      value: true
    },
    mode: {
      type: Number,
      value: 1
    }
  },
  observers: {
    'mode': function (value, old) {
      console.log(value, old, 'mode');
      if (value != 1) {
        this.setData({
          first: data.firstObj,
          formRule: data.formRule
        })
      }
    }

    // 'orderInfo.outTradeNo': function (value) {
    //   console.log(value, 'outTradeNo')
    //   value && this.setData({
    //     textNameObj: {
    //       confirmName: '下一步(1/4)'
    //       // cancelName: '存草稿'
    //     }
    //   })
    // }
  },
  /**
   * 组件的初始数据
   */
  data: {
    defaultLabelWidth,
    formData: {},
    employeeList: [],
    disable: true,
    first: '',
    formRule: '',
    // first: data.firstObjSimple,
    // formRule: data.formRuleSimple,
    referrerPicker: false,
    deliveryPicker:false,
    textNameObj: {
      confirmName: '下一步(1/4)',
      cancelName: '存草稿'
    },
    vinValid: true,
    createAllGoodsFlag: 1,
    showSceneSelect: false,
    sceneColumns: []
  },

  lifetimes: {
    attached() {
      this.getEmployee()
      this.getShopMerchantPointConfig()
      this.getUserSceneList()
      // 没有才走获取档案接口逻辑修改配置,有是必填优先及更高
      // 在createOrderCarQuotationSimple 页面做逻辑判断
      // this.getYqStoreConfig()

    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getUserSceneList() {
      const MOCK_SCENE_LIST = [
        { uuid: '100101', name: '精品升级', baseSceneCode: '100101', sceneType: 1, businessType: null },
        { uuid: '100102', name: '交新车干配', baseSceneCode: '100102', sceneType: 2, businessType: null },
        { uuid: '100103', name: '售后众筹', baseSceneCode: '100103', sceneType: 3, businessType: null },
        { uuid: '110101', name: '售前会员权益升级', baseSceneCode: '110101', sceneType: 0, businessType: 1 },
        { uuid: '110102', name: '售后会员权益升级', baseSceneCode: '110102', sceneType: 0, businessType: 1 },
        { uuid: '110201', name: '售前延保', baseSceneCode: '110201', sceneType: 0, businessType: 2 },
        { uuid: '110202', name: '售后延保', baseSceneCode: '110202', sceneType: 0, businessType: 2 },
        { uuid: '120101', name: '二手车收车', baseSceneCode: '120101', sceneType: 7, businessType: null }
      ]
      const userInfo = wx.$util.getUserInfo() || {}
      commonApi
        .getUserScene({
          sceneType: String(userInfo.sceneType ?? ''),
          phone: userInfo.phone
        })
        .then(res => {
          const list = res?.code == 0 && res?.data?.length ? res.data : MOCK_SCENE_LIST
          this.setData({
            sceneColumns: list.map(item => ({
              ...item,
              name: item.name || item.staffName
            }))
          })
        })
        .catch(() => {
          this.setData({
            sceneColumns: MOCK_SCENE_LIST
          })
        })
    },
    onCloseSceneSelect() {
      this.setData({
        showSceneSelect: false
      })
    },
    onConfirmSceneSelect(e) {
      const scene = e.detail.value || {}
      const thisPage = wx.$router.getPageInstance()
      thisPage.setData({
        'orderInfo.baseSceneCode': scene.baseSceneCode || '',
        'orderInfo.baseSceneName': scene.name || scene.staffName || ''
      })
      // 切换场景后,重新按场景拉取可选商品
      thisPage.resetGoods && thisPage.resetGoods()
      this.setData({
        showSceneSelect: false
      })
    },
    handleScenePicker() {
      this.getUserSceneList()
      this.setData({
        showSceneSelect: true
      })
    },
    getShopMerchantPointConfig() {
        console.log(1111111111)
      let { userInfo } = this.data
      let oParams = {}
      oParams.merchantId = userInfo.shopMerchantId
      commonApi.getShopMerchantPointConfig(oParams).then(res => {
        const { pointsMultiRole, createAllGoodsFlag } = res.data
        this.setData({
          pointsMultiRole,
          createAllGoodsFlag
        })
        // 触发事件通知父页面更新配置
        this.triggerEvent('updateConfig', {
          createAllGoodsFlag
        })
      })
    },
    // 推荐人
    // handleSalesChange(e) {
    //   let idx = e.detail.value || 0
    //   this.setData({
    //     'formData.referrerId': this.data.employeeList[idx].uuid,
    //     'formData.referrer': this.data.employeeList[idx].staffName
    //   })
    // },
    inputEvent(e) {
      let {
        attr
      } = e.detail
      
      // 车架号输入处理:实时转大写 + 实时校验
      if (attr == 'carVin') {
        const thisPage = wx.$router.getPageInstance()
        const { dataAttrName } = this.data
        // 从页面数据中获取刚刚更新的车架号值
        const value = thisPage.data[dataAttrName]?.carVin || ''
        const upperVin = formatVinInput(value)
        // 更新为大写
        thisPage.setData({
          [dataAttrName + '.carVin']: upperVin
        })
        // 当输入满17位时,进行实时校验(防抖500ms)
        if (upperVin.length === 17) {
            validateVin(upperVin).then(res => {
              let { valid } = res.data.data;
              console.log("upperVinRes",valid);
              // 保存 valid 值到组件 data 中
              this.setData({
                vinValid: valid
              });
            }).catch(() => {
              console.log("upperVinErr",upperVin);
            })
        }
      }
      
      // 是车价就重新筛选商品列表
      if (attr == 'price') {
        let thisPage = wx.$router.getPageInstance()
        thisPage.resetGoods && thisPage.resetGoods()
      }
    },
    handleReferrerPicker() {
      this.setData({
        referrerPicker: true
      })
    },
    handleDeliveryPicker() {
      this.setData({
        deliveryPicker: true
      })
    },
    
    handleSalesChange(e) {
      // let value = e.detail
      console.log(e)
      let idx = e.detail.value || 0
      let {
        employeeList,
        disable
      } = this.data
      if (disable) return false
      let thisPage = wx.$router.getPageInstance()

      thisPage.setData({
        ['orderInfo.referrerId']: employeeList[idx].uuid,
        ['orderInfo.referrer']: employeeList[idx].staffName
      })
    },
    handleDeliveryChange(e) {
      // let value = e.detail
      let idx = e.detail.value || 0
      let {
        employeeList,
        disable
      } = this.data
      if (disable) return false
      let thisPage = wx.$router.getPageInstance()

      thisPage.setData({
        ['orderInfo.deliveryId']: employeeList[idx].uuid,
        ['orderInfo.deliveryName']: employeeList[idx].staffName
      })
    },
    // 获取推荐人列表
    getEmployee() {
      let userInfo = wx.$util.getStorageSync('dj_boutique_user_info')
      this.setData({
        userInfo
      })
      let params = {
        merchantId: userInfo.default4SStoreInfo.merchantId
      }
      carLifeApi.getEmployeeList(params).then(res => {
        if (res.code == 0) {
          this.setData({
            employeeList: res.data
          })
        } else {
          wx.$util.showToast(res.message || '接口异常')
        }
      })
    },
    navOcr(e) {
      // idCard:1,
      // vehicleCertificate:5
      let {
        type
      } = e.currentTarget.dataset
      console.log(type)
      // wx.$router.go('ocrEquityModules', { type })
      wx.$router.go(`ocrEquityModules?type=${type}`)
    },

    btnTap(e) {
      // console.log(e)
      let {
        name
      } = e.detail
      if (name == 'confirm') {
        // this.triggerEvent('confirm')
        // 需要校验
        this.handleConfirm()
      } else {
        this.triggerEvent('editSave')
      }
    },
    handleConfirm() {
      var {
        dataAttrName,
        formRule,
        pointsMultiRole,
        vinValid
      } = this.data

      // let thisPage = this.$router.getCurrentPage()
      let thisPage = wx.$router.getPageInstance()
      // console.log(thisPage.data['orderInfo']['actualSalesPersonId'])
      if (!thisPage.data['orderInfo']['referrerId']) {
        wx.$util.showToast(pointsMultiRole=='Y'?'请选择销售顾问/录单员':'请选择推荐人')
        return false
      }
      if (!thisPage.data['orderInfo']['baseSceneCode']) {
        wx.$util.showToast('请选择场景名称')
        return false
      }
      if(pointsMultiRole=='Y'){
        if (!thisPage.data['orderInfo']['deliveryId']) {
          wx.$util.showToast('请选择交付专员')
          return false
        }
        if(thisPage.data['orderInfo']['deliveryId']==thisPage.data['orderInfo']['referrerId']){
          wx.$util.showToast('销售顾问/录单员与交付专员不能选取同一人')
          return false
        }
      }
      // 车架号校验
      const carVin = thisPage.data[dataAttrName]?.carVin
      if (carVin) {
        const isCarVinRequired = formRule?.carVin?.some(rule => rule.required === true) // 再次判断一下车架号是否必填项
        // 前置判断
        if (carVin.length !== 17 && isCarVinRequired) {
          wx.$util.showToast('请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)')
          return false
        }
        // 根据接口校验结果判断
        if (carVin.length === 17 && !vinValid) {
          wx.$util.showToast('车架号校验不匹配,请核对后重新输入')
          return false
        }
      }
      let validObj = fn.checkRequired(thisPage.data[dataAttrName], formRule)
      if (validObj) {
        wx.$util.showToast(validObj.message)
        return false
      }
      
      // debugger
      this.triggerEvent('confirm')
      return true
    },
    showCustomPop() {
      this.setData({
        customerInfoBox: true
      })
    },
    chooseCustomerInfo(e) {
      console.log(e)
      let {
        customer
      } = e.detail
      const thisPage = wx.$router.getPageInstance()
      thisPage.setCustomerInfo(customer)
    },
    changeGender(e) {
      let {
        gender
      } = e.currentTarget.dataset
      wx.vibrateShort()
      const thisPage = wx.$router.getPageInstance()
      thisPage.setData({
        ['owner.ownerGender']: gender
      })
    },
    bindRegionChange(e) {
      const thisPage = wx.$router.getPageInstance(),
        {
          values
        } = e.detail.detail
      let city = Array.from(new Set([...values.map(e => e.name)]))
      thisPage.setData({
        ['owner.city']: city.join('-')
      })
    },
    // 品牌车型
    handleJumpBrand(e) {
      // wx.$router.go('packageEquity.carBrands')
      this.setData({
        showCarBrands: true, // 选择时再加载车型组件
        carBrandBox: true
      })
    },

    chooseCar(e) {
      let { dataAttrName } = this.data
      let { carBrand, carBrandId, carChildsBrandId, carChildsBrandName, carSeriesId, carSeriesName } = e.detail
      let thisPage = wx.$router.getPageInstance()
      thisPage.setData({
        [dataAttrName + '.' + 'carBrand']: carBrand,
        [dataAttrName + '.' + 'carBrandId']: carBrandId,
        [dataAttrName + '.' + 'carChildsBrandId']: carChildsBrandId,
        [dataAttrName + '.' + 'carChildsBrandName']: carChildsBrandName,
        [dataAttrName + '.' + 'carSeriesId']: carSeriesId,
        [dataAttrName + '.' + 'carSeriesName']: carSeriesName
      })
        // 是车价就重新筛选商品列表
        if (carSeriesId) {
          thisPage.resetGoods && thisPage.resetGoods()
        }
    },
    /**获取园区配置 */
    async getYqStoreConfig() {
      const {
        merchantId: yqMerchantId
      } = wx.$util.getUserInfo(), {
        first
      } = this.data, {
        data
      } = await commonApi.getYqStoreConfig({
        yqMerchantId
      })
      let {
        customerFormList,
        carFormList
      } = first
      //是否配置园区店面档案互通 Y / N
      if (data) {
        if (data.customerExchangeFlag == 'N') {
          customerFormList = customerFormList?.filter(item => !item.configItem)
          carFormList = carFormList?.filter(item => !item.configItem)
        }
      }
      this.setData({
        ['first.customerFormList']: customerFormList,
        ['first.carFormList']: carFormList,
        showCustomeBtn: data.customerExchangeFlag == 'Y'
      })

    },
  }
})