recommend.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <div class="saga-recommend">
  3. <div v-if="hasData">
  4. <h4>当前资产:{{fm.FmName}}</h4>
  5. <div class="saga-change-name" v-if="!isChangeFor">
  6. <h3 class="saga-gray saga-explain">您可能需要快捷改值操作</h3>
  7. <!-- 智能推荐按钮 -->
  8. <div v-if="isChangeId">
  9. <template v-if="changeList.length" v-for="item in changeList">
  10. <saga-button @click="getList(item)">修正 "{{getName(key)}}" 为 {{item.value}}</saga-button>
  11. </template>
  12. <template v-if="!changeList.length">
  13. <p>
  14. {{changeMsg}}</p>
  15. </template>
  16. </div>
  17. <!-- 修正按钮 -->
  18. <div v-else>
  19. <saga-button @click="changeToNull">修正 "{{getName(key)}}" 为 {{noIdChangeVal}}</saga-button>
  20. </div>
  21. </div>
  22. <div class="saga-change-name" v-if="!isSameForCreate">
  23. <h3 class="saga-gray saga-explain">您可能需要快捷维护厂商库</h3>
  24. <template>
  25. <saga-button v-if="!isChangeVender" @click="create">
  26. 增加 {{obj.name}} “ {{val ? val : fm.Infos[key]}} ”</saga-button>
  27. <saga-button v-if="isChangeVender" @click="changeVender">更新厂商库中此{{obj.name}}对应值</saga-button>
  28. </template>
  29. <!--<template v-else>
  30. <p>
  31. {{ !!message ? message : "请确定该信息点内有值"}}</p>
  32. </template>-->
  33. </div>
  34. <div class="saga-change-name" v-if="elseBtnsShow">
  35. <h3 class="saga-gray saga-explain">您可能需要其他快捷操作</h3>
  36. <!-- <saga-button @click="checkVenders">先维护 xxx 信息点</saga-button> -->
  37. <saga-button @click="checkVenders" v-if="showBtn">批量维护 {{!!obj ? obj.name : ""}} 相关信息点</saga-button>
  38. <saga-button v-if="!showBtn">先维护 {{objMsg}}</saga-button>
  39. <!-- <saga-button @click="checkVenders"></saga-button> -->
  40. </div>
  41. </div>
  42. <div v-else class="saga-message">
  43. <p>{{!!dataMessage ? dataMessage : "请确定该信息点是支持推荐的信息点"}}</p>
  44. </div>
  45. <venders-change
  46. :create="isCreate"
  47. v-if="dialog.visible"
  48. ref="venders"
  49. :dialog="dialog"
  50. :infosKey="infosKey"
  51. :types="types"
  52. :fmData="fm"
  53. @change="loadFm"
  54. :title="isCreate ? '添加' + obj.name : '修改' + obj.name"
  55. ></venders-change>
  56. </div>
  57. </template>
  58. <script>
  59. import sagaButton from "./sagaButton"
  60. import vendersChange from "./vendersChange"
  61. import getVenderRecommend from "./findId"
  62. import tools from "@/utils/scan/tools"
  63. import getJson from "@/utils/buildData/vendersUtils"
  64. import buildJson from "@/utils/buildData/buildJson"
  65. import cutHeader from "@/utils/scan/cutHeader"
  66. import { upDateTableMain, getBasicMatch } from "@/api/scan/request"
  67. import {mapGetters, mapActions} from "vuex"
  68. export default {
  69. components: {
  70. sagaButton,
  71. vendersChange
  72. },
  73. data() {
  74. return {
  75. hasData: false,
  76. fm: {},
  77. infosKey: null,
  78. dialog: {
  79. visible: false
  80. },
  81. createList: [],
  82. changeList: [],
  83. types: {},
  84. headers: [],
  85. message: "",
  86. obj: {},
  87. key: "",
  88. isCreate: false,
  89. showBtn: false,
  90. createShow: false,
  91. changeMsg: "", //修改的提示
  92. dataMessage: "⬅请点击资产信息点",
  93. falg: false, //上级页面传入的数值,用于实时请求
  94. val: null, //上级传入的val
  95. isSameForCreate: false,
  96. isChangeFor: false,
  97. isChangeVender: false,
  98. isChangeId: true, //是否为修改id
  99. noIdChangeVal: "",
  100. elseBtnsShow: true, //是否显示修改按钮
  101. msgTable: true,
  102. content: {}, //厂商库信息点
  103. objMsg: "相关信息点"
  104. }
  105. },
  106. created() {},
  107. mounted() {},
  108. computed: {
  109. ...mapGetters("layout", [
  110. "projectId",
  111. "secret",
  112. "userId"
  113. ])
  114. },
  115. methods: {
  116. //主页面重新加载
  117. loadFm() {
  118. this.$emit("loadData")
  119. },
  120. //根据id获得信息点名称
  121. getName(code) {
  122. if (!!code) {
  123. let name = ""
  124. this.headers.map(item => {
  125. if (item.InfoPointCode == code) {
  126. name = item.InfoPointName
  127. }
  128. })
  129. return name
  130. } else {
  131. return ""
  132. }
  133. },
  134. //修改
  135. checkVenders() {
  136. this.isCreate = false
  137. this.dialog.visible = true
  138. this.$nextTick(_ => {
  139. this.$refs.venders.getData()
  140. })
  141. },
  142. //获取表头
  143. changeObj() {
  144. buildJson.map(item => {
  145. if (item.name == "型号") {
  146. item.options = []
  147. item.infosArr = []
  148. this.headers.map(child => {
  149. if (child.FirstTag == "技术参数" ||
  150. child.InfoPointCode == "Specification" ||
  151. child.InfoPointCode == "MaintainPeriod" ||
  152. child.InfoPointCode == "ServiceLife") {
  153. item.infosArr.push(child.InfoPointCode)
  154. let option = {
  155. key: "contact.infos." + child.InfoPointCode,
  156. label: child.InfoPointName,
  157. optLabel: child.InfoPointCode,
  158. type: child.DataType,
  159. dataSource: child.DataSource,
  160. FirstTag: child.FirstTag,
  161. SecondTag: child.SecondTag
  162. }
  163. if (child.InfoPointCode == "Specification") {
  164. option.key = "content.specificationName"
  165. }
  166. item.options.push(option)
  167. }
  168. })
  169. item.options = cutHeader(item.options)
  170. }
  171. })
  172. },
  173. changeToNull() {
  174. // let param = {
  175. // FmId: this.fm.FmId,
  176. // Infos: {
  177. // [this.key]: null
  178. // }
  179. // }
  180. // this.updateMain(param)
  181. console.log(this.noIdChangeVal, "this.noIdChangeVal")
  182. this.fm.Infos[this.key] = this.noIdChangeVal
  183. },
  184. //上级页面传输的数据
  185. randerData(idData, infosKey, headers, falg = false, val = null) {
  186. this.isChangeVender = false
  187. console.log(idData, infosKey, headers, falg, "falg")
  188. this.falg = falg
  189. this.val = val
  190. this.fm = tools.deepCopyObj(idData)
  191. this.headers = headers
  192. this.changeObj()
  193. this.infosKey = infosKey
  194. this.message = ""
  195. this.key = infosKey.split(".")[1]
  196. this.obj = getJson(this.infosKey.split(".")[1])
  197. console.log("数据请求", this.obj)
  198. if (!!this.obj) {
  199. console.log("有data")
  200. this.hasData = true
  201. this.getDataForm()
  202. } else {
  203. this.hasData = false
  204. }
  205. },
  206. changeVender() {
  207. // 修改厂商库中对应的值
  208. console.log("修改厂商库中的值", this.obj, this.key)
  209. let webArr = ["SupplierWeb", "InsurerWeb", "MaintainerWeb"],
  210. //三大厂商的key
  211. keysArr = ["DPInsurerID", "DPSupplierID", "DPMaintainerID"]
  212. //如果是三大厂商的网址
  213. if (webArr.indexOf(this.key) > -1) {
  214. let param = {
  215. venderId: this.fm.Infos[this.obj.infosKey],
  216. website: this.fm.Infos[this.key]
  217. }
  218. this.obj.updateVender(param, res => {
  219. this.updateKey(this.key, this.fm)
  220. })
  221. return false
  222. } else if (keysArr.indexOf(this.obj.infosKey) > -1) {
  223. let param = {
  224. venderId: this.fm.Infos[this.obj.infosKey],
  225. projectId: this.projectId
  226. }
  227. //如果存在content的联系人
  228. console.log(this.content, "content")
  229. if (this.content.hasOwnProperty("contact")) {
  230. let contents = this.content.contact
  231. for (let k in contents) {
  232. param[k] = contents[k]
  233. }
  234. }
  235. param[[this.getKey(this.obj.options, this.key)]] = this.fm.Infos[this.key]
  236. this.obj.update(param, res => {
  237. this.updateKey(this.key, this.fm)
  238. })
  239. return false
  240. } else {
  241. let param = {
  242. specificationId: this.fm.Infos.DPSpecificationID,
  243. infos: {
  244. [this.key]: this.fm.Infos[this.key]
  245. }
  246. }
  247. this.obj.updateVender(param, res => {
  248. this.updateKey(this.key, this.fm)
  249. })
  250. return false
  251. }
  252. },
  253. updateKey(key, obj) {
  254. let param = {
  255. FmId: obj.FmId,
  256. Infos: {
  257. [key]: null
  258. }
  259. }
  260. this.updateMain(param)
  261. },
  262. /**
  263. * @param arr 传入的数组
  264. * @param key 传入的key
  265. *
  266. * @return key 对应的key
  267. */
  268. getKey(arr, key) {
  269. let returnKey = ""
  270. arr.map(item => {
  271. if (item.optLabel == key) {
  272. returnKey = item.key.split(".")[1]
  273. console.log(returnKey, item, "item")
  274. }
  275. })
  276. return returnKey
  277. },
  278. //有obj的信息时
  279. getDataForm() {
  280. let idArr = ["DPManufacturerID", "DPSupplierID", "DPInsurerID", "DPMaintainerID", "DPSpecificationID", "DPBrandID", "DPSpecificationID"]
  281. //点击以下按钮触发按钮事件
  282. let vendersArr = ["Manufacturer", "Supplier", "Maintainer", "Insurer", "Brand", "Specification"]
  283. if (!!this.fm.Infos[this.obj.infosKey]) {
  284. this.falgChange(true)
  285. } else {
  286. this.falgChange(false)
  287. }
  288. },
  289. //falg为是否存在id
  290. falgChange(falg) {
  291. let vendersArr = ["Manufacturer", "Supplier", "Maintainer", "Insurer", "Brand", "Specification"]
  292. if (this.val || !!this.fm.Infos[this.key]) {
  293. //存在id且单元格存在值
  294. if (falg) {
  295. if (this.falg && vendersArr.indexOf(this.key) > -1) {
  296. this.noIdDo()
  297. } else {
  298. this.getVendersList()
  299. }
  300. } else {
  301. // 没有id
  302. this.noIdDo()
  303. }
  304. } else {
  305. //不存在值
  306. // this.isChangeFor = false
  307. // this.isSameForCreate = true
  308. // this.changeList = []
  309. this.noIdDo()
  310. // this.changeMsg = "请确定该单元格内存在值"
  311. }
  312. },
  313. //没有id执行
  314. noIdDo() {
  315. console.log("没有id")
  316. let param = {
  317. infoCode: this.key,
  318. infoValue: this.val || this.fm.Infos[this.key]
  319. },
  320. falg = true
  321. this.createShow = true
  322. this.showBtn = false
  323. this.elseBtnsShow = true
  324. if (this.key == "Brand") {
  325. param.manufacturerID = this.fm.Infos.DPManufacturerID
  326. }
  327. if (this.key == "Specification") {
  328. param.manufacturerID = this.fm.Infos.DPManufacturerID
  329. param.brandID = this.fm.Infos.DPBrandID
  330. param.eqFamily = this.fm.Family
  331. }
  332. for (let k in param) {
  333. if (!param[k]) {
  334. falg = false
  335. }
  336. }
  337. console.log(falg, "falg")
  338. //如果传参中某个值为空不发生请求
  339. if (!falg) {
  340. this.noShowTop12()
  341. return false
  342. } else {
  343. this.elseBtnsShow = false
  344. }
  345. console.log(this.obj.infosArr[0], this.infosKey, "this.infosKey")
  346. if (this.obj.infosArr[0] != this.key) {
  347. console.log("其他信息点")
  348. this.noShowTop12()
  349. return false
  350. }
  351. getVenderRecommend(param, res => {
  352. this.changeList = res.content || []
  353. this.isChangeId = true
  354. this.isSameForCreate = false
  355. this.isChangeFor = false
  356. console.log(this.changeList, "changeList")
  357. if (!!this.changeList && this.changeList.length == 1) {
  358. if (this.changeList[0].value == this.fm.Infos[this.key] &&
  359. this.changeList[0].id == this.fm.Infos["DP" + this.key + "ID"]) {
  360. this.isSameForCreate = true
  361. this.isChangeFor = true
  362. if (!!this.val && this.val != this.fm.Infos[this.key]) {
  363. this.isChangeFor = false
  364. this.isSameForCreate = false
  365. }
  366. }
  367. }
  368. if (res.content[0] && res.content[0].similarity == 100) {
  369. this.changeList = []
  370. this.isSameForCreate = true
  371. this.isChangeFor = false
  372. }
  373. if (this.changeList.length <= 0) {
  374. // this.changeMsg = "不存在符合条件的推荐"
  375. }
  376. })
  377. },
  378. //第一栏第二栏不显示
  379. noShowTop12() {
  380. if (!this.val && !this.fm.Infos[this.key]) {
  381. this.elseBtnsShow = false
  382. }
  383. console.log(this.obj.infosKey, this.fm.Infos)
  384. //型号
  385. if (this.obj.infosKey == "DPSpecificationID") {
  386. if (!this.fm.Infos.DPManufacturerID) {
  387. this.elseBtnsShow = true
  388. this.objMsg = "生产厂家"
  389. } else if (!this.fm.Infos.DPBrandID) {
  390. this.elseBtnsShow = true
  391. this.objMsg = "品牌"
  392. } else if (!this.fm.Infos.DPSpecificationID) {
  393. console.log("设备型号")
  394. this.elseBtnsShow = true
  395. this.objMsg = "设备型号"
  396. }
  397. }
  398. //品牌
  399. if (this.obj.infosKey == "DPBrandID") {
  400. if (!this.fm.Infos.DPManufacturerID) {
  401. this.objMsg = "生产厂家"
  402. }
  403. }
  404. //生产厂家
  405. if (this.obj.infosKey == "DPManufacturerID") {
  406. this.elseBtnsShow = false
  407. }
  408. //供应商
  409. if (this.obj.infosKey == "DPSupplierID") {
  410. if (!this.fm.Infos.DPSupplierID) {
  411. console.log("没有供应商id")
  412. this.elseBtnsShow = false
  413. if (this.key != "Supplier") {
  414. this.elseBtnsShow = true
  415. }
  416. this.objMsg = "供应商单位名称"
  417. }
  418. }
  419. //维修商
  420. if (this.obj.infosKey == "DPMaintainerID") {
  421. if (!this.fm.Infos.DPMaintainerID) {
  422. console.log("没有维修商id")
  423. this.elseBtnsShow = false
  424. if (this.key != "Maintainer") {
  425. this.elseBtnsShow = true
  426. }
  427. this.objMsg = "维修商单位名称"
  428. }
  429. }
  430. //保险公司
  431. if (this.obj.infosKey == "DPInsurerID") {
  432. if (!this.fm.Infos.DPInsurerID) {
  433. console.log("没有保险id")
  434. this.elseBtnsShow = false
  435. if (this.key != "Insurer") {
  436. this.elseBtnsShow = true
  437. }
  438. this.objMsg = "保险公司名称"
  439. }
  440. }
  441. this.isSameForCreate = true
  442. this.isChangeFor = true
  443. },
  444. //当前单元格内存在id且单元格存在值
  445. getVendersList() {
  446. //四大厂商名称
  447. this.isChangeId = true
  448. let venderIdArr = ["DPManufacturerID", "DPSupplierID", "DPInsurerID", "DPMaintainerID", "DPBrandID"],
  449. vendersArr = ["Manufacturer", "Supplier", "Maintainer", "Insurer", "Brand"],
  450. infosKey = this.obj.infosKey
  451. this.showBtn = true
  452. this.elseBtnsShow = true
  453. //获取label
  454. let ownLabel = ""
  455. this.obj.options.map(item => {
  456. if (item.optLabel == this.key) {
  457. ownLabel = item.key
  458. }
  459. })
  460. if (venderIdArr.indexOf(infosKey) > -1) {
  461. let param = {
  462. venderId: this.fm.Infos[infosKey],
  463. projectId: this.projectId
  464. }
  465. if (infosKey == "DPBrandID") {
  466. param = {
  467. brandId: this.fm.Infos[infosKey]
  468. }
  469. }
  470. this.obj.getList(param, res => {
  471. console.log(this.key, this.obj.options, res, ownLabel, "ownLabel")
  472. let optArr = ownLabel.split("."),
  473. optContent = ""
  474. if (this.obj.infosKey == "DPBrandID") {
  475. optContent = res[optArr[0]][optArr[1]]
  476. } else {
  477. optContent = res.content[optArr[0]][optArr[1]]
  478. }
  479. if (optContent == (this.val || this.fm.Infos[this.key])) {
  480. //厂商库中的值与现有的值相等
  481. this.isChangeFor = true
  482. this.isSameForCreate = true
  483. let keysBtns = ["DPBrandID", "DPManufacturerID"]
  484. if (keysBtns.indexOf(this.obj.infosKey) > -1) {
  485. this.elseBtnsShow = false
  486. }
  487. } else {
  488. if (!optContent) {
  489. //如果厂商库中没有值
  490. console.log("没有该信息点")
  491. this.isChangeFor = true
  492. this.isChangeVender = true
  493. this.isSameForCreate = false
  494. } else {
  495. //有值
  496. console.log("有值,且值不同")
  497. this.isChangeId = false
  498. this.hasData = true
  499. this.content = res.content
  500. //修改的值(其实做置空操作)
  501. this.noIdChangeVal = optContent
  502. this.isChangeFor = false
  503. this.isSameForCreate = false
  504. this.isChangeVender = true
  505. }
  506. }
  507. })
  508. }
  509. if (infosKey == "DPSpecificationID") {
  510. let paramData = {
  511. specificationId: this.fm.Infos[infosKey]
  512. }
  513. this.obj.getList(paramData, res => {
  514. let optContent = res.content.infos[this.key]
  515. console.log(optContent, this.val, this.fm.Infos[this.key], "optContent")
  516. if (optContent == (this.val || this.fm.Infos[this.key])) {
  517. console.log("有值,且值相同")
  518. this.isChangeFor = true
  519. this.isSameForCreate = true
  520. if (this.key == "Specification") {
  521. this.elseBtnsShow = false
  522. } else {
  523. this.elseBtnsShow = true
  524. }
  525. } else {
  526. if (!optContent) {
  527. //如果厂商库中没有值
  528. console.log("没有该信息点")
  529. this.isChangeFor = true
  530. this.isChangeVender = true
  531. this.isSameForCreate = false
  532. } else {
  533. //有值
  534. console.log("有值,且值不同")
  535. this.isChangeId = false
  536. this.hasData = true
  537. //修改的值(其实做置空操作)
  538. this.noIdChangeVal = optContent
  539. this.isChangeFor = false
  540. this.isSameForCreate = false
  541. this.isChangeVender = true
  542. }
  543. }
  544. })
  545. }
  546. if (vendersArr.indexOf(this.key) > -1) {
  547. this.showBtn = true
  548. }
  549. },
  550. //创建函数
  551. create(item) {
  552. // console.log(this.obj.infosKey)
  553. // let param;
  554. // if(this.obj.infosKey == "DPBrandID" || this.obj.infosKey == "DPManufacturerID"){
  555. // if(this.obj.infosKey == "DPBrandID"){
  556. // param = {
  557. // "venderId": this.fm.Infos.DPManufacturerID, //String,必填,生产商id
  558. // "name": this.fm.Infos.Brand, //String,必填,品牌名称
  559. // }
  560. // }else{
  561. // param = {
  562. // "name": this.fm.Infos.Manufacturer,
  563. // }
  564. // }
  565. // this.obj.createFunc(param,res=>{
  566. // })
  567. // }
  568. this.isCreate = true
  569. this.dialog.visible = true
  570. this.$nextTick(_ => {
  571. this.$refs.venders.getCreateData()
  572. })
  573. },
  574. updateMain(param) {
  575. upDateTableMain({
  576. ProjId: this.projectId,
  577. UserId: this.userId
  578. }, [param]).then(res => {
  579. if (res.data.Result == "success") {
  580. this.loadFm()
  581. } else {
  582. this.$message.error("保存出错")
  583. }
  584. })
  585. },
  586. //点击按钮,对表格操作
  587. getList(data) {
  588. // this.fm.Infos[this.key] = data.value
  589. let infos = tools.deepCopyObj(this.fm.Infos)
  590. infos[this.key] = data.value
  591. let param = {
  592. "projectId": this.projectId,
  593. "criterias": [{
  594. id: this.fm.FmId,
  595. family: this.fm.Family,
  596. infos: infos
  597. }]
  598. }
  599. console.log(param, "paramparam")
  600. this.getIdForVender(param)
  601. },
  602. //判断文案是否相同
  603. getIdForVender(param) {
  604. getBasicMatch(param).then(res => {
  605. if (res.data.result == "success") {
  606. let myParam = res.data.content.map(item => {
  607. return {
  608. Family: item.family,
  609. FmId: item.id,
  610. Infos: item.infos
  611. }
  612. })
  613. this.updateMain(myParam[0])
  614. } else {
  615. this.$message.error("请求错误" + res.data.resultMsg)
  616. }
  617. }).catch(error => {
  618. this.$message.error(error)
  619. })
  620. },
  621. }
  622. }
  623. </script>
  624. <style lang="less" scoped>
  625. .saga-recommend {
  626. height: 100%;
  627. overflow-y: auto; // background-color: red;
  628. .saga-gray {
  629. color: #b7c3c8;
  630. }
  631. .saga-change-name {
  632. padding: 8px;
  633. min-height: 100px; // background-color: yellow;
  634. border-bottom: 1px solid #ccc;
  635. .saga-explain {
  636. font-size: 17px;
  637. font-weight: 600;
  638. }
  639. }
  640. }
  641. .saga-message {
  642. height: 100vh;
  643. line-height: 100vh;
  644. font-size: 20px;
  645. color: #b7c3c8;
  646. background:#fff;
  647. }
  648. </style>