add.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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.url)">
  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,getNoticeEdit } 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,png,jpg,jpeg',
  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. ptype:"add"
  149. }
  150. },
  151. onLoad(e) {
  152. this.init()
  153. if(e.id){
  154. this.id=e.id;
  155. this.getNoticeDetail()
  156. }
  157. if(e.type){
  158. this.ptype=e.type;
  159. }
  160. if(e.type=='old'&&uni.getStorageSync('zcList')){
  161. var newObj=JSON.parse(JSON.stringify(uni.getStorageSync('zcList')))
  162. this.datainfo=newObj;
  163. this.editinfo=newObj.noticeContent;
  164. if(newObj.zxFjList&&newObj.zxFjList.length){
  165. this.filelist=JSON.parse(JSON.stringify(newObj.zxFjList))
  166. }
  167. }
  168. },
  169. methods:{
  170. statusFormat(ite) {
  171. var aite=selectValueKey(this.tzlbList, ite);
  172. this.tzlbidx=aite.key;
  173. this.tzlblabe=aite.actions;
  174. return aite.actions;
  175. },
  176. init(){
  177. getDictionaryFn('sys_notice_type').then(res=>{
  178. if(res.code==200&&res.data.length){
  179. this.tzlbList = res.data.map(v => {
  180. return {
  181. label: v.dictLabel,
  182. value: v.dictValue
  183. }
  184. })
  185. }
  186. })
  187. },
  188. bindDateChangea(e){
  189. var val=e.detail.value;
  190. this.tzlblabe=this.tzlbList[val].label;
  191. this.datainfo.noticeType=this.tzlbList[val].value;
  192. },
  193. getPaiFn(){
  194. this.pbFlag=true;
  195. },
  196. getNoticeDetail(){
  197. var that=this;
  198. getNoticeDetail(this.id).then(res=>{
  199. if(res.code==200){
  200. this.datainfo=res.data;
  201. this.editinfo=res.data.noticeContent;
  202. uni.createSelectorQuery().select('#editor').context(function(res) {
  203. that.editorCtx = res.context;
  204. that.editorCtx.setContents({
  205. html:that.editinfo
  206. })
  207. }).exec();
  208. if(res.data.zxFjList&&res.data.zxFjList.length){
  209. this.filelist=JSON.parse(JSON.stringify(res.data.zxFjList))
  210. }
  211. }
  212. })
  213. },
  214. // 暂存
  215. getZanFnt(){
  216. var that=this;
  217. that.editorCtx.getContents({
  218. success: function(data) {
  219. // noticeContent=data.html;
  220. // that.datainfo.zxFjList=JSON.parse(JSON.stringify(that.filelist));
  221. var params=that.datainfo;
  222. params.noticeContent=data.html;
  223. uni.setStorageSync('zcList', JSON.parse(JSON.stringify(params)))
  224. that.$toast("暂存成功")
  225. }
  226. })
  227. },
  228. getSubmit(){
  229. var that=this;
  230. if(!this.datainfo.noticeTitle){
  231. this.$toast("请输入标题")
  232. return
  233. }
  234. if(!this.tzlblabe){
  235. this.$toast("请选择通知类别")
  236. return
  237. }
  238. var noticeContent='';
  239. that.editorCtx.getContents({
  240. success: function(data) {
  241. var params=that.datainfo;
  242. params.noticeContent=data.html;
  243. if(that.ptype=='edit'){
  244. getNoticeEdit(params).then(res=>{
  245. if(res.code==200){
  246. that.$toast("修改成功")
  247. setTimeout(function(){
  248. uni.$emit('refreshxxlist')
  249. uni.$emit('refreshdetail')
  250. uni.navigateBack({
  251. delta:1
  252. })
  253. },1200)
  254. }
  255. })
  256. }else{
  257. getNoticeAdd(params).then(res=>{
  258. if(res.code==200){
  259. that.$toast("发布成功")
  260. uni.removeStorageSync('zcList')
  261. setTimeout(function(){
  262. uni.$emit('refreshxxlist')
  263. uni.navigateBack({
  264. delta:1
  265. })
  266. },1200)
  267. }
  268. })
  269. }
  270. }
  271. })
  272. },
  273. onuploadEnd(item) {
  274. var newobj={}
  275. var responseText=JSON.parse(item.responseText)
  276. newobj.name=responseText.originalFilename;
  277. newobj.url=responseText.fileName;
  278. this.filelist.push(newobj)
  279. this.datainfo.zxFjList=JSON.parse(JSON.stringify(this.filelist))
  280. },
  281. getDelFj(idx){
  282. var that=this;
  283. uni.showModal({
  284. title: '确认删除',
  285. content: "是否确认删除",
  286. cancelText: '取消',
  287. confirmText: '确认',
  288. success: function(res) {
  289. if (res.confirm) {
  290. that.filelist.splice(idx,1)
  291. that.datainfo.zxFjList=JSON.parse(JSON.stringify(that.filelist))
  292. } else if (res.cancel) {
  293. }
  294. }
  295. });
  296. },
  297. getDown(e){
  298. uni.showLoading({
  299. title: '加载中'
  300. });
  301. var url=baseUrl+e;
  302. uni.downloadFile({
  303. url: url,//文件的下载路径
  304. success(result) {
  305. uni.hideLoading()
  306. var filePath = result.tempFilePath;
  307. uni.openDocument({
  308. filePath: filePath,
  309. showMenu: true,
  310. success: function (res) {
  311. // console.log('打开文档成功');
  312. }
  313. });
  314. },
  315. fail(res) {uni.hideLoading()}
  316. })
  317. },
  318. onStatusChange(e){
  319. console.log(e,2)
  320. },
  321. onEditorReady(e){
  322. var that=this;
  323. uni.createSelectorQuery().select('#editor').context(function(res) {
  324. that.editorCtx = res.context;
  325. that.editorCtx.setContents({
  326. html:that.editinfo
  327. })
  328. }).exec();
  329. }
  330. }
  331. }
  332. </script>
  333. <style scoped lang="scss">
  334. .bgtop{height: 150rpx;background-color: $com-cd3;width: 100%;}
  335. .pdbox{padding: 34rpx 24rpx 16rpx;}
  336. .addbox /deep/ .uni-forms-item{margin-bottom:36rpx;}
  337. .addbox /deep/ .uni-easyinput{flex: 1;text-align: right;font-size: 30rpx;}
  338. .addbox /deep/ .uni-forms-item__label{font-weight: bold;font-size: 30rpx;color: #343434;width: 198rpx !important;padding-left:20rpx;}
  339. .addbox /deep/ .is-required{position: absolute;left: 0;top: 50%;margin-top: -10rpx;}
  340. .addbox /deep/ .uni-data-checklist{display: flex;align-items: center;justify-content: flex-end;}
  341. .addbox /deep/ .uni-easyinput__placeholder-class{font-weight: 500;font-size: 30rpx;color: #AAAAAA;}
  342. .addbox /deep/ .checklist-box{margin-right: 0 !important;margin-left: 40rpx !important;}
  343. .fjadd{
  344. .btn{font-weight: bold;font-size: 30rpx;color: #1D64E2;margin: 0;display: flex;align-items: center;}
  345. }
  346. .addbox{margin-top: -120rpx;
  347. padding: 0 24rpx 50rpx;
  348. .boxs{background: #FFFFFF;border-radius: 30rpx;margin-bottom: 24rpx;overflow: hidden;position: relative;
  349. .titbox{
  350. .tit{
  351. image{width: 32rpx;height: 18rpx;margin-right: 10rpx;}
  352. view{font-weight: bold;font-size: 32rpx;color: #222327;}
  353. }
  354. .titr{width: 146rpx;height: 50rpx;background: #E4EEFF;border-radius: 26rpx;font-weight: 500;font-size: 24rpx;color: #1D64E2;text-align: center;line-height: 50rpx;}
  355. }
  356. .openbox{display: flex;align-items: center;justify-content: flex-end;font-weight: 500;
  357. font-size: 30rpx;height: 100%;color: #AAAAAA;}
  358. .edtip{font-weight: 500;font-size: 22rpx;color: #FF0000;
  359. text{margin: 4rpx 8rpx 0 0;}
  360. &.pa{position: absolute;right: 0;bottom: -15px;text-align: right;width: 702rpx;}
  361. }
  362. }
  363. }
  364. // 附件
  365. .fjlists {display: flex;align-items: flex-start;justify-content: space-between;margin-bottom: 12rpx;
  366. image{margin-right: 18rpx;flex: 0 0 auto;}
  367. .imgl{width: 40rpx;height: 40rpx;display: flex;align-items: center;justify-content: center;margin-right: 16rpx;
  368. image{width: 26rpx;height: 24rpx;}
  369. }
  370. .tit{font-size: 26rpx;color: #343434;font-weight: 500;margin-top: 4rpx;}
  371. .delimg{width: 40rpx;height:40rpx;margin-left: 16rpx;display: flex;align-items: center;justify-content: center;
  372. image{width: 26rpx;height: 26rpx;}
  373. }
  374. }
  375. // 按钮
  376. .addbtn{display: flex;align-items: center;justify-content: space-between;padding-top: 26rpx;
  377. .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;
  378. &.btn1{border: 2rpx solid #1D64E2;background: #ffffff;color: #1D64E2;}
  379. &.btn2{background: #1D64E2;color: #ffffff;}
  380. }
  381. }
  382. .lbtabp{display: flex;align-items: center;flex: 0 0 auto;margin-left: 24rpx;height: 100%;justify-content: flex-end;
  383. view{font-size: 30rpx;color: #222327;}
  384. }
  385. .addbox /deep/ .pbbox .ql-editor p{text-indent: 2rem;}
  386. </style>