release.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. uni.showLoading({
  172. title:"正在提交"
  173. })
  174. that.$api.doRequest('post',
  175. '/settledCompanyDynamics/api/addSettledCompanyDynamics',
  176. that.release)
  177. .then(res => {
  178. console.log("addSettledCompanyDynamics",res)
  179. if (res.data.code == 200) {
  180. uni.showToast({
  181. title: '发布成功!',
  182. icon: 'none',
  183. duration: 2000,
  184. success() {
  185. setTimeout(function() {
  186. uni.navigateBack(1)
  187. }, 1000);
  188. }
  189. })
  190. }
  191. uni.hideLoading()
  192. })
  193. .catch(res => {
  194. uni.showToast({
  195. title: '系统异常,请联系管理员',
  196. icon: 'none',
  197. duration: 2000
  198. })
  199. uni.hideLoading()
  200. })
  201. }
  202. }
  203. })
  204. }
  205. }
  206. })
  207. },
  208. location() {
  209. // uni.navigateTo({
  210. // url: `/pages/grain_pulse/position/position`
  211. // })
  212. uni.navigateTo({
  213. url: "/pages/grain_pulse/selectCity/selectCity"
  214. })
  215. }
  216. }
  217. }
  218. </script>
  219. <style>
  220. .center {
  221. padding: 10rpx 20rpx;
  222. }
  223. .modular {
  224. padding-top: 10rpx;
  225. background-color: #FFFFFF;
  226. border-radius: 20px;
  227. margin-top: 20px;
  228. }
  229. .title {
  230. margin-left: 20rpx;
  231. color: #71747C;
  232. }
  233. .titles {
  234. font-size: 44rpx;
  235. color: #C5CAD4;
  236. }
  237. .write {
  238. margin-right: 20px;
  239. color: #71747C;
  240. }
  241. .c-row {
  242. display: -webkit-box;
  243. display: -webkit-flex;
  244. display: flex;
  245. -webkit-box-align: center;
  246. -webkit-align-items: center;
  247. align-items: center;
  248. padding: 20rpx 30rpx;
  249. position: relative;
  250. }
  251. .inputText {
  252. padding: 2rpx 32rpx;
  253. font-size: 30rpx;
  254. color: #C5CAD4;
  255. margin-top: 20rpx;
  256. }
  257. </style>