writeNote.vue 19 KB

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