Commit c55e1d4c by zhuxiaomei

维护人员地点

parent 8e1e6a81
<template>
<div>
<div class="layout-cont-btn">
<van-form>
<van-field
v-model="count"
name="count"
type="digit"
required center
label="人员随机数量"
placeholder="请输入人员随机数量"
:rules="[{ required: true, message: '' }]">
<template #button>
<van-button size="small" type="info" @click="_create">生成</van-button>
</template>
</van-field>
<van-field label="人员" center>
<template #input>
<Tag v-for="(item,index) in userList" :key="item.id" :name="index" closable @on-close="_handleClose">
{{ item.name }}
</Tag>
<van-button size="small" type="default" @click="_add">添加</van-button>
</template>
</van-field>
</van-form>
<van-form>
<van-field
v-model="locCount"
name="count"
type="digit"
required center
label="地点随机数量"
placeholder="请输入地点随机数量"
:rules="[{ required: true, message: '' }]">
<template #button>
<van-button size="small" type="info" @click="_locCreate">生成</van-button>
</template>
</van-field>
<van-field label="地点" center>
<template #input>
<Tag v-for="(item,index) in locList" :key="item.id" :name="index" closable @on-close="_handleLocClose">
{{ item.name }}
</Tag>
<van-button size="small" type="default" @click="_addLoc">添加</van-button>
</template>
</van-field>
</van-form>
</div>
<van-popup v-model="showAllSelect">
<SelectSamplerChecked @cancel="showAllSelect=false" @on-change="_selectChange"
ref="select"></SelectSamplerChecked>
</van-popup>
<van-popup v-model="showSelect">
<SelectLocChecked @cancel="showSelect=false" @on-change="_selectLocChange" ref="selectLoc"></SelectLocChecked>
</van-popup>
<div class="bottom-btn" style="position: fixed;bottom: 0">
<van-button type="info" block @click="_save">保存</van-button>
</div>
</div>
</template>
<script>
import {samplingPlan} from '../../api'
import SelectSamplerChecked from './sampler/SelectSamplerChecked'
import SelectLocChecked from './add/loc/SelectLocChecked'
export default {
name: "CreateSampler",
components: {
SelectSamplerChecked,
SelectLocChecked
},
data() {
return {
showAllSelect: false,
planId: '',
count: '',
userList: [],
showSelect: false,
locCount: '',
locList: []
}
},
mounted() {
this.planId = this.$route.query.planId
this._getInfo()
},
methods: {
_getInfo: async function () {
const result = await samplingPlan.getSamplerPlace({planId: this.planId})
if (result) {
this.userList = result.samplers
this.locList = result.places;
}
},
_create: async function () {
if (this.count) {
let result = await samplingPlan.generateSampler({count: this.count, planId: this.planId})
if (result) {
this.$toast('生成成功!')
this.userList = result
}
} else {
this.$toast("请输入随机数量")
}
},
_handleClose(event, index) {
this.userList.splice(index, 1);
},
_add() {
this.showAllSelect = true
this.$nextTick(function () {
this.$refs.select._open(this.planId)
})
},
_selectChange(res) {
this.showAllSelect = false
this.userList = [...res, ...this.userList]
},
_save: async function () {
if (this.userList.length === 0) {
this.$toast('请生成人员!')
} else if (this.locList.length === 0) {
this.$toast('请生成地点!')
} else {
let result = await samplingPlan.saveSamplerRandom({
planId: this.planId,
samplerIds: this.userList.map(item => item.id).join(',')
})
let resultLoc = await samplingPlan.savePlace({
planId: this.planId,
placeIds: this.locList.map(item => item.id).join(',')
})
if (result && resultLoc) {
this.$toast('保存成功!')
this.$router.go(-2)
}
}
},
_locCreate: async function () {
if (this.locCount) {
let result = await samplingPlan.generatePlace({count: this.locCount, planId: this.planId})
if (result) {
this.$toast('生成成功!')
this.locList = result
}
} else {
this.$toast("请输入随机数量")
}
},
_handleLocClose(event, name) {
const index = this.locList.indexOf(name);
this.locList.splice(index, 1);
},
_addLoc() {
this.showSelect = true
this.$nextTick(function () {
this.$refs.selectLoc._open(this.planId)
})
},
_selectLocChange(res) {
this.showSelect = false
this.locList = [...res, ...this.locList]
},
_back() {
this.$emit('back')
},
_submit: async function () {
if (this.userList.length === 0) {
this.$toast('请生成人员!')
} else if (this.locList.length === 0) {
this.$toast('请生成地点!')
} else {
let result = await samplingPlan.saveSubmitPlan({
planId: this.planId,
samplerIds: this.userList.map(item => item.id).join(','),
placeIds: this.locList.map(item => item.id).join(',')
})
if (result) {
this.$toast('操作成功!')
this.$router.go(-1)
}
}
}
}
}
</script>
<style scoped>
</style>
...@@ -70,7 +70,6 @@ import LocAdd from './loc/LocAdd' ...@@ -70,7 +70,6 @@ import LocAdd from './loc/LocAdd'
import SelectLoc from './loc/SelectLoc' import SelectLoc from './loc/SelectLoc'
export default { export default {
name: "Maintain",
components: { components: {
SamplerLab, SamplerLab,
LocAdd, LocAdd,
......
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
</van-form> </van-form>
</div> </div>
<div v-else-if="active===1" style="height: calc(100% - 63px)"> <div v-else-if="active===1" style="height: calc(100% - 63px)">
<MaintainComponent ref="maintain" @back="active--" @next="_nextTab3"></MaintainComponent> <AddMaintain ref="maintain" @back="active--" @next="_nextTab3"></AddMaintain>
</div> </div>
<div v-else-if="active===2" style="height: calc(100% - 63px)"> <div v-else-if="active===2" style="height: calc(100% - 63px)">
<TaskRequirements ref="task" @next="_saveCreate" @back="active--"></TaskRequirements> <TaskRequirements ref="task" @next="_saveCreate" @back="active--"></TaskRequirements>
...@@ -119,13 +119,13 @@ ...@@ -119,13 +119,13 @@
<script> <script>
import {samplingPlan} from '../../../api' import {samplingPlan} from '../../../api'
import TaskRequirements from './TaskRequirements' import TaskRequirements from './TaskRequirements'
import MaintainComponent from './MaintainComponent' import AddMaintain from './AddMaintain'
export default { export default {
name: "SamplingPlanAdd", name: "SamplingPlanAdd",
components: { components: {
TaskRequirements, TaskRequirements,
MaintainComponent, AddMaintain,
}, },
data() { data() {
return { return {
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
name="count" name="count"
type="digit" type="digit"
required center required center
label="随机数量" label="地点随机数量"
placeholder="请输入随机数量" placeholder="请输入地点随机数量"
:rules="[{ required: true, message: '' }]"> :rules="[{ required: true, message: '' }]">
<template #button> <template #button>
<van-button size="small" type="info" @click="_locCreate">生成</van-button> <van-button size="small" type="info" @click="_locCreate">生成</van-button>
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<script> <script>
import {samplingPlan} from '../../../api' import {samplingPlan} from '../../../api'
import SelectLocChecked from './SelectLocChecked' import SelectLocChecked from '../add/loc/SelectLocChecked'
export default { export default {
name: "CreateLoc", name: "CreateLoc",
......
<template> <template>
<div> <div>
<div class="layout-cont-btn"> <div class="layout-cont-btn">
<van-form ref="form" @submit="onSubmit"> <van-form ref="form" @submit="onSubmit">
<van-field <van-field
v-model="formObj.name" v-model="formObj.name"
name="name" name="name"
required required
label="地点" label="地点"
placeholder="请输入地点" placeholder="请输入地点"
:rules="[{ required: true, message: '' }]"> :rules="[{ required: true, message: '' }]">
</van-field> </van-field>
<van-field <van-field
v-model="formObj.address" v-model="formObj.address"
name="address" name="address"
label="地址" label="地址"
placeholder="请输入地址"> placeholder="请输入地址">
</van-field> </van-field>
<van-field <van-field
v-model="formObj.longitude" v-model="formObj.longitude"
name="longitude" name="longitude"
label="经度" label="经度"
placeholder="请输入经度"> placeholder="请输入经度">
</van-field> </van-field>
<van-field <van-field
v-model="formObj.latitude" v-model="formObj.latitude"
name="latitude" name="latitude"
label="纬度" label="纬度"
placeholder="请输入纬度"> placeholder="请输入纬度">
</van-field> </van-field>
</van-form> </van-form>
</div>
<div class="bottom-btn">
<van-button type="info" block @click="_save">保存</van-button>
</div>
</div> </div>
<div class="bottom-btn">
<van-button type="info" block @click="_save">保存</van-button>
</div>
</div>
</template> </template>
<script> <script>
import {samplingPlace} from '../../../api' import {samplingPlace} from '../../../api'
export default { export default {
name: "LocAdd", name: "LocAdd",
data() { data() {
return { return {
formObj: { formObj: {
name: '', name: '',
address: '', address: '',
longitude: '', longitude: '',
latitude: '', latitude: '',
}, },
planId: '' planId: ''
} }
}, },
mounted() { // mounted() {
this.planId = this.$route.query.planId // this.planId = this.$route.query.planId
}, // },
methods: { methods: {
_save(){ _open(planId) {
this.$refs.form.submit() this.planId = planId
}, this.formObj = this.$resetFields(this.formObj)
onSubmit(){ },
this._saveOk() _save() {
}, this.$refs.form.submit()
_saveOk: async function () { },
let obj = {...this.formObj, ...{planId: this.planId}} onSubmit() {
let result = await samplingPlace.add(this.$serializeForm(obj)) this._saveOk()
if (result) { },
this.$toast('操作成功!') _saveOk:async function() {
this.$router.go(-1) let obj = {...this.formObj, ...{planId: this.planId}}
} let result = await samplingPlace.add(this.$serializeForm(obj))
} if (result) {
} this.$toast('操作成功!')
this.$emit('on-change')
}
} }
}
}
</script> </script>
<style scoped> <style scoped>
......
<template>
<customer-navBar-layout style="width: 100vw;height:100vh">
<template #navBar>
<van-nav-bar
title="选择人员"
left-arrow
@click-left="_cancel"
></van-nav-bar>
</template>
<template #content>
<search-bar label="地点" @search="_search"></search-bar>
<div class="layout-cont-s layout-cont-s-btn">
<van-pull-refresh v-model="refreshing" @refresh="_refresh">
<van-list
v-model="loading"
:finished="finished"
finished-text="没有更多了"
@load="_load">
<van-checkbox-group v-model="checkListValue" ref="checkboxGroup">
<van-swipe-cell v-for="item in resultList" :key="item.name">
<div class="result-item" @click="_tapItem(item)">
<van-checkbox :name="item" shape="square"></van-checkbox>
<div>姓名:{{ item.name }}</div>
<div>电话:{{ item.tel }}</div>
<div>所属部门:{{ item.department }}</div>
</div>
</van-swipe-cell>
</van-checkbox-group>
</van-list>
</van-pull-refresh>
</div>
<div class="bottom-btn">
<van-button type="info" block @click="_add">添加</van-button>
</div>
</template>
</customer-navBar-layout>
</template>
<script>
/**
* 人员大库的操作
*/
import {sampler,samplingPlan} from '../../../api'
export default {
data() {
return {
resultList: [],
page: 1,
rows: 10,
refreshing: false,//刷新中...
loading: false,//加载中...
finished: false,//没有更多数据
checkListValue: [],
planId: ''
}
},
methods: {
_open(planId) {
this.checkListValue = []
this.planId = planId
this._refresh()
},
_search(value) {
this.key = value
this._refresh()
},
_refresh() {
this.page = 1
this._getData()
},
_searchParams() {
let data = {
page: this.page,
rows: this.rows,
name: this.key,
};
return this.$serializeForm(data)
},
_getData: async function () {
let result = await sampler.page(this._searchParams())
this.resultList = [...(this.page === 1 ? [] : this.resultList), ...result.records]
this.refreshing = false
this.loading = false
if (this.resultList.length === result.total) {
this.finished = true
}
},
_load() {
this.page = this.page + 1;
this._getData()
},
_tapItem(item) {
if (this.checkListValue.indexOf(item) === -1) {
this.checkListValue.push(item);
} else {
this.checkListValue.splice(this.checkListValue.indexOf(item), 1);
}
},
_add: async function () {
if (this.checkListValue.length === 0) {
this.$toast('请至少选择一条数据!')
} else {
const data = {
planId: this.planId,
samplerIds: this.checkListValue.map(item=>item.id).join(',')
}
const result = await samplingPlan.saveSampler(data)
if (result) {
this.$emit('on-change')
}
}
},
_cancel() {
this.$emit('cancel')
}
}
}
</script>
<style scoped>
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment