123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884 |
- <template>
- <view id="hardware-add-page">
- <view class="addForm-max-big-box">
- <view class="addForm-big-box">
- <!-- 状态 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">启用:</view>
- <view>
- <switch :checked="addForm.state" @change="switchChange" color="#0183FA" style="transform:scale(0.8)" />
- </view>
- </view>
- <!-- 名称 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">名称:</view>
- <input class="addForm-input" v-model="addForm.hardwareName" style="width:340rpx;" type="text" :maxlength="20"
- placeholder="输入名称" placeholder-style="color:#999;">
- </view>
- <!-- 编号 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">编号:</view>
- <input class="addForm-input" :disabled="!!addForm.id" v-model="addForm.hardwareNo" style="width:340rpx;"
- type="text" :maxlength="20" placeholder="输入编号" placeholder-style="color:#999;">
- </view>
- <!-- 类型 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">类型:</view>
- <picker @change="typeChange" :value="typeIndex" :range="typeNameList">
- <view class="addForm-input" style="width:340rpx;" :class="!typeName?'addForm-input-placeholder':''">
- {{typeName?typeName:'选择类型'}}
- </view>
- </picker>
- </view>
- <!-- 校区 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">校区:</view>
- <picker @change="schoolChange" :value="schoolIndex" :range="schoolNameList">
- <view class="addForm-input" style="width:340rpx;"
- :class="!schoolName?'addForm-input-placeholder':''">
- {{schoolName?schoolName:'选择校区'}}
- </view>
- </picker>
- </view>
- <!-- 楼栋 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">楼栋:</view>
- <picker @change="buildChange" :value="buildIndex" :range="buildNameList">
- <view class="addForm-input" style="width:340rpx;"
- :class="!buildName?'addForm-input-placeholder':''">
- {{buildName?buildName:'选择楼栋'}}
- </view>
- </picker>
- </view>
- <!-- 楼层 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">楼层:</view>
- <picker @change="floorChange" :value="floorIndex" :range="floorNameList">
- <view class="addForm-input" style="width:340rpx;"
- :class="!floorName?'addForm-input-placeholder':''">
- {{floorName?floorName:'选择楼层'}}
- </view>
- </picker>
- </view>
- <!-- 实验室 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon"></view>
- <view class="addForm-input-title">实验室:</view>
- <picker @change="subChange" :value="subIndex" :range="subNameList">
- <view class="addForm-input" style="width:340rpx;"
- :class="!subName?'addForm-input-placeholder':''">
- {{subName?subName:'选择实验室'}}
- </view>
- </picker>
- </view>
- <!-- 物联设备 -->
- <view class="addForm-input-box">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">物联设备:</view>
- <picker @change="relayChange" :value="relayIndex" :range="relayNameList">
- <view class="addForm-input" style="width:340rpx;" :class="!relayName?'addForm-input-placeholder':''">
- {{relayName?relayName:'选择物联设备'}}
- </view>
- </picker>
- </view>
- <!-- 参数A -->
- <view class="addForm-input-box" v-if="reservedTypeOne">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">{{reservedNameOne}}:</view>
- <input class="addForm-input" v-model="addForm.reservedOne" style="width:340rpx;" type="text" :maxlength="20"
- :placeholder="'请输入'+reservedNameOne" placeholder-style="color:#999;">
- </view>
- <!-- 参数B -->
- <view class="addForm-input-box" v-if="reservedTypeTwo">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">{{reservedNameTwo}}:</view>
- <input class="addForm-input" v-model="addForm.reservedTwo" style="width:340rpx;" type="text" :maxlength="20"
- :placeholder="'请输入'+reservedNameTwo" placeholder-style="color:#999;">
- </view>
- <!-- 参数C -->
- <view class="addForm-input-box" v-if="reservedTypeThree">
- <view class="addForm-input-icon">*</view>
- <view class="addForm-input-title">{{reservedNameThree}}:</view>
- <input class="addForm-input" v-model="addForm.reservedThree" style="width:340rpx;" type="text" :maxlength="20"
- :placeholder="'请输入'+reservedNameThree" placeholder-style="color:#999;">
- </view>
- </view>
- </view>
- <view class="addForm-button-box">
- <view class="button-null"></view>
- <view class="button-view" @click="submitForm">提交</view>
- <view class="button-null"></view>
- </view>
- </view>
- </template>
- <script>
- import {
- systemBuildingGetTreeList,
- laboratorySubRelInfoGetListByFloor,
- iotHardwareFindHardwareType,
- iotDeviceFindByType,
- iotHardwareAdd,
- iotHardwareUpdate,
- iotAttributeDetail
- } from '@/api/index.js'
- export default {
- data() {
- return {
- addForm: {
- hardwareName: "",
- hardwareNo: "",
- hardwareTypeId: "",
- hardwareTypeKey: "",
- hardwareTypeName: "",
- deviceTypeKey: "",
- deviceId: "",
- deviceNo: "",
- attributeId: "",
- schoolId: '',
- schoolName: '',
- buildId: '',
- buildName: '',
- floorId: '',
- floorName: '',
- subjectId: '',
- subjectName: '',
- state: true,
- reservedOne: "",
- reservedTwo: "",
- reservedThree: "",
- },
- //硬件类型下拉列表
- typeList: [],
- typeNameList: [],
- typeIndex: 0,
- typeName: '',
- //继电器下拉列表
- relayList: [],
- relayNameList: [],
- relayIndex: 0,
- relayName: '',
- //硬件参数数据
- reservedNameOne: '',
- reservedTypeOne: false,
- reservedNameTwo: '',
- reservedTypeTwo: false,
- reservedNameThree: '',
- reservedTypeThree: false,
- //校区/楼栋/楼层树
- treeOptions: [],
- //校区
- schoolList: [],
- schoolNameList: [],
- schoolIndex: 0,
- schoolName: '',
- //楼栋
- buildList: [],
- buildNameList: [],
- buildIndex: 0,
- buildName: '',
- //楼层
- floorList: [],
- floorNameList: [],
- floorIndex: 0,
- floorName: '',
- //实验室
- subList: [],
- subNameList: [],
- subIndex: 0,
- subName: '',
- }
- },
- onLoad(option) {
- Promise.all([
- this.systemBuildingGetTreeList(),
- this.iotHardwareFindHardwareType(),
- ]).then((result) => {
- if (option.item) {
- this.initialize(option.item);
- }
- }).catch((error) => {
- wx.showToast({
- title: '数据异常,请稍候再试!',
- icon: "none",
- duration: 3000
- });
- })
- },
- onShow() {
- },
- methods: {
- //编辑-初始化
- initialize(item) {
- let obj = JSON.parse(decodeURIComponent(item));
- this.$set(this, 'addForm', {
- id: obj.id,
- state: obj.state,
- hardwareName: obj.hardwareName,
- hardwareNo: obj.hardwareNo,
- hardwareTypeId: obj.hardwareTypeId,
- hardwareTypeKey: obj.hardwareTypeKey,
- hardwareTypeName: obj.hardwareTypeName,
- deviceTypeKey: obj.deviceTypeKey,
- schoolId: obj.schoolId,
- schoolName: obj.schoolName,
- buildId: obj.buildId,
- buildName: obj.buildName,
- floorId: obj.floorId,
- floorName: obj.floorName,
- subjectId: obj.subjectId,
- subjectName: obj.subjectName,
- deviceId: obj.deviceId,
- deviceNo: obj.deviceNo,
- attributeId: obj.attributeId,
- reservedOne: obj.reservedOne,
- reservedTwo: obj.reservedTwo,
- reservedThree: obj.reservedThree,
- });
- this.typeList.forEach((item) => {
- if (obj.hardwareTypeId == item.hardwareTypeId) {
- this.$set(this, 'typeName', item.hardwareTypeName);
- }
- })
- this.iotAttributeDetail(obj.attributeId);
- this.getAddress(obj);
- },
- //编辑匹配位置数据
- async getAddress(item){
- if(item.schoolId){
- this.$set(this, 'schoolName', item.schoolName);
- let buildList = [];
- let buildNameList = [];
- let floorList = [];
- let floorNameList = [];
- this.treeOptions.forEach((maxItem) => {
- if (item.schoolId == maxItem.id && maxItem.buildFloorVoList[0]) {
- maxItem.buildFloorVoList.forEach((bigItem) => {
- buildList.push({
- id: bigItem.id,
- name: bigItem.name
- })
- buildNameList.push(bigItem.name);
- if(item.buildId){
- this.$set(this, 'buildName', item.buildName);
- if(item.buildId == bigItem.id && bigItem.buildFloorVoList[0]){
- bigItem.buildFloorVoList.forEach((minItem) => {
- floorList.push({
- id: minItem.id,
- name: minItem.name
- })
- floorNameList.push(minItem.name);
- })
- if(item.floorId){
- this.$set(this, 'floorName', item.floorName);
- }
- }
- }
- })
- }
- })
- this.$set(this, 'buildList', buildList);
- this.$set(this, 'buildNameList', buildNameList);
- this.$set(this, 'floorList', floorList);
- this.$set(this, 'floorNameList', floorNameList);
- if(item.schoolId && item.buildId && item.floorId){
- const {
- data
- } = await laboratorySubRelInfoGetListByFloor({
- floorId: item.floorId
- });
- if (data.code == 200) {
- this.$set(this, 'subList', data.data);
- let list = [];
- data.data.forEach((subItem) => {
- list.push(subItem.subName);
- })
- this.$set(this, 'subNameList', list);
- this.$set(this, 'subIndex', 0);
- if(item.subjectId){
- this.$set(this, 'subName', item.subjectName);
- }
- }
- }
- }
- this.$nextTick(()=>{
- this.iotDeviceFindByType(item.deviceId);
- })
- },
- async iotAttributeDetail(attributeId){
- const {
- data
- } = await iotAttributeDetail({id:attributeId});
- if (data.code == 200) {
- let list = data.data.relateField?JSON.parse(data.data.relateField):[];
- list.forEach((item,index)=>{
- if(index == 0){
- if(item.state){
- this.$set(this, 'reservedNameOne', item.relateFieldName)
- this.$set(this, 'reservedTypeOne', true)
- }else{
- this.$set(this, 'reservedNameOne', '')
- this.$set(this, 'reservedTypeOne', false)
- }
- }else if(index == 1){
- if(item.state){
- this.$set(this, 'reservedNameTwo', item.relateFieldName)
- this.$set(this, 'reservedTypeTwo', true)
- }else{
- this.$set(this, 'reservedNameTwo', '')
- this.$set(this, 'reservedTypeTwo', false)
- }
- }else if(index == 2){
- if(item.state){
- this.$set(this, 'reservedNameThree', item.relateFieldName)
- this.$set(this, 'reservedTypeThree', true)
- }else{
- this.$set(this, 'reservedNameThree', '')
- this.$set(this, 'reservedTypeThree', false)
- }
- }
- })
- }
- },
- /***************** 地址查询相关 *****************/
- //楼栋tree列表
- async systemBuildingGetTreeList() {
- const {
- data
- } = await systemBuildingGetTreeList();
- if (data.code == 200) {
- this.$set(this, 'treeOptions', data.data);
- let list = [];
- let nameList = [];
- data.data.forEach((item) => {
- list.push({
- id: item.id,
- name: item.name
- })
- nameList.push(item.name);
- })
- this.$set(this, 'schoolList', list);
- this.$set(this, 'schoolNameList', nameList);
- }
- },
- //校区选中
- schoolChange(event) {
- if (this.schoolList[0]) {
- this.$set(this, 'schoolIndex', event.target.value);
- this.$set(this, 'schoolName', this.schoolList[event.target.value].name);
- this.$set(this.addForm, 'schoolId', this.schoolList[event.target.value].id);
- this.$set(this.addForm, 'schoolName', this.schoolList[event.target.value].name);
- this.$set(this.addForm, 'buildId', '');
- this.$set(this.addForm, 'buildName', '');
- this.$set(this.addForm, 'floorId', '');
- this.$set(this.addForm, 'floorName', '');
- this.$set(this.addForm, 'subjectId', '');
- this.$set(this.addForm, 'subjectName', '');
- let list = [];
- let nameList = [];
- this.treeOptions.forEach((item) => {
- if (this.schoolList[event.target.value].id == item.id && item.buildFloorVoList[0]) {
- item.buildFloorVoList.forEach((minItem) => {
- list.push({
- id: minItem.id,
- name: minItem.name
- })
- nameList.push(minItem.name);
- })
- }
- })
- this.$set(this, 'buildList', list);
- this.$set(this, 'buildNameList', nameList);
- this.$set(this, 'buildIndex', 0);
- this.$set(this, 'buildName', '');
- this.$set(this, 'floorList', []);
- this.$set(this, 'floorNameList', []);
- this.$set(this, 'floorIndex', 0);
- this.$set(this, 'floorName', '');
- this.$set(this, 'subList', []);
- this.$set(this, 'subNameList', []);
- this.$set(this, 'subIndex', 0);
- this.$set(this, 'subName', '');
- this.$set(this, 'relayIndex', 0);
- this.$set(this, 'relayName', '');
- this.$set(this.addForm, 'deviceId', '');
- this.$set(this.addForm, 'deviceNo', '');
- this.$set(this.addForm, 'attributeId', '');
- this.$set(this, 'reservedNameOne', '')
- this.$set(this, 'reservedTypeOne', false)
- this.$set(this, 'reservedNameTwo', '')
- this.$set(this, 'reservedTypeTwo', false)
- this.$set(this, 'reservedNameThree', '')
- this.$set(this, 'reservedTypeThree', false)
- this.$nextTick(()=>{
- this.iotDeviceFindByType();
- })
- }
- },
- //楼栋选中
- buildChange(event) {
- if (this.buildList[0]) {
- this.$set(this, 'buildIndex', event.target.value);
- this.$set(this, 'buildName', this.buildList[event.target.value].name);
- this.$set(this.addForm, 'buildId', this.buildList[event.target.value].id);
- this.$set(this.addForm, 'buildName', this.buildList[event.target.value].name);
- this.$set(this.addForm, 'floorId', '');
- this.$set(this.addForm, 'floorName', '');
- this.$set(this.addForm, 'subjectId', '');
- this.$set(this.addForm, 'subjectName', '');
- let list = [];
- let nameList = [];
- this.treeOptions.forEach((item) => {
- if (this.addForm.schoolId == item.id && item.buildFloorVoList[0]) {
- item.buildFloorVoList.forEach((maxItem) => {
- if (this.buildList[event.target.value].id == maxItem.id && maxItem.buildFloorVoList[0]) {
- maxItem.buildFloorVoList.forEach((minItem) => {
- list.push({
- id: minItem.id,
- name: minItem.name
- })
- nameList.push(minItem.name);
- })
- }
- })
- }
- })
- this.$set(this, 'floorList', list);
- this.$set(this, 'floorNameList', nameList);
- this.$set(this, 'floorIndex', 0);
- this.$set(this, 'floorName', '');
- this.$set(this, 'subList', []);
- this.$set(this, 'subNameList', []);
- this.$set(this, 'subIndex', 0);
- this.$set(this, 'subName', '');
- this.$set(this, 'relayIndex', 0);
- this.$set(this, 'relayName', '');
- this.$set(this.addForm, 'deviceId', '');
- this.$set(this.addForm, 'deviceNo', '');
- this.$set(this.addForm, 'attributeId', '');
- this.$set(this, 'reservedNameOne', '')
- this.$set(this, 'reservedTypeOne', false)
- this.$set(this, 'reservedNameTwo', '')
- this.$set(this, 'reservedTypeTwo', false)
- this.$set(this, 'reservedNameThree', '')
- this.$set(this, 'reservedTypeThree', false)
- this.$nextTick(()=>{
- this.iotDeviceFindByType();
- })
- }
- },
- //楼层选中
- floorChange(event) {
- if (this.floorList[0]) {
- this.$set(this, 'floorIndex', event.target.value);
- this.$set(this, 'floorName', this.floorList[event.target.value].name);
- this.$set(this.addForm, 'floorId', this.floorList[event.target.value].id);
- this.$set(this.addForm, 'floorName', this.floorList[event.target.value].name);
- this.$set(this.addForm, 'subjectId', '');
- this.$set(this.addForm, 'subjectName', '');
- this.laboratorySubRelInfoGetListByFloor(this.floorList[event.target.value].id);
- this.$set(this, 'relayIndex', 0);
- this.$set(this, 'relayName', '');
- this.$set(this.addForm, 'deviceId', '');
- this.$set(this.addForm, 'deviceNo', '');
- this.$set(this.addForm, 'attributeId', '');
- this.$set(this, 'reservedNameOne', '')
- this.$set(this, 'reservedTypeOne', false)
- this.$set(this, 'reservedNameTwo', '')
- this.$set(this, 'reservedTypeTwo', false)
- this.$set(this, 'reservedNameThree', '')
- this.$set(this, 'reservedTypeThree', false)
- this.$nextTick(()=>{
- this.iotDeviceFindByType();
- })
- }
- },
- //实验室选中
- subChange(event) {
- if (this.subList[0]) {
- this.$set(this, 'subIndex', event.target.value);
- this.$set(this, 'subName', this.subList[event.target.value].subName);
- this.$set(this.addForm, 'subjectId', this.subList[event.target.value].subId);
- this.$set(this.addForm, 'subjectName', this.subList[event.target.value].subName);
- this.$set(this, 'relayIndex', 0);
- this.$set(this, 'relayName', '');
- this.$set(this.addForm, 'deviceId', '');
- this.$set(this.addForm, 'deviceNo', '');
- this.$set(this.addForm, 'attributeId', '');
- this.$set(this, 'reservedNameOne', '')
- this.$set(this, 'reservedTypeOne', false)
- this.$set(this, 'reservedNameTwo', '')
- this.$set(this, 'reservedTypeTwo', false)
- this.$set(this, 'reservedNameThree', '')
- this.$set(this, 'reservedTypeThree', false)
- this.$nextTick(()=>{
- this.iotDeviceFindByType();
- })
- }
- },
- //查询实验室
- async laboratorySubRelInfoGetListByFloor(floorId) {
- const {
- data
- } = await laboratorySubRelInfoGetListByFloor({
- floorId: floorId
- });
- if (data.code == 200) {
- this.$set(this, 'subList', data.data);
- let list = [];
- data.data.forEach((item) => {
- list.push(item.subName);
- })
- this.$set(this, 'subNameList', list);
- this.$set(this, 'subIndex', 0);
- this.$set(this, 'subName', '');
- }
- },
- //数据提交
- submitForm() {
- let self = this;
- if (!this.addForm.hardwareName) {
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请输入名称',
- duration: 1000
- });
- return
- } else if (!this.addForm.hardwareNo) {
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请输入编号',
- duration: 1000
- });
- return
- } else if (!this.addForm.hardwareTypeId) {
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请选择设备类型',
- duration: 1000
- });
- return
- } else if (!this.addForm.deviceId) {
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请选择物联设备',
- duration: 1000
- });
- return
- }else if(!this.addForm.schoolId){
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请选择校区',
- duration: 1000
- });
- return
- }else if(!this.addForm.buildId){
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请选择楼栋',
- duration: 1000
- });
- return
- }else if(!this.addForm.floorId){
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请选择楼层',
- duration: 1000
- });
- return
- }
- if(this.reservedTypeOne){
- if(!this.addForm.reservedOne){
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请选输入'+this.reservedNameOne,
- duration: 1000
- });
- return
- }
- }
- if(this.reservedTypeTwo){
- if(!this.addForm.reservedTwo){
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请选输入'+this.reservedNameTwo,
- duration: 1000
- });
- return
- }
- }
- if(this.reservedTypeThree){
- if(!this.addForm.reservedThree){
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: '请选输入'+this.reservedNameThree,
- duration: 1000
- });
- return
- }
- }
- let obj = {
- state: this.addForm.state,
- hardwareName: this.addForm.hardwareName,
- hardwareNo: this.addForm.hardwareNo,
- hardwareTypeId: this.addForm.hardwareTypeId,
- hardwareTypeKey: this.addForm.hardwareTypeKey,
- hardwareTypeName: this.addForm.hardwareTypeName,
- deviceTypeKey: this.addForm.deviceTypeKey,
- schoolId:this.addForm.schoolId,
- schoolName:this.addForm.schoolName,
- buildId:this.addForm.buildId,
- buildName:this.addForm.buildName,
- floorId:this.addForm.floorId,
- floorName:this.addForm.floorName,
- subjectId:this.addForm.subjectId,
- subjectName:this.addForm.subjectName,
- deviceId: this.addForm.deviceId,
- deviceNo: this.addForm.deviceNo,
- attributeId: this.addForm.attributeId,
- reservedOne: this.reservedTypeOne?this.addForm.reservedOne:'',
- reservedTwo: this.reservedTypeTwo?this.addForm.reservedTwo:'',
- reservedThree: this.reservedTypeThree?this.addForm.reservedThree:'',
- }
- uni.showModal({
- title: '警告',
- content: '是否确认提交?',
- showCancel: true,
- cancelColor: '#999999,',
- confirmColor: '#0183FA',
- success: (res) => {
- if (res.confirm) {
- if (self.addForm.id) {
- obj.id = self.addForm.id;
- self.iotHardwareUpdate(obj);
- } else {
- self.iotHardwareAdd(obj);
- }
- }
- },
- fail: (res) => {}
- })
- },
- //状态开关
- switchChange(event) {
- this.$set(this.addForm, 'state', event.target.value);
- },
- //设备类型选中
- typeChange(event) {
- if (this.typeList[0]) {
- this.$set(this, 'typeIndex', event.target.value);
- this.$set(this, 'typeName', this.typeList[event.target.value].hardwareTypeName);
- this.$set(this.addForm, 'hardwareTypeId', this.typeList[event.target.value].hardwareTypeId);
- this.$set(this.addForm, 'hardwareTypeKey', this.typeList[event.target.value].hardwareTypeKey);
- this.$set(this.addForm, 'hardwareTypeName', this.typeList[event.target.value].hardwareTypeName);
- this.$set(this.addForm, 'deviceTypeKey', this.typeList[event.target.value].deviceTypeKey);
- this.$set(this, 'relayIndex', 0);
- this.$set(this, 'relayName', '');
- this.$set(this.addForm, 'deviceId', '');
- this.$set(this.addForm, 'deviceNo', '');
- this.$set(this.addForm, 'attributeId', '');
- this.$set(this, 'reservedNameOne', '')
- this.$set(this, 'reservedTypeOne', false)
- this.$set(this, 'reservedNameTwo', '')
- this.$set(this, 'reservedTypeTwo', false)
- this.$set(this, 'reservedNameThree', '')
- this.$set(this, 'reservedTypeThree', false)
- this.$nextTick(()=>{
- this.iotDeviceFindByType();
- })
- }
- },
- //物联设备选中
- relayChange(event) {
- if (this.relayList[0]) {
- this.$set(this, 'relayIndex', event.target.value);
- this.$set(this, 'relayName', this.relayList[event.target.value].deviceName);
- this.$set(this.addForm, 'deviceId', this.relayList[event.target.value].id);
- this.$set(this.addForm, 'deviceNo', this.relayList[event.target.value].deviceNo);
- this.$set(this.addForm, 'attributeId', this.relayList[event.target.value].attributeId);
- this.iotAttributeDetail(this.relayList[event.target.value].attributeId);
- }
- },
- //获取硬件类型
- async iotHardwareFindHardwareType() {
- const {
- data
- } = await iotHardwareFindHardwareType();
- if (data.code == 200) {
- this.$set(this, 'typeList', data.data);
- let list = [];
- data.data.forEach((item) => {
- list.push(item.hardwareTypeName);
- })
- this.$set(this, 'typeNameList', list);
- }
- },
- //获取物联设备列表
- async iotDeviceFindByType(deviceId) {
- if(this.addForm.floorId&&this.addForm.deviceTypeKey){
- const {
- data
- } = await iotDeviceFindByType({
- floorId: this.addForm.floorId,
- subjectId: this.addForm.subjectId,
- typeKeyList: [this.addForm.deviceTypeKey]
- });
- if (data.code == 200) {
- this.$set(this, 'relayList', data.data);
- let list = [];
- data.data.forEach((item) => {
- list.push(item.deviceName);
- if (deviceId) {
- if (item.id == deviceId) {
- this.$set(this, 'relayName', item.deviceName);
- }
- }
- })
- this.$set(this, 'relayNameList', list);
- }
- }
- },
- //新增
- async iotHardwareAdd(obj) {
- const {
- data
- } = await iotHardwareAdd(obj);
- if (data.code == 200) {
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: data.message,
- duration: 2000
- });
- setTimeout(function() {
- uni.navigateBack();
- }, 1800);
- }
- },
- //编辑
- async iotHardwareUpdate(obj) {
- const {
- data
- } = await iotHardwareUpdate(obj);
- if (data.code == 200) {
- uni.showToast({
- mask: true,
- icon: "none",
- position: "center",
- title: data.message,
- duration: 2000
- });
- setTimeout(function() {
- uni.navigateBack();
- }, 1800);
- }
- },
- }
- }
- </script>
- <style lang="stylus" scoped>
- #hardware-add-page {
- display: flex;
- flex: 1;
- flex-direction: column;
- overflow: hidden;
- .addForm-max-big-box {
- flex: 1;
- overflow-x: hidden;
- overflow-y: scroll;
- .addForm-big-box {
- background-color: #fff;
- margin: 20rpx;
- border-radius: 12rpx;
- padding: 0 0 30rpx;
- .addForm-input-box {
- display: flex;
- margin: 10rpx 0 0 10rpx;
- font-size: 28rpx;
- padding: 20rpx 0 0 0;
- .addForm-input-icon {
- color: #FF6666;
- width: 40rpx;
- margin-right: 10rpx;
- text-align: right;
- line-height: 60rpx;
- }
- .addForm-input-title {
- width: 200rpx;
- color: #333;
- line-height: 60rpx;
- }
- .addForm-input {
- padding: 0 20rpx;
- height: 60rpx;
- line-height: 60rpx;
- font-size: 26rpx;
- border-radius: 8rpx;
- border: 1px solid #dedede;
- }
- .addForm-input-placeholder {
- color: #999 !important;
- }
- }
- }
- }
- .addForm-button-box {
- height: 80rpx;
- display: flex;
- .button-null {
- flex: 1;
- }
- .button-view {
- width: 260rpx;
- margin: 10rpx 0 0 0;
- background-color: #0183FA;
- color: #fff;
- font-size: 26rpx;
- text-align: center;
- line-height: 60rpx;
- height: 60rpx;
- border-radius: 12rpx;
- }
- }
- }
- </style>
|