| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- import {
- createGuestDec,
- fetchBrandAmbassadorInfo,
- fetchGuestDec,
- fetchGuestFullInfo,
- fetchGuestInspectNetwork
- } from '@/api/user'
- import tool from '@/utils/tool'
- import usersInfo from '@/utils/usersInfo'
- // 注册页的私有业务实现源自旧 Welcome Pack;保留接口字段与计价规则,避免引入旧页全局样式。
- export default {
- data() {
- return {
- loading: false,
- draft: {},
- // 公开注册页使用固定选项,不依赖后台国家、语言列表请求或缓存。
- countriesList: [
- {
- ID: '620699181539139625',
- NAME: 'Nigeria',
- DEFAULT_LANGUAGE_ID: '620713695651307520'
- }
- ],
- languageList: [
- { ID: '620713695718416384', NAME: '中文' },
- { ID: '620713695651307520', NAME: 'English' }
- ],
- allGoods: [],
- payList: [],
- multipleSelection: [],
- sellPriceSum: 0.0,
- pricePvSum: 0.0,
- taxSum: 0.0,
- storeNums: [],
- tableData: [],
- payAmount: 0.0,
- submitButtonStat: false,
- visible: false,
- paymentComplete: false,
- paymentOrder: {
- orderSn: '', amount: 0, currency: '', reference: '', accessCode: ''
- },
- userBalance: {
- cash: 0
- },
- visibleProduct: false,
- product: {
- GOODS_NAME: '',
- GOODS_NO: '',
- COVER: '',
- SELL_PRICE: 0,
- PRICE_PV: 0,
- TAX_RATE: 0,
- taxAmount: 0
- },
- decWay: '2',
- regionData: [],
- form: {
- countryId: '',
- languageId: '',
- decType: 'normal',
- realName: '',
- decLv: '',
- insertUserName: '',
- decUserName: '',
- recUserName: '',
- conUserName: '',
- insertUserIdCard: '',
- consignee: '',
- acceptMobile: '',
- areaSelected: [],
- address: '',
- openBank: '',
- bankAddress: '',
- bankNo: '',
- bankAreaSelected: [],
- password: '111111',
- payPassword: '111111',
- mobile: '',
- email: '',
- packageId: '',
- goodsId: [],
- goodsNum: [],
- cityName: '',
- lgaName: '',
- way: 'express',
- payType: '',
- autoPlace: ''
- },
- conRealName: '-',
- recRealName: '-',
- areaDisabled: false,
- addressDisabled: false,
- userReadOnly: true,
- allDecLevel: [],
- allOpenBank: [],
- isDec: null,
- currencyUnitCode: ''
- }
- },
- computed: {
- submitLabel() {
- if (this.paymentComplete) return 'Payment submitted'
- return this.paymentOrder.accessCode ? 'Continue Payment' : 'Save'
- }
- },
- created() {
- // 邀请链接只提供初始值,不覆盖用户后续编辑,也不触发推荐人变更时的清空逻辑。
- const ref = this.$route && this.$route.query.ref
- if (typeof ref === 'string') {
- this.form.recUserName = ref.trim()
- this.form.conUserName = ref.trim()
- }
- },
- watch: {
- isDec: {
- handler(newValue) {
- if (String(newValue) === '1') {
- this.form.decUserName = usersInfo.userName()
- }
- }
- }
- },
- methods: {
- countriesChange() {
- const country = this.countriesList.find(item => item.ID === this.form.countryId)
- if (country) this.form.languageId = country.DEFAULT_LANGUAGE_ID
- this.fetchWelcomePack()
- },
- showLoadError(error) {
- this.$message.error(String(error.message || error))
- },
- // 游客报单初始化;临时标识只保存在本页,不写入会员登录缓存。
- fetchWelcomePack() {
- this.loading = true
- this.draft = {}
- this.form.insertUserName = ''
- const countryId = this.form.countryId
- fetchGuestDec({ countryId })
- .then((response) => {
- if (countryId !== this.form.countryId) return
- this.draft = response.data.draft || {}
- this.form.insertUserName = this.draft.insertUserName
- this.allOpenBank = response.data.allOpenBank || []
- this.allGoods = response.data.allGoods
- this.userBalance = response.data.userBalance || { cash: 0 }
- this.regionData = response.data.region
- this.allDecLevel = response.data.decLevel
- this.currencyUnitCode = this.draft.currency || ''
- if (!this.currencyUnitCode && response.data.allGoods && response.data.allGoods.length > 0) {
- this.currencyUnitCode = response.data.allGoods[0].CODE
- }
- // 是否是报单中心
- this.isDec = response.data.isDec
- const settingObj = this.allGoods
- for (const i in this.allGoods) {
- this.storeNums[i] = 1
- settingObj[i].goodsNum = 0
- }
- this.tableData = Object.values(settingObj)
- // 切换国家时清空选择与汇总,保持旧表格替换数据时的行为。
- this.multipleSelection = []
- this.handleSureChange()
- // 支付方式
- this.payList = response.data.payList || response.data.sellType[0]['sell_type']
- // 延续默认选中第二项的规则;单项或空列表时回退,避免读取不存在的选项。
- this.form.payType =
- (Object.values(this.payList)[1] || Object.values(this.payList)[0] || {}).label || ''
- setTimeout(() => {
- this.loading = false
- }, 0.5 * 1000)
- })
- .catch((err) => {
- if (countryId !== this.form.countryId) return
- this.showLoadError(err)
- this.loading = false
- })
- },
- // 商品详情
- handleProduct(row) {
- this.product = row
- this.product.taxAmount = tool.calculateTax(row.MARKET_PRICE, row.TAX_RATE)
- this.visibleProduct = true
- },
- // 选择商品计数
- handleInputNumber(current, row) {
- const pageList = this.multipleSelection
- let selectStatus = false
- for (const i in pageList) {
- if (pageList[i].ID === row.ID) {
- pageList[i].goodsNum = current
- selectStatus = true
- break
- }
- }
- if (selectStatus) {
- this.multipleSelection = pageList
- this.handleSureChange()
- }
- },
- // 汇总继续按市场价计费;销售价仅用于展示,税额使用原含税算法。
- handleSureChange() {
- if (this.multipleSelection.length > 0) {
- let accumulatorSellPrice = 0
- let accumulatorPricePv = 0
- let accumulatorTax = 0
- this.multipleSelection.forEach((accumulator) => {
- accumulatorSellPrice += accumulator.MARKET_PRICE * accumulator.goodsNum
- accumulatorPricePv += Number(accumulator.PRICE_PV) * Number(accumulator.goodsNum)
- accumulatorTax += tool.calculateTax(
- Number(accumulator.MARKET_PRICE),
- Number(accumulator.TAX_RATE),
- Number(accumulator.goodsNum)
- )
- })
- this.sellPriceSum = tool.formatPrice(accumulatorSellPrice)
- this.pricePvSum = tool.formatPrice(accumulatorPricePv)
- this.taxSum = tool.formatPrice(accumulatorTax)
- } else {
- this.sellPriceSum = this.pricePvSum = this.taxSum = 0.0
- }
- },
- // 选择商品
- handleSelectionChange(val) {
- let idx = -1
- let num
- for (const i in this.tableData) {
- for (const v in val) {
- if (val[v].ID === this.tableData[i].ID) {
- idx = i
- num = this.storeNums[idx]
- val[v]['goodsNum'] = num
- break
- }
- }
- }
- this.multipleSelection = val
- // 计算统计
- this.handleSureChange()
- },
- // 会员查询
- handleChkRecUser() {
- this.form.conUserName = ''
- this.conRealName = '-'
- this.form.autoPlace = ''
- if (this.form.recUserName) {
- this.loading = true
- fetchGuestFullInfo({ userName: this.form.recUserName })
- .then((response) => {
- this.recRealName = response.data.REAL_NAME
- this.loading = false
- })
- .catch(() => {
- this.recRealName = '-'
- this.loading = false
- })
- }
- },
- // 自提仅禁用地址输入;是否提交配送方式仍遵循旧接口契约。
- wayChange() {
- if (this.form.way === 'pickup') {
- this.areaDisabled = true
- this.addressDisabled = true
- } else {
- this.areaDisabled = false
- this.addressDisabled = false
- }
- },
- // 游客报单
- onSubmit() {
- if (this.submitButtonStat || this.paymentComplete) return
- if (!this.form.decLv) {
- this.$message({
- message: this.$t('profile.selectLevel'),
- type: 'error'
- })
- return false
- }
- if (String(this.isDec) === '0' && !this.form.decUserName) {
- this.$message({
- message: this.$t('shop.declarationCenterNumberTips'),
- type: 'error'
- })
- return false
- }
- if (!this.form.recUserName.trim()) {
- this.$message.error('Please enter the referrer ID.')
- return false
- }
- if (!this.form.conUserName.trim()) {
- this.$message.error('Please enter the actual referrer ID.')
- return false
- }
- // 已选择商品
- this.selectProduct()
- if (this.multipleSelection.length <= 0) {
- this.$message.error(this.$t('shop.chooseTips'))
- return false
- }
- // 余额
- const amountBalance = this.userBalance[this.form.payType] || 0
- // 余额是否充足
- if (this.form.payType === 'cash' && amountBalance - this.payAmount < 0) {
- // 账户类型提示信息
- const payListArray = Array.from(this.form.payType)
- const account = payListArray.filter((item) => {
- return this.form.payType === item.label
- })
- const accountType = (account[0] && account[0].name) || ''
- this.$message({
- message: accountType + this.$t('shop.balanceNotAllow'),
- type: 'error'
- })
- return false
- }
- if (!this.draft.draftId || !this.draft.accessToken) {
- this.$message.error('Please select your country again to load the guest order details.')
- return false
- }
- this.submitButtonStat = true
- // 字段与默认值沿用旧页,不能因新 UI 没有对应控件就删减提交参数。
- const params = {
- draftId: this.draft.draftId,
- accessToken: this.draft.accessToken,
- consignee: this.form.consignee,
- acceptMobile: this.form.acceptMobile,
- province: this.form.areaSelected[0] ? this.form.areaSelected[0] : '',
- city: this.form.areaSelected[1] ? this.form.areaSelected[1] : '',
- county: this.form.areaSelected[2] ? this.form.areaSelected[2] : '',
- address: this.form.address,
- decType: this.form.decType,
- insertUserName: this.form.insertUserName,
- decLv: this.form.decLv,
- realName: this.form.realName,
- decUserName: this.form.decUserName,
- conUserName: this.form.conUserName,
- recUserName: this.form.recUserName,
- insertUserIdCard: this.form.insertUserIdCard,
- openBank: this.form.openBank,
- bankAddress: this.form.bankAddress,
- mobile: this.form.mobile,
- email: this.form.email,
- cityName: this.form.cityName,
- lgaName: this.form.lgaName,
- bankProvince: this.form.bankAreaSelected[0] ? this.form.bankAreaSelected[0] : '',
- bankCity: this.form.bankAreaSelected[1] ? this.form.bankAreaSelected[1] : '',
- bankCounty: this.form.bankAreaSelected[2] ? this.form.bankAreaSelected[2] : '',
- bankNo: this.form.bankNo,
- password: this.form.password,
- payPassword: this.form.payPassword,
- packageId: this.form.packageId,
- goodsId: this.form.goodsId,
- goodsNum: this.form.goodsNum,
- location: 1, // 自动安置
- decWay: this.decWay,
- payType: this.form.payType,
- countryId: this.form.countryId,
- languageId: this.form.languageId
- }
- createGuestDec(params)
- .then((response) => {
- const order = response.data || response
- if (!order.accessCode || !order.reference) {
- throw new Error('Payment details are missing. Please contact customer service.')
- }
- this.paymentOrder = order
- this.submitButtonStat = false
- this.visible = true
- })
- .catch((err) => {
- this.$message({
- message: err.message || err,
- type: 'error'
- })
- this.submitButtonStat = false
- })
- },
- handleClose() {
- // 关闭只隐藏弹窗,继续支付时重新向后端获取支付信息。
- this.visible = false
- },
- processPayment(response) {
- if (!response || response.reference !== this.paymentOrder.reference) {
- this.showLoadError(new Error('Payment reference does not match the current order.'))
- return
- }
- this.visible = false
- this.paymentComplete = true
- this.$message({
- message: 'Payment submitted. Please wait for order confirmation.',
- type: 'success'
- })
- },
- // 已选择商品
- selectProduct() {
- this.payAmount = 0
- this.form.goodsId = []
- this.form.goodsNum = []
- this.multipleSelection.map((item) => {
- this.form.goodsId.push(item.ID)
- this.form.goodsNum.push(item.goodsNum)
- this.payAmount += item.goodsNum * item.MARKET_PRICE
- })
- },
- // BA会员查询
- checkBaUser() {
- if (this.form.decType === 'ba' && this.form.insertUserName !== '') {
- this.loading = true
- fetchBrandAmbassadorInfo({ userName: this.form.insertUserName })
- .then((response) => {
- this.form.recUserName = response.data.REC_USER_NAME
- this.form.realName = response.data.REAL_NAME
- this.handleChkRecUser()
- this.loading = false
- })
- .catch(() => {
- this.loading = false
- })
- }
- },
- // 查询安置人
- handleChkRecommenderActualName() {
- if (this.form.conUserName) {
- this.loading = true
- fetchGuestInspectNetwork({
- recommenderName: this.form.recUserName,
- recommenderActualName: this.form.conUserName
- })
- .then((response) => {
- this.conRealName = response.data.REAL_NAME
- this.loading = false
- })
- .catch(() => {
- this.conRealName = '-'
- this.loading = false
- })
- }
- }
- }
- }
|