editnotice.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <!-- editniotice -->
  2. <template>
  3. <view class="editniotice">
  4. <!-- <Header :title="title" /> -->
  5. <!-- <view style="height: 94upx;"></view> -->
  6. <view class="content">
  7. <view class="content-warp">
  8. <view class="uni-list-cell">
  9. <view class="name">选择店铺:</view>
  10. <view class="uni-list-cell-db">
  11. <picker
  12. @change="bindPickerChange"
  13. :value="storeIndex"
  14. :range="storeList"
  15. :disabled="storeDisabled"
  16. range-key="name"
  17. class="uni-upd"
  18. >
  19. <view class="uni-input">{{ storeList[storeIndex].name }}</view>
  20. </picker>
  21. <view class="icon-warp">
  22. <image
  23. src="../../../static/images/moreicon.png"
  24. class="iconRight"
  25. ></image>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="inputnamt">
  30. <view class="title">新闻标题:</view>
  31. <input
  32. class="txt"
  33. v-model="noticeMessage.title"
  34. type="text"
  35. placeholder="请输入新闻标题"
  36. placeholder-style="color:#8f8f8f;"
  37. />
  38. </view>
  39. <view class="icon-warp">
  40. <view class="title">上传图标:</view>
  41. <image
  42. class="icon"
  43. :src="noticeMessage.icon"
  44. v-if="noticeMessage.icon"
  45. ></image>
  46. <view class="upload" @tap="upload">
  47. <text class="load">点击上传</text>
  48. <text class="per">{{progress}}%</text>
  49. </view>
  50. </view>
  51. <view class="noticeContent">
  52. <view class="container">
  53. <editor
  54. id="editor"
  55. class="ql-container"
  56. :placeholder="placeholder"
  57. @input="saveTxt"
  58. @ready="onEditorReady"
  59. ></editor>
  60. </view>
  61. </view>
  62. <view class="btn-warp">
  63. <view class="btn" @tap="saveNotice">提交发布</view>
  64. </view>
  65. </view>
  66. </view>
  67. <rf-loading v-if="loading"></rf-loading>
  68. </view>
  69. </template>
  70. <script>
  71. let myCloud;
  72. import Header from '../../components/header';
  73. import moment from '@/common/moment';
  74. import indexConfig from '@/config/index.config';
  75. export default {
  76. name: 'editniotice',
  77. components: {
  78. Header,
  79. },
  80. data() {
  81. //这里存放数据
  82. return {
  83. loading: true,
  84. scenicId: '',
  85. title: '公告编辑',
  86. storeList: [{ name: '请选择公告所属店铺', id: '' }],
  87. storeIndex: 0,
  88. storeId: '',
  89. storeDisabled: true,
  90. newid: '',
  91. placeholder: '请输入公告内容',
  92. mastknow: '',
  93. iconUrl: '',
  94. progress: 0,
  95. noticeMessage: {
  96. content: '',
  97. icon: '',
  98. title: '',
  99. sid: '',
  100. id: '',
  101. type: '2'
  102. },
  103. };
  104. },
  105. onReady () {
  106. myCloud = uniCloud.init({
  107. provider: 'aliyun',
  108. spaceId: 'db8671a1-69bd-470d-ad59-ba927c88f4a4',
  109. clientSecret: '8nOzV70edtpCd0El6qce3g==',
  110. });
  111. },
  112. onLoad(option) {
  113. this.newid = option.id;
  114. this.getShopMessage();
  115. if (this.newid === 'add') {
  116. this.title = '添加公告';
  117. this.loading = false;
  118. } else {
  119. this.getNoticeBuyId();
  120. }
  121. },
  122. //方法集合
  123. methods: {
  124. // 选择店铺
  125. bindPickerChange(e) {
  126. this.storeIndex = e.detail.value;
  127. this.storeId = this.storeList[this.storeIndex].id;
  128. this.noticeMessage.sid = this.storeId
  129. },
  130. // 商家信息
  131. async getShopMessage() {
  132. await this.$http.get('/getUserInfo').then(async (res) => {
  133. if (res.data) {
  134. this.scenicId = res.data.id;
  135. this.getShopList();
  136. }
  137. });
  138. },
  139. async getShopList() {
  140. this.storeList = [{ name: '请选择公告所属店铺', id: '' }];
  141. await this.$http
  142. .get('/shop/getList', {
  143. mid: this.scenicId,
  144. })
  145. .then(async (res) => {
  146. if (res.data) {
  147. let arr = [];
  148. res.data.forEach((element) => {
  149. arr.push({ name: element.name, id: element.id });
  150. });
  151. this.storeList = this.storeList.concat(arr);
  152. this.storeDisabled = false;
  153. if (this.noticeMessage) {
  154. // 店铺回显
  155. this.storeId = this.noticeMessage.sid;
  156. this.storeList.forEach((item, index) => {
  157. if (this.storeId === item.id) {
  158. this.storeIndex = index;
  159. }
  160. });
  161. }
  162. }
  163. });
  164. },
  165. // 获取单个公告的信息
  166. async getNoticeBuyId() {
  167. this.loading = true;
  168. await this.$http.get('/news/getById/' + this.newid).then(async (res) => {
  169. if (res.code === 200) {
  170. this.noticeMessage = res.data;
  171. this.loading = false;
  172. }
  173. });
  174. },
  175. // 富文本
  176. onEditorReady() {
  177. uni
  178. .createSelectorQuery()
  179. .select('#editor')
  180. .context((res) => {
  181. console.log(this.noticeMessage.content);
  182. this.editorCtx = res.context;
  183. this.editorCtx.setContents({ html: this.noticeMessage.content});
  184. })
  185. .exec()
  186. },
  187. saveTxt(e) {
  188. this.noticeMessage.content = e.detail.html;
  189. },
  190. // 保存编辑
  191. saveNotice() {
  192. console.log(this.noticeMessage);
  193. this.$http.post('/news/add', this.noticeMessage).then((res) => {
  194. if (res.code === 200 && res.msg === 'OK') {
  195. this.$mHelper.toast('提交成功!');
  196. setTimeout(() => {
  197. this.$mRouter.back();
  198. }, 800);
  199. }
  200. });
  201. },
  202. // --------------------------
  203. // 图标上传
  204. upload() {
  205. this.noticeMessage.icon = ''
  206. let _self = this;
  207. uni.chooseImage({
  208. count: 1,
  209. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  210. sourceType: ['album'], // camera 使用相机 album 从相册中选
  211. success: function (res) {
  212. // 成功则返回图片的本地文件路径列表 tempFilePaths
  213. _self.iconUrl = res.tempFilePaths[0];
  214. myCloud.uploadFile({
  215. url: indexConfig.uploadUrl,
  216. filePath: _self.iconUrl,
  217. cloudPath: _self.iconUrl,
  218. name: 'file',
  219. success:(res)=>{
  220. if (res.fileID) {
  221. _self.noticeMessage.icon = res.fileID
  222. }
  223. },
  224. onUploadProgress: function (progressEvent){
  225. _self.progress = 1
  226. _self.progress = Math.round((progressEvent.loaded * 100) / progressEvent.total);
  227. }
  228. });
  229. },
  230. fail: function (error) {
  231. console.log(error);
  232. }
  233. });
  234. },
  235. },
  236. };
  237. </script>
  238. <style lang="scss" scoped>
  239. .editniotice {
  240. .content {
  241. padding: 25upx 0;
  242. height: 100vh;
  243. }
  244. .content-warp {
  245. padding: 0 33upx 100upx;
  246. background-color: #fff;
  247. box-sizing: border-box;
  248. height: 100%;
  249. }
  250. .uni-list-cell {
  251. border-bottom: 2px solid #f4f4f4;
  252. .name {
  253. color: #2f2f2f;
  254. font-size: 28upx;
  255. }
  256. .uni-list-cell-db {
  257. height: 80upx;
  258. font-size: 28upx;
  259. display: flex;
  260. justify-content: space-between;
  261. align-items: center;
  262. background-color: #fff;
  263. color: #8f8f8f;
  264. font-size: 30upx;
  265. .uni-upd {
  266. width: 100%;
  267. }
  268. }
  269. .uni-input {
  270. height: 100%;
  271. line-height: 80upx;
  272. }
  273. .icon-warp {
  274. width: 19upx;
  275. .iconRight {
  276. width: 19upx;
  277. height: 27upx;
  278. }
  279. }
  280. }
  281. .inputnamt {
  282. height: 80upx;
  283. display: flex;
  284. align-items: center;
  285. border-bottom: 2px solid #f4f4f4;
  286. .title {
  287. color: #2f2f2f;
  288. }
  289. .txt {
  290. flex: 1;
  291. }
  292. }
  293. .icon-warp {
  294. display: flex;
  295. justify-content: space-between;
  296. align-items: center;
  297. padding: 20upx 0;
  298. border-bottom: 2px solid #f4f4f4;
  299. .title {
  300. color: #2f2f2f;
  301. }
  302. .icon {
  303. width: 185upx;
  304. height: 185upx;
  305. border-radius: 20upx;
  306. }
  307. .upload {
  308. width: 185upx;
  309. height: 185upx;
  310. border: 2px dashed #ccc;
  311. display: flex;
  312. justify-content: center;
  313. align-items: center;
  314. flex-direction: column;
  315. .load {
  316. margin-top: 25upx;
  317. }
  318. .per {
  319. margin-top: 10upx;
  320. }
  321. }
  322. }
  323. .noticeContent {
  324. padding: 40upx;
  325. border: 2px solid #f4f4f4;
  326. margin-top: 20upx;
  327. }
  328. .btn-warp {
  329. margin-top: 80upx;
  330. display: flex;
  331. justify-content: center;
  332. .btn {
  333. width: 600upx;
  334. height: 90upx;
  335. border-radius: 20upx;
  336. text-align: center;
  337. line-height: 90upx;
  338. color: #fff;
  339. font-size: 30upx;
  340. font-weight: 700;
  341. letter-spacing: 2upx;
  342. background-color: #9e5dfc;
  343. }
  344. }
  345. }
  346. </style>