myarticle.vue 9.6 KB

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