fabuArticle.vue 8.7 KB

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