|
@@ -1,25 +1,13 @@
|
|
|
<template>
|
|
|
- <div class="page-form-container">
|
|
|
+ <div class="app-container">
|
|
|
<el-form ref="form" label-width="110px" :model="formData" :rules="rules">
|
|
|
<el-form-item label="认证方式:">关联已认证设备</el-form-item>
|
|
|
- <!-- <el-form-item label="选设备SN码:" prop="sncodeType">
|
|
|
- <el-radio-group v-model="formData.sncodeType" size="mini">
|
|
|
- <el-radio :label="1">所有设备SN码</el-radio>
|
|
|
- <el-radio :label="2">关联机构设备SN码</el-radio>
|
|
|
- </el-radio-group>
|
|
|
- </el-form-item> -->
|
|
|
<el-form-item label="SN码列表:" prop="snList">
|
|
|
<el-checkbox-group v-model="formData.snList" />
|
|
|
<el-button size="mini" type="primary" @click="onChooseCode">选择SN码</el-button>
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
- <sncode-list
|
|
|
- class="sncode-list"
|
|
|
- :selection="false"
|
|
|
- :control="true"
|
|
|
- :list="filterSelectedCodeList"
|
|
|
- @filter="onSelectCodeFilter"
|
|
|
- >
|
|
|
+ <sncode-list class="snCode-list" :selection="false" :control="true" :list="selectedCodeList">
|
|
|
<template #control="{ row }">
|
|
|
<el-button size="mini" type="danger" @click="onSelectCodeRemove(row)">删除</el-button>
|
|
|
</template>
|
|
@@ -34,22 +22,13 @@
|
|
|
</div>
|
|
|
|
|
|
<!-- 选择sn码 -->
|
|
|
- <el-dialog :title="dialogTextTip" :visible.sync="dialogCodeListVisible" width="30%" :show-close="false">
|
|
|
- <div class="sncode-cate">
|
|
|
- <div class="lable">选设备SN码:</div>
|
|
|
- <el-radio-group v-model="formData.sncodeType" size="mini" @change="onChooseCode">
|
|
|
- <el-radio :label="1">所有设备SN码</el-radio>
|
|
|
- <el-radio :label="2">关联机构设备SN码</el-radio>
|
|
|
- </el-radio-group>
|
|
|
- </div>
|
|
|
+ <el-dialog title="选择关联设备" :visible.sync="dialogCodeListVisible" width="70%" :show-close="false">
|
|
|
<sncode-list
|
|
|
- v-if="dialogCodeListVisible"
|
|
|
:selection="true"
|
|
|
:control="false"
|
|
|
- :list="filterCodeList"
|
|
|
- height="280"
|
|
|
- @filter="onCodeFilter"
|
|
|
- @selected="onCodeChange"
|
|
|
+ :list="unselectedCodeList"
|
|
|
+ height="380"
|
|
|
+ @selected="onCodeSelected"
|
|
|
/>
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
<el-button type="primary" size="mini" @click="onCodeCancel">取 消</el-button>
|
|
@@ -61,8 +40,9 @@
|
|
|
|
|
|
<script>
|
|
|
import { SncodeList } from '@/views/components'
|
|
|
-import { fetchProductSnList, fetchProductSnListType, saveProductRelation } from '@/api/product'
|
|
|
+import { fetchClubDeviceSnList, saveProductRelation } from '@/api/product'
|
|
|
import { getStorage } from '@/utils/storage'
|
|
|
+import { uniqueArr } from '@/utils'
|
|
|
export default {
|
|
|
components: {
|
|
|
SncodeList
|
|
@@ -73,25 +53,30 @@ export default {
|
|
|
formData: {
|
|
|
authType: 2,
|
|
|
authId: '',
|
|
|
- sncodeType: 1,
|
|
|
snList: []
|
|
|
},
|
|
|
rules: {
|
|
|
snList: [{ type: 'array', required: true, message: 'SN码列表不能为空', trigger: ['change'] }]
|
|
|
},
|
|
|
listQuery: {
|
|
|
- sncode: ''
|
|
|
+ authId: '',
|
|
|
+ downStatus: 0,
|
|
|
+ productName: '',
|
|
|
+ snCode: '',
|
|
|
+ authParty: ''
|
|
|
},
|
|
|
- codeList: [],
|
|
|
- filterCodeList: [],
|
|
|
- selectedCodeList: [],
|
|
|
- selectedCodeListAll: [],
|
|
|
- filterSelectedCodeList: []
|
|
|
+ codeList: [], // sn码列表
|
|
|
+ preSelectedCodeList: [] // table中已选中的sn码列表
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- dialogTextTip() {
|
|
|
- return this.formData.sncodeType === 1 ? '所有设备SN码' : '关联机构设备SN码'
|
|
|
+ // 选中的sn码列表
|
|
|
+ selectedCodeList() {
|
|
|
+ return this.codeList.filter((item) => this.formData.snList.includes(item.snCode))
|
|
|
+ },
|
|
|
+ // 剩余未选中的sn码列表
|
|
|
+ unselectedCodeList() {
|
|
|
+ return this.codeList.filter((item) => !this.formData.snList.includes(item.snCode))
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
@@ -102,37 +87,33 @@ export default {
|
|
|
created() {
|
|
|
// 获取当前设备所属机构的id
|
|
|
this.formData.authId = getStorage('device-setting-authId')
|
|
|
+ this.listQuery.authId = this.formData.authId
|
|
|
+ this.fetchSnCodeList()
|
|
|
},
|
|
|
methods: {
|
|
|
// 选择sn码
|
|
|
onChooseCode() {
|
|
|
this.dialogCodeListVisible = true
|
|
|
- if (this.formData.sncodeType === 1) {
|
|
|
- this.fetchSnCodeListAll()
|
|
|
- } else {
|
|
|
- this.fetchSnCodeListSelf()
|
|
|
- }
|
|
|
},
|
|
|
// 获取全部sn码列表
|
|
|
- async fetchSnCodeListSelf() {
|
|
|
- try {
|
|
|
- const res = await fetchProductSnListType({ authId: this.formData.authId })
|
|
|
- if (!res.data) return
|
|
|
- this.codeList = res.data.filter((code) => !this.selectedCodeListAll.includes(code))
|
|
|
- this.filterCodeList = this.codeList
|
|
|
- console.log(res)
|
|
|
- } catch (error) {
|
|
|
- console.log(error)
|
|
|
- }
|
|
|
- },
|
|
|
- // 获取关联机构sn码列表
|
|
|
- async fetchSnCodeListAll() {
|
|
|
+ async fetchSnCodeList() {
|
|
|
try {
|
|
|
- const res = await fetchProductSnList({ authId: this.formData.authId })
|
|
|
- if (!res.data) return
|
|
|
- this.codeList = res.data.filter((code) => !this.selectedCodeListAll.includes(code))
|
|
|
- this.filterCodeList = this.codeList
|
|
|
- console.log(res)
|
|
|
+ // 获取全部sn码列表
|
|
|
+ this.listQuery.downStatus = 0
|
|
|
+ const res1 = await fetchClubDeviceSnList(this.listQuery)
|
|
|
+ res1.data = res1.data.map((item) => {
|
|
|
+ item.downStatus = 0
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ // 获取与该机构有关联sn码列表
|
|
|
+ this.listQuery.downStatus = 1
|
|
|
+ const res2 = await fetchClubDeviceSnList(this.listQuery)
|
|
|
+ res2.data = res2.data.map((item) => {
|
|
|
+ item.downStatus = 0
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ this.codeList = [...res1.data, ...res2.data]
|
|
|
+ console.log('🚀 ~ file: bind.vue:108 ~ fetchSnCodeList ~ this.codeList:', this.codeList)
|
|
|
} catch (error) {
|
|
|
console.log(error)
|
|
|
}
|
|
@@ -157,44 +138,34 @@ export default {
|
|
|
console.log(error)
|
|
|
}
|
|
|
},
|
|
|
- // 筛选sn码列表
|
|
|
- onCodeFilter(query) {
|
|
|
- this.filterCodeList = this.codeList.filter((code) => new RegExp(query.sncode, 'gi').test(code))
|
|
|
- },
|
|
|
// 选中sn码
|
|
|
- onCodeChange(value) {
|
|
|
- this.selectedCodeList = value
|
|
|
+ onCodeSelected(list) {
|
|
|
+ this.preSelectedCodeList = list
|
|
|
},
|
|
|
// 取消选择sn码
|
|
|
onCodeCancel() {
|
|
|
- this.selectedCodeListAll = [...this.selectedCodeListAll, ...this.selectedCodeList]
|
|
|
- this.selectedCodeList = []
|
|
|
- this.filterCodeList = []
|
|
|
+ this.preSelectedCodeList = []
|
|
|
this.dialogCodeListVisible = false
|
|
|
},
|
|
|
// 确认选择sn码
|
|
|
onCodeConfirm() {
|
|
|
- this.selectedCodeListAll = [...this.selectedCodeListAll, ...this.selectedCodeList]
|
|
|
- this.filterSelectedCodeList = this.selectedCodeListAll
|
|
|
- this.filterCodeList = []
|
|
|
+ const sncodeList = this.preSelectedCodeList.map((item) => item.snCode)
|
|
|
+ const snList = [...this.formData.snList, ...sncodeList]
|
|
|
+ this.formData.snList = uniqueArr(snList)
|
|
|
this.dialogCodeListVisible = false
|
|
|
},
|
|
|
- // 已选中sn码筛选
|
|
|
- onSelectCodeFilter(query) {
|
|
|
- this.filterSelectedCodeList = this.filterSelectedCodeList.filter((code) =>
|
|
|
- new RegExp(query.sncode, 'gi').test(code)
|
|
|
- )
|
|
|
- },
|
|
|
// 已选中sn码删除
|
|
|
onSelectCodeRemove(row) {
|
|
|
- this.selectedCodeListAll = this.selectedCodeListAll.filter((code) => code !== row)
|
|
|
- this.filterSelectedCodeList = this.selectedCodeListAll
|
|
|
+ this.formData.snList = this.formData.snList.filter((code) => code !== row.snCode)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
+.app-container {
|
|
|
+ width: 80%;
|
|
|
+}
|
|
|
.filter-container {
|
|
|
background: #eee;
|
|
|
padding: 6px 10px;
|
|
@@ -203,7 +174,7 @@ export default {
|
|
|
margin-bottom: 0;
|
|
|
}
|
|
|
}
|
|
|
-.sncode-cate {
|
|
|
+.snCode-cate {
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
margin-bottom: 16px;
|