release.vue 5.7 KB

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