batchlink.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <div class="box">
  3. <div class="condition">
  4. <div class="header">
  5. <el-button style="float:left;" size="small" type="default" icon="el-icon-back" @click="goBack"></el-button>
  6. <span class="statistics-title">发现未关联资产的设备:<b>{{ unlinkNumber }}</b></span>
  7. <span class="statistics-title">可在此功能中批量关联的:<b>{{ linkNumber }}</b></span>
  8. <el-button style="float:right;margin-top:1px;" @click="handleClickCreate">保存选定的设备资产关联关系</el-button>
  9. <el-button v-show="Object.keys(radio).length" style="float:right;margin-top:1px;margin-right:15px;"
  10. @click="handleClickReset">重置
  11. </el-button>
  12. <span style="float:right;margin-top:5px;font-size:12px;margin-right:10px;color:#999;">不能批量处理的请在设备台账列表中操作</span>
  13. </div>
  14. <div class="main">
  15. <el-table ref="multipleTable" :data="tableData" v-loading='loading' stripe height="100%"
  16. :span-method="objectSpanMethod" :header-cell-style="headerStyle">
  17. <el-table-column prop="localName" label="设备本地名称" show-overflow-tooltip width="150">
  18. <!-- <template slot-scope="scope">{{ scope.row.EquipLocalName?scope.row.EquipLocalName:scope.row.EquipName }}</template> -->
  19. </el-table-column>
  20. <el-table-column prop="localId" label="设备本地编码" show-overflow-tooltip max-width="150">
  21. <!-- <template slot-scope="scope">{{ scope.row.EquipLocalID?scope.row.EquipLocalID:scope.row.EquipID }}</template> -->
  22. </el-table-column>
  23. <el-table-column prop="equipCategory.name" label="设备类" show-overflow-tooltip
  24. width="100"></el-table-column>
  25. <el-table-column prop="cADID" label="设计图纸中编码" show-overflow-tooltip max-width="150"></el-table-column>
  26. <el-table-column label="所属建筑楼层">
  27. <template slot-scope="scope">
  28. {{
  29. scope.row.building ? scope.row.building.localName : ''
  30. }}-{{ scope.row.floor ? scope.row.floor.localName : '' }}
  31. </template>
  32. </el-table-column>
  33. <el-table-column prop="PropertyItem.localName" label="资产本地名称" show-overflow-tooltip width="150">
  34. <!-- <template slot-scope="scope">{{ scope.row.AssetsLocalName }}</template> -->
  35. </el-table-column>
  36. <el-table-column prop="PropertyItem.localId" label="资产本地编码" show-overflow-tooltip max-width="150">
  37. <!-- <template slot-scope="scope">{{ scope.row.AssetsLocalId }}</template> -->
  38. </el-table-column>
  39. <el-table-column prop="PropertyItem.familyName.name" label="设备族" show-overflow-tooltip
  40. width="100"></el-table-column>
  41. <el-table-column prop="PropertyItem.cADID" label="设计图纸中编码" show-overflow-tooltip
  42. max-width="150"></el-table-column>
  43. <el-table-column label="所属建筑楼层" show-overflow-tooltip width="200">
  44. <template slot-scope="scope">
  45. {{
  46. scope.row.PropertyItem.building ? scope.row.PropertyItem.building.localName : ''
  47. }}-{{ scope.row.PropertyItem.floor ? scope.row.PropertyItem.floor.localName : '' }}
  48. </template>
  49. </el-table-column>
  50. <el-table-column prop="address" label="操作" width="100">
  51. <template slot-scope="scope">
  52. <el-radio v-model="radio[scope.row.id]" :label="scope.row.PropertyItem.id"
  53. :disabled="scope.row.disabled" @change="handleChangeLink(scope.row)">&nbsp;
  54. </el-radio>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. </div>
  59. <!-- <div class=footer>
  60. <el-pagination
  61. class="right"
  62. v-show="tableData && tableData.length"
  63. @size-change="handleSizeChange"
  64. @current-change="handleCurrentChange"
  65. :current-page="page.pageNumber"
  66. :page-sizes="page.pageSizes"
  67. :page-size="page.pageSize"
  68. layout="total, sizes, prev, pager, next, jumper"
  69. :total="page.total">
  70. </el-pagination>
  71. </div> -->
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. import {mapGetters} from "vuex"
  77. //api
  78. import {equipCategoryProperty, equipRproperty} from "@/api/scan/request";
  79. export default {
  80. components: {},
  81. computed: {
  82. ...mapGetters("layout", ["projectId", "userId", "secret"])
  83. },
  84. created() {
  85. this.params = this.$route.params
  86. this.getTableData()
  87. },
  88. data() {
  89. return {
  90. params: {},
  91. loading: false,
  92. unlinkNumber: 0,
  93. linkNumber: 0,
  94. // page: {
  95. // pageSize: 50,
  96. // pageSizes: [10, 20, 50, 100],
  97. // pageNumber: 1,
  98. // total: 0
  99. // },
  100. radio: {},
  101. contentData: [],
  102. tableData: [],
  103. mergeCol: [],
  104. headerStyle: {
  105. backgroundColor: '#e1e4e5',
  106. color: '#2b2b2b',
  107. lineHeight: '30px'
  108. }, // 列表样式
  109. }
  110. },
  111. methods: {
  112. //获取表格数据
  113. getTableData(pageNum) {
  114. this.loading = true
  115. let fl = this.formatFilter(pageNum)
  116. let param = {
  117. category: fl.category || undefined,
  118. spaceIdList: fl.spaceIdList || undefined,
  119. orders: "createTime desc",
  120. pageNumber: 1,
  121. pageSize: 1000
  122. }
  123. equipCategoryProperty(param, res => {
  124. this.unlinkNumber = res.total
  125. this.linkNumber += res.content.length
  126. // this.page.total = res.Total
  127. this.contentData = this.contentData.concat(res.content)
  128. if (res.total / (res.pageSize * res.pageNumber) > 1) {
  129. this.getTableData(res.pageNumber + 1)
  130. } else {
  131. this.contentData.forEach(item => {
  132. if (item.propertyList && item.propertyList.length) {
  133. item.propertyList.forEach((Assets, index) => {
  134. let obj = JSON.parse(JSON.stringify(Object.assign(item, { PropertyItem: Assets, disabled: false })))
  135. delete obj.propertyList
  136. this.tableData.push(obj)
  137. if (index == 0) {
  138. this.mergeCol.push(item.propertyList.length)
  139. } else {
  140. this.mergeCol.push(false)
  141. }
  142. })
  143. }
  144. })
  145. this.loading = false
  146. }
  147. })
  148. },
  149. //格式化条件
  150. formatFilter(pageNum) {
  151. pageNum = pageNum ? pageNum : 1
  152. let param = {
  153. data: {
  154. // Cascade: [
  155. // {
  156. // Name: "equipCategory",
  157. // Projection: ["EquipCode", "EquipName"]
  158. // },
  159. // {
  160. // Name: "building",
  161. // Projection: [ "BuildLocalName", "BuildName", "BuildID" ]
  162. // },
  163. // {
  164. // Name: "floor",
  165. // Projection: [ "FloorLocalName", "FloorName", "FloorID" ]
  166. // }
  167. // ],
  168. orders: "createTime desc, id asc",
  169. pageNumber: pageNum,
  170. pageSize: 1000
  171. },
  172. category: this.params.deviceType
  173. }
  174. if (this.params.buildFloor[0] == "noKnow") {
  175. param.data.filters = `buildingId isNull`
  176. } else if (this.params.buildFloor[0] && this.params.buildFloor[0] != "all") {
  177. param.data.filters = `buildingId='${this.params.buildFloor[0]}'`
  178. if (this.params.buildFloor[1] == "noKnow") {
  179. param.data.filters += `;floorId isNull`
  180. } else if (this.params.buildFloor[1] && this.params.buildFloor[1] != "all") {
  181. param.data.filters += `;floorId='${this.params.buildFloor[1]}'`
  182. }
  183. }
  184. if (this.params.hasOwnProperty('spaceList')) {
  185. if (typeof this.params.spaceList == 'string') {
  186. param.spaceIdList = `&spacrType=${this.params.spaceList}`
  187. } else {
  188. let spaceIdList = ''
  189. this.params.spaceList.forEach(item => {
  190. spaceIdList += `&spaceIdList=${item}`
  191. })
  192. param.spaceIdList = spaceIdList
  193. }
  194. }
  195. return param
  196. },
  197. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  198. if (columnIndex < 5) {
  199. if (this.mergeCol[rowIndex]) {
  200. return {
  201. rowspan: this.mergeCol[rowIndex],
  202. colspan: 1
  203. };
  204. } else {
  205. return {
  206. rowspan: 0,
  207. colspan: 1
  208. };
  209. }
  210. }
  211. },
  212. //切换关联
  213. handleChangeLink(row) {
  214. this.tableData.forEach(item => {
  215. item.disabled = false
  216. if (Object.keys(this.radio).length) {
  217. for (let key in this.radio) {
  218. if (item.id != key && item.PropertyItem.id == this.radio[key]) {
  219. item.disabled = true
  220. }
  221. }
  222. }
  223. })
  224. },
  225. //重置关联选择
  226. handleClickReset() {
  227. this.tableData.forEach(item => {
  228. item.disabled = false
  229. })
  230. this.radio = {}
  231. },
  232. //创建已选
  233. handleClickCreate() {
  234. let params = {
  235. content: []
  236. }
  237. if (Object.keys(this.radio).length) {
  238. for (let key in this.radio) {
  239. params.content.push({
  240. id: this.radio[key],
  241. equipId: key
  242. })
  243. console.log(params.content)
  244. }
  245. equipRproperty(params, res => {
  246. this.radio = {}
  247. this.linkNumber = 0
  248. this.contentData = []
  249. this.tableData = []
  250. this.getTableData()
  251. this.$message.success('关联成功!')
  252. })
  253. } else {
  254. this.$message.info('请选择要关联的关系!')
  255. }
  256. },
  257. //切换每页显示多少条数据
  258. // handleSizeChange(val) {
  259. // this.page.pageSize = val
  260. // this.getTableData()
  261. // },
  262. //切换页数
  263. // handleCurrentChange(val) {
  264. // this.page.pageNumber = val
  265. // this.getTableData()
  266. // },
  267. //返回
  268. goBack() {
  269. this.$router.push({ name: "facilityLedger" })
  270. }
  271. },
  272. watch: {
  273. projectId() {
  274. this.$router.push({ name: "facilityLedger" })
  275. }
  276. }
  277. };
  278. </script>
  279. <style scoped lang='less'>
  280. .box {
  281. .condition {
  282. padding: 10px;
  283. display: flex;
  284. height: 100%;
  285. flex-direction: column;
  286. border: 1px solid #dfe6ec;
  287. background: #fff;
  288. .header {
  289. padding-bottom: 10px;
  290. border-bottom: 1px solid #bcbcbc;
  291. .statistics-title {
  292. margin-left: 20px;
  293. line-height: 32px;
  294. }
  295. }
  296. .main {
  297. margin-top: 10px;
  298. height: calc(100% - 46px);
  299. }
  300. }
  301. }
  302. </style>
  303. <style lang="less">
  304. .el-table th {
  305. background-color: #d9d9d9;
  306. color: #000;
  307. }
  308. </style>