index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <QStemplate :title="title" :titleHide="titleHide" :fontSize="fontSize" :width="width" :titleFlex="titleFlex"
  3. :contentFlex="contentFlex" :titleStyle="titleStyle" :contentStyle="contentStyle" :required="required" :requiredSign="requiredSign"
  4. :layout="layout" :titleLayout="titleLayout" :itemDisabled="itemDisabled" :titleColor="titleColor">
  5. <view class="width100 padding_10rpx_15rpx wrap" :class="itemLayout_computed">
  6. <view
  7. class="flex_column_c_c border_radius_4px transition_border_point6s padding_10rpx"
  8. v-for="(picsItem, picsIndex) in itemArray"
  9. :key="picsIndex">
  10. <view
  11. class="flex_row_c_c border1pxf2f2f2 position_relative border_radius_4px backgrounColor_f8f8f8 picsBox"
  12. @tap="chooseImg"
  13. :data-picsindex="picsIndex"
  14. :data-customtapid="picsItem.customTapId">
  15. <image :src="itemArray[picsIndex].path"
  16. class="border_radius_4px box_shadow_2px_2px_5px_ADADAD picsBox" mode="aspectFill" v-if="itemArray[picsIndex].path"
  17. @tap.stop.prevent="showImg" :data-picsindex="picsIndex">
  18. </image>
  19. <view v-else>
  20. <uni-icon type="image" :size="45" color="#999999" />
  21. </view>
  22. <view class="picsClear" v-if="itemArray[picsIndex].path"
  23. @tap.stop.prevent="clearPic" :data-picsindex="picsIndex">
  24. <uni-icon type="clear" :color="picsItem.clearColor||clearColor||'#f5105c'" :size="34" />
  25. </view>
  26. </view>
  27. <view class="flex_row_c_c fontColorADADAD picsItemTitle" v-if="picsItem.title">
  28. <view class="requiredSign" v-if="picsItem.required">{{requiredSign}}</view>{{picsItem.title}}
  29. </view>
  30. </view>
  31. </view>
  32. </QStemplate>
  33. </template>
  34. <script>
  35. import _app from '../../js/app.js';
  36. import QStemplate from '../../template/template.vue';
  37. import QSInputsMixin from '../../js/QSInputsMixin.js';
  38. import uniIcon from '../../uniIcons/uni-icons.vue';
  39. export default {
  40. components: {
  41. QStemplate,
  42. uniIcon
  43. },
  44. props: {
  45. clearColor: {
  46. type: String,
  47. default: '#f5105c'
  48. }
  49. },
  50. data() {
  51. let itemArray;
  52. if(this.value && this.value instanceof Array && this.value.length > 0) {
  53. itemArray = this.value;
  54. }else{
  55. itemArray = [];
  56. }
  57. return {
  58. itemArray,
  59. upLoadData: null
  60. }
  61. },
  62. methods: {
  63. chooseImg(
  64. {currentTarget: { dataset: { picsindex, infinite, customtapid } } } = {}
  65. ) {
  66. if(this.itemArray[picsindex].path) return;
  67. if(customtapid) {
  68. this.$emit('picsTap', {
  69. title: this.title,
  70. variableName: this.variableName,
  71. picsIndex: picsindex,
  72. customTapId: customtapid
  73. });
  74. }else{
  75. uni.chooseImage({
  76. success: res => {
  77. this.$set(this.itemArray[picsindex], 'path', res.tempFilePaths[0]);
  78. this.setValue(this.itemArray);
  79. }
  80. })
  81. }
  82. },
  83. clearPic(
  84. {currentTarget: { dataset: { picsindex } } } = {}
  85. ) {
  86. if(this.itemArray[picsindex].path) {
  87. this.itemArray[picsindex].path = '';
  88. this.setValue(this.itemArray);
  89. }
  90. },
  91. showImg(
  92. {currentTarget: { dataset: { picsindex } } } = {}
  93. ) {
  94. _app.previewImage(this.itemArray.map(item=>item.path), picsindex);
  95. },
  96. setData(newArr) {
  97. this.itemArray = newArr;
  98. this.setValue(this.itemArray);
  99. },
  100. setUpLoadData(obj) {
  101. this.upLoadData = obj;
  102. },
  103. getUpLoadPromiseArray() {
  104. return _app.getUpLoadPromiseArray({
  105. itemArray: [...this.itemArray],
  106. customId: this.customId,
  107. upLoadData: this.upLoadData
  108. });
  109. }
  110. },
  111. mixins: [QSInputsMixin({
  112. QSInputsType: _app.typeObj.pics
  113. })]
  114. };
  115. </script>
  116. <style scoped>
  117. @import url("../../css/inputs.css");
  118. @import url("../../config/css/picsAndInfinitePics.css");
  119. </style>