release.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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="1000" placeholder="请发布粮食类商品交易信息,建议包含联系方式、地址等信息,不超过1000个字"
  32. @input="wordJiSuan" :clearable="clear" />
  33. </view>
  34. <view style="text-align: right;color: #C5CAD4;font-size: 30rpx;margin-right: 20rpx;">{{wordCount}}/1000字
  35. </view>
  36. <upload class="upload" ref="upload" :action="action" :max-count="9" :size-type="['compressed']"
  37. @on-success="getImgUrl" @on-remove="onRemove" :options="uploadOptions"
  38. @on-uploaded="isAdd = true" :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. clear: false,
  57. border: false,
  58. height: 300,
  59. autoHeight: true,
  60. wordCount: 0,
  61. action: "https://www.zthymaoyi.com/upload/admin",
  62. uploadOptions: {
  63. "text": "上传照片",
  64. "bgc": ""
  65. },
  66. companyIndex: 0,
  67. companyType: [],
  68. release: {},
  69. address: [],
  70. getCompany: {},
  71. companyType1: [],
  72. }
  73. },
  74. computed: {
  75. ...mapState(['hasLogin', 'userInfo'])
  76. },
  77. onShow() {
  78. var city = uni.getStorageSync("nowRegion")
  79. if(city.positionName.cityName){
  80. this.release.city = city.positionName.cityName
  81. }
  82. this.companyList()
  83. },
  84. methods: {
  85. companyList() {
  86. this.getCompany.loginPhone = this.userInfo.phone
  87. this.$api.doRequest('get', '/settledCompanyInfo/companyList', this.getCompany)
  88. .then(res => {
  89. if (res.data.code == 200) {
  90. this.release.compName = res.data.data[0].compName
  91. for (let i = 0; i < res.data.data.length; i++) {
  92. this.companyType.push(res.data.data[i].compName)
  93. }
  94. }
  95. })
  96. },
  97. wordJiSuan() {
  98. this.wordCount = this.release.content.length
  99. },
  100. filterFileType(index, lists) {
  101. if (lists[index].fileType != 'jpg' && lists[index].fileType != 'png' && lists[index].fileType != 'gif') {
  102. lists.splice(index, 1);
  103. // 当前文件不支持
  104. uni.showModal({
  105. title: '暂不支持当前图片类型',
  106. showCancel: false
  107. });
  108. } else {
  109. this.isAdd = false;
  110. }
  111. },
  112. companyChange(e) {
  113. this.companyIndex = e.detail.value
  114. this.release.compName = this.companyType[this.companyIndex]
  115. },
  116. getImgUrl(e) {
  117. this.address.push(e)
  118. },
  119. onRemove(e) {
  120. this.address.splice(e, 1)
  121. },
  122. submit() {
  123. if (!this.release.compName) {
  124. this.$api.msg('发布主体不能为空')
  125. return
  126. }
  127. if (!this.release.city) {
  128. this.$api.msg('城市不能为空,功能没完成')
  129. return
  130. }
  131. if (!this.release.title) {
  132. this.$api.msg('标题不能为空')
  133. return
  134. }
  135. if (this.release.title.length < 2 || this.release.title.length > 16) {
  136. this.$api.msg('标题长度2-16个字')
  137. return
  138. }
  139. if (this.release.content != null) {
  140. if (this.release.content.length > 1000) {
  141. this.$api.msg('动态内容不能超过1000字')
  142. return
  143. }
  144. }
  145. if (!this.release.content && this.address.length == 0) {
  146. this.$api.msg("动态内容和图片不能同时为空")
  147. return
  148. }
  149. var that = this
  150. that.$api.doRequest('get', '/settledCompanyDynamics/count', {
  151. phone: this.userInfo.phone
  152. })
  153. .then(res => {
  154. if (res.data.code == 200) {
  155. if (res.data.data > 5) {
  156. uni.showToast({
  157. title: '今日发布已达上限!',
  158. icon: 'none',
  159. duration: 2000,
  160. })
  161. } else {
  162. this.release.address = this.address.toString()
  163. this.release.phone = this.userInfo.phone
  164. var that = this
  165. uni.showModal({
  166. content: "确定发布动态?",
  167. showCancel: true,
  168. confirmText: '确定',
  169. success: function(res) {
  170. if (res.confirm) {
  171. that.$api.doRequest('post',
  172. '/settledCompanyDynamics/api/addSettledCompanyDynamics',
  173. that.release)
  174. .then(res => {
  175. if (res.data.code == 200) {
  176. uni.showToast({
  177. title: '发布成功!',
  178. icon: 'none',
  179. duration: 2000,
  180. success() {
  181. setTimeout(function() {
  182. uni.navigateBack(1)
  183. }, 1000);
  184. }
  185. })
  186. }
  187. })
  188. }
  189. }
  190. })
  191. }
  192. }
  193. })
  194. },
  195. location() {
  196. // uni.navigateTo({
  197. // url: `/pages/grain_pulse/position/position`
  198. // })
  199. uni.navigateTo({
  200. url: "/pages/grain_pulse/selectCity/selectCity"
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style>
  207. .center {
  208. padding: 10rpx 20rpx;
  209. }
  210. .modular {
  211. padding-top: 10rpx;
  212. background-color: #FFFFFF;
  213. border-radius: 20px;
  214. margin-top: 20px;
  215. }
  216. .title {
  217. margin-left: 20rpx;
  218. color: #71747C;
  219. }
  220. .titles {
  221. font-size: 44rpx;
  222. color: #C5CAD4;
  223. }
  224. .write {
  225. margin-right: 20px;
  226. color: #71747C;
  227. }
  228. .c-row {
  229. display: -webkit-box;
  230. display: -webkit-flex;
  231. display: flex;
  232. -webkit-box-align: center;
  233. -webkit-align-items: center;
  234. align-items: center;
  235. padding: 20rpx 30rpx;
  236. position: relative;
  237. }
  238. .inputText {
  239. padding: 2rpx 32rpx;
  240. font-size: 30rpx;
  241. color: #C5CAD4;
  242. margin-top: 20rpx;
  243. }
  244. </style>