release.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 && 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. for (let i = 0; i < res.data.data.length; i++) {
  91. if(i ==0 && !this.release.compName){
  92. this.release.compName = res.data.data[i].compName
  93. }
  94. this.companyType.push(res.data.data[i].compName)
  95. }
  96. }
  97. })
  98. },
  99. wordJiSuan() {
  100. this.wordCount = this.release.content.length
  101. },
  102. filterFileType(index, lists) {
  103. if (lists[index].fileType != 'jpg' && lists[index].fileType != 'png' && lists[index].fileType != 'gif') {
  104. lists.splice(index, 1);
  105. // 当前文件不支持
  106. uni.showModal({
  107. title: '暂不支持当前图片类型',
  108. showCancel: false
  109. });
  110. } else {
  111. this.isAdd = false;
  112. }
  113. },
  114. companyChange(e) {
  115. this.companyIndex = e.detail.value
  116. this.release.compName = this.companyType[this.companyIndex]
  117. console.log("companyChange",e,this.release.compName)
  118. },
  119. getImgUrl(e) {
  120. this.address.push(e)
  121. },
  122. onRemove(e) {
  123. this.address.splice(e, 1)
  124. },
  125. submit() {
  126. if (!this.release.compName) {
  127. this.$api.msg('发布主体不能为空')
  128. return
  129. }
  130. if (!this.release.city) {
  131. this.$api.msg('城市不能为空,功能没完成')
  132. return
  133. }
  134. if (!this.release.title) {
  135. this.$api.msg('标题不能为空')
  136. return
  137. }
  138. if (this.release.title.length < 2 || this.release.title.length > 16) {
  139. this.$api.msg('标题长度2-16个字')
  140. return
  141. }
  142. if (this.release.content != null) {
  143. if (this.release.content.length > 1000) {
  144. this.$api.msg('动态内容不能超过1000字')
  145. return
  146. }
  147. }
  148. if (!this.release.content && this.address.length == 0) {
  149. this.$api.msg("动态内容和图片不能同时为空")
  150. return
  151. }
  152. var that = this
  153. that.$api.doRequest('get', '/settledCompanyDynamics/count', {
  154. phone: this.userInfo.phone
  155. })
  156. .then(res => {
  157. if (res.data.code == 200) {
  158. if (res.data.data > 5) {
  159. uni.showToast({
  160. title: '今日发布已达上限!',
  161. icon: 'none',
  162. duration: 2000,
  163. })
  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. uni.showLoading({
  175. title:"正在提交"
  176. })
  177. console.log("addSettledCompanyDynamics",that.release)
  178. that.$api.doRequest('post',
  179. '/settledCompanyDynamics/api/addSettledCompanyDynamics',
  180. that.release)
  181. .then(res => {
  182. console.log("addSettledCompanyDynamics",res)
  183. if (res.data.code == 200) {
  184. uni.showToast({
  185. title: '发布成功!',
  186. icon: 'none',
  187. duration: 2000,
  188. success() {
  189. setTimeout(function() {
  190. uni.navigateBack(1)
  191. }, 1000);
  192. }
  193. })
  194. }
  195. uni.hideLoading()
  196. })
  197. .catch(res => {
  198. uni.showToast({
  199. title: '系统异常,请联系管理员',
  200. icon: 'none',
  201. duration: 2000
  202. })
  203. uni.hideLoading()
  204. })
  205. }
  206. }
  207. })
  208. }
  209. }
  210. })
  211. },
  212. location() {
  213. // uni.navigateTo({
  214. // url: `/pages/grain_pulse/position/position`
  215. // })
  216. uni.navigateTo({
  217. url: "/pages/grain_pulse/selectCity/selectCity"
  218. })
  219. }
  220. }
  221. }
  222. </script>
  223. <style>
  224. .center {
  225. padding: 10rpx 20rpx;
  226. }
  227. .modular {
  228. padding-top: 10rpx;
  229. background-color: #FFFFFF;
  230. border-radius: 20px;
  231. margin-top: 20px;
  232. }
  233. .title {
  234. margin-left: 20rpx;
  235. color: #71747C;
  236. }
  237. .titles {
  238. font-size: 44rpx;
  239. color: #C5CAD4;
  240. }
  241. .write {
  242. margin-right: 20px;
  243. color: #71747C;
  244. }
  245. .c-row {
  246. display: -webkit-box;
  247. display: -webkit-flex;
  248. display: flex;
  249. -webkit-box-align: center;
  250. -webkit-align-items: center;
  251. align-items: center;
  252. padding: 20rpx 30rpx;
  253. position: relative;
  254. }
  255. .inputText {
  256. padding: 2rpx 32rpx;
  257. font-size: 30rpx;
  258. color: #C5CAD4;
  259. margin-top: 20rpx;
  260. }
  261. </style>