default.vue 6.9 KB

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