release.vue 16 KB

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