honor.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="input_box">
  5. <view class="label"><text> * </text>荣誉名称:</view>
  6. <view class="box">
  7. <input type="text" value="" placeholder="请输入荣誉名称" v-model="imageName" />
  8. </view>
  9. </view>
  10. <view class="input_box">
  11. <view class="label"><text> * </text>上传图片:</view>
  12. <view class="img_box">
  13. <view class="item" v-if="data.path">
  14. <view class="img">
  15. <image :src="data.path" mode=""></image>
  16. </view>
  17. <view class="text">data.imageName</view>
  18. </view>
  19. <view class="item" v-if="!data.path">
  20. <view class="img">
  21. <view class="add" @click="up_image()">+</view>
  22. </view>
  23. <view class="text" style="color: #FFFFFF;">xxx</view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="btn" @click="add()">提交</view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. base_url: "",
  36. honor_list: [],
  37. imageName: "",
  38. data: {}
  39. };
  40. },
  41. onLoad() {
  42. const eventChannel = this.getOpenerEventChannel();
  43. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  44. eventChannel.on('acceptDataFromOpenerPage', (data) => {
  45. console.log(data.data)
  46. this.base_url = data.data.base_url
  47. this.honor_list = data.data.honor_list
  48. })
  49. },
  50. methods: {
  51. up_image() {
  52. uni.chooseImage({
  53. count: 1,
  54. success: (chooseImageRes) => {
  55. const tempFilePaths = chooseImageRes.tempFilePaths;
  56. console.log(chooseImageRes.tempFiles[0]);
  57. uni.showLoading({
  58. mask: true,
  59. title: "上传中..."
  60. })
  61. uni.uploadFile({
  62. url: this.base_url + "/worksheet/design/up_images",
  63. header: {
  64. 'Authorization': uni.getStorageSync('token_type') +' '+uni.getStorageSync('Authorization')
  65. },
  66. filePath: tempFilePaths[0],
  67. name: 'file',
  68. // formData只有H5存在
  69. formData: {
  70. image: chooseImageRes.tempFiles[0]
  71. },
  72. success: (uploadFileRes) => {
  73. // console.log(uploadFileRes.data);
  74. console.log(JSON.parse(uploadFileRes.data));
  75. this.data = JSON.parse(uploadFileRes.data).data
  76. uni.hideLoading()
  77. uni.showToast({
  78. icon: "none",
  79. title: "上传成功"
  80. })
  81. }
  82. })
  83. }
  84. })
  85. },
  86. add() {
  87. if (this.imageName != '' && this.data.path) {
  88. console.log(this.imageName, this.data.path)
  89. this.data.imageName = this.imageName
  90. if (!this.honor_list) {
  91. this.honor_list = []
  92. this.honor_list.push(this.data)
  93. } else {
  94. this.honor_list.push(this.data)
  95. }
  96. console.log(this.honor_list)
  97. this.$api.user_updateUserMessage({
  98. honor: JSON.stringify(this.honor_list)
  99. }).then((res) => {
  100. console.log(res)
  101. uni.showToast({
  102. icon: "none",
  103. title: "提交成功"
  104. })
  105. setTimeout(() => {
  106. uni.navigateBack()
  107. }, 1500)
  108. })
  109. } else {
  110. uni.showToast({
  111. icon: "none",
  112. title: "请填写荣誉名称或上传图片"
  113. })
  114. }
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. .content {
  121. margin-bottom: 50rpx;
  122. box-sizing: border-box;
  123. padding: 25rpx;
  124. .input_box {
  125. margin-bottom: 20rpx;
  126. font-size: 32rpx;
  127. .label {
  128. min-height: 80rpx;
  129. line-height: 80rpx;
  130. color: #6C6F74;
  131. text {
  132. color: red;
  133. }
  134. }
  135. .box {
  136. width: 700rpx;
  137. background: #FFFFFF;
  138. border-radius: 8rpx;
  139. border: 2rpx solid #E9EBF2;
  140. box-sizing: border-box;
  141. padding: 0 25rpx;
  142. .uni-input {
  143. font-size: 30rpx;
  144. height: 90rpx;
  145. line-height: 90rpx;
  146. color: #666;
  147. }
  148. input {
  149. font-size: 30rpx;
  150. height: 90rpx;
  151. line-height: 90rpx;
  152. }
  153. /deep/.uni-date-editor--x {
  154. .uniui-clear {
  155. display: none;
  156. }
  157. }
  158. /deep/.uni-date-x--border {
  159. box-sizing: border-box;
  160. border-radius: 4px;
  161. border: none;
  162. }
  163. /deep/.uni-date-x {
  164. padding: 0;
  165. }
  166. }
  167. .img_box {
  168. margin-top: 20rpx;
  169. overflow: hidden;
  170. .item {
  171. float: left;
  172. margin-right: 50rpx;
  173. width: 300rpx;
  174. text-align: center;
  175. .img {
  176. margin-bottom: 10rpx;
  177. image {
  178. width: 300rpx;
  179. height: 180rpx;
  180. }
  181. .add {
  182. font-size: 140rpx;
  183. color: #DCDCDC;
  184. text-align: center;
  185. height: 180rpx;
  186. line-height: 160rpx;
  187. background-color: #EEEEEE;
  188. }
  189. }
  190. .text {
  191. width: 260rpx;
  192. font-size: 30rpx;
  193. color: #8e8e8e;
  194. overflow: hidden;
  195. white-space: nowrap;
  196. text-overflow: ellipsis;
  197. }
  198. }
  199. }
  200. }
  201. .btn {
  202. margin-top: 40rpx;
  203. background-color: #009FE8;
  204. padding: 25rpx 50rpx;
  205. color: #FFFFFF;
  206. text-align: center;
  207. }
  208. }
  209. </style>