honor.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. console.log(this.honor_list)
  91. console.log(this.data)
  92. if (!this.honor_list) {
  93. this.honor_list = []
  94. this.honor_list.push(this.data)
  95. } else {
  96. this.honor_list.push(this.data)
  97. }
  98. console.log(this.honor_list)
  99. this.$api.user_updateUserMessage({
  100. honor: JSON.stringify(this.honor_list)
  101. }).then((res) => {
  102. console.log(res)
  103. uni.showToast({
  104. icon: "none",
  105. title: "提交成功"
  106. })
  107. setTimeout(() => {
  108. uni.navigateBack()
  109. }, 1500)
  110. })
  111. } else {
  112. uni.showToast({
  113. icon: "none",
  114. title: "请填写荣誉名称或上传图片"
  115. })
  116. }
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss">
  122. .content {
  123. margin-bottom: 50rpx;
  124. box-sizing: border-box;
  125. padding: 25rpx;
  126. .input_box {
  127. margin-bottom: 20rpx;
  128. font-size: 32rpx;
  129. .label {
  130. min-height: 80rpx;
  131. line-height: 80rpx;
  132. color: #6C6F74;
  133. text {
  134. color: red;
  135. }
  136. }
  137. .box {
  138. width: 700rpx;
  139. background: #FFFFFF;
  140. border-radius: 8rpx;
  141. border: 2rpx solid #E9EBF2;
  142. box-sizing: border-box;
  143. padding: 0 25rpx;
  144. .uni-input {
  145. font-size: 30rpx;
  146. height: 90rpx;
  147. line-height: 90rpx;
  148. color: #666;
  149. }
  150. input {
  151. font-size: 30rpx;
  152. height: 90rpx;
  153. line-height: 90rpx;
  154. }
  155. /deep/.uni-date-editor--x {
  156. .uniui-clear {
  157. display: none;
  158. }
  159. }
  160. /deep/.uni-date-x--border {
  161. box-sizing: border-box;
  162. border-radius: 4px;
  163. border: none;
  164. }
  165. /deep/.uni-date-x {
  166. padding: 0;
  167. }
  168. }
  169. .img_box {
  170. margin-top: 20rpx;
  171. overflow: hidden;
  172. .item {
  173. float: left;
  174. margin-right: 50rpx;
  175. width: 300rpx;
  176. text-align: center;
  177. .img {
  178. margin-bottom: 10rpx;
  179. image {
  180. width: 300rpx;
  181. height: 180rpx;
  182. }
  183. .add {
  184. font-size: 140rpx;
  185. color: #DCDCDC;
  186. text-align: center;
  187. height: 180rpx;
  188. line-height: 160rpx;
  189. background-color: #EEEEEE;
  190. }
  191. }
  192. .text {
  193. width: 260rpx;
  194. font-size: 30rpx;
  195. color: #8e8e8e;
  196. overflow: hidden;
  197. white-space: nowrap;
  198. text-overflow: ellipsis;
  199. }
  200. }
  201. }
  202. }
  203. .btn {
  204. margin-top: 40rpx;
  205. background-color: #009FE8;
  206. padding: 25rpx 50rpx;
  207. color: #FFFFFF;
  208. text-align: center;
  209. }
  210. }
  211. </style>