writeNote.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <view class="container write-note">
  3. <view class="nav-bar-wrap" :style="{ height: navBarStyle.height, paddingTop: navBarStyle.paddingTop, paddingBottom: navBarStyle.paddingBottom }">
  4. <view class="content-box" :style="{ color: '#333' }">
  5. <text>发布新内容</text>
  6. <view class="arrow-left-icon">
  7. <van-icon name="arrow-left" size="20px" @click="goHandler" />
  8. </view>
  9. </view>
  10. </view>
  11. <view class="write-note-top">
  12. <view @click="topLableHandler(item)" :class="['write-text', topLableActive == item.value && 'act-top-lable']" v-for="item in topLableList" :key="item.value"> {{ item.name }}</view>
  13. </view>
  14. <view class="write-note-content">
  15. <view class="title-note"> <input v-model="articleTitle" placeholder="请输入标题" /></view>
  16. <view class="content-note">
  17. <editor id="editor" v-model="advice_content" placeholder="请输入正文(更轻松的创作,上传文档,请先登录查研观向网页版)" @input="contentChange" />
  18. <view class="new-lable" @click="showPopup = true">
  19. <view style="flex-shrink: 0">+ 标签(至少添加一个)</view>
  20. <view v-for="item in industryCompanyLable" :key="item" class="lable-li active">
  21. {{ item }}
  22. <van-icon name="cross" style="margin-left: 8rpx" />
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="write-note-img">
  28. <robbyImageUpload ref="robbyImageUpload" class="image-add-upload" v-model="fileList" :server-url="uploadUrl" :header="header" :limit="6" />
  29. </view>
  30. <view class="write-note-button">
  31. <view class="draft" @click="draftBtnHandler"> 草稿箱</view>
  32. <view class="release" @click="releaseBtnHandler"> 发布</view>
  33. </view>
  34. <van-popup :show="showPopup" position="bottom" custom-style="height: 85%;" round custom-class="lable-class-popup">
  35. <viwe class="add-lable-box">
  36. <view class="add-txt"> 添加标签 <view @click="addCompleteHandler"> 完成 </view></view>
  37. <view class="select-item">
  38. <view @click="industryOfCompanyHanler(item)" v-for="item in lableList" :key="item.value" :class="['item', lableActive == item.value && 'act-item']"> {{ item.name }}</view>
  39. </view>
  40. <view class="input-box">
  41. <icon type="search" size="15" class="sea_ico" />
  42. <input v-model="columnName" placeholder="专栏名称" @confirm="searchHandle" />
  43. <view v-if="lableActive == 2" style="color: #376cbb" @click="addCompanyLableHandler">+ &nbsp;创建</view>
  44. </view>
  45. <view class="text-box"> 已选标签 <view class="one-lable-text"> 至少添加一个标签 </view></view>
  46. <view class="lable-ul">
  47. <block v-if="lableActive == 1">
  48. <view :class="['lable-li', 'active']" v-for="item in selectedLableList" :key="item">
  49. {{ item }}
  50. <van-icon name="cross" style="margin-left: 8rpx" @click="selectedLableHandle(item)" />
  51. </view>
  52. </block>
  53. <block v-else>
  54. <view :class="['lable-li', 'active']" v-for="item in companySelectedLable" :key="item">
  55. {{ item }}
  56. <van-icon name="cross" style="margin-left: 8rpx" @click="selectedLableHandle(item)" />
  57. </view>
  58. </block>
  59. </view>
  60. <view class="text-box"> 标签</view>
  61. <view class="lable-ul">
  62. <!-- 这里就不用计算属性了 不知道会不会有隐藏的问题 -->
  63. <block v-if="lableActive == 1">
  64. <view :class="['lable-li']" @click="industryLabelHandler(item)" v-for="item in industryLabel" :key="item">{{ item }}</view>
  65. </block>
  66. <block v-else>
  67. <block v-for="item in companyLable" :key="item">
  68. <view :class="['lable-li']" @click="industryLabelHandler(item)" v-if="!item.search">
  69. {{ item }}
  70. </view>
  71. </block>
  72. </block>
  73. </view>
  74. </viwe>
  75. </van-popup>
  76. </view>
  77. </template>
  78. <script>
  79. import robbyImageUpload from "../components/imageUpload.vue";
  80. import { purchaserApi, uploadurl } from "@/config/api";
  81. export default {
  82. components: { robbyImageUpload },
  83. data() {
  84. return {
  85. navBarStyle: {
  86. height: 60 + "px",
  87. paddingTop: 40 + "px",
  88. paddingBottom: "4px",
  89. },
  90. showPopup: false,
  91. fileList: [],
  92. articleTitle: "", // 标题
  93. advice_content: "",
  94. columnName: "",
  95. industryCompanyLable: [], //添加的标签
  96. lableList: [
  97. { name: "行业标签", value: 1 },
  98. { name: "公司标签", value: 2 },
  99. ], // 公司或者行业标签
  100. lableActive: 1,
  101. topLableList: [
  102. { name: "笔记", value: 1 },
  103. { name: "观点", value: 2 },
  104. ], // 笔记或者观点的标签
  105. topLableActive: 1, // 笔记或者观点的选中
  106. industryLabel: [], // 行业标签
  107. selectedLableList: [], // 行业标签已选项
  108. companyLable: [], // 公司标签
  109. companySelectedLable: [], // 公司标签已选项
  110. detailId: 0,
  111. detailDataForm: {},
  112. editorCtx: null,
  113. };
  114. },
  115. computed: {
  116. uploadUrl() {
  117. return uploadurl;
  118. },
  119. },
  120. methods: {
  121. // 初始获取导航栏
  122. initNavBar() {
  123. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  124. this.navBarStyle = {
  125. height: menuButtonInfo.height + menuButtonInfo.top + 8 + "px",
  126. paddingTop: menuButtonInfo.top - 4 + "px",
  127. paddingBottom: "4px",
  128. };
  129. },
  130. // 添加标签完成事件
  131. addCompleteHandler() {
  132. this.industryCompanyLable = [...this.selectedLableList, ...this.companySelectedLable];
  133. this.showPopup = false;
  134. this.$nextTick(() => {
  135. this.selectedLableList = [];
  136. this.companySelectedLable = [];
  137. });
  138. },
  139. // 左上角的返回按钮
  140. goHandler() {
  141. let { Title, Content, ImgUrl, Tags } = this.detailDataForm;
  142. if (Title && Tags && (Title != this.articleTitle || (this.advice_content != Content && this.fileList.join(",") != ImgUrl) || this.industryCompanyLable.join(",") != Tags)) {
  143. this.draftBtnHandler();
  144. return;
  145. } else if (Title && Tags) {
  146. uni.navigateBack();
  147. return;
  148. }
  149. if (this.articleTitle || this.advice_content || this.fileList > 0 || this.industryCompanyLable.length > 0) {
  150. this.draftBtnHandler();
  151. } else {
  152. uni.navigateBack();
  153. }
  154. },
  155. // 创建标签公司Lable
  156. addCompanyLableHandler() {
  157. if (!this.columnName) return;
  158. this.companySelectedLable.push(this.columnName);
  159. },
  160. // 行业公司标签的点击事件
  161. industryOfCompanyHanler(item) {
  162. this.lableActive = item.value;
  163. },
  164. // 内容输入框
  165. contentChange(e) {
  166. this.advice_content = e.detail.html;
  167. },
  168. // 头部 table 的点击事件
  169. topLableHandler(item) {
  170. this.topLableActive = item.value;
  171. },
  172. // 行业的标签点击事件
  173. industryLabelHandler(item) {
  174. if (this.lableActive == 1) {
  175. if (this.selectedLableList.includes(item)) {
  176. let index = this.selectedLableList.findIndex((key) => key == item);
  177. this.selectedLableList.splice(index, 1);
  178. } else {
  179. this.selectedLableList.push(item);
  180. }
  181. } else {
  182. if (this.companySelectedLable.includes(item)) {
  183. let index = this.companySelectedLable.findIndex((key) => key == item);
  184. this.companySelectedLable.splice(index, 1);
  185. } else {
  186. this.companySelectedLable.push(item);
  187. }
  188. }
  189. },
  190. // 点击取消标签的事件
  191. selectedLableHandle(item) {
  192. if (this.lableActive == 1) {
  193. let index = this.selectedLableList.findIndex((key) => key == item);
  194. this.selectedLableList.splice(index, 1);
  195. } else {
  196. let index = this.companySelectedLable.findIndex((key) => key == item);
  197. this.companySelectedLable.splice(index, 1);
  198. }
  199. },
  200. // 草稿箱
  201. draftBtnHandler() {
  202. uni.showModal({
  203. title: "是否保存当前修改",
  204. content: "保存的草稿可在【内容中心】查看",
  205. confirmColor: "#3385FF",
  206. cancelColor: "#606266",
  207. cancelText: "不保存",
  208. confirmText: "保存",
  209. success: async (res) => {
  210. if (res.confirm) {
  211. const resSave = await purchaserApi.yanxuanSpecialSave({
  212. Content: this.advice_content,
  213. title: this.articleTitle,
  214. Type: this.topLableActive,
  215. Tags: this.industryCompanyLable.join(","),
  216. ImgUrl: this.$refs.robbyImageUpload.imageList.join(","),
  217. DoType: 1,
  218. Id: this.detailId,
  219. });
  220. if (resSave.Ret === 200) {
  221. this.$util.toast("已保存至草稿箱");
  222. uni.navigateBack();
  223. }
  224. }
  225. },
  226. });
  227. },
  228. // 发布
  229. releaseBtnHandler() {
  230. uni.showModal({
  231. title: "确认发布",
  232. content: "内容将提交给管理员审核后发布,确定要提交审核吗?",
  233. confirmColor: "#3385FF",
  234. cancelColor: "#606266",
  235. success: async (res) => {
  236. if (res.confirm) {
  237. const resSave = await purchaserApi.yanxuanSpecialSave({
  238. Content: this.advice_content,
  239. title: this.articleTitle,
  240. Type: this.topLableActive,
  241. Tags: this.industryCompanyLable.join(","),
  242. ImgUrl: this.$refs.robbyImageUpload.imageList.join(","),
  243. DoType: 2,
  244. Id: this.detailId,
  245. });
  246. if (resSave.Ret === 200) {
  247. this.$util.toast("发布成功");
  248. uni.navigateBack();
  249. }
  250. }
  251. },
  252. });
  253. },
  254. searchHandle() {
  255. this.lableActive == 1 ? this.getIndustryList() : this.getCompanySearch();
  256. },
  257. // 获取行业标签
  258. async getIndustryList() {
  259. const res = await purchaserApi.yanxuanSpecialIndustrySearch({
  260. Keyword: this.columnName,
  261. });
  262. if (res.Ret === 200) {
  263. this.industryLabel = res.Data;
  264. }
  265. },
  266. // 获取公司标签
  267. async getCompanySearch() {
  268. const res = await purchaserApi.yanxuanSpecialCompanySearch({
  269. Keyword: this.columnName,
  270. });
  271. if (res.Ret === 200) {
  272. this.companyLable = res.Data;
  273. }
  274. },
  275. deleteImage(e) {
  276. this.fileList = [...e.allImages];
  277. },
  278. addImage(e) {
  279. // console.log(e);
  280. this.fileList = [...e.allImages];
  281. },
  282. // 获取专栏详情
  283. async getDetaliData() {
  284. const res = await purchaserApi.yanxuanSpecialDetail({
  285. Id: this.detailId,
  286. });
  287. if (res.Ret === 200) {
  288. this.detailDataForm = res.Data;
  289. this.articleTitle = this.detailDataForm.Title;
  290. this.advice_content = this.detailDataForm.Content;
  291. setTimeout(() => {
  292. this.editorCtx.setContents({
  293. html: this.detailDataForm.Content, //this.EditGoodsDetail.content为赋值内容。
  294. });
  295. // this.editorCtx.insertText({
  296. // text: ,
  297. // });
  298. }, 200);
  299. this.fileList = this.detailDataForm.ImgUrl ? this.detailDataForm.ImgUrl.split(",") : [];
  300. this.industryCompanyLable = this.detailDataForm.Tags.split(",");
  301. }
  302. },
  303. },
  304. onLoad(options) {
  305. uni
  306. .createSelectorQuery()
  307. .in(this)
  308. .select("#editor")
  309. .context((res2) => {
  310. this.editorCtx = res2.context;
  311. })
  312. .exec();
  313. this.detailId = Number(options.id) || 0;
  314. this.detailId > 0 && this.getDetaliData();
  315. this.initNavBar();
  316. this.getIndustryList();
  317. },
  318. };
  319. </script>
  320. <style lang="scss" scope>
  321. .write-note {
  322. .nav-bar-wrap {
  323. position: sticky;
  324. top: 0;
  325. left: 0;
  326. width: 100%;
  327. display: flex;
  328. align-items: center;
  329. z-index: 99;
  330. background-color: #fff;
  331. .content-box {
  332. position: relative;
  333. display: flex;
  334. align-items: center;
  335. width: 100%;
  336. justify-content: center;
  337. color: #fff;
  338. font-size: 34rpx;
  339. .arrow-left-icon {
  340. position: absolute;
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. width: 40rpx;
  345. height: 40rpx;
  346. left: 39rpx;
  347. top: 50%;
  348. transform: translateY(-50%);
  349. z-index: 99;
  350. }
  351. }
  352. }
  353. background-color: #f3f5f9;
  354. padding-bottom: 200rpx;
  355. .write-note-content {
  356. background-color: #fff;
  357. margin-top: 1rpx;
  358. padding: 30rpx;
  359. .title-note {
  360. width: 100%;
  361. height: 112rpx;
  362. display: flex;
  363. align-items: center;
  364. border-bottom: 2rpx solid #f3f5f9;
  365. }
  366. .content-note {
  367. width: 100%;
  368. height: 880rpx;
  369. padding-top: 20rpx;
  370. .ql-container {
  371. height: calc(100% - 80rpx);
  372. }
  373. .new-lable {
  374. margin-top: 20px;
  375. color: #376cbb;
  376. display: flex;
  377. width: 100%;
  378. overflow: hidden;
  379. overflow-x: auto;
  380. .lable-li {
  381. flex-shrink: 0;
  382. display: flex;
  383. align-items: center;
  384. margin: 0 20rpx 30rpx 0;
  385. height: 56rpx;
  386. padding: 0 24rpx;
  387. border-radius: 153rpx;
  388. background-color: #f8f8fa;
  389. }
  390. .active {
  391. background-color: #376cbb;
  392. color: #fff;
  393. }
  394. }
  395. }
  396. }
  397. .write-note-img {
  398. margin-top: 20rpx;
  399. background-color: #fff;
  400. width: 100%;
  401. padding: 20rpx;
  402. .image-add-upload {
  403. width: 100%;
  404. }
  405. }
  406. .write-note-button {
  407. position: fixed;
  408. width: 100%;
  409. bottom: 50rpx;
  410. left: 0rpx;
  411. z-index: 99;
  412. display: flex;
  413. padding: 0 35rpx;
  414. padding-bottom: constant(safe-area-inset-bottom);
  415. padding-bottom: env(safe-area-inset-bottom);
  416. .draft {
  417. margin-right: 20rpx;
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. width: 216rpx;
  422. height: 72rpx;
  423. color: #376cbb;
  424. background-color: #e5efff;
  425. border-radius: 9rpx;
  426. }
  427. .release {
  428. flex: 1;
  429. display: flex;
  430. align-items: center;
  431. justify-content: center;
  432. height: 72rpx;
  433. border-radius: 9rpx;
  434. color: #ffff;
  435. background-color: #376cbb;
  436. }
  437. }
  438. .lable-class-popup {
  439. padding: 30rpx;
  440. }
  441. .add-lable-box {
  442. font-size: 28rpx;
  443. width: 100%;
  444. .add-txt {
  445. position: relative;
  446. height: 60rpx;
  447. line-height: 60rpx;
  448. font-weight: 600;
  449. font-size: 36rpx;
  450. color: #000;
  451. text-align: center;
  452. view {
  453. position: absolute;
  454. top: 0;
  455. right: 20rpx;
  456. color: #376cbb;
  457. font-size: 28rpx;
  458. }
  459. }
  460. .select-item {
  461. display: flex;
  462. margin: 20rpx 0;
  463. .item {
  464. width: 176rpx;
  465. height: 64rpx;
  466. border-radius: 100rpx;
  467. display: flex;
  468. align-items: center;
  469. justify-content: center;
  470. background-color: #f3f3f3;
  471. margin-right: 30rpx;
  472. }
  473. .act-item {
  474. color: #376cbb;
  475. background-color: #e5efff;
  476. }
  477. }
  478. .input-box {
  479. background-color: #f3f3f3;
  480. display: flex;
  481. align-items: center;
  482. height: 80rpx;
  483. width: 100%;
  484. position: relative;
  485. padding-left: 50rpx;
  486. padding-right: 20rpx;
  487. input {
  488. background-color: #f3f3f3;
  489. flex: 1;
  490. height: 80rpx;
  491. }
  492. .sea_ico {
  493. position: absolute;
  494. width: 31rpx;
  495. height: 31rpx;
  496. left: 10rpx;
  497. top: 50%;
  498. transform: translateY(-50%);
  499. }
  500. }
  501. .text-box {
  502. color: #333;
  503. font-size: 28rpx;
  504. font-weight: 600;
  505. display: flex;
  506. justify-content: space-between;
  507. margin: 30rpx 0;
  508. .one-lable-text {
  509. color: #999;
  510. font-size: 24rpx;
  511. font-weight: 400;
  512. }
  513. }
  514. .lable-ul {
  515. display: flex;
  516. flex-wrap: wrap;
  517. max-height: 500rpx;
  518. overflow: hidden;
  519. overflow-y: auto;
  520. .lable-li {
  521. flex-shrink: 0;
  522. display: flex;
  523. align-items: center;
  524. margin: 0 20rpx 30rpx 0;
  525. height: 56rpx;
  526. padding: 0 24rpx;
  527. border-radius: 153rpx;
  528. background-color: #f8f8fa;
  529. }
  530. .active {
  531. background-color: #376cbb;
  532. color: #fff;
  533. }
  534. }
  535. }
  536. .write-note-top {
  537. display: flex;
  538. background-color: #fff;
  539. padding: 15rpx 35rpx;
  540. .write-text {
  541. display: flex;
  542. align-items: center;
  543. justify-content: center;
  544. font-size: 28rpx;
  545. width: 148rpx;
  546. height: 64rpx;
  547. padding: 10rpx 32rpx 10rpx 32rpx;
  548. border-radius: 0rpx 6rpx 6rpx 0rpx;
  549. border: 1rpx solid #e7e7e7;
  550. }
  551. .act-top-lable {
  552. background-color: #376cbb;
  553. color: #fff;
  554. border: none;
  555. }
  556. }
  557. }
  558. </style>