addPage.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="addPage">
  3. <div class="title-p">
  4. <p>发布</p>
  5. <p class="reset-button-one" @click="backPage">关闭</p>
  6. <p class="inquire-button-one"@click="submitForm">确定</p>
  7. </div>
  8. <el-form ref="form" class="addPageFormBox" :model="form" :rules="rules" label-width="80px">
  9. <el-form-item label="标题" prop="title" class="form-item">
  10. <el-input v-model="form.title" maxLength="30" placeholder="请输入通知标题" style="width:300px;"/>
  11. </el-form-item>
  12. <el-form-item label="发布单位" prop="company" class="form-item">
  13. <el-input v-model="form.company" maxLength="12" placeholder="请输入发布单位" style="width:300px;"/>
  14. </el-form-item>
  15. <el-form-item label="发布内容" prop="content" class="form-item">
  16. <div class="button-max-box">
  17. <div class="button-big-box">
  18. <p class="name-p" v-if="form.contentName">{{form.contentName}}</p>
  19. <el-upload
  20. class="avatar-uploader button-p"
  21. :action="uploadImgUrl"
  22. :show-file-list="false"
  23. :on-success="(res)=>handleAvatarSuccess(res)"
  24. :headers="headers"
  25. :before-upload="beforeAvatarUpload">
  26. {{form.contentName?'重新上传':'上传文件'}}
  27. </el-upload>
  28. <p class="null-p" v-if="form.contentName"></p>
  29. <p class="del-p" v-if="form.contentName" @click="delItem">删除</p>
  30. </div>
  31. <p class="right-text-p" @click="exportModel">下载范例</p>
  32. </div>
  33. </el-form-item>
  34. </el-form>
  35. </div>
  36. </template>
  37. <script>
  38. import { addNotifyplan,exportModel } from "@/api/laboratory/notifyplan";
  39. import { getToken } from "@/utils/auth";
  40. export default {
  41. name: "addPage",
  42. data() {
  43. return {
  44. uploadImgUrl: this.uploadUrl(), // 上传的图片服务器地址
  45. headers: {
  46. Authorization: "Bearer " + getToken(),
  47. },
  48. // 表单参数
  49. form: {},
  50. // 表单校验
  51. rules: {
  52. title: [
  53. { required: true, message: "请输入通知标题", trigger: "blur" },
  54. { required: true, message: "请输入通知标题", validator: this.spaceJudgment, trigger: "blur" }
  55. ],
  56. company: [
  57. { required: true, message: "请输入发布单位", trigger: "blur" },
  58. { required: true, message: "请输入发布单位", validator: this.spaceJudgment, trigger: "blur" }
  59. ],
  60. content: [
  61. { required: true, message: "请上传文件", trigger: "blur" }
  62. ],
  63. },
  64. }
  65. },
  66. created() {
  67. },
  68. mounted(){
  69. },
  70. methods: {
  71. //下载模板
  72. exportModel(){
  73. this.download('/laboratory/notifyplan/exportModel', {}, `计划范例.xlsx`)
  74. },
  75. //删除上传文件
  76. delItem(){
  77. this.form.content = "";
  78. this.form.contentName = "";
  79. this.$forceUpdate();
  80. },
  81. //后退
  82. backPage(){
  83. this.$parent.pageTypeClick(1);
  84. },
  85. //提交
  86. submitForm(){
  87. this.$refs["form"].validate(valid => {
  88. if (valid) {
  89. this.form.type = 2;
  90. this.form.contentUrl = this.form.content;
  91. addNotifyplan(this.form).then( response => {
  92. this.msgSuccess("新增成功");
  93. this.$parent.pageTypeClick(1);
  94. });
  95. }
  96. });
  97. },
  98. //上传相关
  99. handleAvatarSuccess(res) {
  100. let obj ={
  101. name:this.upDataName,
  102. url:res.data.url,
  103. };
  104. this.form.content = res.data.url;
  105. this.form.contentName = this.upDataName;
  106. this.$forceUpdate()
  107. },
  108. beforeAvatarUpload(file) {
  109. let type = false;
  110. console.log('file',file);
  111. if (file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || file.type == 'application/vnd.ms-excel') {
  112. this.upDataName = file.name;
  113. type = true;
  114. }else{
  115. this.$message.error('只能上传xls或xlsx格式表格');
  116. type = false;
  117. }
  118. return type;
  119. },
  120. }
  121. }
  122. </script>
  123. <style scoped lang="scss">
  124. .addPage{
  125. flex:1;
  126. display: flex !important;
  127. flex-direction: column;
  128. padding:0 20px 20px!important;
  129. *{
  130. margin:0;
  131. }
  132. .title-p{
  133. display: flex;
  134. border-bottom:1px solid #E0E0E0;
  135. margin-bottom:30px;
  136. p:nth-child(1){
  137. flex:1;
  138. line-height:80px;
  139. color:#0045AF;
  140. font-size:18px;
  141. }
  142. p:nth-child(2){
  143. font-size:14px;
  144. margin:20px 20px 0 0;
  145. }
  146. p:nth-child(3){
  147. font-size:14px;
  148. margin:20px 0 0;
  149. }
  150. }
  151. .form-item{
  152. margin-bottom:30px;
  153. }
  154. .button-max-box{
  155. display: flex;
  156. font-size:14px;
  157. line-height:40px;
  158. font-weight:500;
  159. .button-big-box{
  160. display: flex;
  161. border:1px solid #e0e0e0;
  162. width:300px;
  163. border-radius:4px;
  164. .name-p{
  165. width:150px;
  166. margin-left:10px;
  167. color:#486CC2;
  168. display:block;
  169. overflow:hidden;
  170. text-overflow:ellipsis;
  171. white-space:nowrap;
  172. }
  173. .button-p{
  174. color:#486CC2;
  175. }
  176. .null-p{
  177. height:12px;
  178. width:1px;
  179. background: #e0e0e0;
  180. margin:14px 0;
  181. }
  182. .del-p{
  183. width:60px;
  184. text-align: center;
  185. color:#FF3A3A;
  186. cursor: pointer;
  187. }
  188. }
  189. .right-text-p{
  190. margin-left:20px;
  191. cursor: pointer;
  192. color:#486CC2;
  193. }
  194. }
  195. }
  196. </style>