VersionDesc.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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,scope.$index)">删除</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" :disabled="confirmDisable" @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. confirmDisable: false
  121. }
  122. },
  123. created(){
  124. // if(this.versionId){
  125. // this.getList();
  126. // }
  127. },
  128. mounted(){
  129. this.list = JSON.parse(JSON.stringify(this.detail));
  130. },
  131. props:['detail','versionId','isFirst','isCopy'],
  132. methods:{
  133. // 按回车添加换行<br />
  134. contentInp(e){
  135. if(e.keyCode==13){
  136. this.form.description += '<br />'
  137. }
  138. },
  139. //用于修改时及时更新明细信息,若用本地信息,建立时间和操作人无法及时更新。
  140. getList(){
  141. api.getVersionDetlInfo({id:this.versionId}).then((res)=>{
  142. const result = res.data;
  143. if(result.code==0){
  144. this.list = result.data;
  145. }else{
  146. this.$message({
  147. message:result.msg,
  148. type:'warning'
  149. });
  150. }
  151. })
  152. },
  153. indexMethod(index) {
  154. return index + 1;
  155. },
  156. toEditDesc(item,index){//修改备注
  157. this.minTitle='修改说明';
  158. this.showBox = true;
  159. this.form.title = item.title;
  160. this.form.description = item.description;
  161. this.modiId = item.id;
  162. this.modiIndex = index;
  163. },
  164. addDesc(){//添加备注
  165. this.minTitle='添加说明';
  166. this.showBox = true;
  167. },
  168. comfirn(form){//记得清空modiId
  169. /*if(!this.form.title.trim() || !this.form.description.trim()){
  170. this.$message({
  171. message:'请填写相关信息',
  172. type:'warning'
  173. });
  174. return
  175. }*/
  176. this.$refs[form].validate((valid) => {
  177. if (valid) {
  178. // 修改--直接调修改接口;复制--新增
  179. this.confirmDisable = true
  180. if(this.modiId){//修改
  181. if(!this.isCopy){
  182. const param = {
  183. title:this.form.title,
  184. description:this.form.description,
  185. detailId:this.modiId
  186. }
  187. api.modiVersionInfo(param).then((res)=>{
  188. this.confirmDisable = false
  189. if(res.data.code==0){
  190. this.$message({
  191. message:"修改成功",
  192. type:'success'
  193. })
  194. this.getList();
  195. /*for(let i in this.list){
  196. if(this.list[i].id==this.modiId){
  197. this.list[i].title=this.form.title;
  198. this.list[i].description=this.form.description;
  199. }
  200. }*/
  201. this.reset();
  202. }else{
  203. this.$message({
  204. message:res.data.msg,
  205. type:'warning'
  206. });
  207. }
  208. })
  209. }else{
  210. for(let i in this.list){
  211. if(this.list[i].id==this.modiId){
  212. this.list[i].title=this.form.title;
  213. this.list[i].description=this.form.description;
  214. }
  215. }
  216. this.$emit('func',this.list);//向父组件传明细
  217. this.reset();
  218. }
  219. }else if(this.showDesc){//明细
  220. this.reset();
  221. }else{//添加
  222. const item = {
  223. description: this.form.description,
  224. title: this.form.title,
  225. }
  226. if(!this.isCopy && this.versionId){
  227. const params = {
  228. versionDetail: [
  229. item
  230. ],
  231. versionInfoId: this.versionId
  232. }
  233. api.addVersionInfo(params).then((res)=>{
  234. this.confirmDisable = false
  235. if(res.data.code==0){
  236. this.$message({
  237. message:"添加成功",
  238. type:'success'
  239. })
  240. this.getList();
  241. /*this.list.push(item);*/
  242. this.reset();
  243. }else{
  244. this.$message({
  245. message:res.data.msg,
  246. type:'warning'
  247. });
  248. }
  249. })
  250. }else{//仅添加到本地list
  251. this.confirmDisable = false
  252. if(this.modiIndex !==null){
  253. this.list[this.modiIndex].description = this.form.description;
  254. this.list[this.modiIndex].title = this.form.title;
  255. }else{
  256. this.list.push(item);
  257. }
  258. this.$emit('func',this.list);
  259. this.reset();
  260. }
  261. }
  262. // this.reset();
  263. } else {
  264. return false;
  265. }
  266. });
  267. },
  268. reset(){//关闭弹窗复原数据
  269. this.showBox = false;
  270. this.showDesc = false;
  271. this.form.title = "";
  272. this.form.description = "";
  273. this.modiId = null;
  274. this.minTitle= "";
  275. this.tip = true;
  276. this.modiIndex = null;
  277. },
  278. cancel(){
  279. this.reset();
  280. },
  281. getDetail(item){//明细
  282. this.minTitle='说明明细';
  283. this.tip = false;
  284. this.showDesc = true;
  285. this.showBox = true;
  286. this.form.title = item.title;
  287. this.form.description = item.description;
  288. },
  289. warning(msg,type){
  290. this.$message({
  291. showClose: true,
  292. message:msg,
  293. type:type||'warning'
  294. })
  295. },
  296. showConfirmDialog(msg,resolve){
  297. this.$alert(msg, '提示', {
  298. confirmButtonText: '确定',
  299. type: 'warning'
  300. }).then(() => {
  301. resolve();
  302. }).catch(() => {});
  303. },
  304. showDelDialog(item,id,index){
  305. console.log('cancel',item,id,index)
  306. this.showConfirmDialog('是否删除该版本说明?',()=>{
  307. if(!this.isCopy&&id){
  308. api.delVersionInfo({id}).then((res)=>{
  309. if(res.data.code=='0'){
  310. this.warning(res.data.msg||'操作成功','success');
  311. this.getList();
  312. /*let newList = JSON.parse(JSON.stringify(this.list));
  313. for(let i in newList){
  314. if(newList[i].id==id){
  315. this.list.splice(i,1);
  316. }
  317. }*/
  318. }else{
  319. this.warning(res.data.msg);
  320. }
  321. }).catch((error)=>{
  322. this.warning(error);
  323. })
  324. }else{
  325. let newList = JSON.parse(JSON.stringify(this.list));
  326. for(let i in newList){
  327. if(id && newList[i].id==id){
  328. this.list.splice(i,1);
  329. }else {//新增的没有id
  330. this.list.splice(index,1);
  331. }
  332. }
  333. this.$emit('func',this.list);
  334. }
  335. });
  336. },
  337. },
  338. watch:{
  339. list:function(newVal,oldVal){
  340. return newVal;
  341. }
  342. }
  343. }
  344. </script>
  345. <style lang="less" >
  346. @import "../../less/admin.less";
  347. .disclButn1{
  348. margin: 30px 0 10px;
  349. }
  350. .boxMark{
  351. position: fixed;
  352. top: 0;
  353. bottom: 0;
  354. left: 0;
  355. right: 0;
  356. text-align: center;
  357. // background: #808080;
  358. background-color:rgba(0,0,0,0.3);
  359. z-index: 1001;
  360. }
  361. // .el-form{
  362. .add-desc-form{
  363. width: 680px;
  364. position: absolute;
  365. top: 15%;
  366. left: 50%;
  367. // margin-top: -143px;
  368. margin-left: -340px;
  369. background: #fff;
  370. padding: 20px;
  371. max-height: 660px;
  372. overflow-y: auto;
  373. }
  374. .top{
  375. font-size: 15px;
  376. font-weight: bold;
  377. color: #545455;
  378. text-align: left;
  379. // padding-bottom: 10px;
  380. margin-bottom: 15px;
  381. // border-bottom: 1px solid #C9C9C9;
  382. position: relative;
  383. img{
  384. position: absolute;
  385. right: 5px;
  386. }
  387. }
  388. .can,.can:hover{
  389. background: #9B9B9B;
  390. border-color: #9B9B9B;
  391. }
  392. .cont{
  393. text-align: left;
  394. }
  395. .version-desc .el-table__body-wrapper{
  396. max-height: 340px;
  397. overflow-y: auto;
  398. }
  399. .version-desc .el-table th{
  400. padding: 0px;
  401. }
  402. .tip{
  403. font-weight: normal;
  404. font-size: 13px;
  405. color:#22ccc8;
  406. }
  407. </style>