PatentField.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <div class="patent-articles-patent-field">
  3. <el-form label-position="top" class="custom-field-form">
  4. <template v-for="(item, index) in customField">
  5. <el-form-item :key="item.id">
  6. <template slot="label">
  7. <span :title="item.name" class="name">{{ item.name }}</span>
  8. </template>
  9. <div class="option">
  10. <el-dropdown size="small">
  11. <span class="el-dropdown-link">
  12. <i class="el-icon-more el-icon--right"></i>
  13. </span>
  14. <el-dropdown-menu slot="dropdown">
  15. <el-dropdown-item @click.native="handleOption(0, index)">上移</el-dropdown-item>
  16. <el-dropdown-item @click.native="handleOption(1, index)">下移</el-dropdown-item>
  17. </el-dropdown-menu>
  18. </el-dropdown>
  19. </div>
  20. <template v-if="(item.type === 0 || item.type === 2 || item.type === 1) && !item.showField">
  21. <el-date-picker v-if="item.type === 1" v-model="item.selectedValue" value-format="yyyy-MM-dd" type="date"
  22. size="small" placeholder="选择日期" class="width_100" @blur="onChange($event, item)"></el-date-picker>
  23. <el-input v-else type="textarea" v-model="item.selectedValue" placeholder="请输入内容" size="small"
  24. @blur="onChange($event, item)"></el-input>
  25. </template>
  26. <template v-if="item.type === 4 && !item.showField">
  27. <div class="showValue">
  28. <div>
  29. <!-- <div v-for="fieldValue in item.selected" :key="fieldValue.value" class="value">{{ fieldValue.value }}
  30. </div> -->
  31. <el-tag
  32. v-for="tag in item.selected"
  33. :key="tag.value"
  34. closable
  35. type=""
  36. @close="handleCloseValue(item,tag)">
  37. {{tag.value}}
  38. </el-tag>
  39. </div>
  40. <el-button size="small" @click="changeShow(item)">{{ item.show ? '收起' : '修改' }}</el-button>
  41. </div>
  42. <el-radio-group v-model="item.selectedValue" v-show="item.show">
  43. <div v-for="option in item.option" :key="option.id">
  44. <el-radio class="custom-radio" :label="option.id" @change="onChange($event, item)"
  45. @click.native.prevent="clickItem(option, item)">{{
  46. option.name }}</el-radio>
  47. </div>
  48. </el-radio-group>
  49. </template>
  50. <template v-if="item.type === 5 && !item.showField">
  51. <div class="showValue">
  52. <div>
  53. <!-- <div v-for="fieldValue in item.selected" :key="fieldValue.valueId" class="value">{{ fieldValue.value }}
  54. </div> -->
  55. <el-tag
  56. v-for="tag in item.selected"
  57. :key="tag.value"
  58. closable
  59. type=""
  60. @close="handleCloseValue(item,tag)">
  61. {{tag.value}}
  62. </el-tag>
  63. </div>
  64. <el-button size="small" @click="changeShow(item)">{{ item.show ? '收起' : '修改' }}</el-button>
  65. </div>
  66. <el-checkbox-group :value="item.selectedValue" v-show="item.show">
  67. <el-checkbox class="custom-checkbox" v-for="option in item.option" :label="option.id" :key="option.id"
  68. @change="(val) => onChange(option, item, val)">{{ option.name }}</el-checkbox>
  69. </el-checkbox-group>
  70. </template>
  71. <template v-if="[6,7,8,9].includes(item.type) && !item.showField">
  72. <div class="showValue">
  73. <div>
  74. <!-- <div v-for="fieldValue in item.selected" :key="fieldValue.valueId" class="value">{{ fieldValue.value }}
  75. </div> -->
  76. <el-tag
  77. v-for="tag in item.selected"
  78. :key="tag.value"
  79. closable
  80. type=""
  81. @close="handleCloseValue(item,tag)">
  82. {{tag.value}}
  83. </el-tag>
  84. </div>
  85. <el-button size="small" @click="changeShow(item)">{{ item.show ? '收起' : '修改' }}</el-button>
  86. </div>
  87. <div v-show="item.show">
  88. <el-tree :data="item.option" node-key="id" default-expand-all :props="defaultProps">
  89. <span class="custom-tree-node" slot-scope="{ node, data }">
  90. <el-checkbox-group :value="item.selectedValue">
  91. <el-checkbox :label="data.id" @change="(val) => onChange(data, item, val)">{{ data.name
  92. }}</el-checkbox>
  93. </el-checkbox-group>
  94. </span>
  95. </el-tree>
  96. </div>
  97. </template>
  98. </el-form-item>
  99. </template>
  100. </el-form>
  101. </div>
  102. </template>
  103. <script>
  104. export default {
  105. props: {
  106. projectId: {
  107. default: 0
  108. },
  109. taskId: {
  110. default: null,
  111. },
  112. patentNo: ''
  113. },
  114. data() {
  115. return {
  116. customField: [],
  117. defaultProps: {
  118. children: 'child',
  119. label: 'name'
  120. },
  121. }
  122. },
  123. watch: {
  124. patentNo() {
  125. this.getOptionsAndSelected()
  126. }
  127. },
  128. mounted() {
  129. this.getCustomField()
  130. },
  131. methods: {
  132. //上移下移
  133. handleOption(type, index) {
  134. if (index == 0 && type == 0) {
  135. this.$message.warning('已是最顶层')
  136. return false
  137. }
  138. if (index == this.customField.length - 1 && type == 1) {
  139. this.$message.warning('已是最后一层')
  140. return false
  141. }
  142. if (type == 0) {
  143. var current = index - 1
  144. var next = index
  145. } else {
  146. var current = index
  147. var next = index + 1
  148. }
  149. var order = this.customField[current].sysOrder
  150. this.customField[current].sysOrder = this.customField[next].sysOrder
  151. this.customField[next].sysOrder = order
  152. var temp = JSON.parse(JSON.stringify(this.customField[current]))
  153. this.customField[current] = JSON.parse(JSON.stringify(this.customField[next]))
  154. this.customField[next] = temp
  155. let params = {
  156. taskId: this.taskId,
  157. projectId: this.projectId,
  158. allCustomFieldVOs: this.customField
  159. }
  160. this.$api.addAllPatentCustomFieldOrder(params).then(res => {
  161. if (res.code == 200) {
  162. this.$message.success('移动成功')
  163. // this.getCustomField()
  164. this.$forceUpdate()
  165. }
  166. })
  167. },
  168. //
  169. clickItem(data, item) {
  170. this.gong(data, item)
  171. },
  172. handleCloseValue(item,tag){
  173. var params = {
  174. projectId: this.projectId,
  175. taskId: this.taskId,
  176. fieldType: item.type,
  177. fieldId: item.id,
  178. fieldValue: [tag.valueId],
  179. patentNo: this.patentNo,
  180. optionType: 0,
  181. }
  182. this.$api.addCustomFieldValue(params).then(response => {
  183. if (response.code == 200) {
  184. this.$message.success('修改成功')
  185. var index = item.selected.findIndex(i=>{
  186. return i.valueId == tag.valueId
  187. })
  188. item.selected.splice(index,1)
  189. if(item.type == 4){
  190. this.$set(item,'selectedValue','')
  191. }else{
  192. item.selectedValue.splice(index,1)
  193. }
  194. this.refresh(item)
  195. }
  196. }).catch(error => {
  197. })
  198. },
  199. //切换选择
  200. onChange(data, item, checked) {
  201. this.gong(data, item, checked)
  202. },
  203. // change与clickItem公用
  204. gong(data, item, checked) {
  205. var params = {
  206. projectId: this.projectId,
  207. taskId: this.taskId,
  208. fieldType: item.type,
  209. fieldId: item.id,
  210. fieldValue: [data.id || data],
  211. patentNo: this.patentNo,
  212. optionType: '',
  213. }
  214. if (item.type == 0 || item.type == 1 || item.type == 2 || item.type == 4) {
  215. if (item.type != 4) {
  216. params.fieldValue[0] = item.selectedValue
  217. } else {
  218. if (item && item.selectedValue == data.id) {//单选的id
  219. this.$set(item, 'selectedValue', '')
  220. this.$set(item, 'selected', [])
  221. } else {
  222. this.$set(item, 'selectedValue', data.id)
  223. // item.selected.push(
  224. // {
  225. // value: data.name,
  226. // valueId: data.id
  227. // }
  228. // )
  229. item.selected = [
  230. {
  231. value: data.name,
  232. valueId: data.id
  233. }
  234. ]
  235. }
  236. }
  237. params.optionType = 2
  238. }
  239. // 判断optionType 0取消1添加2覆盖
  240. if (item.type == 6 || item.type == 5) {
  241. if (checked) {
  242. item.selectedValue.push(data.id)
  243. var name = ''
  244. if (data.pathName == '/') {
  245. name = data.pathName + data.name
  246. } else if (data.pathName) {
  247. name = data.pathName + '/' + data.name
  248. } else {
  249. name = data.name
  250. }
  251. item.selected.push(
  252. {
  253. value: name,
  254. valueId: data.id
  255. }
  256. )
  257. params.optionType = 1
  258. } else {
  259. let index = item.selectedValue.findIndex(valIndex => {
  260. return valIndex == data.id
  261. })
  262. if (index != -1) {
  263. item.selectedValue.splice(index, 1)
  264. item.selected.splice(index, 1)
  265. }
  266. params.optionType = 0
  267. }
  268. }
  269. this.$api.addCustomFieldValue(params).then(response => {
  270. if (response.code == 200) {
  271. this.$message.success('修改成功')
  272. // this.getSelected(item)
  273. this.refresh(item)
  274. }
  275. }).catch(error => {
  276. })
  277. },
  278. //刷新
  279. refresh(item) {
  280. this.$set(item, 'showField', true)
  281. this.$nextTick(() => {
  282. this.$set(item, 'showField', false)
  283. })
  284. },
  285. // 获取栏位
  286. getCustomField() {
  287. var params = {
  288. projectId: this.projectId,
  289. taskId: this.taskId
  290. }
  291. this.$api.getAllPatentCustomField(params).then(response => {
  292. if (response.code == 200) {
  293. this.customField = response.data.data
  294. this.getOptionsAndSelected()
  295. }
  296. }).catch(error => {
  297. this.customField = []
  298. })
  299. },
  300. //获取栏位的选项和选项值(0数字,1日期,2文本,4单选,5多选,6树,7产品8产品类别9技术分类)
  301. getOptionsAndSelected() {
  302. this.customField.forEach(item => {
  303. this.getSelected(item)
  304. });
  305. },
  306. //切换是否修改
  307. changeShow(item) {
  308. this.$set(item, 'show', !item.show)
  309. if (item.option && item.option.length > 0) {
  310. return;
  311. }
  312. this.getOption(item)
  313. },
  314. getOption(item) {
  315. switch (item.type) {
  316. case 4:
  317. case 5:
  318. this.getCustomOption(item)
  319. break;
  320. case 6:
  321. this.queryProductCategory(item, 4)
  322. break;
  323. case 7://接口传值类型:1产品类别,2产品,3技术分类,4自定义树
  324. this.queryProductCategory(item, 2)
  325. break;
  326. case 8:
  327. this.queryProductCategory(item, 1)
  328. break;
  329. case 9:
  330. this.queryProductCategory(item, 3)
  331. break;
  332. }
  333. },
  334. //获取已选中选项值、已添加的值
  335. getSelected(item) {
  336. let params = {
  337. projectId: this.projectId,
  338. taskId: this.taskId,
  339. fieldType: item.type,
  340. fieldId: item.id,
  341. patentNo: this.patentNo,
  342. }
  343. this.$api.getCustomFieldValues(params).then(response => {
  344. if (response.code == 200) {
  345. // item.selected = response.data.data
  346. this.$set(item,'selected',response.data.data)
  347. switch (item.type) {
  348. case 0://数字,日期,文字
  349. case 1:
  350. case 2:
  351. this.$set(item, 'selectedValue', (item.selected && item.selected.length > 0) ? item.selected[0].value : '')
  352. break;
  353. case 4://单选
  354. this.$set(item, 'selectedValue', (item.selected && item.selected.length > 0) ? item.selected[0].valueId : '')
  355. break;
  356. case 6://多选和树
  357. case 5:
  358. var a = []
  359. // item.selectedValue = []
  360. a = (item.selected && item.selected.length > 0) ? item.selected.map(item => item.valueId) : []
  361. this.$set(item, 'selectedValue', a)
  362. break;
  363. default:
  364. break;
  365. }
  366. }
  367. }).catch(error => {
  368. item.selected = []
  369. })
  370. },
  371. //查询自定义栏位选项
  372. getCustomOption(item) {
  373. var params = {
  374. customFieldId: item.id
  375. }
  376. this.$api.queryCustomOption(params).then(response => {
  377. if (response.code == 200) {
  378. this.$set(item, 'option', response.data.data)
  379. }
  380. }).catch(error => {
  381. this.$set(item, 'option', [])
  382. })
  383. },
  384. //获取产品或产品类别架构以及技术分类
  385. queryProductCategory(item, type) {
  386. let params = {
  387. projectId: this.projectId,
  388. taskId: this.taskId,
  389. type: type,//类型:1产品类别,2产品,3技术分类,4自定义树
  390. typeId: item.id,//产品或类别id
  391. }
  392. this.$api.queryTreeNodeTree(params).then(res => {
  393. if (res.code == 200) {
  394. this.$set(item, 'option', res.data.data)
  395. }
  396. }).catch(err => {
  397. this.$set(item, 'option', [])
  398. })
  399. },
  400. }
  401. }
  402. </script>
  403. <style lang="scss">
  404. .patent-articles-patent-field {
  405. .custom-field-form {
  406. .name {
  407. display: block;
  408. width: 170px;
  409. overflow: hidden;
  410. text-overflow: ellipsis;
  411. white-space: nowrap;
  412. }
  413. .option {
  414. position: absolute;
  415. right: 0;
  416. top: -50px;
  417. color: #1e9fff;
  418. i {
  419. cursor: pointer;
  420. }
  421. }
  422. .el-form-item {
  423. margin-bottom: 0 !important;
  424. .el-form-item__label {
  425. font-size: 16px;
  426. border-bottom: 1px solid #d2d2d2;
  427. margin-bottom: 10px;
  428. color: #EE6666;
  429. }
  430. }
  431. .custom-input {
  432. margin-bottom: 10px;
  433. .el-input {}
  434. .el-button {
  435. float: right;
  436. margin-top: 5px;
  437. }
  438. }
  439. .custom-checkbox,
  440. .custom-radio {
  441. width: 100%;
  442. margin-right: 0 !important;
  443. line-height: 30px;
  444. }
  445. .el-form-item__label {
  446. width: 100%;
  447. padding: 0 !important;
  448. }
  449. }
  450. }
  451. </style>
  452. <style lang="scss" scoped>
  453. .showValue {
  454. width: 100%;
  455. display: flex;
  456. align-items: center;
  457. &>div {
  458. width: 100%;
  459. min-height: 30px;
  460. border: 1px solid var(--color1);
  461. }
  462. .value {
  463. padding: 5px;
  464. line-height: 20px;
  465. }
  466. }
  467. </style>