detail.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="container">
  3. <unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" :options="options" collection="opendb-feedback" field="content,imgs,contact,mobile" :where="queryWhere" :getone="true" :manual="true">
  4. <view v-if="error">{{error.message}}</view>
  5. <view v-else-if="loading">
  6. <uni-load-more :contentText="loadMore" status="loading"></uni-load-more>
  7. </view>
  8. <view v-else-if="data">
  9. <view>
  10. <text>留言内容/回复内容</text>
  11. <text>{{data.content}}</text>
  12. </view>
  13. <view>
  14. <text>图片列表</text>
  15. <template v-for="(file, j) in data.imgs">
  16. <uni-file-picker v-if="file.fileType == 'image'" :value="file" :file-mediatype="file.fileType" return-type="object" readonly></uni-file-picker>
  17. <uni-link v-else :href="file.url" :text="file.url"></uni-link>
  18. </template>
  19. </view>
  20. <view>
  21. <text>联系人</text>
  22. <text>{{data.contact}}</text>
  23. </view>
  24. <view>
  25. <text>联系电话</text>
  26. <text>{{data.mobile}}</text>
  27. </view>
  28. </view>
  29. </unicloud-db>
  30. <view class="btns">
  31. <button type="primary" @click="handleUpdate">修改</button>
  32. <button type="warn" class="btn-delete" @click="handleDelete">删除</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. // 由schema2code生成,包含校验规则和enum静态数据
  38. import { enumConverter } from '../../js_sdk/validator/opendb-feedback.js';
  39. export default {
  40. data() {
  41. return {
  42. queryWhere: '',
  43. loadMore: {
  44. contentdown: '',
  45. contentrefresh: '',
  46. contentnomore: ''
  47. },
  48. options: {
  49. // 将scheme enum 属性静态数据中的value转成text
  50. ...enumConverter
  51. }
  52. }
  53. },
  54. onLoad(e) {
  55. this._id = e.id
  56. },
  57. onReady() {
  58. if (this._id) {
  59. this.queryWhere = '_id=="' + this._id + '"'
  60. }
  61. },
  62. methods: {
  63. handleUpdate() {
  64. // 打开修改页面
  65. uni.navigateTo({
  66. url: './edit?id=' + this._id,
  67. events: {
  68. // 监听修改页面成功修改数据后, 刷新当前页面数据
  69. refreshData: () => {
  70. this.$refs.udb.loadData({
  71. clear: true
  72. })
  73. }
  74. }
  75. })
  76. },
  77. handleDelete() {
  78. this.$refs.udb.remove(this._id, {
  79. success: (res) => {
  80. // 删除数据成功后跳转到list页面
  81. uni.navigateTo({
  82. url: './list'
  83. })
  84. }
  85. })
  86. }
  87. }
  88. }
  89. </script>
  90. <style>
  91. .container {
  92. padding: 10px;
  93. }
  94. .btns {
  95. margin-top: 10px;
  96. /* #ifndef APP-NVUE */
  97. display: flex;
  98. /* #endif */
  99. flex-direction: row;
  100. }
  101. .btns button {
  102. flex: 1;
  103. }
  104. .btn-delete {
  105. margin-left: 10px;
  106. }
  107. </style>