VersionDesc.vue 12 KB

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