release.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <template>
  2. <view class="content">
  3. <view class="content1">
  4. <view class='row'>
  5. <view class="textarea">
  6. <textarea placeholder-style="color:#AFB3BF;" placeholder="请发布粮食类商品交易信息,建议包含联系方式" maxlength="2000"
  7. v-model="dataObj.publishingContent"></textarea>
  8. <view class="textarea-left">
  9. <view class="clear" @click="clear()">清除全部</view>
  10. </view>
  11. <view class="textarea-bottom">
  12. {{dataObj.publishingContent?dataObj.publishingContent.length:'0'}}/2000字
  13. </view>
  14. </view>
  15. <!-- <view class="number">
  16. {{dataObj.publishingContent.length}}/2000个字
  17. </view> -->
  18. </view>
  19. <view style="padding-left: 10rpx;">
  20. <view style='flex-wrap:wrap;' class='flex'>
  21. <view v-for='(item,index) in imgList2' v-if="imgList2 && imgList2.length > 0"
  22. style="position: relative;margin-left: 20rpx;">
  23. <view class="delete_img" @click="deleteImg(index)">
  24. <u-icon size='4' name="close"></u-icon>
  25. </view>
  26. <image :src="item.appendixPath" mode="" style="width: 100px;height: 100px;border:1px solid #ccc;border-radius: 5rpx;"></image>
  27. </view>
  28. <view class="biankuang" @click="uploadClick" v-if="imgList2.length < 9">
  29. <view class="tubiao">
  30. <image class="upload" src="../../static/img/jiaoyi/tianjiazhaopian.png" mode="">
  31. </image>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- <upload :file-list='businesslicense' class="upload" ref="upload" :action="action" :max-size="maxSize"
  36. delIconSize='30' delBgColor='rgba(0,0,0,0.4)' delIcon="trash" :max-count="9"
  37. :size-type="['compressed']" @on-success="getImgUrl" @on-remove="onRemove"
  38. :before-upload="filterFileType"></upload> -->
  39. </view>
  40. </view>
  41. <view class="content2">
  42. <u-cell-group class='wrap'>
  43. <u-cell-item title="交易类型" :arrow="false" :title-style="titleStyle">
  44. <u-radio-group v-model="dataObj.tranType">
  45. <u-radio @change="radioChange" v-for="(item, index) in list" :key="index" :name="item.name"
  46. :disabled="item.disabled" active-color="#303030">
  47. {{item.name}}
  48. </u-radio>
  49. </u-radio-group>
  50. </u-cell-item>
  51. <u-cell-item :title="placeTitle" :title-style="titleStyle">
  52. <selectAddress :disabled="true" @selectAddress='selectAddress' series='3' :textStyle='textStyle'
  53. :searchPlace='searchPlaceHolder'>
  54. </selectAddress>
  55. </u-cell-item>
  56. <u-cell-item title="发布者昵称" :title-style="titleStyle" :border-bottom='false' @click="editNicknamee">
  57. <view :style='textStyle'>
  58. {{dataObj.publisher}}
  59. </view>
  60. <!-- <selectAddress @selectAddress='selectAddress' series='3' :textStyle='textStyle'></selectAddress> -->
  61. </u-cell-item>
  62. </u-cell-group>
  63. </view>
  64. <view class="submit" @click="submit">
  65. 发布
  66. </view>
  67. <u-popup v-model="showNickname" mode='center' border-radius="14" width='70%' @close='closePopup'>
  68. <view class="edit-nickname">
  69. <view>昵称长度限制在2-24个字符内</view>
  70. <u-input v-model="dataObj.publisher" border class='nickname-input' />
  71. <view style="text-align: center;">
  72. <u-button type="success" size="medium" class="nickname-btn" @click="nickNamesubmit">保存</u-button>
  73. </view>
  74. </view>
  75. </u-popup>
  76. </view>
  77. </template>
  78. <script>
  79. import * as config from '../../config'
  80. import upload from '@/components/upload_small.vue';
  81. import selectAddress from "@/components/selectAddress.vue"
  82. import {
  83. mapState
  84. } from 'vuex';
  85. export default {
  86. components: {
  87. upload,
  88. selectAddress
  89. },
  90. data() {
  91. return {
  92. searchPlaceHolder: '选择地区',
  93. placeTitle: '交货地',
  94. imgList: [],
  95. imgList2:[],
  96. disabled:false,
  97. showNickname: false,
  98. dataObj: {
  99. userId: '',
  100. tranType: '采购',
  101. placeDelivery: '',
  102. urlImg: '',
  103. publishingContent: '',
  104. publisher: '',
  105. },
  106. titleStyle: {
  107. "font-size": "28rpx",
  108. "color": "#333333",
  109. // "font-weight": 700
  110. },
  111. textStyle: {
  112. "font-size": "32rpx",
  113. // "font-weight": 700,
  114. "color": "#333333",
  115. "margin-right": '16rpx'
  116. },
  117. list: [{
  118. name: '采购',
  119. disabled: false
  120. },
  121. {
  122. name: '销售',
  123. disabled: false
  124. }
  125. ],
  126. businesslicense: [],
  127. value: '',
  128. action: this.$uploadUrl,
  129. maxSize: 50 * 1024 * 1024, //限制文件大小 50M
  130. isAdd: false,
  131. num:0
  132. };
  133. },
  134. onShow() {
  135. let _tl = uni.getStorageSync('transactionPlace')
  136. if (_tl) {
  137. this.dataObj.placeDelivery = _tl.address
  138. } else {
  139. }
  140. },
  141. onLoad() {
  142. console.log("user", this.userInfo)
  143. this.dataObj.userId = this.userInfo.id
  144. this.dataObj.publisher = this.userInfo.wechatNo
  145. this.dataObj.remark = this.userInfo.phone
  146. },
  147. onNavigationBarButtonTap(e) {
  148. console.log(e)
  149. uni.navigateTo({
  150. url: 'record'
  151. })
  152. },
  153. computed: {
  154. ...mapState(['hasLogin', 'userInfo', 'clientId']),
  155. },
  156. watch: {
  157. imgList: {
  158. handler: function() {
  159. var that = this
  160. setTimeout(()=>{
  161. that.$api.doRequest('get', 'appendix/query/getFileList', {
  162. appendixIds: that.imgList.toString()
  163. }).then(res => {
  164. that.imgList2 = res.data.data
  165. that.$forceUpdate()
  166. })
  167. },1000)
  168. },
  169. deep: true,
  170. immediate:true
  171. }
  172. },
  173. methods: {
  174. deleteImg(index) {
  175. this.num=this.imgList.length
  176. this.imgList.splice(index, 1)
  177. },
  178. async uploadClick() {
  179. let baseUrlNew = config.def().baseUrlNew
  180. let pcUserInfo = uni.getStorageSync('pcUserInfo')
  181. console.log('baseUrlNew',baseUrlNew)
  182. if(!pcUserInfo){
  183. uni.showToast({
  184. title:"登录已失效,请重新登录"
  185. })
  186. return
  187. }
  188. await uni.chooseImage({
  189. count:9,
  190. success: (chooseImageRes) => {
  191. console.log('chooseImageRes',chooseImageRes)
  192. let files = []
  193. for (let item of chooseImageRes.tempFiles) {
  194. files.push({
  195. name: 'fileName',
  196. url : item.path
  197. });
  198. }
  199. console.log(files)
  200. for (let i = 0; i < files.length; i++) {
  201. this.num++
  202. if(this.num<10){
  203. console.log(this.num)
  204. uni.uploadFile({
  205. url: baseUrlNew + 'appendix/api/uploadFiles',
  206. // url: baseUrlNew+'appendix/api/uploadFiles', //仅为示例,非真实的接口地址
  207. // files: files[i],
  208. filePath:files[i].url,
  209. name:files[i].name,
  210. formData: {
  211. // fileName: chooseImageRes.tempFiles[0],
  212. companyId: pcUserInfo.compId,
  213. modelId: '',
  214. vesselId: '',
  215. },
  216. success: (uploadFileRes) => {
  217. console.log(JSON.parse(uploadFileRes.data))
  218. var data = JSON.parse(uploadFileRes.data).data
  219. data.compId = pcUserInfo.compId
  220. this.$api.doRequest('post', '/appendix/api/saveFilesApp', {
  221. newAppendixs: [data],
  222. oldAppendixIds: ""
  223. }).then(res => {
  224. console.log(res.data.data)
  225. this.imgList.push(res.data.data[0])
  226. })
  227. console.log(uploadFileRes.data);
  228. },
  229. fail(res) {
  230. console.log(res);
  231. }
  232. });
  233. }else{
  234. break;
  235. }
  236. }
  237. }
  238. });
  239. },
  240. clear() {
  241. this.dataObj.publishingContent = ''
  242. },
  243. closePopup() {
  244. this.dataObj.publisher = this.userInfo.wechatNo
  245. },
  246. nickNamesubmit() {
  247. if (this.dataObj.publisher == null || this.dataObj.publisher == "") {
  248. this.$api.msg('请输入昵称!')
  249. return
  250. }
  251. if (this.dataObj.publisher.length < 2 || this.dataObj.publisher.length > 24) {
  252. this.$api.msg('请正确输入昵称!')
  253. return
  254. }
  255. let _obj = {
  256. wechatNo: this.dataObj.publisher,
  257. id: this.userInfo.id
  258. }
  259. uni.showLoading({
  260. title: '数据加载中',
  261. mask: true
  262. })
  263. let that = this
  264. that.$api.doRequest('post', '/commonUser/editUserInfo', _obj).then(
  265. res => {
  266. if (res.data.code == 200) {
  267. uni.showToast({
  268. title: '修改成功!',
  269. icon: 'success',
  270. duration: 2000,
  271. success() {
  272. setTimeout(() => {
  273. var _student = uni.getStorageSync('userInfo');
  274. _student.wechatNo = that.dataObj.publisher;
  275. uni.setStorageSync('userInfo', _student);
  276. var name = 'userInfo';
  277. var value = _student;
  278. that.$store.commit('$uStore', {
  279. name,
  280. value
  281. });
  282. uni.hideLoading()
  283. that.showNickname = false
  284. }, 2000)
  285. }
  286. })
  287. }
  288. })
  289. .catch(res => {
  290. if (res.errmsg) {
  291. uni.showToast({
  292. title: res.errmsg,
  293. icon: 'none',
  294. duration: 2000
  295. })
  296. } else {
  297. uni.showToast({
  298. title: "系统异常,请联系管理员",
  299. icon: 'none',
  300. duration: 2000
  301. })
  302. }
  303. });
  304. },
  305. editNicknamee() {
  306. console.log(this.dataObj)
  307. this.showNickname = true
  308. },
  309. submit() {
  310. if (!this.dataObj.publishingContent && this.businesslicense.length == 0) {
  311. uni.showToast({
  312. title: "图片和文字不能同时为空,错误提示“发布内容不能为空",
  313. icon: 'none',
  314. duration: 2000
  315. })
  316. }
  317. uni.showLoading({
  318. title: '数据加载中',
  319. mask: true
  320. })
  321. this.dataObj.urlImg = this.imgList.toString()
  322. this.dataObj.remark3 = this.dateFormat(new Date().getTime())
  323. this.$api.doRequest('post', '/transactionExchangeInfo/addInfo', this.dataObj).then(res => {
  324. console.log(res)
  325. if (res.data.code == 200) {
  326. this.num=0
  327. uni.navigateBack({
  328. delta: 1
  329. })
  330. } else {
  331. uni.showToast({
  332. title: res.message,
  333. icon: 'none',
  334. duration: 2000
  335. })
  336. }
  337. })
  338. },
  339. dateFormat(time) {
  340. let date = new Date(time);
  341. let year = date.getFullYear();
  342. // 在日期格式中,月份是从0开始的,因此要加0,使用三元表达式在小于10的前面加0,以达到格式统一 如 09:11:05
  343. let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  344. let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  345. let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  346. let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  347. let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  348. // 拼接
  349. return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
  350. // return year + "-" + month + "-" + day;
  351. },
  352. selectAddress(val) {
  353. console.log(val)
  354. console.log(this.dataObj.tranType)
  355. if (!val.check) {
  356. uni.showToast({
  357. title: '地点必须选到区县一级',
  358. icon: 'none',
  359. duration: 2000
  360. })
  361. return
  362. }
  363. try {
  364. uni.setStorageSync('transactionPlace', val);
  365. this.dataObj.placeDelivery = val.address
  366. } catch (e) {
  367. // error
  368. }
  369. },
  370. radioChange(e) {
  371. console.log(e);
  372. if (e == '销售') {
  373. this.placeTitle = '货源地'
  374. // this.searchPlaceHolder = '选择货源地区'
  375. } else {
  376. this.placeTitle = '交货地'
  377. // this.searchPlaceHolder = '选择交货地区'
  378. }
  379. },
  380. filterFileType(index, lists) {
  381. if (lists[index].fileType != 'jpg' && lists[index].fileType != 'png' && lists[index].fileType != 'gif') {
  382. lists.splice(index, 1);
  383. // 当前文件不支持
  384. uni.showModal({
  385. title: '暂不支持当前图片类型',
  386. showCancel: false
  387. });
  388. } else {
  389. this.isAdd = false;
  390. }
  391. },
  392. onRemove(index) {
  393. console.log("index", index)
  394. this.imgList.splice(index, 1)
  395. console.log(this.imgList)
  396. },
  397. getImgUrl(res) {
  398. console.log(res)
  399. console.log('------------res-----------')
  400. this.imgList.push(res)
  401. console.log(this.imgList)
  402. },
  403. onUploaded(lists) {
  404. this.filesArr = lists;
  405. let res = lists[0];
  406. if (res.response === undefined) {
  407. uni.showToast({
  408. title: '文件错误',
  409. icon: 'none'
  410. })
  411. }
  412. },
  413. },
  414. }
  415. </script>
  416. <style lang="scss" scoped>
  417. .content {
  418. // overflow: hidden;
  419. padding-bottom: 100rpx;
  420. }
  421. .content1 {
  422. background: #fff;
  423. margin: 20rpx;
  424. border-radius: 20rpx;
  425. padding-bottom: 40rpx;
  426. }
  427. /deep/.placeholder-class {
  428. color: #C5CAD4;
  429. font-size: 28rpx;
  430. }
  431. // .textarea {
  432. // padding: 20rpx 20rpx 50rpx 20rpx;
  433. // width: 100%;
  434. // font-size: 28rpx;
  435. // background: red
  436. // }
  437. .top {
  438. position: relative;
  439. .number {
  440. position: absolute;
  441. right: 32rpx;
  442. bottom: 0;
  443. color: #C5CAD4;
  444. font-size: 26rpx;
  445. }
  446. }
  447. .content2 {
  448. padding: 20rpx;
  449. }
  450. /deep/.u-cell-item-box,
  451. /deep/.u-cell-box {
  452. border-radius: 20rpx;
  453. }
  454. .submit {
  455. margin: 40rpx auto;
  456. width: 654rpx;
  457. height: 92rpx;
  458. background: #22C572;
  459. border-radius: 46rpx;
  460. font-size: 34rpx;
  461. font-weight: 400;
  462. color: #FFFFFF;
  463. line-height: 92rpx;
  464. text-align: center;
  465. // position: fixed;
  466. // bottom: 76rpx;
  467. // left: 0;
  468. // right: 0;
  469. // margin: auto;
  470. }
  471. .edit-nickname {
  472. padding: 40rpx 80rpx;
  473. }
  474. .nickname-input {
  475. margin: 20rpx 0;
  476. }
  477. .nickname-btn {
  478. margin-top: 20rpx;
  479. }
  480. .row {
  481. display: flex;
  482. justify-content: space-between;
  483. position: relative;
  484. background: #fff;
  485. border-radius: 20rpx;
  486. input {
  487. font-size: 28rpx;
  488. // color: #333333;
  489. }
  490. .left {
  491. display: flex;
  492. align-items: center;
  493. color: #333333;
  494. font-size: 34rpx;
  495. font-weight: 600;
  496. }
  497. }
  498. .row_css {
  499. font-size: 26rpx;
  500. color: #333333;
  501. margin-top: 60rpx;
  502. font-weight: 500;
  503. }
  504. .textarea {
  505. background: #F9F9FA;
  506. font-size: 28rpx;
  507. text-align: left;
  508. width: 100%;
  509. padding: 30rpx 30rpx;
  510. border-radius: 5px;
  511. margin: 30rpx;
  512. height: 46vh;
  513. padding-bottom: 20rpx;
  514. color: #333;
  515. }
  516. .textarea textarea {
  517. height: 90%;
  518. }
  519. .textarea-left {
  520. position: absolute;
  521. bottom: 40rpx;
  522. left: 50rpx;
  523. color: #606266;
  524. }
  525. .textarea-bottom {
  526. position: absolute;
  527. bottom: 40rpx;
  528. right: 40rpx;
  529. color: #AFB3BF;
  530. }
  531. .clear {
  532. /* width: 90%; */
  533. // background: #ffffff;
  534. color: #22C572;
  535. // border: 1px solid #22C572;
  536. // border-radius: 50rpx;
  537. // font-size: 28rpx;
  538. // padding: 9rpx 24rpx;
  539. }
  540. .bottom-btn {
  541. position: fixed;
  542. bottom: 30rpx;
  543. width: 90%;
  544. }
  545. .biankuang {
  546. // border: 1px dashed #AFB3BF;
  547. border-radius: 10rpx;
  548. width: 200rpx;
  549. height: 200rpx;
  550. margin-left: 20rpx;
  551. text-align:center;
  552. line-height: 220rpx;
  553. background:#F5F6FA;
  554. .upload {
  555. width: 46rpx;
  556. height: 46rpx;
  557. }
  558. }
  559. .delete_img {
  560. position: absolute;
  561. z-index: 100;
  562. right: 0px;
  563. border-radius:0 5rpx 0 10px;
  564. color: #ffffff;
  565. font-size: 28rpx;
  566. border: 1px;
  567. // border-radius: 5rpx;
  568. width: 40rpx;
  569. height: 38rpx;
  570. background-color: rgba(17, 26, 52, 0.50);
  571. text-align: center;
  572. }
  573. /deep/.pickerClass{
  574. width: 80%;
  575. position: absolute;
  576. right:11px;
  577. padding:0 30px 0 0;
  578. top:50%;
  579. transform: translateY(-50%);
  580. z-index:2
  581. }
  582. </style>