295 lines
6.6 KiB
Vue
Raw Normal View History

2022-06-08 15:48:09 +08:00
<template>
<view class="fullHeight bgWhite">
<headers :showBack="true">
<view class="headerName">
存放位置设置
</view>
</headers>
<scroll-view scroll-y="true" class="pageContent">
<view class="pageInner">
<view class="typeBox" v-for="(item,index) in typeList" :key="index" @click="editFn(item)">
<image src="/static/markRoomImg/bg_bule.png" class="bg"></image>
<view class="name">
{{item.locationName}}
</view>
</view>
<view class="addBox" @click="addFn">
<view class="">
<image src="/static/icon-add.png" class="icon-add"></image>
<view class="">
添加存放位置
</view>
</view>
</view>
</view>
</scroll-view>
<dialogs ref="dialogs">
<!-- <template v-slot:title>
{{isAdd?'添加':'编辑'}}
</template> -->
2023-06-19 09:02:35 +08:00
<template v-slot:content>
<view class="formBox2">
<form @submit="formSubmit">
2022-06-08 15:48:09 +08:00
<view class="uni-form-item">
<view class="uni-form-label">
<text class="star">*</text>父级位置
</view>
<view class="uni-form-input">
2023-06-19 09:02:35 +08:00
<picker @change="bindPickerChange" :value="selectIndex" :range="selectList"
range-key="locationName">
2022-06-08 15:48:09 +08:00
<view class="uni-input uni-select cl" v-if="selectIndex==null">
2023-06-19 09:02:35 +08:00
请选择 <image class="icon-down" src="/static/icon-down-black.png"></image>
</view>
<view class="uni-input uni-select" v-else>{{selectList[selectIndex].locationName}}
<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
2022-06-08 15:48:09 +08:00
</view>
</picker>
</view>
</view>
<view class="uni-form-item">
<view class="uni-form-label">
<text class="star">*</text>位置名称
</view>
<view class="uni-form-input">
2023-06-19 09:02:35 +08:00
<input class="uni-input" placeholder-class="cl" name="locationName"
v-model="form.locationName" placeholder="请输入" />
2022-06-08 15:48:09 +08:00
</view>
</view>
2023-06-19 09:02:35 +08:00
<button form-type="submit" type="primary" class="btn submitBtn">保存</button>
2022-06-08 15:48:09 +08:00
<button form-type="submit" class="btn deleteBtn" v-show="!isAdd" @click="deleteFn">删除</button>
<view class="closeBtn" @click="closeDialogFn">
关闭
</view>
2023-06-19 09:02:35 +08:00
</form>
</view>
</template>
2022-06-08 15:48:09 +08:00
</dialogs>
</view>
</template>
<script>
import headers from "../../../../components/headers/headers.vue"
import dialogs from "../../../../components/dialog/dialog.vue"
export default {
2023-06-19 09:02:35 +08:00
components: {
headers,
dialogs
},
2022-06-08 15:48:09 +08:00
data() {
return {
2023-06-19 09:02:35 +08:00
projectDetail: {},
typeList: [],
form: {
projectSn: '',
locationName: '',
parentId: ''
2022-06-08 15:48:09 +08:00
},
2023-06-19 09:02:35 +08:00
isAdd: true,
devSn: '',
selectList: [],
selectIndex: null
2022-06-08 15:48:09 +08:00
};
},
onLoad(options) {
2023-06-19 09:02:35 +08:00
this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'))
this.devSn = options.devSn
2022-06-08 15:48:09 +08:00
this.loadData2()
this.loadData()
},
mounted() {
2023-06-19 09:02:35 +08:00
2022-06-08 15:48:09 +08:00
},
2023-06-19 09:02:35 +08:00
methods: {
2022-06-08 15:48:09 +08:00
bindPickerChange: function(e) {
console.log('picker发送选择改变携带值为', e.target.value)
this.selectIndex = e.target.value
},
2023-06-19 09:02:35 +08:00
closeDialogFn() {
2022-06-08 15:48:09 +08:00
this.$refs.dialogs.hideFn()
},
2023-06-19 09:02:35 +08:00
editFn(item) {
this.isAdd = false
this.form = JSON.parse(JSON.stringify(item))
this.selectIndex = null
if (item.parentId != 0) {
2022-06-08 15:48:09 +08:00
for (var i = 0; i < this.selectList.length; i++) {
2023-06-19 09:02:35 +08:00
if (this.selectList[i].id == item.parentId) {
this.selectIndex = i
this.form.locationName = item.locationName.split('>')[1]
2022-06-08 15:48:09 +08:00
}
}
}
2023-06-19 09:02:35 +08:00
2022-06-08 15:48:09 +08:00
this.$refs.dialogs.showFn()
},
2023-06-19 09:02:35 +08:00
addFn() {
this.form.locationName = ''
this.form.parentId = ''
this.selectIndex = null
this.isAdd = true
2022-06-08 15:48:09 +08:00
this.$refs.dialogs.showFn()
},
2023-06-19 09:02:35 +08:00
loadData() {
2022-06-08 15:48:09 +08:00
var that = this
this.sendRequest({
url: "xmgl/standardLocation/selectChildrenLocationList",
2023-06-19 09:02:35 +08:00
data: {
projectSn: this.projectDetail.projectSn,
devSn: this.devSn
},
2022-06-08 15:48:09 +08:00
method: "POST",
2023-06-19 09:02:35 +08:00
success(res) {
2022-06-08 15:48:09 +08:00
that.typeList = res.result
}
})
},
2023-06-19 09:02:35 +08:00
loadData2() {
2022-06-08 15:48:09 +08:00
var that = this
this.sendRequest({
url: "xmgl/standardLocation/list",
2023-06-19 09:02:35 +08:00
data: {
projectSn: this.projectDetail.projectSn,
devSn: this.devSn
},
2022-06-08 15:48:09 +08:00
method: "POST",
2023-06-19 09:02:35 +08:00
success(res) {
2022-06-08 15:48:09 +08:00
that.selectList = res.result
}
})
},
2023-06-19 09:02:35 +08:00
deleteFn() {
2022-06-08 15:48:09 +08:00
var that = this
this.sendRequest({
url: 'xmgl/standardLocation/delete',
2023-06-19 09:02:35 +08:00
data: {
id: this.form.id
},
2022-06-08 15:48:09 +08:00
method: "POST",
2023-06-19 09:02:35 +08:00
success(res) {
2022-06-08 15:48:09 +08:00
uni.showToast({
2023-06-19 09:02:35 +08:00
title: '删除成功!'
2022-06-08 15:48:09 +08:00
})
that.$refs.dialogs.hideFn()
that.loadData()
that.loadData2()
}
})
},
2023-06-19 09:02:35 +08:00
formSubmit(e) {
2022-06-08 15:48:09 +08:00
var that = this
console.log(e)
var params = e.detail.value
2023-06-19 09:02:35 +08:00
params.projectSn = this.projectDetail.projectSn
if (params.locationName == '') {
2022-06-08 15:48:09 +08:00
uni.showToast({
2023-06-19 09:02:35 +08:00
title: '请输入位置名称',
icon: 'none'
2022-06-08 15:48:09 +08:00
})
return false;
}
2023-06-19 09:02:35 +08:00
if (this.selectIndex != null) {
params.parentId = this.selectList[this.selectIndex].id
2022-06-08 15:48:09 +08:00
}
2023-06-19 09:02:35 +08:00
2022-06-08 15:48:09 +08:00
var url = 'xmgl/standardLocation/edit'
2023-06-19 09:02:35 +08:00
if (this.isAdd) {
2022-06-08 15:48:09 +08:00
url = 'xmgl/standardLocation/add'
2023-06-19 09:02:35 +08:00
params.devSn = this.devSn
} else {
params.id = this.form.id
2022-06-08 15:48:09 +08:00
}
this.sendRequest({
url: url,
data: params,
method: "POST",
2023-06-19 09:02:35 +08:00
success(res) {
2022-06-08 15:48:09 +08:00
uni.showToast({
2023-06-19 09:02:35 +08:00
title: '保存成功!'
2022-06-08 15:48:09 +08:00
})
2023-06-19 09:02:35 +08:00
uni.navigateTo({
url: '/pages/projectEnd/markRoom/locationManage/locationManage'
});
2022-06-08 15:48:09 +08:00
that.$refs.dialogs.hideFn()
that.loadData()
that.loadData2()
2023-06-19 09:02:35 +08:00
2022-06-08 15:48:09 +08:00
}
})
}
}
}
</script>
<style lang="scss" scoped>
2023-06-19 09:02:35 +08:00
.typeBox {
width: 85px;
height: 80px;
display: inline-flex;
align-items: center;
justify-content: center;
margin-right: 10px;
font-size: 12px;
text-align: center;
border-radius: 10px;
2022-06-08 15:48:09 +08:00
position: relative;
2023-06-19 09:02:35 +08:00
margin-bottom: 10px;
color: white;
vertical-align: top;
padding: 0 10px;
.name {
font-size: 18px;
position: relative;
z-index: 2;
word-break: break-all;
}
.desc {
position: relative;
z-index: 2;
}
2022-06-08 15:48:09 +08:00
}
2023-06-19 09:02:35 +08:00
.bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.pageInner {
padding: 15px;
2022-06-08 15:48:09 +08:00
}
2023-06-19 09:02:35 +08:00
.addBox {
text-align: center;
width: 105px;
height: 78px;
display: inline-flex;
align-items: center;
justify-content: center;
border: 1px solid rgba(42, 43, 91, 0.1);
border-radius: 10px;
font-size: 12px;
color: rgba(42, 43, 91, 1);
background-color: #f6f5f8;
vertical-align: top;
.icon-add {
width: 18px;
height: 18px;
}
}
.closeBtn {
font-size: 15px;
color: rgba(42, 43, 91, 0.5);
padding: 10px 0;
text-align: center;
2022-06-08 15:48:09 +08:00
}
</style>