VersionDesc.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div class="version-desc">
  3. <el-table v-if="list&&list.length>0"
  4. :data="list"
  5. border
  6. style="width: 100%">
  7. <el-table-column
  8. type="index"
  9. :index="indexMethod"
  10. label="编号"
  11. width="60">
  12. </el-table-column>
  13. <el-table-column
  14. v-if="!isCopy"
  15. prop="gmtCreate"
  16. label="建立时间"
  17. :show-overflow-tooltip="true">
  18. </el-table-column>
  19. <el-table-column
  20. prop="title"
  21. label="标题">
  22. </el-table-column>
  23. <el-table-column
  24. v-if="!isCopy"
  25. prop="modifierid"
  26. label="操作人">
  27. </el-table-column>
  28. <el-table-column v-if="isFirst"
  29. label="操作">
  30. <template slot-scope="scope">
  31. <el-button type="text" size="small" @click="toEditDesc(scope.row,scope.$index)">修改</el-button>
  32. <span style="margin:0 3px;">|</span>
  33. <el-button type="text" size="small" class="delete" @click="showDelDialog(scope.row,scope.row.id)">删除</el-button>
  34. </template>
  35. </el-table-column>
  36. <el-table-column
  37. label="详情">
  38. <template slot-scope="scope">
  39. <el-button type="text" size="small" @click="getDetail(scope.row)">明细</el-button>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <el-button v-if="isFirst" class="disclButn1" size="small" type="primary" @click="addDesc">+ 添加说明</el-button>
  44. <div class="boxMark" v-if="showBox">
  45. <el-form ref="form" :model="form" :rules="showDesc?{}:rules" label-width="65px" class="add-desc-form">
  46. <p class="top">
  47. {{minTitle}}
  48. <span v-if="tip" class="tip">(&lt;br /&gt;代表换行符,如果需要可在需要处输入)</span>
  49. <img src="../../images/close.png" height="12" width="12" @click="cancel">
  50. </p>
  51. <el-form-item label="标题:" prop="title">
  52. <p v-if="showDesc" class="cont">{{form.title}}</p>
  53. <el-input v-else v-model="form.title" placeholder="请输入标题" maxlength="31"></el-input>
  54. </el-form-item>
  55. <el-form-item label="内容:" prop="description" class="discDesc">
  56. <p v-if="showDesc" v-html="form.description" class="cont">{{form.description}}</p>
  57. <el-input v-else type="textarea" :rows="3" placeholder="请输入内容" v-model="form.description" maxlength="501" @keydown.native="contentInp"></el-input>
  58. </el-form-item>
  59. <el-button class="disclButn1" size="small" type="primary" @click="comfirn('form')">确定</el-button>
  60. <!-- <el-button class="disclButn can" size="small" type="primary" @click="cancel">取消</el-button> -->
  61. </el-form>
  62. </div>
  63. </div>
  64. </template>
  65. <script type="text/javascript">
  66. import api from '@api/icss.js';
  67. export default {
  68. name:'VersionDesc',
  69. data(){
  70. const titleVaild = (rule, value, callback) => {
  71. if (!value) {
  72. return callback(new Error('请输入标题'));
  73. }
  74. if (value.length > 30) {
  75. this.form.title = value.substr(0, 30);
  76. this.$message({
  77. showClose: true,
  78. type: 'warning',
  79. message: '标题已超过最大限制30字'
  80. })
  81. }
  82. callback();
  83. };
  84. const descVaild = (rule,value,callback) => {
  85. if(!value){
  86. return callback(new Error('请输入内容'));
  87. }
  88. if (value.length > 500) {
  89. this.form.description = value.substr(0, 500);
  90. this.$message({
  91. showClose: true,
  92. type: 'warning',
  93. message: '内容已超过最大限制500字'
  94. })
  95. }
  96. callback();
  97. }
  98. return{
  99. list:[],//版本说明列表
  100. form:{
  101. title:'',
  102. description:''
  103. },
  104. rules: {
  105. title:[
  106. { required: true, validator: titleVaild, trigger: [ 'change'] },
  107. { required: true, message: '请输入标题', trigger: ['blur', 'change'] }
  108. ],
  109. description:[
  110. { required: true, validator: descVaild, trigger: [ 'change'] },
  111. { required: true, message: '请输入内容', trigger: ['blur', 'change'] }
  112. ]
  113. },
  114. minTitle:'',
  115. showBox:false,
  116. modiId:null,
  117. showDesc:false,
  118. tip:true,
  119. modiIndex:null
  120. }
  121. },
  122. created(){
  123. // if(this.versionId){
  124. // this.getList();
  125. // }
  126. },
  127. mounted(){
  128. this.list = JSON.parse(JSON.stringify(this.detail));
  129. },
  130. props:['detail','versionId','isFirst','isCopy'],
  131. methods:{
  132. // 按回车添加换行<br />
  133. contentInp(e){
  134. if(e.keyCode==13){
  135. this.form.description += '<br />'
  136. }
  137. },
  138. //用于修改时及时更新明细信息,若用本地信息,建立时间和操作人无法及时更新。
  139. getList(){
  140. api.getVersionDetlInfo({id:this.versionId}).then((res)=>{
  141. const result = res.data;
  142. if(result.code==0){
  143. this.list = result.data;
  144. }else{
  145. this.$message({
  146. message:result.msg,
  147. type:'warning'
  148. });
  149. }
  150. })
  151. },
  152. indexMethod(index) {
  153. return index + 1;
  154. },
  155. toEditDesc(item,index){//修改备注
  156. this.minTitle='修改说明';
  157. this.showBox = true;
  158. this.form.title = item.title;
  159. this.form.description = item.description;
  160. this.modiId = item.id;
  161. this.modiIndex = index;
  162. },
  163. addDesc(){//添加备注
  164. this.minTitle='添加说明';
  165. this.showBox = true;
  166. },
  167. comfirn(form){//记得清空modiId
  168. /*if(!this.form.title.trim() || !this.form.description.trim()){
  169. this.$message({
  170. message:'请填写相关信息',
  171. type:'warning'
  172. });
  173. return
  174. }*/
  175. this.$refs[form].validate((valid) => {
  176. if (valid) {
  177. // 修改--直接调修改接口;复制--新增
  178. if(this.modiId){//修改
  179. if(!this.isCopy){
  180. const param = {
  181. title:this.form.title,
  182. description:this.form.description,
  183. detailId:this.modiId
  184. }
  185. api.modiVersionInfo(param).then((res)=>{
  186. if(res.data.code==0){
  187. this.$message({
  188. message:"修改成功",
  189. type:'success'
  190. })
  191. this.getList();
  192. /*for(let i in this.list){
  193. if(this.list[i].id==this.modiId){
  194. this.list[i].title=this.form.title;
  195. this.list[i].description=this.form.description;
  196. }
  197. }*/
  198. this.reset();
  199. }else{
  200. this.$message({
  201. message:res.data.msg,
  202. type:'warning'
  203. });
  204. }
  205. })
  206. }else{
  207. for(let i in this.list){
  208. if(this.list[i].id==this.modiId){
  209. this.list[i].title=this.form.title;
  210. this.list[i].description=this.form.description;
  211. }
  212. }
  213. this.$emit('func',this.list);//向父组件传明细
  214. this.reset();
  215. }
  216. }else if(this.showDesc){//明细
  217. this.reset();
  218. }else{//添加
  219. const item = {
  220. description: this.form.description,
  221. title: this.form.title,
  222. }
  223. if(!this.isCopy && this.versionId){
  224. const params = {
  225. versionDetail: [
  226. item
  227. ],
  228. versionInfoId: this.versionId
  229. }
  230. api.addVersionInfo(params).then((res)=>{
  231. if(res.data.code==0){
  232. this.$message({
  233. message:"添加成功",
  234. type:'success'
  235. })
  236. this.getList();
  237. /*this.list.push(item);*/
  238. this.reset();
  239. }else{
  240. this.$message({
  241. message:res.data.msg,
  242. type:'warning'
  243. });
  244. }
  245. })
  246. }else{//仅添加到本地list
  247. if(this.modiIndex !==null){
  248. this.list[this.modiIndex].description = this.form.description;
  249. this.list[this.modiIndex].title = this.form.title;
  250. }else{
  251. this.list.push(item);
  252. }
  253. this.$emit('func',this.list);
  254. this.reset();
  255. }
  256. }
  257. // this.reset();
  258. } else {
  259. return false;
  260. }
  261. });
  262. },
  263. reset(){//关闭弹窗复原数据
  264. this.showBox = false;
  265. this.showDesc = false;
  266. this.form.title = "";
  267. this.form.description = "";
  268. this.modiId = null;
  269. this.minTitle= "";
  270. this.tip = true;
  271. this.modiIndex = null;
  272. },
  273. cancel(){
  274. this.reset();
  275. },
  276. getDetail(item){//明细
  277. this.minTitle='说明明细';
  278. this.tip = false;
  279. this.showDesc = true;
  280. this.showBox = true;
  281. this.form.title = item.title;
  282. this.form.description = item.description;
  283. },
  284. warning(msg,type){
  285. this.$message({
  286. showClose: true,
  287. message:msg,
  288. type:type||'warning'
  289. })
  290. },
  291. showConfirmDialog(msg,resolve){
  292. this.$alert(msg, '提示', {
  293. confirmButtonText: '确定',
  294. type: 'warning'
  295. }).then(() => {
  296. resolve();
  297. }).catch(() => {});
  298. },
  299. showDelDialog(item,id){
  300. this.showConfirmDialog('是否删除该版本说明?',()=>{
  301. if(!this.isCopy){
  302. api.delVersionInfo({id}).then((res)=>{
  303. if(res.data.code=='0'){
  304. this.warning(res.data.msg||'操作成功','success');
  305. this.getList();
  306. /*let newList = JSON.parse(JSON.stringify(this.list));
  307. for(let i in newList){
  308. if(newList[i].id==id){
  309. this.list.splice(i,1);
  310. }
  311. }*/
  312. }else{
  313. this.warning(res.data.msg);
  314. }
  315. }).catch((error)=>{
  316. this.warning(error);
  317. })
  318. }else{
  319. let newList = JSON.parse(JSON.stringify(this.list));
  320. for(let i in newList){
  321. if(id && newList[i].id==id){
  322. this.list.splice(i,1);
  323. }else if(newList[i].title == item.title && newList[i].description == item.description){//新增的没有id
  324. this.list.splice(i,1);
  325. }
  326. }
  327. this.$emit('func',this.list);
  328. }
  329. });
  330. },
  331. },
  332. watch:{
  333. list:function(newVal,oldVal){
  334. return newVal;
  335. }
  336. }
  337. }
  338. </script>
  339. <style lang="less" >
  340. @import "../../less/admin.less";
  341. .disclButn1{
  342. margin: 30px 0 10px;
  343. }
  344. .boxMark{
  345. position: fixed;
  346. top: 0;
  347. bottom: 0;
  348. left: 0;
  349. right: 0;
  350. text-align: center;
  351. // background: #808080;
  352. background-color:rgba(0,0,0,0.3);
  353. z-index: 1001;
  354. }
  355. // .el-form{
  356. .add-desc-form{
  357. width: 680px;
  358. position: absolute;
  359. top: 15%;
  360. left: 50%;
  361. // margin-top: -143px;
  362. margin-left: -340px;
  363. background: #fff;
  364. padding: 20px;
  365. max-height: 660px;
  366. overflow-y: auto;
  367. }
  368. .top{
  369. font-size: 15px;
  370. font-weight: bold;
  371. color: #545455;
  372. text-align: left;
  373. // padding-bottom: 10px;
  374. margin-bottom: 15px;
  375. // border-bottom: 1px solid #C9C9C9;
  376. position: relative;
  377. img{
  378. position: absolute;
  379. right: 5px;
  380. }
  381. }
  382. .can,.can:hover{
  383. background: #9B9B9B;
  384. border-color: #9B9B9B;
  385. }
  386. .cont{
  387. text-align: left;
  388. }
  389. .version-desc .el-table__body-wrapper{
  390. max-height: 340px;
  391. overflow-y: auto;
  392. }
  393. .version-desc .el-table th{
  394. padding: 0px;
  395. }
  396. .tip{
  397. font-weight: normal;
  398. font-size: 13px;
  399. color:#22ccc8;
  400. }
  401. </style>