PatentField.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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) {
  135. this.$message.warning('已是最顶层')
  136. return false
  137. }
  138. if (index == this.customField.length - 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('移动成功')
  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. item.selectedValue.splice(index,1)
  190. this.refresh(item)
  191. }
  192. }).catch(error => {
  193. })
  194. },
  195. //切换选择
  196. onChange(data, item, checked) {
  197. this.gong(data, item, checked)
  198. },
  199. // change与clickItem公用
  200. gong(data, item, checked) {
  201. var params = {
  202. projectId: this.projectId,
  203. taskId: this.taskId,
  204. fieldType: item.type,
  205. fieldId: item.id,
  206. fieldValue: [data.id || data],
  207. patentNo: this.patentNo,
  208. optionType: '',
  209. }
  210. if (item.type == 0 || item.type == 1 || item.type == 2 || item.type == 4) {
  211. if (item.type != 4) {
  212. params.fieldValue[0] = item.selectedValue
  213. } else {
  214. if (item && item.selectedValue) {//单选的id
  215. this.$set(item, 'selectedValue', '')
  216. this.$set(item, 'selected', [])
  217. } else {
  218. this.$set(item, 'selectedValue', data.id)
  219. item.selected.push(
  220. {
  221. value: data.name,
  222. valueId: data.id
  223. }
  224. )
  225. }
  226. }
  227. params.optionType = 2
  228. }
  229. // 判断optionType 0取消1添加2覆盖
  230. if (item.type == 6 || item.type == 5) {
  231. if (checked) {
  232. item.selectedValue.push(data.id)
  233. var name = ''
  234. if (data.pathName == '/') {
  235. name = data.pathName + data.name
  236. } else if (data.pathName) {
  237. name = data.pathName + '/' + data.name
  238. } else {
  239. name = data.name
  240. }
  241. item.selected.push(
  242. {
  243. value: name,
  244. valueId: data.id
  245. }
  246. )
  247. params.optionType = 1
  248. } else {
  249. let index = item.selectedValue.findIndex(valIndex => {
  250. return valIndex == data.id
  251. })
  252. if (index != -1) {
  253. item.selectedValue.splice(index, 1)
  254. item.selected.splice(index, 1)
  255. }
  256. params.optionType = 0
  257. }
  258. }
  259. this.$api.addCustomFieldValue(params).then(response => {
  260. if (response.code == 200) {
  261. this.$message.success('修改成功')
  262. // this.getSelected(item)
  263. this.refresh(item)
  264. }
  265. }).catch(error => {
  266. })
  267. },
  268. //刷新
  269. refresh(item) {
  270. this.$set(item, 'showField', true)
  271. this.$nextTick(() => {
  272. this.$set(item, 'showField', false)
  273. })
  274. },
  275. // 获取栏位
  276. getCustomField() {
  277. var params = {
  278. projectId: this.projectId,
  279. taskId: this.taskId
  280. }
  281. this.$api.getAllPatentCustomField(params).then(response => {
  282. if (response.code == 200) {
  283. this.customField = response.data.data
  284. this.getOptionsAndSelected()
  285. }
  286. }).catch(error => {
  287. this.customField = []
  288. })
  289. },
  290. //获取栏位的选项和选项值(0数字,1日期,2文本,4单选,5多选,6树,7产品8产品类别9技术分类)
  291. getOptionsAndSelected() {
  292. this.customField.forEach(item => {
  293. this.getSelected(item)
  294. });
  295. },
  296. //切换是否修改
  297. changeShow(item) {
  298. this.$set(item, 'show', !item.show)
  299. if (item.option && item.option.length > 0) {
  300. return;
  301. }
  302. this.getOption(item)
  303. },
  304. getOption(item) {
  305. switch (item.type) {
  306. case 4:
  307. case 5:
  308. this.getCustomOption(item)
  309. break;
  310. case 6:
  311. this.queryProductCategory(item, 4)
  312. break;
  313. case 7://接口传值类型:1产品类别,2产品,3技术分类,4自定义树
  314. this.queryProductCategory(item, 2)
  315. break;
  316. case 8:
  317. this.queryProductCategory(item, 1)
  318. break;
  319. case 9:
  320. this.queryProductCategory(item, 3)
  321. break;
  322. }
  323. },
  324. //获取已选中选项值、已添加的值
  325. getSelected(item) {
  326. let params = {
  327. projectId: this.projectId,
  328. taskId: this.taskId,
  329. fieldType: item.type,
  330. fieldId: item.id,
  331. patentNo: this.patentNo,
  332. }
  333. this.$api.getCustomFieldValues(params).then(response => {
  334. if (response.code == 200) {
  335. // item.selected = response.data.data
  336. this.$set(item,'selected',response.data.data)
  337. switch (item.type) {
  338. case 0://数字,日期,文字
  339. case 1:
  340. case 2:
  341. this.$set(item, 'selectedValue', (item.selected && item.selected.length > 0) ? item.selected[0].value : '')
  342. break;
  343. case 4://单选
  344. this.$set(item, 'selectedValue', (item.selected && item.selected.length > 0) ? item.selected[0].valueId : '')
  345. break;
  346. case 6://多选和树
  347. case 5:
  348. var a = []
  349. // item.selectedValue = []
  350. a = (item.selected && item.selected.length > 0) ? item.selected.map(item => item.valueId) : []
  351. this.$set(item, 'selectedValue', a)
  352. break;
  353. default:
  354. break;
  355. }
  356. }
  357. }).catch(error => {
  358. item.selected = []
  359. })
  360. },
  361. //查询自定义栏位选项
  362. getCustomOption(item) {
  363. var params = {
  364. customFieldId: item.id
  365. }
  366. this.$api.queryCustomOption(params).then(response => {
  367. if (response.code == 200) {
  368. this.$set(item, 'option', response.data.data)
  369. }
  370. }).catch(error => {
  371. this.$set(item, 'option', [])
  372. })
  373. },
  374. //获取产品或产品类别架构以及技术分类
  375. queryProductCategory(item, type) {
  376. let params = {
  377. projectId: this.projectId,
  378. taskId: this.taskId,
  379. type: type,//类型:1产品类别,2产品,3技术分类,4自定义树
  380. typeId: item.id,//产品或类别id
  381. }
  382. this.$api.queryTreeNodeTree(params).then(res => {
  383. if (res.code == 200) {
  384. this.$set(item, 'option', res.data.data)
  385. }
  386. }).catch(err => {
  387. this.$set(item, 'option', [])
  388. })
  389. },
  390. }
  391. }
  392. </script>
  393. <style lang="scss">
  394. .patent-articles-patent-field {
  395. .custom-field-form {
  396. .name {
  397. display: block;
  398. width: 170px;
  399. overflow: hidden;
  400. text-overflow: ellipsis;
  401. white-space: nowrap;
  402. }
  403. .option {
  404. position: absolute;
  405. right: 0;
  406. top: -50px;
  407. color: #1e9fff;
  408. i {
  409. cursor: pointer;
  410. }
  411. }
  412. .el-form-item {
  413. margin-bottom: 0 !important;
  414. .el-form-item__label {
  415. font-size: 16px;
  416. border-bottom: 1px solid #d2d2d2;
  417. margin-bottom: 10px;
  418. color: #EE6666;
  419. }
  420. }
  421. .custom-input {
  422. margin-bottom: 10px;
  423. .el-input {}
  424. .el-button {
  425. float: right;
  426. margin-top: 5px;
  427. }
  428. }
  429. .custom-checkbox,
  430. .custom-radio {
  431. width: 100%;
  432. margin-right: 0 !important;
  433. line-height: 30px;
  434. }
  435. .el-form-item__label {
  436. width: 100%;
  437. padding: 0 !important;
  438. }
  439. }
  440. }
  441. </style>
  442. <style lang="scss" scoped>
  443. .showValue {
  444. width: 100%;
  445. display: flex;
  446. align-items: center;
  447. &>div {
  448. width: 100%;
  449. min-height: 30px;
  450. border: 1px solid var(--color1);
  451. }
  452. .value {
  453. padding: 5px;
  454. line-height: 20px;
  455. }
  456. }
  457. </style>