add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <view >
  3. <view class="bgtop"></view>
  4. <uni-forms :modelValue="datainfo">
  5. <view class="addbox">
  6. <view class="boxs pdbox" style="padding-bottom: 2rpx;">
  7. <view class="titbox mb14">
  8. <view class="tit flexc">
  9. <image :src="titimg"></image>
  10. <view>基本详情</view>
  11. </view>
  12. </view>
  13. <uni-forms-item label="题目" name="noticeTitle" required>
  14. <uni-easyinput :inputBorder="false" type="text" v-model="datainfo.noticeTitle" placeholder="请输入标题" />
  15. </uni-forms-item>
  16. <picker range-key='label' :value="tzlbidx" :range="tzlbList" @change='bindDateChangea'>
  17. <uni-forms-item label="通知类别" name="noticeType" required>
  18. <view class="lbtabp">
  19. <view v-if="datainfo.noticeType&&!tzlblabe">{{statusFormat(datainfo.noticeType)}}</view>
  20. <view v-else :class="tzlblabe?'':'coa'">{{tzlblabe||"请选择通知类别"}}</view>
  21. </view>
  22. </uni-forms-item>
  23. </picker>
  24. <uni-forms-item label="发布人" name="issuer" required>
  25. <uni-easyinput disabled :inputBorder="false" type="text" v-model="datainfo.issuer" placeholder="请输入发布人" />
  26. </uni-forms-item>
  27. <uni-forms-item label="发布单位" name="issuerDept" required>
  28. <uni-easyinput disabled :inputBorder="false" type="text" v-model="datainfo.issuerDept" placeholder="请输入发布单位" />
  29. </uni-forms-item>
  30. </view>
  31. <view class="boxs pdbox">
  32. <view class="titbox mb14 flexc">
  33. <view class="tit flexc flex1">
  34. <image :src="titimg"></image>
  35. <view>通知内容</view>
  36. </view>
  37. <view class="titr" @click="getPaiFn">一键排版</view>
  38. </view>
  39. <editor id="editor" :class="pbFlag?'pbbox':''" class="ql-container" placeholder="请输入通知内容" show-img-size show-img-toolbar
  40. show-img-resize @statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady">
  41. </editor>
  42. <view class="edtip flext mb24 mt14"><text>*</text>通知正文内容输入完毕后,可点击右上角的“一键排版”按钮进行快 速排版</view>
  43. </view>
  44. <view class="boxs pdbox">
  45. <view class="titbox mb14">
  46. <view class="tit flexc">
  47. <image :src="titimg"></image>
  48. <view>附件内容</view>
  49. </view>
  50. </view>
  51. <view class="flexcj mb10">
  52. <view class="fw f15 co34">添加附件</view>
  53. <view class="fjadd"><lsj-upload
  54. ref="lsjUpload"
  55. childId="upload1"
  56. :width="width"
  57. :height="height"
  58. :option="option"
  59. :size="size"
  60. :formats="formats"
  61. :debug="debug"
  62. :instantly="instantly"
  63. @progress=""
  64. @uploadEnd="onuploadEnd" >
  65. <view class="btn" :style="{width: width,height: height}">上传附件</view>
  66. </lsj-upload>
  67. </view>
  68. </view>
  69. <view class="ptb12" v-if="filelist&&filelist.length">
  70. <view class="fjlists" v-for="(ite,idx) in filelist" :key='idx'>
  71. <view class="flext" @click="getDown(ite.path)">
  72. <view class="imgl"><image :src="fjimg" ></image></view>
  73. <view class="tit">{{ite.name}}</view>
  74. </view>
  75. <!-- 删除 -->
  76. <view class="delimg flex0" @click.stop="getDelFj(idx)">
  77. <image :src="delimg"></image>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. <view class="addbtn">
  83. <view class="btn btn1" @click="getZanFnt">暂存</view>
  84. <view class="btn btn2" @click="getSubmit">提交</view>
  85. </view>
  86. </view>
  87. </uni-forms>
  88. </view>
  89. </template>
  90. <script>
  91. import {getDictionaryFn} from "@/api/mine/register.js"
  92. import {getNoticeAdd,getNoticeDetail} from "@/api/mine/news.js"
  93. import { selectValueKey } from '@/utils/common.js';
  94. import config from '@/config'
  95. const baseUrl = config.baseUrl
  96. import { getToken } from '@/utils/auth'
  97. export default{
  98. data(){
  99. return{
  100. //附件
  101. option: {
  102. // 上传服务器地址,需要替换为你的接口地址
  103. url: baseUrl+'/common/upload', // 该地址非真实路径,需替换为你项目自己的接口地址
  104. // 上传附件的key
  105. name: 'file',
  106. // 根据你接口需求自定义请求头,默认不要写content-type,让浏览器自适配
  107. header: {
  108. // 示例参数可删除
  109. 'Authorization': 'Bearer ' + getToken(),
  110. },
  111. // 根据你接口需求自定义body参数
  112. formData: {}
  113. },
  114. // 选择文件后是否立即自动上传,true=选择后立即上传
  115. instantly: true,
  116. // 必传宽高且宽高应与slot宽高保持一致
  117. width: '',
  118. height: '48rpx',
  119. // 限制允许上传的格式,空串=不限制,默认为空
  120. formats: 'doc,docx,xls,xlsx,ppt,txt,pdf,zip,rar,word',
  121. // 文件上传大小限制
  122. size: 100,
  123. // 文件数量限制 默认10
  124. count: 5,
  125. // 文件回显列表
  126. files: new Map(),
  127. // 微信小程序Map对象for循环不显示,所以转成普通数组,不要问为什么,我也不知道
  128. wxFiles: [],
  129. // 是否打印日志
  130. debug: false,
  131. filelist:[],
  132. pbFlag:false,
  133. readOnly:false,
  134. editorCtx:'',
  135. fjimg:require("@/work/static/images/fjimg.png"),
  136. delimg:require("@/work/static/images/delimg.png"),
  137. titimg:require("@/work/static/images/titbg.png"),
  138. datainfo:{
  139. noticeTitle:'',
  140. issuer:this.$store.state.user.name,
  141. issuerDept:this.$store.state.user.deptName,
  142. },
  143. tzlbList:[],
  144. tzlblabe:'',
  145. tzlbidx:'',
  146. id:'',
  147. editinfo:''
  148. }
  149. },
  150. onLoad(e) {
  151. this.init()
  152. if(e.id){
  153. this.id=e.id;
  154. this.getNoticeDetail()
  155. }
  156. if(e.type=='old'&&uni.getStorageSync('zcList')){
  157. var newObj=JSON.parse(JSON.stringify(uni.getStorageSync('zcList')))
  158. this.datainfo=newObj;
  159. this.editinfo=newObj.noticeContent;
  160. if(newObj.zxFjList&&newObj.zxFjList.length){
  161. this.filelist=JSON.parse(JSON.stringify(newObj.zxFjList))
  162. }
  163. }
  164. },
  165. methods:{
  166. statusFormat(ite) {
  167. var aite=selectValueKey(this.tzlbList, ite);
  168. this.tzlbidx=aite.key;
  169. return aite.actions;
  170. },
  171. init(){
  172. getDictionaryFn('sys_notice_type').then(res=>{
  173. if(res.code==200&&res.data.length){
  174. this.tzlbList = res.data.map(v => {
  175. return {
  176. label: v.dictLabel,
  177. value: v.dictValue
  178. }
  179. })
  180. }
  181. })
  182. },
  183. bindDateChangea(e){
  184. var val=e.detail.value;
  185. this.tzlblabe=this.tzlbList[val].label;
  186. this.datainfo.noticeType=this.tzlbList[val].value;
  187. },
  188. getPaiFn(){
  189. this.pbFlag=true;
  190. },
  191. getNoticeDetail(){
  192. getNoticeDetail(this.id).then(res=>{
  193. if(res.code==200){
  194. this.datainfo=res.data;
  195. this.editinfo=res.data.noticeContent;
  196. if(res.data.zxFjList&&res.data.zxFjList.length){
  197. this.filelist=JSON.parse(JSON.stringify(res.data.zxFjList))
  198. }
  199. }
  200. })
  201. },
  202. // 暂存
  203. getZanFnt(){
  204. var that=this;
  205. that.editorCtx.getContents({
  206. success: function(data) {
  207. // noticeContent=data.html;
  208. // that.datainfo.zxFjList=JSON.parse(JSON.stringify(that.filelist));
  209. var params=that.datainfo;
  210. params.noticeContent=data.html;
  211. uni.setStorageSync('zcList', JSON.parse(JSON.stringify(params)))
  212. that.$toast("暂存成功")
  213. }
  214. })
  215. },
  216. getSubmit(){
  217. var that=this;
  218. if(!this.datainfo.noticeTitle){
  219. this.$toast("请输入标题")
  220. return
  221. }
  222. if(!this.tzlblabe){
  223. this.$toast("请选择通知类别")
  224. return
  225. }
  226. var noticeContent='';
  227. that.editorCtx.getContents({
  228. success: function(data) {
  229. var params=that.datainfo;
  230. params.noticeContent=data.html;
  231. console.log(params)
  232. getNoticeAdd(params).then(res=>{
  233. if(res.code==200){
  234. that.$toast("发布成功")
  235. }
  236. })
  237. }
  238. })
  239. },
  240. onuploadEnd(item) {
  241. var newobj={}
  242. var responseText=JSON.parse(item.responseText)
  243. newobj.name=responseText.originalFilename;
  244. newobj.path=responseText.fileName;
  245. this.filelist.push(newobj)
  246. this.datainfo.zxFjList=JSON.parse(JSON.stringify(this.filelist))
  247. },
  248. getDelFj(idx){
  249. var that=this;
  250. uni.showModal({
  251. title: '确认删除',
  252. content: "是否确认删除",
  253. cancelText: '取消',
  254. confirmText: '确认',
  255. success: function(res) {
  256. if (res.confirm) {
  257. that.filelist.splice(idx,1)
  258. that.datainfo.zxFjList=JSON.parse(JSON.stringify(that.filelist))
  259. } else if (res.cancel) {
  260. }
  261. }
  262. });
  263. },
  264. getDown(e){
  265. uni.showLoading({
  266. title: '加载中'
  267. });
  268. var url=baseUrl+e;
  269. uni.downloadFile({
  270. url: url,//文件的下载路径
  271. success(result) {
  272. uni.hideLoading()
  273. var filePath = result.tempFilePath;
  274. uni.openDocument({
  275. filePath: filePath,
  276. showMenu: true,
  277. success: function (res) {
  278. // console.log('打开文档成功');
  279. }
  280. });
  281. },
  282. fail(res) {uni.hideLoading()}
  283. })
  284. },
  285. onStatusChange(e){
  286. console.log(e,2)
  287. },
  288. onEditorReady(e){
  289. var that=this;
  290. uni.createSelectorQuery().select('#editor').context(function(res) {
  291. that.editorCtx = res.context;
  292. that.editorCtx.setContents({
  293. html:that.editinfo
  294. })
  295. }).exec();
  296. }
  297. }
  298. }
  299. </script>
  300. <style scoped lang="scss">
  301. .bgtop{height: 150rpx;background-color: $com-cd3;width: 100%;}
  302. .pdbox{padding: 34rpx 24rpx 16rpx;}
  303. .addbox /deep/ .uni-forms-item{margin-bottom:36rpx;}
  304. .addbox /deep/ .uni-easyinput{flex: 1;text-align: right;font-size: 30rpx;}
  305. .addbox /deep/ .uni-forms-item__label{font-weight: bold;font-size: 30rpx;color: #343434;width: 198rpx !important;padding-left:20rpx;}
  306. .addbox /deep/ .is-required{position: absolute;left: 0;top: 50%;margin-top: -10rpx;}
  307. .addbox /deep/ .uni-data-checklist{display: flex;align-items: center;justify-content: flex-end;}
  308. .addbox /deep/ .uni-easyinput__placeholder-class{font-weight: 500;font-size: 30rpx;color: #AAAAAA;}
  309. .addbox /deep/ .checklist-box{margin-right: 0 !important;margin-left: 40rpx !important;}
  310. .fjadd{
  311. .btn{font-weight: bold;font-size: 30rpx;color: #1D64E2;margin: 0;display: flex;align-items: center;}
  312. }
  313. .addbox{margin-top: -120rpx;
  314. padding: 0 24rpx 50rpx;
  315. .boxs{background: #FFFFFF;border-radius: 30rpx;margin-bottom: 24rpx;overflow: hidden;position: relative;
  316. .titbox{
  317. .tit{
  318. image{width: 32rpx;height: 18rpx;margin-right: 10rpx;}
  319. view{font-weight: bold;font-size: 32rpx;color: #222327;}
  320. }
  321. .titr{width: 146rpx;height: 50rpx;background: #E4EEFF;border-radius: 26rpx;font-weight: 500;font-size: 24rpx;color: #1D64E2;text-align: center;line-height: 50rpx;}
  322. }
  323. .openbox{display: flex;align-items: center;justify-content: flex-end;font-weight: 500;
  324. font-size: 30rpx;height: 100%;color: #AAAAAA;}
  325. .edtip{font-weight: 500;font-size: 22rpx;color: #FF0000;
  326. text{margin: 4rpx 8rpx 0 0;}
  327. &.pa{position: absolute;right: 0;bottom: -15px;text-align: right;width: 702rpx;}
  328. }
  329. }
  330. }
  331. // 附件
  332. .fjlists {display: flex;align-items: flex-start;justify-content: space-between;margin-bottom: 12rpx;
  333. image{margin-right: 18rpx;flex: 0 0 auto;}
  334. .imgl{width: 40rpx;height: 40rpx;display: flex;align-items: center;justify-content: center;margin-right: 16rpx;
  335. image{width: 26rpx;height: 24rpx;}
  336. }
  337. .tit{font-size: 26rpx;color: #343434;font-weight: 500;margin-top: 4rpx;}
  338. .delimg{width: 40rpx;height:40rpx;margin-left: 16rpx;display: flex;align-items: center;justify-content: center;
  339. image{width: 26rpx;height: 26rpx;}
  340. }
  341. }
  342. // 按钮
  343. .addbtn{display: flex;align-items: center;justify-content: space-between;padding-top: 26rpx;
  344. .btn{width: 336rpx;height: 80rpx;font-weight: bold;font-size: 30rpx;box-sizing: border-box;border-radius: 40rpx;display: flex;align-items: center;justify-content: center;
  345. &.btn1{border: 2rpx solid #1D64E2;background: #ffffff;color: #1D64E2;}
  346. &.btn2{background: #1D64E2;color: #ffffff;}
  347. }
  348. }
  349. .lbtabp{display: flex;align-items: center;flex: 0 0 auto;margin-left: 24rpx;height: 100%;justify-content: flex-end;
  350. view{font-size: 30rpx;color: #222327;}
  351. }
  352. .addbox /deep/ .pbbox .ql-editor p{text-indent: 2rem;}
  353. </style>