managePhoto.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="page">
  3. <view class="list_info">
  4. <view class="item_tag">
  5. <view class="tag" v-for="(item,index) in list">
  6. <image class="logo" :src="item" mode="aspectFill"></image>
  7. <image class="close" src="../../static/me/close2.png" mode="widthFix" @click="delImg(item)" />
  8. </view>
  9. <view class="tagAdd" @click="upload">
  10. <image class="add" src="../../static/me/icon_add.png" mode="widthFix" />
  11. </view>
  12. </view>
  13. <view class="tips">*最多上传{{maxImageCount}}张图片</view>
  14. <view class="blankHeight"></view>
  15. </view>
  16. <view class="btn_submit" @click="submitData">提交</view>
  17. <!-- 提示框 -->
  18. <DialogBox ref="DialogBox"></DialogBox>
  19. </view>
  20. </template>
  21. <script>
  22. import { isArray } from '../../uni_modules/cl-uni/utils';
  23. export default {
  24. components: {},
  25. data() {
  26. return {
  27. title: '',
  28. sel: 1,
  29. list_tag: [
  30. 'xx', 'ff', 'vv'
  31. ],
  32. list: [],
  33. maxImageCount:5
  34. }
  35. },
  36. onLoad() {
  37. this.loadData();
  38. },
  39. onShow() {},
  40. methods: {
  41. onBack() {},
  42. chkSel() {
  43. if (this.sel == 1) {
  44. this.sel = 0;
  45. } else {
  46. this.sel = 1;
  47. }
  48. },
  49. loadData() {
  50. console.log({
  51. uuid: getApp().globalData.uuid,
  52. skey: getApp().globalData.skey
  53. });
  54. uni.request({
  55. url: this.$apiHost + '/Member/getphoto',
  56. data: {
  57. uuid: getApp().globalData.uuid
  58. },
  59. header: {
  60. "content-type": "application/json",
  61. 'sign': getApp().globalData.headerSign
  62. },
  63. success: (res) => {
  64. console.log("----:", res.data);
  65. if (res.data.list != null) {
  66. let list2 = [];
  67. for (var i = 0; i < res.data.list.length; i++) {
  68. list2.push(res.data.list[i].image);
  69. }
  70. this.list = list2;
  71. }
  72. },
  73. complete: (com) => {
  74. // uni.hideLoading();
  75. },
  76. fail: (e) => {
  77. console.log("----e:", e);
  78. }
  79. });
  80. },
  81. submitData() {
  82. let str = "";
  83. if (this.list.length > 5) {
  84. uni.showToast({
  85. title: "最多上传5张图片",
  86. icon: 'none'
  87. });
  88. return;
  89. }
  90. if (this.list != null) {
  91. for (var i = 0; i < this.list.length; i++) {
  92. str += this.list[i] + "|";
  93. }
  94. }
  95. uni.request({
  96. url: this.$apiHost + '/Member/uploadPhoto',
  97. data: {
  98. uuid: getApp().globalData.uuid,
  99. imgs: str,
  100. },
  101. header: {
  102. 'content-type': 'application/json'
  103. },
  104. success: (res) => {
  105. console.log("----", res.data);
  106. uni.showToast({
  107. title: res.data.str,
  108. icon: 'none'
  109. });
  110. if (res.data.success == "yes") {
  111. setTimeout(()=>{
  112. uni.navigateBack(1)
  113. },1500)
  114. }
  115. }
  116. });
  117. },
  118. delImg(img) {
  119. if (this.list != null) {
  120. let list2 = [];
  121. for (var i = 0; i < this.list.length; i++) {
  122. if (img != this.list[i]) {
  123. list2.push(this.list[i]);
  124. }
  125. }
  126. this.list = list2;
  127. }
  128. },
  129. upload() {
  130. console.log("----upload");
  131. var that = this;
  132. if (this.list.length >= this.maxImageCount) {
  133. uni.showToast({
  134. title: "最多上传5张图片",
  135. icon: 'none'
  136. });
  137. return;
  138. }
  139. let count = this.maxImageCount - this.list.length
  140. uni.chooseImage({
  141. count,
  142. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  143. sourceType: ['album', 'camera'], //从相册、相机选择
  144. extension: ['.png', '.jpeg', '.jpg'],
  145. success: function(res) {
  146. console.log('res:', res)
  147. uni.showLoading({})
  148. if (res.tempFilePaths.length > 0) {
  149. for (var i = 0; i < res.tempFilePaths.length; i++) {
  150. const tempFilePaths = res.tempFilePaths[i];
  151. console.log('tempFilePaths:', tempFilePaths);
  152. // 图片上传
  153. const uploadTask = uni.uploadFile({
  154. url: that.$apiHost + '/Xweb/upload_img?skey=' + that.skey,
  155. filePath: tempFilePaths,
  156. name: 'file',
  157. success: function(uploadFileRes) {
  158. let resdata = JSON.parse(uploadFileRes.data)
  159. if (resdata.success == 'yes') {
  160. that.list.push(resdata.url);
  161. }
  162. },
  163. fail: function(uploadFileFail) {
  164. console.log('Error:', uploadFileFail.data);
  165. },
  166. complete: () => {
  167. console.log('Complete:');
  168. if (i >= res.tempFilePaths.length - 1) {
  169. uni.hideLoading()
  170. }
  171. }
  172. });
  173. }
  174. setTimeout(function() {
  175. uni.hideLoading()
  176. }, 20000);
  177. }
  178. },
  179. error: function(e) {
  180. console.log(e);
  181. }
  182. });
  183. },
  184. }
  185. }
  186. </script>
  187. <style scoped lang="scss">
  188. @import 'managePhoto.scss';
  189. </style>