VersionDesc.vue 11 KB

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