myarticle.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <template>
  2. <view class="content">
  3. <view class="main">
  4. <view class="box-1">
  5. <view class="box-left">标题:</view>
  6. <input type="text" :disabled="lx != 0" v-model="title" placeholder-class="placeholder"
  7. class="list-input" placeholder="请填写文章标题" />
  8. </view>
  9. <view class="box-1">
  10. <view class="box-left">作者:</view>
  11. <input type="text" :disabled="lx != 0" v-model="author" placeholder-class="placeholder"
  12. class="list-input" placeholder="请填写文章作者" />
  13. </view>
  14. <view class="box-1">
  15. <view class="box-left">文章简介:</view>
  16. <input type="text" :disabled="lx != 0" v-model="synopsis" placeholder-class="placeholder"
  17. class="list-input" placeholder="请填写文章简介" />
  18. </view>
  19. <view class="upload-box">
  20. <view class="upload-left">文章头图</view>
  21. <view class="upload-right " @click.stop="banner_img_up()">
  22. <view class="upload-imgbox">
  23. <image v-if="!banner_img" class="upload-img " src="/static/img/add.png"></image>
  24. <image v-if="banner_img" class="upload-img " :src="banner_img"></image>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="upload-box">
  29. <view class="upload-left">分享素材</view>
  30. <view class="flex">
  31. <view class="upload-right flex-start">
  32. <view class="position-relative upload-imgbox" v-for="(src,ind) in image_input">
  33. <image :src="src" class="upload-img "></image>
  34. <view class="delText" @click="image_input.splice(ind,1)">
  35. 删除
  36. </view>
  37. </view>
  38. <view class="upload-imgbox">
  39. <image @click.stop="scImgMian()" class="upload-img " src="/static/img/add.png"></image>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- <view class="box-1">
  45. <view class="box-left">
  46. 关联商品 :
  47. </view>
  48. <view class="list-input" v-if="!product" @click="open()">
  49. 请选择关联商品
  50. </view>
  51. <view class="list-input clamp" v-else @click="open()">
  52. {{product.store_name}}
  53. </view>
  54. </view> -->
  55. <view class="bjq" v-if="showwz == 0&&lx ==0">
  56. <jinEdit ref="set" placeholder="请输入文章内容" @editOk="editOk" uploadFileUrl="/api/upload/image"
  57. :header="{'Authori-zation': AuthoriZation}" :showImgSize="true" :html="content" height="50vh">
  58. </jinEdit>
  59. </view>
  60. <view class="bjq" v-if="lx !=0">
  61. <view v-html="content"></view>
  62. </view>
  63. </view>
  64. <view @click.stop="submit('1')" v-if="lx == 0" class="address-box submit-box"><text
  65. class="submit-btn">提交文章</text></view>
  66. <view @click.stop="submit('0')" v-if="lx == 0" class="address-box submit-box"><text
  67. class="submit-btn gren">保存草稿</text></view>
  68. <!-- <uni-popup ref="choose" type="bottom">
  69. <view class="choose-main">
  70. <view class="choose-top flex">
  71. <view class="choose-font" @click="close()">
  72. 取消
  73. </view>
  74. </view>
  75. <view class="top-box">
  76. <view class="top">
  77. <view class="top-icon">
  78. <image src="../../static/icon/icon.png" mode=""></image>
  79. </view>
  80. <view class="top-main"><input type="text" v-model="keyworld" placeholder="请输入商品名称"></view>
  81. </view>
  82. <view class="top-font" @click="clickSearch()">
  83. 搜索
  84. </view>
  85. </view>
  86. <scroll-view scroll-y="true" style="height: 600rpx;" @scrolltolower="getProduct()">
  87. <view class="choose-item flex" v-for="(item,index) in productlist" @click="xuanzhe(item)">
  88. <view class="choose-image">
  89. <image :src="item.image" mode=""></image>
  90. </view>
  91. <view class="choose-rigt">
  92. <view class="choose-name">
  93. {{item.store_name}}
  94. </view>
  95. <view class="choose-price">
  96. {{item.price}}
  97. </view>
  98. </view>
  99. </view>
  100. </scroll-view>
  101. </view>
  102. </uni-popup> -->
  103. </view>
  104. </template>
  105. <script>
  106. import {
  107. upload
  108. } from '@/api/order.js';
  109. // import {
  110. // getProducts,
  111. // goodsDetail
  112. // } from '@/api/product.js'
  113. import {
  114. my_detail,
  115. add_article
  116. } from '@/api/user.js';
  117. import jinEdit from '@/components/jin-edit/jin-edit.vue';
  118. export default {
  119. components: {
  120. jinEdit
  121. },
  122. data() {
  123. return {
  124. lx: 0,
  125. AuthoriZation: '',
  126. id: 0,
  127. title: '', //文章标题
  128. author: '', //文章作者
  129. banner_img: '', //头图
  130. image_input: [], //文章图片
  131. content: '', //文章内容
  132. synopsis: '', //文章简介
  133. product: '', //关联商品
  134. productlist: [], //商品列表
  135. page: 1,
  136. limit: 10,
  137. loadType: 'more',
  138. keyworld: '',
  139. showwz: 0,
  140. };
  141. },
  142. onLoad(opt) {
  143. if (opt.id) {
  144. this.showwz = 1;
  145. this.id = opt.id;
  146. this.loadData();
  147. }
  148. if (opt.type) {
  149. this.lx = opt.type
  150. }
  151. console.log(this.product);
  152. // this.getProduct();
  153. this.AuthoriZation = 'Bearer ' + uni.getStorageSync('token')
  154. },
  155. onShow() {},
  156. onReachBottom() {},
  157. onReady() {},
  158. methods: {
  159. editOk(res) {
  160. // 保存富文本转出的html
  161. this.content = res.html
  162. console.log(this.content);
  163. },
  164. // getProduct() {
  165. // const obj = this
  166. // if (obj.loadType == 'noMore' || obj.loadType == 'loading') {
  167. // return
  168. // }
  169. // obj.loadType = 'loading'
  170. // getProducts({
  171. // page: obj.page,
  172. // limit: obj.limit,
  173. // keyword: obj.keyworld
  174. // }).then(({
  175. // data
  176. // }) => {
  177. // obj.productlist = obj.productlist.concat(data);
  178. // obj.page++
  179. // if (data.length == obj.limit) {
  180. // obj.loadType = 'more'
  181. // } else {
  182. // obj.loadType = 'noMore'
  183. // }
  184. // })
  185. // },
  186. loadData() {
  187. my_detail({}, this.id).then(({
  188. data
  189. }) => {
  190. this.title = data.news.title
  191. this.author = data.news.author
  192. this.image_input =data.news.share_images;
  193. this.banner_img = data.news.image_input[0];
  194. this.synopsis = data.news.synopsis
  195. // this.spxq(data.news.product_id)
  196. this.content = data.news.content
  197. this.showwz = 0
  198. })
  199. },
  200. // spxq(id) {
  201. // goodsDetail({}, id).then(({
  202. // data
  203. // }) => {
  204. // this.product = data.storeInfo
  205. // console.log(data);
  206. // })
  207. // },
  208. banner_img_up() {
  209. if (this.lx != 0) {
  210. return
  211. }
  212. let obj = this;
  213. upload({
  214. file: ''
  215. })
  216. .then(e => {
  217. console.log(e, 'e');
  218. obj.banner_img = e[0].url;
  219. })
  220. .catch(e => {});
  221. },
  222. scImgMian() {
  223. if (this.lx != 0) {
  224. return
  225. }
  226. let obj = this;
  227. upload({
  228. file: ''
  229. })
  230. .then(e => {
  231. console.log(e, 'e');
  232. obj.image_input.push(e[0].url);
  233. })
  234. .catch(e => {});
  235. },
  236. // clickSearch() {
  237. // this.page = 1;
  238. // this.limit = 10;
  239. // this.loadType = 'more'
  240. // this.getProduct();
  241. // },
  242. // open() {
  243. // if (this.lx != 0) {
  244. // return
  245. // }
  246. // this.$refs.choose.open()
  247. // },
  248. // close() {
  249. // this.$refs.choose.close()
  250. // },
  251. xuanzhe(opt) {
  252. this.product = opt;
  253. console.log(this.product, '123456');
  254. this.$refs.choose.close();
  255. },
  256. submit(type) {
  257. const obj = this
  258. this.$refs.set.release(true)
  259. setTimeout(() => {
  260. if (!obj.title) {
  261. return this.$api.msg('请输入文章标题')
  262. }
  263. if (!obj.author) {
  264. return this.$api.msg('请输入文章作者')
  265. }
  266. if (!obj.image_input) {
  267. return this.$api.msg('请输入文章头图')
  268. }
  269. if (!obj.synopsis) {
  270. return this.$api.msg('请输入文章简介')
  271. }
  272. if (!obj.content) {
  273. return this.$api.msg('请输入文章内容')
  274. }
  275. add_article({
  276. type: type,
  277. id: obj.id,
  278. title: obj.title,
  279. author: obj.author,
  280. image_input: obj.banner_img,
  281. synopsis: obj.synopsis,
  282. share_title: obj.title,
  283. share_synopsis: obj.synopsis,
  284. share_images: obj.image_input.join(','),
  285. content: obj.content,
  286. product_id: 0
  287. }).then(e => {
  288. uni.navigateTo({
  289. url: '/pages/user/release?id=0'
  290. })
  291. })
  292. }, 10)
  293. }
  294. }
  295. };
  296. </script>
  297. <style lang="scss">
  298. page,
  299. .content {
  300. min-height: 100%;
  301. height: auto;
  302. }
  303. .box-1 {
  304. background: #ffffff;
  305. display: flex;
  306. justify-content: space-between;
  307. align-items: center;
  308. width: 100%;
  309. padding: 20rpx;
  310. .box-left {
  311. width: 25%;
  312. text-align: left;
  313. color: #000000;
  314. }
  315. .list-input {
  316. width: 75%;
  317. font-size: 28rpx;
  318. color: #959595;
  319. text-align: right;
  320. padding-right: 24rpx;
  321. }
  322. }
  323. .upload-box {
  324. width: 100%;
  325. background: #ffffff;
  326. border-radius: 27rpx;
  327. display: flex;
  328. flex-direction: column;
  329. padding: 30rpx 40rpx;
  330. margin: 20rpx auto 30rpx;
  331. padding-right: 0;
  332. .upload-left {
  333. font-weight: 400;
  334. font-size: 28rpx;
  335. }
  336. .upload-right {
  337. flex-wrap: wrap;
  338. .delText {
  339. background-color: rgba(0, 0, 0, 0.6);
  340. color: #FFF;
  341. text-align: center;
  342. position: absolute;
  343. bottom: 0;
  344. width: 100%;
  345. }
  346. .upload-imgbox {
  347. margin-top: 20rpx;
  348. margin-right: 20rpx;
  349. .upload-img {
  350. width: 200rpx;
  351. height: 200rpx;
  352. }
  353. }
  354. }
  355. }
  356. .main {
  357. padding: 20rpx;
  358. }
  359. .bjq {
  360. margin-top: 20rpx;
  361. background: #ffffff;
  362. padding: 20rpx;
  363. }
  364. .address-box {
  365. padding: 15rpx 40rpx;
  366. margin-bottom: 10px;
  367. }
  368. .submit-box {
  369. bottom: 0;
  370. left: 0;
  371. width: 750rpx;
  372. }
  373. .submit-btn {
  374. margin-top: 10px;
  375. display: inline-block;
  376. width: 670rpx;
  377. height: 96rpx;
  378. line-height: 96rpx;
  379. text-align: center;
  380. background-color: #000000;
  381. opacity: 1;
  382. box-shadow: 0rpx 8rpx 12rpx rgba(0, 0, 0, 0.16);
  383. border-radius: 56rpx;
  384. font-size: 39rpx;
  385. font-weight: bold;
  386. color: rgba(255, 255, 255, 1);
  387. }
  388. .gren {
  389. background: #ffffff;
  390. color: #000000;
  391. border: 1px solid #000000;
  392. }
  393. .choose-main {
  394. background: #ffffff;
  395. }
  396. .choose-top {
  397. padding: 20rpx 40rpx 20rpx;
  398. font-size: 32rpx;
  399. justify-content: flex-end;
  400. .choose-font {
  401. color: #d4c7c2;
  402. }
  403. }
  404. .choose-item {
  405. padding: 40rpx 20rpx;
  406. justify-content: flex-start;
  407. .choose-image {
  408. width: 100rpx;
  409. height: 100rpx;
  410. image {
  411. width: 100%;
  412. height: 100%
  413. }
  414. }
  415. .choose-rigt {
  416. height: 100rpx;
  417. margin-left: 20rpx;
  418. padding: 10rpx 0;
  419. display: flex;
  420. flex-direction: column;
  421. justify-content: space-between;
  422. .choose-name {
  423. font-size: $font-base;
  424. color: $font-color-dark;
  425. font-weight: bold;
  426. }
  427. .choose-price {
  428. font-size: 32rpx;
  429. font-family: PingFang SC;
  430. font-weight: 800;
  431. color: #ff4c4c;
  432. line-height: 1;
  433. }
  434. }
  435. }
  436. .top-box {
  437. display: flex;
  438. justify-content: center;
  439. align-items: center;
  440. }
  441. .top-font {
  442. font-size: 32rpx;
  443. color: #000000;
  444. margin-left: 20rpx;
  445. }
  446. .top {
  447. width: 550rpx;
  448. height: 58rpx;
  449. background: #ededed;
  450. border-radius: 29rpx;
  451. display: flex;
  452. justify-content: center;
  453. align-items: center;
  454. .top-icon {
  455. width: 32rpx;
  456. height: 32rpx;
  457. image {
  458. width: 100%;
  459. height: 100%;
  460. }
  461. }
  462. .top-main {
  463. margin-left: 20rpx;
  464. font-size: 28rpx;
  465. font-family: PingFang SC;
  466. font-weight: 500;
  467. color: #cbcbcb;
  468. }
  469. }
  470. </style>