my-updata.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="my-updata">
  3. <custom-nav ref="ltm" :title="title" />
  4. <view class="content">
  5. <view class="total">
  6. <view class="area">
  7. <text>付款金额:<text class="basecolor">{{ total }}</text></text>
  8. <input type="number" maxlength="11" v-model="money" />
  9. <text>元</text>
  10. </view>
  11. </view>
  12. <view class="add">
  13. <view class="imgs">
  14. <view class="choose" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
  15. <image :src="imgList[index]" mode="aspectFill"></image>
  16. <view class="del" @tap.stop="DelImg" :data-index="index">
  17. <text></text>
  18. </view>
  19. </view>
  20. <view class="choose" @tap="ChooseImage" v-if="imgList.length < maxnum">
  21. <text class="cuIcon-add"></text>
  22. </view>
  23. </view>
  24. <view class="remark">
  25. <textarea placeholder="可添加备注:最多20个字" maxlength="20" v-model="remark"></textarea>
  26. </view>
  27. </view>
  28. <view class="big-btn bg" @tap="upload">提交凭证</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { _API_Proxy_Upload, _API_Proxy_UploadUrls } from '@/apis/user.js'
  34. export default {
  35. data() {
  36. return {
  37. title: '我的升级',
  38. total: '',
  39. money: '',
  40. remark: '',
  41. maxnum: 3,
  42. imgList: []
  43. }
  44. },
  45. onLoad(opt) {
  46. this.total = opt.total
  47. },
  48. methods: {
  49. ChooseImage() { // 选择截图
  50. uni.chooseImage({
  51. count: this.maxnum - this.imgList.length,
  52. sizeType: ['original '], //可以指定是原图还是压缩图,默认二者都有
  53. sourceType: ['album'], //从相册选择
  54. success: (res) => {
  55. this.imgList = this.imgList.concat(res.tempFilePaths)
  56. }
  57. });
  58. },
  59. ViewImage(e) { // 预览截图
  60. uni.previewImage({
  61. urls: this.imgList,
  62. current: e.currentTarget.dataset.url
  63. })
  64. },
  65. DelImg(e) { // 删除截图
  66. this.$refs.ltm.modal('提示', ['确定删除这张截图?']).then(() => {
  67. this.imgList.splice(e.currentTarget.dataset.index, 1)
  68. }).catch(() => {
  69. this.$refs.ltm.toast('取消删除')
  70. })
  71. },
  72. async upload() {
  73. if (!this.money) {
  74. this.$refs.ltm.toast('请输入付款金额')
  75. return
  76. }
  77. if (!this.imgList.length) {
  78. this.$refs.ltm.toast('请选择付款截图')
  79. return
  80. }
  81. this.$refs.ltm.loading()
  82. const list = []
  83. for(let i = 0; i < this.imgList.length; i ++) {
  84. list.push(await this.uploadImg(this.imgList[i]))
  85. }
  86. _API_Proxy_UploadUrls({ list }).then(res => {
  87. this.$refs.ltm.loading()
  88. uni.$emit('UPLOADED')
  89. uni.navigateBack()
  90. })
  91. },
  92. uploadImg(path) { // 上传图片
  93. return new Promise((resolve, reject) => {
  94. plus.zip.compressImage({ src: path, dst: '_doc/a.jpg', overwrite: true, quality: 20 }, e => {
  95. _API_Proxy_Upload({
  96. name: 'img',
  97. filePath: e.target,
  98. formData: {
  99. money: this.money,
  100. remark: this.remark
  101. }
  102. }).then(res => {
  103. resolve(res.data.url)
  104. })
  105. })
  106. })
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss">
  112. .my-updata {
  113. @include page();
  114. .content {
  115. .total {
  116. @include flex();
  117. height: 160rpx;
  118. background: #FFFFFF;
  119. margin-bottom: 10rpx;
  120. .area {
  121. @include flex();
  122. width: 690rpx;
  123. height: 90rpx;
  124. padding: 0 20rpx;
  125. border-radius: 10rpx;
  126. box-sizing: border-box;
  127. border: 2rpx solid #F5F5F5;
  128. justify-content: space-between;
  129. input {
  130. flex: 1;
  131. height: 100%;
  132. padding: 0 20rpx;
  133. text-align: right;
  134. box-sizing: border-box;
  135. }
  136. }
  137. }
  138. .add {
  139. .imgs {
  140. @include flex();
  141. height: 240rpx;
  142. background: #FFFFFF;
  143. margin-bottom: 2rpx;
  144. padding: 35rpx 30rpx;
  145. box-sizing: border-box;
  146. justify-content: flex-start;
  147. .choose {
  148. @include flex();
  149. width: 140rpx;
  150. height: 140rpx;
  151. position: relative;
  152. margin-right: 20rpx;
  153. border: 1rpx solid #999999;
  154. .del {
  155. @include flex();
  156. top: -15rpx;
  157. width: 30rpx;
  158. height: 30rpx;
  159. right: -15rpx;
  160. border-radius: 50%;
  161. position: absolute;
  162. background: $app-base-color;
  163. text {
  164. width: 19rpx;
  165. height: 3rpx;
  166. background: #FFFFFF;
  167. }
  168. }
  169. text {
  170. font-size: 60rpx;
  171. }
  172. image {
  173. width: 100%;
  174. height: 100%;
  175. }
  176. }
  177. }
  178. .remark {
  179. @include flex();
  180. height: 160rpx;
  181. background: #FFFFFF;
  182. textarea {
  183. width: 690rpx;
  184. height: 120rpx;
  185. padding: 20rpx;
  186. box-sizing: border-box;
  187. border: 2rpx solid #F5F5F5;
  188. }
  189. }
  190. }
  191. .big-btn {
  192. width: 480rpx;
  193. }
  194. }
  195. }
  196. </style>