writeNote.vue 19 KB

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