writeNote.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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 this.$util.toast("标签已存在");
  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. IndustryTags: this.selectedLableList.join(","),
  207. CompanyTags: this.companySelectedLable.join(","),
  208. ImgUrl: this.fileList.join(","),
  209. DoType: 1,
  210. Id: this.detailId,
  211. });
  212. if (resSave.Ret === 200) {
  213. this.$util.toast("已保存至草稿箱");
  214. setTimeout(() => {
  215. uni.navigateBack();
  216. }, 300);
  217. }
  218. },
  219. // 发布
  220. releaseBtnHandler() {
  221. if (!this.articleTitle || !this.advice_content || !this.industryCompanyLable.length > 0) {
  222. let str = !this.articleTitle ? "请输入标题" : !this.advice_content ? "请输入内容" : "请至少添加一个标签";
  223. return this.$util.toast(str);
  224. }
  225. uni.showModal({
  226. title: "确认发布",
  227. content: "内容将提交给管理员审核后发布,确定要提交审核吗?",
  228. confirmColor: "#3385FF",
  229. cancelColor: "#606266",
  230. success: async (res) => {
  231. if (res.confirm) {
  232. const resCheck = await purchaserApi.yanxuanSpecialCheck({
  233. Content: this.advice_content,
  234. ImgUrl: this.fileList,
  235. });
  236. if (resCheck.Ret === 200) {
  237. const resSave = await purchaserApi.yanxuanSpecialSave({
  238. Content: this.advice_content,
  239. Title: this.articleTitle,
  240. Type: this.topLableActive,
  241. TIndustryTags: this.selectedLableList.join(","),
  242. CompanyTags: this.companySelectedLable.join(","),
  243. ImgUrl: this.fileList.join(","),
  244. DoType: 2,
  245. Id: this.detailId,
  246. });
  247. if (resSave.Ret === 200) {
  248. uni.showModal({
  249. content: "提交成功,审核结果将通过公众号消息提醒您,请留意【查研观向小助手】公众号",
  250. confirmText: "知道了",
  251. showCancel: false,
  252. confirmColor: "#3385FF",
  253. success: function (r) {
  254. if (r.confirm) {
  255. uni.navigateBack();
  256. }
  257. },
  258. });
  259. }
  260. }
  261. }
  262. },
  263. });
  264. },
  265. searchHandle() {
  266. this.lableActive == 1 ? this.getIndustryList() : this.getCompanySearch();
  267. },
  268. savePromptHandler() {
  269. uni.showModal({
  270. title: "是否保存当前修改",
  271. content: "保存的草稿可在【内容中心】查看",
  272. confirmColor: "#3385FF",
  273. cancelColor: "#606266",
  274. cancelText: "不保存",
  275. confirmText: "保存",
  276. success: async (res) => {
  277. if (res.confirm) {
  278. const resSave = await purchaserApi.yanxuanSpecialSave({
  279. Content: this.advice_content,
  280. Title: this.articleTitle,
  281. Type: this.topLableActive,
  282. IndustryTags: this.selectedLableList.join(","),
  283. CompanyTags: this.companySelectedLable.join(","),
  284. ImgUrl: this.fileList.join(","),
  285. DoType: 1,
  286. Id: this.detailId,
  287. });
  288. if (resSave.Ret === 200) {
  289. this.$util.toast("已保存至草稿箱");
  290. setTimeout(() => {
  291. uni.navigateBack();
  292. }, 300);
  293. }
  294. } else {
  295. uni.navigateBack();
  296. }
  297. },
  298. });
  299. },
  300. // 获取行业标签
  301. async getIndustryList() {
  302. const res = await purchaserApi.yanxuanSpecialIndustrySearch({
  303. Keyword: this.columnName.replace(/\s+/g, ""),
  304. });
  305. if (res.Ret === 200) {
  306. this.industryLabel = res.Data;
  307. }
  308. },
  309. // 获取公司标签
  310. async getCompanySearch() {
  311. const res = await purchaserApi.yanxuanSpecialCompanySearch({
  312. Keyword: this.columnName.replace(/\s+/g, ""),
  313. });
  314. if (res.Ret === 200) {
  315. this.companyLable = res.Data;
  316. }
  317. },
  318. delImage(done) {
  319. uni.showModal({
  320. content: "是否删除?",
  321. success: (res) => {
  322. if (res.confirm) {
  323. // 执行 done() 删除
  324. done();
  325. }
  326. },
  327. });
  328. },
  329. addImage(e) {
  330. this.$util.upload.Single(uploadurl, (res) => {
  331. let data = JSON.parse(res.data);
  332. if (data.Ret === 200) {
  333. this.fileList.push(data.Data.ResourceUrl);
  334. }
  335. });
  336. },
  337. // 获取专栏详情
  338. async getDetaliData() {
  339. const res = await purchaserApi.yanxuanSpecialDetail({
  340. Id: this.detailId,
  341. });
  342. if (res.Ret === 200) {
  343. this.detailDataForm = res.Data;
  344. this.articleTitle = this.detailDataForm.Title;
  345. this.advice_content = this.detailDataForm.Content;
  346. this.selectedLableList = this.detailDataForm.IndustryTags;
  347. this.companySelectedLable = this.detailDataForm.CompanyTags;
  348. this.industryCompanyLable = [...this.selectedLableList, ...this.companySelectedLable];
  349. setTimeout(() => {
  350. this.editorCtx.setContents({
  351. html: this.detailDataForm.Content, //this.EditGoodsDetail.content为赋值内容。
  352. });
  353. }, 200);
  354. this.fileList = this.detailDataForm.ImgUrl ? this.detailDataForm.ImgUrl.split(",") : [];
  355. // this.industryCompanyLable = this.detailDataForm.Tags ? this.detailDataForm.Tags.split(",") : [];
  356. // this.industryCompanyLable.forEach((item) => {
  357. // if (this.industryLabel.includes(item)) {
  358. // this.selectedLableList.push(item);
  359. // } else {
  360. // this.companySelectedLable.push(item);
  361. // }
  362. // });
  363. }
  364. },
  365. editorFocus() {
  366. uni.pageScrollTo({
  367. scrollTop: 0,
  368. duration: 0,
  369. });
  370. },
  371. },
  372. onLoad(options) {
  373. uni
  374. .createSelectorQuery()
  375. .in(this)
  376. .select("#editor")
  377. .context((res2) => {
  378. this.editorCtx = res2.context;
  379. })
  380. .exec();
  381. this.detailId = Number(options.id) || 0;
  382. this.detailId > 0 && this.getDetaliData();
  383. this.initNavBar();
  384. this.getIndustryList();
  385. },
  386. };
  387. </script>
  388. <style lang="scss" scope>
  389. .write-note {
  390. padding-top: 200rpx;
  391. overflow: hidden;
  392. .nav-bar-wrap {
  393. position: fixed;
  394. top: 0;
  395. left: 0;
  396. width: 100%;
  397. display: flex;
  398. align-items: center;
  399. z-index: 999;
  400. background-color: #fff;
  401. .content-box {
  402. position: relative;
  403. display: flex;
  404. align-items: center;
  405. width: 100%;
  406. justify-content: center;
  407. color: #fff;
  408. font-size: 34rpx;
  409. .arrow-left-icon {
  410. position: absolute;
  411. display: flex;
  412. align-items: center;
  413. justify-content: center;
  414. width: 40rpx;
  415. height: 40rpx;
  416. left: 39rpx;
  417. top: 50%;
  418. transform: translateY(-50%);
  419. z-index: 99;
  420. }
  421. }
  422. }
  423. background-color: #f3f5f9;
  424. padding-bottom: 200rpx;
  425. .write-note-content {
  426. background-color: #fff;
  427. margin-top: 1rpx;
  428. padding: 30rpx;
  429. .title-note {
  430. width: 100%;
  431. height: 112rpx;
  432. display: flex;
  433. align-items: center;
  434. border-bottom: 2rpx solid #f3f5f9;
  435. input {
  436. height: 100%;
  437. width: 100%;
  438. }
  439. }
  440. .content-note {
  441. width: 100%;
  442. height: 880rpx;
  443. padding-top: 20rpx;
  444. .ql-container {
  445. height: calc(100% - 80rpx);
  446. }
  447. .new-lable {
  448. margin-top: 20px;
  449. color: #376cbb;
  450. display: flex;
  451. width: 100%;
  452. overflow: hidden;
  453. overflow-x: auto;
  454. .lable-li {
  455. flex-shrink: 0;
  456. display: flex;
  457. align-items: center;
  458. margin: 0 20rpx 30rpx 0;
  459. height: 56rpx;
  460. padding: 0 24rpx;
  461. border-radius: 153rpx;
  462. background-color: #f8f8fa;
  463. }
  464. .active {
  465. background-color: #376cbb;
  466. color: #fff;
  467. }
  468. }
  469. }
  470. }
  471. .write-note-img {
  472. margin-top: 20rpx;
  473. background-color: #fff;
  474. width: 100%;
  475. padding: 20rpx;
  476. .image-add-upload {
  477. width: 100%;
  478. }
  479. }
  480. .write-note-button {
  481. display: flex;
  482. .draft {
  483. padding: 8rpx 18rpx;
  484. margin-right: 10rpx;
  485. color: #6698e1;
  486. }
  487. .release {
  488. padding: 8rpx 18rpx;
  489. color: #376cbb;
  490. }
  491. }
  492. .lable-class-popup {
  493. padding: 30rpx;
  494. }
  495. .add-lable-box {
  496. font-size: 28rpx;
  497. width: 100%;
  498. .add-txt {
  499. position: relative;
  500. height: 60rpx;
  501. line-height: 60rpx;
  502. font-weight: 600;
  503. font-size: 36rpx;
  504. color: #000;
  505. text-align: center;
  506. view {
  507. position: absolute;
  508. top: 0;
  509. right: 20rpx;
  510. color: #376cbb;
  511. font-size: 28rpx;
  512. }
  513. }
  514. .select-item {
  515. display: flex;
  516. margin: 20rpx 0;
  517. .item {
  518. width: 176rpx;
  519. height: 64rpx;
  520. border-radius: 100rpx;
  521. display: flex;
  522. align-items: center;
  523. justify-content: center;
  524. background-color: #f3f3f3;
  525. margin-right: 30rpx;
  526. }
  527. .act-item {
  528. color: #376cbb;
  529. background-color: #e5efff;
  530. }
  531. }
  532. .input-box {
  533. background-color: #f3f3f3;
  534. display: flex;
  535. align-items: center;
  536. height: 80rpx;
  537. width: 100%;
  538. position: relative;
  539. padding-left: 50rpx;
  540. padding-right: 20rpx;
  541. input {
  542. background-color: #f3f3f3;
  543. flex: 1;
  544. height: 80rpx;
  545. }
  546. .sea_ico {
  547. position: absolute;
  548. width: 31rpx;
  549. height: 31rpx;
  550. left: 10rpx;
  551. top: 50%;
  552. transform: translateY(-50%);
  553. }
  554. }
  555. .text-box {
  556. color: #333;
  557. font-size: 28rpx;
  558. font-weight: 600;
  559. display: flex;
  560. justify-content: space-between;
  561. margin: 30rpx 0;
  562. .one-lable-text {
  563. color: #999;
  564. font-size: 24rpx;
  565. font-weight: 400;
  566. }
  567. }
  568. .lable-ul {
  569. display: flex;
  570. flex-wrap: wrap;
  571. overflow: hidden;
  572. overflow-y: auto;
  573. .lable-li {
  574. flex-shrink: 0;
  575. display: flex;
  576. align-items: center;
  577. margin: 0 20rpx 30rpx 0;
  578. height: 56rpx;
  579. padding: 0 24rpx;
  580. border-radius: 153rpx;
  581. background-color: #f8f8fa;
  582. }
  583. .active {
  584. background-color: #376cbb;
  585. color: #fff;
  586. }
  587. }
  588. .lable-ul-two {
  589. height: 500rpx;
  590. }
  591. }
  592. .write-note-top {
  593. display: flex;
  594. justify-content: space-between;
  595. background-color: #fff;
  596. padding: 15rpx 35rpx;
  597. .write-text {
  598. display: flex;
  599. align-items: center;
  600. justify-content: center;
  601. font-size: 28rpx;
  602. width: 148rpx;
  603. height: 64rpx;
  604. padding: 10rpx 32rpx 10rpx 32rpx;
  605. border: 1rpx solid #e7e7e7;
  606. }
  607. view:nth-child(1) {
  608. border-radius: 6rpx 0rpx 0rpx 6rpx;
  609. }
  610. view:nth-child(2) {
  611. border-radius: 0rpx 6rpx 6rpx 0rpx;
  612. }
  613. .act-top-lable {
  614. background-color: #376cbb;
  615. color: #fff;
  616. border: none;
  617. }
  618. }
  619. }
  620. </style>