default.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <view class="align-center justify-between wrap">
  5. <view class="add-img" @tap="chooseImage">
  6. <image src="/static/images/user/add_picture_icon24.png" class="w40 h40"></image>
  7. </view>
  8. <!-- <view class="img" v-for="(item,index) in imgList" :key="index" @tap="viewImage" :data-url="imgList[index]">
  9. <image :src="item"></image>
  10. <image class="close-img" src="@/static/images/close32.png" mode="" @tap.stop="delImg" :data-index="index"></image>
  11. <view class="text">
  12. <view class="title">体检报告</view>
  13. <view class="time">2021-04-21</view>
  14. </view>
  15. </view> -->
  16. <view class="img" v-for="(item,index) in dataList" :key="index" @tap="viewImage" :data-url="dataList[index]" @longpress="cancel(item)">
  17. <image :src="item.url" ></image>
  18. <!-- <image class="close-img" src="@/static/images/close32.png" mode="" @tap.stop="delImg" :data-index="index"></image> -->
  19. <view class="text">
  20. <view class="title">体检报告</view>
  21. <view class="time">{{utils.timeFormat(item.createTime,'yyyy-mm-dd')}}</view>
  22. </view>
  23. </view>
  24. <view class="img"></view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. addAttachment,addUrl,
  32. getAttachment,deleteAttachment
  33. } from '@/api/companyUser.js'
  34. export default {
  35. data() {
  36. return {
  37. curDate: '',
  38. markDays: [],
  39. type: null,
  40. patientId: null,
  41. famaleurl: "/static/images/health/female_profile.png",
  42. maleurl: "/static/images/health/my_heads.png",
  43. checked: 1,
  44. dataList:[],
  45. imgList:[],
  46. photos:[],
  47. list:[]
  48. };
  49. },
  50. onLoad(option) {
  51. console.log(option)
  52. if(option.id){
  53. this.parentId=option.id
  54. uni.setNavigationBarTitle({
  55. title: option.fileName
  56. });
  57. this.getAttachment()
  58. }
  59. },
  60. methods: {
  61. //日历
  62. onDayClick(data) {
  63. this.curDate = data.date;
  64. },
  65. navgetTo() {
  66. uni.navigateTo({
  67. url: '/pages_user/user/addIndicator'
  68. })
  69. },
  70. getAttachment() {
  71. let data = {
  72. parentId:this.parentId,
  73. pageNum: 1,
  74. pageSize: 100
  75. }
  76. getAttachment(data).then(
  77. res => {
  78. if (res.code == 200) {
  79. this.dataList = res.data.list
  80. this.list=res.data.list.map(item=>item.url)
  81. } else {
  82. uni.showToast({
  83. icon: 'none',
  84. title: res.msg,
  85. });
  86. }
  87. },
  88. rej => {}
  89. );
  90. },
  91. cancel(item){
  92. var that=this
  93. uni.showModal({
  94. title: '提示',
  95. content: '确定删除文件吗',
  96. success: function (res) {
  97. if (res.confirm) {
  98. deleteAttachment(item.attachmentId).then(res => {
  99. if(res.code==200){
  100. uni.showToast({
  101. icon:'success',
  102. title: '删除成功!',
  103. });
  104. uni.$emit('refreshMyFolder');
  105. that.getAttachment()
  106. }else{
  107. uni.showToast({
  108. icon:'none',
  109. title: res.msg,
  110. });
  111. }
  112. });
  113. }
  114. else if (res.cancel) {
  115. }
  116. }
  117. });
  118. },
  119. // 选择上传的图片
  120. chooseImage() {
  121. console.log('图片')
  122. var that = this;
  123. uni.showActionSheet({
  124. itemList: ['相册', '拍照'],
  125. success: function(res) {
  126. if (res.tapIndex == 0) {
  127. //从相册选择
  128. that.chooseImageFunction('album')
  129. } else if (res.tapIndex == 1) {
  130. //拍照
  131. that.chooseImageFunction('camera')
  132. }
  133. },
  134. fail: function(res) {
  135. }
  136. });
  137. },
  138. chooseImageFunction: function(type) {
  139. var that = this;
  140. uni.chooseImage({
  141. count:10, // 默认9
  142. sourceType: [type],
  143. success: (res) => {
  144. console.log(res,'res')
  145. uni.uploadFile({
  146. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
  147. filePath: res.tempFilePaths[0],
  148. name: 'file',
  149. formData: {
  150. 'user': 'test' // 上传附带参数
  151. },
  152. success: (uploadFileRes) => {
  153. console.log(uploadFileRes.data,'data')
  154. if (this.imgList.length != 0) {
  155. this.imgList = this.imgList.concat(res.tempFilePaths)
  156. } else {
  157. this.imgList = res.tempFilePaths
  158. }
  159. this.photos=this.photos.concat(JSON.parse(uploadFileRes.data).url)
  160. this.addAttachment()
  161. }
  162. });
  163. }
  164. });
  165. },
  166. addAttachment(){
  167. var data={
  168. type:1,
  169. urlList:this.photos,
  170. parentId:this.parentId
  171. }
  172. addUrl(data).then(
  173. res => {
  174. if (res.code == 200) {
  175. uni.showToast({
  176. icon: 'success',
  177. title: "操作成功",
  178. });
  179. uni.$emit('refreshMyFolder');
  180. this.getAttachment()
  181. } else {
  182. uni.showToast({
  183. icon: 'none',
  184. title: res.msg,
  185. });
  186. }
  187. },
  188. rej => {}
  189. );
  190. },
  191. // 查看图片
  192. viewImage(e) {
  193. var data=e.currentTarget.dataset.url
  194. // console.log(data.url,'url')
  195. uni.previewImage({
  196. urls: this.list,
  197. current: data.url
  198. });
  199. },
  200. // 删除上传的图片
  201. delImg(e) {
  202. var that = this;
  203. uni.showModal({
  204. title: '提示',
  205. content: '确定要删除照片吗?',
  206. cancelText: '取消',
  207. confirmText: '确定',
  208. success: res => {
  209. if (res.confirm) {
  210. that.imgList.splice(e.currentTarget.dataset.index, 1)
  211. this.photos.splice(e.currentTarget.dataset.index, 1);
  212. }
  213. },
  214. })
  215. },
  216. // 出生日期选择
  217. bindDateChange: function(e) {
  218. this.form.birthday = e.target.value
  219. },
  220. }
  221. }
  222. </script>
  223. <style lang="scss">
  224. page {
  225. height: 100%;
  226. background: #fff;
  227. }
  228. .content {
  229. height: 100%;
  230. display: flex;
  231. flex-direction: column;
  232. justify-content: space-between;
  233. .top-fixed {
  234. position: absolute;
  235. top: 0;
  236. background: #FFFFFF;
  237. padding: 20rpx;
  238. width: 100%;
  239. box-sizing: border-box;
  240. }
  241. .inner {
  242. // height: calc(100% - 120upx);
  243. padding:20upx;
  244. // padding-top: 110rpx;
  245. .add-img{
  246. width: 226rpx;
  247. height: 264rpx;
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. background: #F5F7FA;
  252. border-radius: 16rpx 16rpx 16rpx 16rpx;
  253. margin-bottom:20rpx ;
  254. }
  255. .img{
  256. width: 226rpx;
  257. height: 264rpx;
  258. border-radius:16rpx;
  259. overflow: hidden;
  260. position: relative;
  261. margin-bottom:20rpx ;
  262. image{
  263. width: 100%;
  264. height: 100%;
  265. }
  266. .close-img{
  267. width: 32upx;
  268. height: 32upx;
  269. position: absolute;
  270. top:2upx;
  271. right: 2upx;
  272. }
  273. .text{
  274. position: absolute;
  275. bottom: 0;
  276. z-index: 9;
  277. display: flex;
  278. flex-direction: column;
  279. align-items: flex-start;
  280. width: 100%;
  281. padding: 20rpx;
  282. box-sizing: border-box;
  283. .title{
  284. font-family: PingFang SC, PingFang SC;
  285. font-weight: 500;
  286. font-size: 28rpx;
  287. color: #FFFFFF;
  288. text-align: left;
  289. }
  290. .time{
  291. font-weight: 400;
  292. font-size: 22rpx;
  293. color: #FFFFFF;
  294. text-align: left;
  295. }
  296. }
  297. }
  298. }
  299. }
  300. </style>