fabuArticle.vue 10.0 KB

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