release.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="center">
  3. <u-form class="forList">
  4. <view class="modular">
  5. <view class="c-row b-b ">
  6. <view style="width: 30%;color: #71747C;font-size: 30rpx;">发布主体</view>
  7. <view class="flex" style="width: 70%;justify-content: flex-end;">
  8. <picker :range="companyType" @change="companyChange($event)"
  9. style="margin-right: 6rpx;font-size: 30rpx;">
  10. <view>{{companyIndex > -1?companyType[companyIndex] :'请选择发布主体'}}</view>
  11. </picker>
  12. <u-icon name="arrow-right" color="#AFB3BF" :custom-style="{'marginRight':'10rpx'}"></u-icon>
  13. </view>
  14. </view>
  15. <view class="c-row" @click="location">
  16. <view style="width: 30%;color: #71747C;font-size: 30rpx;">城市</view>
  17. <view class="flex"
  18. style="width: 70%;justify-content: flex-end;margin-right: 6rpx;font-size: 30rpx;">
  19. {{release.city == null || release.city == "" ? "请选择城市": release.city}}
  20. </view>
  21. <u-icon name="arrow-right" color="#AFB3BF" :custom-style="{'marginRight':'10rpx'}"></u-icon>
  22. </view>
  23. </view>
  24. <view class="modular">
  25. <view style="margin: 20rpx 30rpx 0;border-bottom: 1px solid #C5CAD4;">
  26. <input type="text" placeholder="标题(2-16个字)" style="font-size: 44rpx;" maxlength="16"
  27. v-model="release.title" />
  28. </view>
  29. <view class="inputText">
  30. <u-input v-model="release.content" type="textarea" :border="border" :height="height"
  31. :auto-height="autoHeight" maxlength="200" placeholder="请发布粮食类商品交易信息,建议包含联系方式、地址等信息,不超过200个字"
  32. @input="wordJiSuan" :clearable="clear" />
  33. </view>
  34. <view style="text-align: right;color: #C5CAD4;font-size: 30rpx;margin-right: 20rpx;">{{wordCount}}/200字
  35. </view>
  36. <upload class="upload" ref="upload" :action="action" :max-count="9" :size-type="['compressed']"
  37. @on-success="getImgUrl" @on-error="onError" @on-remove="onRemove" :options="uploadOptions"
  38. @on-uploaded="isAdd = true" @on-progress="onProgress" :before-upload="filterFileType"></upload>
  39. </view>
  40. </u-form>
  41. <u-button type="success" shape="circle" style="margin-top: 40rpx;" @click="submit">发布</u-button>
  42. </view>
  43. </template>
  44. <script>
  45. import upload from '@/components/upload.vue';
  46. import {
  47. mapState
  48. } from 'vuex';
  49. export default {
  50. components: {
  51. upload
  52. },
  53. data() {
  54. return {
  55. deptList: {},
  56. chengshi: [], //城市
  57. clear: false,
  58. border: false,
  59. height: 300,
  60. autoHeight: true,
  61. wordCount: 0,
  62. action: "https://www.zthymaoyi.com/upload/admin",
  63. uploadOptions: {
  64. "text": "上传照片",
  65. "bgc": ""
  66. },
  67. companyIndex: 0,
  68. companyType: [],
  69. release: {},
  70. address: [],
  71. getCompany: {},
  72. companyType1: [],
  73. }
  74. },
  75. computed: {
  76. ...mapState(['hasLogin', 'userInfo'])
  77. },
  78. onShow() {
  79. this.chengshi = uni.getStorageSync("Visit_key")
  80. if (this.chengshi.length > 0) {
  81. this.release.city = this.chengshi[0].cityName
  82. }
  83. this.companyList()
  84. },
  85. methods: {
  86. companyList() {
  87. this.getCompany.loginPhone = this.userInfo.phone
  88. this.$api.doRequest('get', '/settledCompanyInfo/companyList', this.getCompany)
  89. .then(res => {
  90. if (res.data.code == 200) {
  91. this.release.compName = res.data.data[0].compName
  92. for (let i = 0; i < res.data.data.length; i++) {
  93. this.companyType.push(res.data.data[i].compName)
  94. }
  95. }
  96. })
  97. },
  98. wordJiSuan() {
  99. this.wordCount = this.release.content.length
  100. },
  101. filterFileType(index, lists) {
  102. if (lists[index].fileType != 'jpg' && lists[index].fileType != 'png' && lists[index].fileType != 'gif') {
  103. lists.splice(index, 1);
  104. // 当前文件不支持
  105. uni.showModal({
  106. title: '暂不支持当前图片类型',
  107. showCancel: false
  108. });
  109. } else {
  110. this.isAdd = false;
  111. }
  112. },
  113. companyChange(e) {
  114. this.companyIndex = e.detail.value
  115. this.release.compName = this.companyType[this.companyIndex]
  116. },
  117. getImgUrl(e) {
  118. this.address.push(e)
  119. },
  120. onRemove(e) {
  121. this.address.splice(e, 1)
  122. },
  123. submit() {
  124. if (!this.release.compName) {
  125. this.$api.msg('发布主体不能为空')
  126. return
  127. }
  128. if (!this.release.city) {
  129. this.$api.msg('城市不能为空,功能没完成')
  130. // return
  131. }
  132. if (!this.release.title) {
  133. this.$api.msg('标题不能为空')
  134. return
  135. }
  136. if (this.release.title.length < 2 || this.release.title.length > 16) {
  137. this.$api.msg('标题长度2-16个字')
  138. return
  139. }
  140. if (this.release.content != null) {
  141. if (this.release.content.length > 200) {
  142. this.$api.msg('动态内容不能超过200字')
  143. return
  144. }
  145. }
  146. if (!this.release.content && this.address.length == 0) {
  147. this.$api.msg("动态内容和图片不能同时为空")
  148. return
  149. }
  150. if (this.companyType.length == 0) {
  151. uni.showModal({
  152. content: "您还没有入驻粮脉,不能发布,是否前去完善入驻信息!",
  153. showCancel: true,
  154. confirmText: '前往',
  155. success: function(res) {
  156. if (res.confirm) {
  157. uni.navigateTo({
  158. url: `/pages/grain_pulse/enter`
  159. })
  160. }
  161. }
  162. })
  163. return
  164. } else {
  165. this.release.address = this.address.toString()
  166. this.release.phone = this.userInfo.phone
  167. var that = this
  168. uni.showModal({
  169. content: "确定发布动态?",
  170. showCancel: true,
  171. confirmText: '确定',
  172. success: function(res) {
  173. if (res.confirm) {
  174. that.$api.doRequest('post',
  175. '/settledCompanyDynamics/api/addSettledCompanyDynamics', that.release)
  176. .then(res => {
  177. if (res.data.code == 200) {
  178. uni.showToast({
  179. title: '发布成功!',
  180. icon: 'none',
  181. duration: 2000,
  182. success() {
  183. setTimeout(function() {
  184. uni.navigateBack(1)
  185. }, 1000);
  186. }
  187. })
  188. }
  189. })
  190. }
  191. }
  192. })
  193. }
  194. },
  195. location() {
  196. uni.navigateTo({
  197. url: `/pages/grain_pulse/position/position`
  198. })
  199. }
  200. }
  201. }
  202. </script>
  203. <style>
  204. .center {
  205. padding: 10rpx 20rpx;
  206. }
  207. .modular {
  208. padding-top: 10rpx;
  209. background-color: #FFFFFF;
  210. border-radius: 20px;
  211. margin-top: 20px;
  212. }
  213. .title {
  214. margin-left: 20rpx;
  215. color: #71747C;
  216. }
  217. .titles {
  218. font-size: 44rpx;
  219. color: #C5CAD4;
  220. }
  221. .write {
  222. margin-right: 20px;
  223. color: #71747C;
  224. }
  225. .c-row {
  226. display: -webkit-box;
  227. display: -webkit-flex;
  228. display: flex;
  229. -webkit-box-align: center;
  230. -webkit-align-items: center;
  231. align-items: center;
  232. padding: 20rpx 30rpx;
  233. position: relative;
  234. }
  235. .inputText {
  236. padding: 2rpx 32rpx;
  237. font-size: 30rpx;
  238. color: #C5CAD4;
  239. margin-top: 20rpx;
  240. }
  241. </style>