release.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. var that = this
  151. that.$api.doRequest('get', '/settledCompanyDynamics/count', {
  152. phone: this.userInfo.phone
  153. })
  154. .then(res => {
  155. if (res.data.code == 200) {
  156. if (res.data.data > 5) {
  157. uni.showToast({
  158. title: '今日发布已达上限!',
  159. icon: 'none',
  160. duration: 2000,
  161. })
  162. } else {
  163. this.release.address = this.address.toString()
  164. this.release.phone = this.userInfo.phone
  165. var that = this
  166. uni.showModal({
  167. content: "确定发布动态?",
  168. showCancel: true,
  169. confirmText: '确定',
  170. success: function(res) {
  171. if (res.confirm) {
  172. that.$api.doRequest('post',
  173. '/settledCompanyDynamics/api/addSettledCompanyDynamics',
  174. that.release)
  175. .then(res => {
  176. if (res.data.code == 200) {
  177. uni.showToast({
  178. title: '发布成功!',
  179. icon: 'none',
  180. duration: 2000,
  181. success() {
  182. setTimeout(function() {
  183. uni.navigateBack(1)
  184. }, 1000);
  185. }
  186. })
  187. }
  188. })
  189. }
  190. }
  191. })
  192. }
  193. }
  194. })
  195. },
  196. location() {
  197. uni.navigateTo({
  198. url: `/pages/grain_pulse/position/position`
  199. })
  200. }
  201. }
  202. }
  203. </script>
  204. <style>
  205. .center {
  206. padding: 10rpx 20rpx;
  207. }
  208. .modular {
  209. padding-top: 10rpx;
  210. background-color: #FFFFFF;
  211. border-radius: 20px;
  212. margin-top: 20px;
  213. }
  214. .title {
  215. margin-left: 20rpx;
  216. color: #71747C;
  217. }
  218. .titles {
  219. font-size: 44rpx;
  220. color: #C5CAD4;
  221. }
  222. .write {
  223. margin-right: 20px;
  224. color: #71747C;
  225. }
  226. .c-row {
  227. display: -webkit-box;
  228. display: -webkit-flex;
  229. display: flex;
  230. -webkit-box-align: center;
  231. -webkit-align-items: center;
  232. align-items: center;
  233. padding: 20rpx 30rpx;
  234. position: relative;
  235. }
  236. .inputText {
  237. padding: 2rpx 32rpx;
  238. font-size: 30rpx;
  239. color: #C5CAD4;
  240. margin-top: 20rpx;
  241. }
  242. </style>