瀏覽代碼

1. fix bug: 经纬度未在初始化时设置
2. AI优化页面
- 已删除未使用的组件与导入:去除 AppAvatarModule、AppUploader、mapActions、regionData,合并 @/api/shop 的重复导入,统一表单校验模块为 validator。
- 修复生命周期与初始化:onLoad(option) 接收参数并保存 this.option,存在 id 时直接拉取详情 _getDet();onShow 仅负责设置标题。
- 统一事件与类型:所有 switch/radio/picker 事件改为使用 e.detail.value,并对需要的值做 Number(...) 转换,避免字符串数值引发逻辑分支错误。
- 健壮化详情回填:openStartTime/openEndTime 为空用 09:00/18:00 默认值;判空由 == '' 改为更稳健的 !data.openStartTime/!data.openEndTime。
- 统一异步错误处理与加载态:详情获取与提交新增 catch 分支,finally 中关闭 uni.showLoading(),避免异常时 Loading 不消失。
- 清理调试输出:删除 console.log 与未使用的中间方法 _resultData。

shizhongqi 11 月之前
父節點
當前提交
e15e0e2c95
共有 1 個文件被更改,包括 69 次插入82 次删除
  1. 69 82
      ghsApp/src/admin/shop/add.vue

+ 69 - 82
ghsApp/src/admin/shop/add.vue

@@ -242,22 +242,16 @@
 
 <script>
 import TuiListCell from '@/components/plugin/list-cell'
-import AppAvatarModule from '@/components/module/app-avatar'
 import SimpleAddress from '@/components/plugin/simple-address'
 import AppAreaSel from '@/components/app-area-sel'
-import AppUploader from "@/components/app-uploader";
-const form = require('@/utils/formValidation.js')
-import { updateShop as update, addShop as add } from '@/api/shop'
-import {mapActions} from "vuex";
-import {getDetail} from "@/api/shop"
+const validator = require('@/utils/formValidation.js')
+import { getDetail, updateShop as update, addShop as add } from '@/api/shop'
 export default {
 	name: 'add',
 	components: {
 		TuiListCell,
-		AppAvatarModule,
 		SimpleAddress,
-		AppAreaSel,
-		AppUploader
+		AppAreaSel
 	},
 	data() {
 		return {
@@ -308,14 +302,17 @@ export default {
 				lat: 0,
 				long: 0
 			},
-			regionData: [],
 			cityPickerValueDefault: [0, 0],
 			id:0,
 			hasMap:0 // 是否具备定位功能 0不具备 1具备
 		}
 	},
-	onLoad() {
+	onLoad(option) {
+		this.option = option || {}
 		this.id = this.option.id ? this.option.id : 0
+		if (this.option.id) {
+			this._getDet()
+		}
 	},
 	onShow() {
 		if (this.option.id) {
@@ -329,83 +326,67 @@ export default {
 		}
 	},
 	methods: {
-		...mapActions(['setUserShopAll']),
-		init() {
-			this._getDet()
-		},
-		_resultData(val) {
-			console.log(val)
-			this.form.img = val;
-		},
+		init() {},
 		_getDet() {
-
 			if(this.option.id && !this.$util.isEmpty(this.option.id)){
-				getDetail({shopId:this.option.id}).then(res=>{
-					let data = res.data.info
-
-					if (this.$util.isEmpty(data)) return
-					Object.keys(this.form).forEach((i, index) => {
-						this.form[i] = data[i]
+				getDetail({shopId:this.option.id})
+					.then(res=>{
+						let data = res.data.info
+						if (this.$util.isEmpty(data)) return
+						Object.keys(this.form).forEach((i) => {
+							this.form[i] = data[i]
+						})
+						this.region.lat = data.lat
+						this.region.long = data.long
+						this.visible = this.form.open == 1 ? true : false
+						this.openTimeVisible = true
+						this.form.openType = 1
+						this.start_time = this.form.openStartTime
+						this.end_time = this.form.openEndTime
+						if (!data.openStartTime) {
+							this.openTimeVisible = false
+							this.form.openType = 0
+							this.start_time = '09:00'
+							this.form.openStartTime = this.start_time
+						}
+						if (!data.openEndTime) {
+							this.end_time = '18:00'
+							this.form.openEndTime = this.end_time
+						}
+						this.hasMap = data.hasMap || 0
+					})
+					.catch(() => {
+						this.$msg('获取门店详情失败')
 					})
-
-					this.visible = this.form.open == 1 ? true : false
-					this.openTimeVisible = true
-					this.form.openType = 1
-					this.start_time = this.form.openStartTime
-					this.end_time = this.form.openEndTime
-					if (data.openStartTime == '') {
-						this.openTimeVisible = false
-						this.form.openType = 0
-						this.start_time = '09:00'
-						this.form.openStartTime = this.start_time
-					}
-					if (data.openEndTime == '') {
-						this.end_time = '18:00'
-						this.form.openEndTime = this.end_time
-					}
-					this.hasMap = data.hasMap || 0
-				})
 			}
 		},
 		itemToClassChange(e){
-			this.form.itemToClass = e.target.value ? 1 : 0
+			this.form.itemToClass = e.detail.value ? 1 : 0
 		},
 		presellChange(e){
-			this.form.presell = e.target.value ? 1 : 0
-		},
-		isHdChange(e){
-			this.form.isHd = e.target.value ? 0 : 1
-		},
-		showStockChange(e){
-			this.form.showStock = e.target.value ? 1 : 0
+			this.form.presell = e.detail.value ? 1 : 0
 		},
 		cgUnitTypeChange(e){
-			this.form.cgUnitType = e.target.value ? 1 : 0
+			this.form.cgUnitType = e.detail.value ? 1 : 0
 		},
 		pfLevelChange(e){
-			this.form.pfLevel = e.target.value ? 1 : 0
+			this.form.pfLevel = e.detail.value ? 1 : 0
 		},
 		afterSaleChange(e){
-			this.form.afterSale = e.target.value ? 1 : 0
-		},
-		showSoldChange(e){
-			this.form.showSold = e.target.value ? 1 : 0
+			this.form.afterSale = e.detail.value ? 1 : 0
 		},
 		carSaleChange(e){
-			this.form.carSale = e.target.value ? 1 : 0
+			this.form.carSale = e.detail.value ? 1 : 0
 		},
 		defaultChange(e){
-			this.form.default = e.target.value ? 1 : 0
+			this.form.default = e.detail.value ? 1 : 0
 		},
 		allowDebtChange(e){
-			this.form.allowDebt = e.target.value ? 1 : 0
-		},
-		needCheckChange(e){
-			this.form.needCheck = e.target.value ? 1 : 0
+			this.form.allowDebt = e.detail.value ? 1 : 0
 		},
 		openChange(e) {
-			this.visible = e.target.value ? true : false
-			this.form.open = e.target.value ? 1 : 0
+			this.visible = e.detail.value ? true : false
+			this.form.open = e.detail.value ? 1 : 0
 		},
 		startTimeChange: function(e) {
 			this.start_time = e.detail.value
@@ -416,15 +397,15 @@ export default {
 			this.form.openEndTime = e.detail.value
 		},
 		joinChange(e){
-			this.form.join = e.detail.value
+			this.form.join = Number(e.detail.value)
 		},
 		cutStyleChange(e){
-			this.form.cutStyle = e.detail.value
-			console.log(this.form.cutStyle)
+			this.form.cutStyle = Number(e.detail.value)
 		},
 		radioChange(e) {
-			this.openTimeVisible = e.detail.value == 0 ? false : true;
-			this.form.openType = e.detail.value == 0 ? 0 : 1; // openType: 0. 24小时 1. xx ~ xx
+			const selected = Number(e.detail.value)
+			this.openTimeVisible = selected === 0 ? false : true;
+			this.form.openType = selected === 0 ? 0 : 1; // openType: 0. 24小时 1. xx ~ xx
 			if (this.openTimeVisible) {
 				this.start_time = '09:00'
 				this.end_time = '18:00'
@@ -438,8 +419,8 @@ export default {
 			this.form.city = e.cityName
 			this.form.address = ''
 			this.form.showAddress = ''
-			this.region.lat = 10
-			this.region.long = 11
+			this.region.lat = 0
+			this.region.long = 0
 		},
 		selectRegion() {
 			if (!this.form.city) {
@@ -472,14 +453,20 @@ export default {
 			this.form.showAddress = this.form.city+this.form.address+this.form.floor
 			this.form = {...this.form,...this.region}
 			uni.showLoading({mask:true})
-			hostFn(this.form).then(res => {
-				uni.hideLoading()
-				let promptText = this.option.id ? '修改成功' : '添加成功'
-				this.$msg(promptText)
-				setTimeout(() => {
-					this.$util.pageTo(1)
-				}, 1000)
-			})
+			hostFn(this.form)
+				.then(() => {
+					let promptText = this.option.id ? '修改成功' : '添加成功'
+					this.$msg(promptText)
+					setTimeout(() => {
+						this.$util.pageTo(1)
+					}, 1000)
+				})
+				.catch(() => {
+					this.$msg('提交失败,请稍后重试')
+				})
+				.finally(() => {
+					uni.hideLoading()
+				})
 		},
 		// 表单验证
 		formSubmit(e) {
@@ -508,7 +495,7 @@ export default {
 			]
 			// 进行npm表单检查
 			let formData = e.detail.value
-			let checkRes = form.validation(formData, rules)
+			let checkRes = validator.validation(formData, rules)
 			// 验证通过!
 			if (!checkRes) {
 				this.confirmFn()