release.vue 15 KB

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