addDeviceManagement.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="alert-body__main_content">
  3. <zz-form :cols="formCols" :data="formData" :rules="formRules" :errors="formErrors" labelWidth="120" ref="form">
  4. <template slot="communityId">
  5. <el-select v-model="formData.communityId">
  6. <el-option v-for="(item, index) in communityArr" :key="index" :label="item.communityName" :value="item.id"></el-option>
  7. </el-select>
  8. </template>
  9. <template slot="useType">
  10. <el-select v-model="formData.useType" placeholder="选择用途" clearable>
  11. <el-option label="房间表" :value="1"></el-option>
  12. <el-option label="公摊表" :value="2"></el-option>
  13. </el-select>
  14. </template>
  15. <template slot="address">
  16. <el-input v-model="formData.address" clearable>
  17. <i slot="suffix" class="zoniot_font zoniot-icon-dizhi" @click="addressQueryClick"></i>
  18. </el-input>
  19. </template>
  20. <template slot="productId">
  21. <el-cascader
  22. v-model="formData.productId"
  23. :options="productOptions"
  24. :props="defaultProps"
  25. clearable
  26. placeholder="设备类型"
  27. ></el-cascader>
  28. </template>
  29. </zz-form>
  30. </div>
  31. </template>
  32. <script>
  33. export default {
  34. props: ['params'],
  35. data() {
  36. return {
  37. formData: {
  38. productId: '',
  39. communityId: '',
  40. deviceNo: '',
  41. deviceName: '',
  42. useType: '',
  43. beginDegree: '',
  44. address: '',
  45. categoryId: ''
  46. },
  47. formCols: [
  48. [
  49. {
  50. label: '选择社区',
  51. prop: 'communityId',
  52. slot: 'communityId'
  53. },
  54. {
  55. label: '设备类型',
  56. prop: 'productId',
  57. slot: 'productId'
  58. },
  59. {
  60. label: '设备编号',
  61. prop: 'deviceNo',
  62. input: true
  63. },
  64. {
  65. label: '设备名称',
  66. prop: 'deviceName',
  67. input: true
  68. },
  69. {
  70. label: '用途',
  71. prop: 'useType',
  72. slot: 'useType'
  73. },
  74. {
  75. label: '起始读数',
  76. prop: 'beginDegree',
  77. input: true
  78. },
  79. {
  80. label: '地址',
  81. prop: 'address',
  82. slot: 'address'
  83. }
  84. ]
  85. ],
  86. addressTree: [],
  87. formRules: {
  88. communityId: [this.$valid.selectRequired('选择社区')],
  89. productId: [this.$valid.selectRequired('设备类型')],
  90. deviceNo: [this.$valid.selectRequired('设备编号')],
  91. deviceName: [this.$valid.inputRequired('设备名称')],
  92. useType: [this.$valid.selectRequired('用途')],
  93. beginDegree: [this.$valid.inputRequired('起始读数')]
  94. },
  95. formErrors: {},
  96. productOptions: [],
  97. defaultProps: {
  98. value: 'value', // 唯一标识
  99. label: 'name', // 标签显示
  100. children: 'children' // 子级
  101. }
  102. };
  103. },
  104. watch: {
  105. 'formData.communityId'(val, old) {
  106. if (val) {
  107. this.getTenantsTree(val);
  108. }
  109. }
  110. },
  111. computed: {
  112. communityArr() {
  113. return this.$store.getters['getAreaSelect'];
  114. }
  115. },
  116. methods: {
  117. getTenantsTree(va) {
  118. this.$http.get('/sc-energy/assets/tree/community/findByFloor').then(({ status, data, msg }) => {
  119. if (status === 0 && data) {
  120. data.forEach((element) => {
  121. if (element.value == va) {
  122. this.addressTree = element.children;
  123. }
  124. });
  125. }
  126. });
  127. },
  128. addressQueryClick() {
  129. if (!this.formData.communityId) {
  130. this.$message.error('请先选择社区');
  131. return;
  132. }
  133. new Promise((resolve) => {
  134. this.$store.dispatch('addPopup', {
  135. url: '/instrumentManagement/popups/poptreeSelect.vue',
  136. width: '300px',
  137. height: '400px',
  138. props: {
  139. tenantsTree: this.addressTree,
  140. callback: resolve
  141. },
  142. hideStar: true,
  143. title: '楼栋信息'
  144. });
  145. }).then((e) => {
  146. debugger;
  147. let address = '';
  148. if (!!e.roomId) {
  149. this.formData.addressType = 5;
  150. this.formData.buildingId = e.buildingId;
  151. this.formData.unitName = e.unitId;
  152. this.formData.floorName = e.floorId;
  153. this.formData.houseId = e.roomId;
  154. address = e.buildingName + '-' + e.unitName + '-' + e.floor + '-' + e.roomName;
  155. } else if (!!e.floorId) {
  156. this.formData.addressType = 4;
  157. this.formData.buildingId = e.buildingId;
  158. this.formData.unitName = e.unitId;
  159. this.formData.floorName = e.floorId;
  160. this.formData.houseId = '';
  161. address = e.buildingName + '-' + e.unitName + '-' + e.floor;
  162. } else if (!!e.unitId) {
  163. this.formData.addressType = 3;
  164. this.formData.buildingId = e.buildingId;
  165. this.formData.unitName = e.unitId;
  166. this.formData.floorName = '';
  167. this.formData.houseId = '';
  168. address = e.buildingName + '-' + e.unitName;
  169. } else if (!!e.buildingId) {
  170. this.formData.addressType = 2;
  171. this.formData.buildingId = e.buildingId;
  172. this.formData.unitName = '';
  173. this.formData.floorName = '';
  174. this.formData.houseId = '';
  175. address = e.buildingName;
  176. }
  177. // console.log(e);
  178. // debugger;
  179. // if (e.ids.length) {
  180. // let lengthSum = e.ids.length;
  181. // switch (lengthSum) {
  182. // case 1:
  183. // this.formData.addressType = 1;
  184. // break;
  185. // case 2:
  186. // this.formData.addressType = 2;
  187. // this.formData.buildingId = e.ids[1];
  188. // break;
  189. // case 3:
  190. // this.formData.addressType = 3;
  191. // this.formData.buildingId = e.ids[1];
  192. // this.formData.unitName = e.ids[2];
  193. // break;
  194. // case 4:
  195. // this.formData.addressType = 4;
  196. // this.formData.buildingId = e.ids[1];
  197. // this.formData.unitName = e.ids[2];
  198. // this.formData.floorName = e.ids[3];
  199. // break;
  200. // case 5:
  201. // this.formData.addressType = 5;
  202. // this.formData.buildingId = e.ids[1];
  203. // this.formData.unitName = e.ids[2];
  204. // this.formData.floorName = e.ids[3];
  205. // this.formData.houseId = e.ids[4];
  206. // break;
  207. // default:
  208. // break;
  209. // }
  210. // }
  211. this.formData.address = address;
  212. });
  213. },
  214. submit() {
  215. new Promise((resolve) => {
  216. this.$refs.form.validate(resolve);
  217. }).then(() => {
  218. var loading = this.$loading();
  219. let url = '/sc-energy/device/add';
  220. if (this.params.todo == 'edit') {
  221. url = '/sc-energy/device/edit';
  222. }
  223. let params = JSON.parse(JSON.stringify(this.formData));
  224. params.productId = _.last(params.productId);
  225. this.$http
  226. .post(url, params)
  227. .then(({ status, msg }) => {
  228. if (status == 0) {
  229. this.$message.success(msg);
  230. this.params.callback();
  231. this.$emit('close');
  232. }
  233. loading.close();
  234. })
  235. .catch(() => {
  236. loading.close();
  237. });
  238. });
  239. }
  240. },
  241. created() {
  242. this.formData.categoryId = this.params.mixins_query.categoryId;
  243. this.getTenantsTree();
  244. this.productOptions = this.params.productOptions;
  245. if (this.params.todo == 'edit') {
  246. this.formData = JSON.parse(JSON.stringify(this.params.data));
  247. this.formData.productId = [null, null, this.formData.productId + ''];
  248. }
  249. }
  250. };
  251. </script>