fabuArticle.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <view class="page">
  3. <view class="nav-bar">
  4. <view class="left">
  5. <view class="uni-btn-icon" @click="goBack">&#xe601;</view>
  6. <view class="center">发表想法</view>
  7. </view>
  8. <view class="right">
  9. <!-- <view class="btn" @click="onManage">管理</view> -->
  10. <view class="btn" @click="onSubmit" v-if="id && id < 1">发布</view>
  11. <view class="btn" @click="onSubmit" v-else>更新</view>
  12. </view>
  13. </view>
  14. <view class="enterContentDetails">
  15. <view class="content-title">
  16. <input class="edit" v-model="ainfo.title" maxlength="20" placeholder="标题(必填)" />
  17. </view>
  18. <view class="content-textarea">
  19. <textarea class="edit2" auto-height v-model="ainfo.content" :maxlength="1000"
  20. placeholder="添加描述"></textarea>
  21. </view>
  22. <view class="agree">
  23. <text class="xy">{{ ainfo.content.length }}/1000</text>
  24. </view>
  25. <!-- 上限五张图片 -->
  26. <view class="img_list">
  27. <view class="image" v-for="(item, index) in img_list" :key="index">
  28. <image class="upimg" :src="item" mode="aspectFill"></image>
  29. <image class="del" src="@/static/icon/img-del.png" @click="delIt(index)"></image>
  30. </view>
  31. <view class="image" @click="upload('list')" v-if="img_list.length < 9">
  32. <!-- <text class="txt">+</text> -->
  33. <image class="txt" src="../../static/icon/sy_icon_jiahao02.png"></image>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="worksBox">
  38. <view class="optionalWorks" @click="onManage">
  39. <view class="title">
  40. 可选作品
  41. <text v-if="id < 1">(图片或作品必选一个发布)</text>
  42. </view>
  43. <view class="selectLeft">
  44. <text class="prompt" v-if="id > 1">已选择一个作品</text>
  45. <image class="rightArrow" src="../../static/me/wd_icon_jiantou2.png"></image>
  46. </view>
  47. </view>
  48. <view class="activeItem" v-if="selectedWork.images">
  49. <view class="img-box">
  50. <image :src="selectedWork.images"></image>
  51. </view>
  52. <view class="info">
  53. <view class="title">{{ selectedWork.title }}</view>
  54. </view>
  55. <view class="select-box" @click="deleteWorkInfo()">
  56. <image src="../../static/icon/close.png"></image>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="nav-bar" v-if="false">
  61. <view class="left">
  62. <view class="uni-btn-icon" @click="goBack">&#xe601;</view>
  63. </view>
  64. <view class="center">发表想法</view>
  65. <view class="right">
  66. <view class="btn" @click="onManage">管理</view>
  67. <view class="btn" @click="onSubmit" v-if="id < 1">发布</view>
  68. <view class="btn" @click="onSubmit" v-else>更新</view>
  69. </view>
  70. </view>
  71. <view class="user-list" v-if="false">
  72. <view class="content">
  73. <input class="edit" v-model="ainfo.title" maxlength="20" placeholder="填写标题会有更多赞哦~" />
  74. </view>
  75. <view class="content">
  76. <textarea class="edit2" v-model="ainfo.content" :maxlength="1000"
  77. placeholder="美好的一天,写点什么吧..."></textarea>
  78. </view>
  79. <view class="agree">
  80. <text>还可以输入<text class="xy">{{ 1000 - ainfo.content.length }}</text>字</text>
  81. </view>
  82. <view class="img_list">
  83. <view class="image" v-for="(item, index) in img_list" :key="index">
  84. <image class="upimg" :src="item" mode="aspectFill"></image>
  85. <image class="del" src="../../static/del.svg" @click="delIt(index)"></image>
  86. </view>
  87. <view class="image" @click="upload('list')" v-if="img_list.length < 9">
  88. <text class="txt">+</text>
  89. </view>
  90. </view>
  91. <view style="display:flex;flex-direction: column;height:200rpx;"></view>
  92. </view>
  93. </view>
  94. </template>
  95. <script>
  96. export default {
  97. components: {},
  98. data() {
  99. return {
  100. skey: '',
  101. uinfo: {},
  102. is_first: 0,
  103. pid: 0,
  104. sel: 0,
  105. pop_sel: false,
  106. cate: '',
  107. cid: 0,
  108. catename: '',
  109. img2: '',
  110. cateNames: [],
  111. cate_list: [],
  112. CateIndex: 0,
  113. nameList1: [],
  114. nameList2: [],
  115. content: '',
  116. cate: '',
  117. ainfo: {
  118. id: 0,
  119. title: '',
  120. content: '',
  121. name: '',
  122. telphone: '',
  123. address: '',
  124. contact: '',
  125. num: '',
  126. },
  127. TypeArray: ['请选择', '线下服务', '电话咨询', '远程服务', '视频咨询', '其他服务'],
  128. TypeIndex: 0,
  129. TypeArray2: ['请选择', '次', '天', '小时', '分钟', '周', '月', '年', '单', '份'],
  130. TypeIndex2: 0,
  131. img_list: [],
  132. img_list2: [],
  133. img_list1: [],
  134. visible: false,
  135. maskCloseAble: true,
  136. str: '',
  137. defaultValue: '',
  138. listData: [],
  139. cateTag: [],
  140. money: '',
  141. item_gz: -1,
  142. item_time: [],
  143. item_dx: [],
  144. is_top: false,
  145. is_agree: 0,
  146. selectedWork: {}
  147. }
  148. },
  149. onLoad(params) {
  150. if (getApp().globalData.skey != "") {
  151. this.skey = getApp().globalData.skey;
  152. } else {
  153. this.skey = params.skey || ''; //1234567xef
  154. }
  155. if (params.id) {
  156. this.id = params.id;
  157. } else {
  158. this.id = -1;
  159. }
  160. let that = this;
  161. // this.getCate();
  162. that.getInfo();
  163. // this.getData();
  164. // 添加事件监听
  165. uni.$on('selectItem', this.handleSelect);
  166. },
  167. onUnload() {
  168. uni.$off('selectItem', this.handleSelect);
  169. },
  170. onShow() {
  171. let that = this;
  172. },
  173. methods: {
  174. goBack() {
  175. uni.navigateBack();
  176. },
  177. handleSelect(item) {
  178. console.log(item, '收到修改的数据');
  179. this.selectedWork = item;
  180. },
  181. onManage() {
  182. // 处理管理按钮点击
  183. // uni.redirectTo({
  184. // url: '/pages/make/manageArticle'
  185. // })
  186. uni.navigateTo({
  187. url: '/pages/make/relatedWorks'
  188. })
  189. },
  190. onPublish() {
  191. this.onSubmit();
  192. },
  193. copyKd(item_data) {
  194. if (item_data != "") {
  195. uni.setClipboardData({
  196. data: item_data, // e是需要设置的内容
  197. success: function () {
  198. uni.showToast({
  199. title: '网址已复制',
  200. icon: 'none'
  201. })
  202. }
  203. })
  204. }
  205. },
  206. agreeChk() {
  207. if (this.is_agree == 0) {
  208. this.is_agree = 1;
  209. } else {
  210. this.is_agree = 0;
  211. }
  212. },
  213. showPicker() {
  214. this.pop_sel = true;
  215. },
  216. open() {
  217. this.visible = true
  218. },
  219. confirm(val) {
  220. console.log(val)
  221. this.defaultValue = val.code
  222. this.ainfo.city = val.desc
  223. this.visible = false
  224. },
  225. cancel() {
  226. this.visible = false
  227. },
  228. delIt(ind) {
  229. let arr = [];
  230. if (this.img_list.length > 0) {
  231. for (let i = 0; i < this.img_list.length; i++) {
  232. if (i == ind) { } else {
  233. arr.push(this.img_list[i]);
  234. }
  235. }
  236. this.img_list = arr;
  237. }
  238. },
  239. getInfo() {
  240. var that = this;
  241. uni.request({
  242. url: this.$apiHost + '/Article/getinfo', //仅为示例,并非真实接口地址。
  243. data: {
  244. uuid: getApp().globalData.uuid,
  245. id: this.id
  246. },
  247. header: {
  248. 'content-type': 'application/json' //自定义请求头信息
  249. },
  250. success: (res) => {
  251. console.log("====", res.data);
  252. this.ainfo = res.data.article;
  253. that.img_list1 = [];
  254. that.img_list = [];
  255. that.img_list2 = [];
  256. this.selectedWork = res.data.work_info;
  257. if (res.data.article.images.length > 1) {
  258. let arr = res.data.article.images.split("|");
  259. if (arr.length > 0) {
  260. for (let i = 0; i < arr.length; i++) {
  261. if (arr[i].length > 10) {
  262. that.img_list.push(arr[i]);
  263. }
  264. }
  265. }
  266. }
  267. }
  268. });
  269. },
  270. checkField(str, tips) {
  271. if (str.length < 2) {
  272. uni.showToast({
  273. title: tips,
  274. icon: 'none'
  275. });
  276. return false;
  277. }
  278. return true;
  279. },
  280. onSubmit() {
  281. console.log("skey", this.skey);
  282. if (this.checkField(this.ainfo.title, "请输入名称") == false) {
  283. return;
  284. }
  285. if (this.checkField(this.ainfo.content, "请输入具体内容") == false) {
  286. return;
  287. }
  288. if (this.is_submit > 0) {
  289. return;
  290. }
  291. if (!this.selectedWork.id) {
  292. uni.showToast({
  293. title: '请选择一个作品',
  294. icon: 'none'
  295. });
  296. return;
  297. }
  298. if (this.img_list.length >= 5) {
  299. uni.showToast({
  300. title: '最多只能上传5张图片',
  301. icon: 'none'
  302. });
  303. return
  304. }
  305. let img_str = '';
  306. if (this.img_list.length > 0) {
  307. for (let i = 0; i < this.img_list.length; i++) {
  308. img_str += this.img_list[i] + "|";
  309. }
  310. }
  311. if (this.checkField(img_str, "请上传至少一张图片") == false) {
  312. return;
  313. }
  314. let that = this;
  315. this.is_submit = 1;
  316. uni.request({
  317. url: this.$apiHost + '/Article/add',
  318. data: {
  319. uuid: getApp().globalData.uuid,
  320. id: this.ainfo.id,
  321. title: this.ainfo.title,
  322. content: this.ainfo.content,
  323. img_list: img_str,
  324. work_id: this.selectedWork.id
  325. },
  326. //data: formdata, // 这里传入你的参数(json格式)
  327. method: 'POST',
  328. header: {
  329. 'Content-Type': 'application/x-www-form-urlencoded',
  330. 'sign': getApp().globalData.headerSign
  331. },
  332. dataType: 'json',
  333. success: (res) => {
  334. console.log("---", res.data);
  335. uni.showToast({
  336. title: res.data.str,
  337. icon: 'none'
  338. });
  339. if (res.data.success == "yes") {
  340. // if (that.ainfo.id > 0) {
  341. console.log(1);
  342. setTimeout(function () {
  343. uni.switchTab({ url: '/pages/index/index?' })
  344. }, 500);
  345. // } else {
  346. console.log(2);
  347. that.ainfo.title = '';
  348. that.ainfo.content = '';
  349. that.ainfo.num = '';
  350. that.img_list = [];
  351. // }
  352. } else { }
  353. this.is_submit = 0;
  354. },
  355. fail: (err) => {
  356. console.log('登录失败:', err);
  357. this.is_submit = 0;
  358. },
  359. complete: (com) => { }
  360. })
  361. },
  362. select(e) {
  363. console.log('选择文件:', e)
  364. },
  365. upload(type) {
  366. if (this.img_list.length >= 5) {
  367. uni.showToast({
  368. title: '最多只能上传5张图片',
  369. icon: 'none'
  370. });
  371. return
  372. }
  373. this.upload2(type)
  374. },
  375. upload2(type) {
  376. console.log("----upload");
  377. // this.$refs.files.upload();
  378. // 图片选择上传upload() {
  379. var _self = this;
  380. // 图片选择,只支持一次选择一张图片
  381. uni.chooseImage({
  382. count: 5,
  383. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  384. sourceType: ['album', 'camera'], //从相册、相机选择
  385. success: function (res) {
  386. console.log('res:', res)
  387. for (let index = 0; index < res.tempFilePaths.length; index++) {
  388. let filepath = "";
  389. // #ifdef H5
  390. filepath = res.tempFiles[index].path;
  391. // #endif
  392. // #ifdef APP-PLUS
  393. filepath = res.tempFilePaths[index];
  394. // #endif
  395. _self.imglocal = filepath; //res.tempFilePaths[0]
  396. const uploadTask = uni.uploadFile({
  397. url: _self.$apiHost + '/Xweb/upload_img?skey=' + _self.skey, // post请求地址
  398. filePath: filepath,
  399. name: 'file', // 待确认
  400. success: function (uploadFileRes) {
  401. let resdata = JSON.parse(uploadFileRes.data)
  402. console.log('Success1:', uploadFileRes);
  403. if (resdata.success == 'no') {
  404. uni.showToast({
  405. title: resdata.str,
  406. icon: 'none'
  407. });
  408. return;
  409. }
  410. if (resdata.code == 0) {
  411. console.log('Success2:', resdata.data.path);
  412. if (type == 'avatar') {
  413. _self.img2 = resdata.data.path;
  414. } else if (type == 'list') {
  415. _self.img_list.push(resdata.data.path)
  416. console.log('_self.img_list:', _self.img_list);
  417. } else if (type == 'list2') {
  418. _self.img_list2.push(resdata.data.path)
  419. } else if (type == 'list1') {
  420. _self.img_list1.push(resdata.data.path)
  421. }
  422. }
  423. },
  424. fail: function (uploadFileFail) {
  425. console.log('Error:', uploadFileFail.data);
  426. },
  427. complete: () => {
  428. console.log('Complete:');
  429. }
  430. });
  431. }
  432. },
  433. error: function (e) {
  434. console.log(e);
  435. }
  436. });
  437. },
  438. deleteWorkInfo(){
  439. this.selectedWork={}
  440. }
  441. }
  442. }
  443. </script>
  444. <style scoped lang="scss">
  445. @import 'fabuArticle.scss';
  446. </style>