editCase.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="caseDetail">
  3. <uni-menubar title="编辑" />
  4. <tm-sheet :padding="[0,20]" :margin="[0,20]">
  5. <tm-form @submit="submit" ref="formData" @request="success" method="post">
  6. <tm-input name="name" required title="案例标题" v-model="form.name"></tm-input>
  7. <picker @change="bindPickerChange" :value="form.cate_id" range-key="name" :range="cateList">
  8. <tm-input required title="选择分类" placeholder="请选择分类" disabled
  9. :value="form.cate_id ? cateList.find(v=>v.id == form.cate_id)['name'] : '请选择分类'"></tm-input>
  10. </picker>
  11. <view class="py-12 px-24 mx-12 round-3 border-b-1 grey text">
  12. <text class="text-size-n text-weight-b ">上传封面图片</text>
  13. <text class="text-grey text-size-xs px-10">(最多可以上传1张)</text>
  14. </view>
  15. <view class="py-32 mx-12">
  16. <tm-upload ref="upload" :code="200" :max="1" :tips="false" :grid="4"
  17. url="https://cardoa.platomix.net/api/upload" url-key="data" :auto-upload="true" :header="header"
  18. :filelist.sync="form.path"></tm-upload>
  19. </view>
  20. <view class="py-12 px-24 mx-12 round-3 border-b-1 grey text flex flex-between">
  21. <text class="text-size-n text-weight-b">图片列表(点击图片可编辑)</text>
  22. <tm-button theme="bg-gradient-blue-accent" size="m" @click="addImage">添加图片</tm-button>
  23. </view>
  24. <view style="height: 20rpx;"></view>
  25. <view v-if="list.length" class="py-12 mx-12 round-3 border-b-1 grey text" style="font-size: 24rpx;"
  26. theme="bg-gradient-blue-accent" block @click="disabledGrid=!disabledGrid">
  27. {{disabledGrid ? '长按图片拖动排序' : '关闭排序'}}
  28. </view>
  29. <tm-dragGrid v-if="list.length" :disabled="disabledGrid" @change="changeList" :list="list">
  30. <template v-slot:default="{item}">
  31. <view @click="editImage(item)" @longpress="disabledGrid=!disabledGrid">
  32. <tm-images :width="150" :height="100" :previmage="false" :src="item.path"></tm-images>
  33. <view @click.stop="delitem(item)" style="position: absolute;right: 5px;top: -20rpx;">
  34. <tm-icons color="red" :size="20" name="icon-minus-circle-fill"></tm-icons>
  35. </view>
  36. </view>
  37. </template>
  38. </tm-dragGrid>
  39. <view class="flex flex-between" style="width: 80%;margin: 0 auto;">
  40. <tm-button theme="red" @click="del">删除</tm-button>
  41. <tm-button theme="blue" navtie-type="form">保存</tm-button>
  42. </view>
  43. </tm-form>
  44. <tm-dialog v-if="editShow" v-model="editShow" title="编辑图片" confirmText="保存" @confirm="saveImage">
  45. <tm-input title="图片名称" v-model="editForm.name"></tm-input>
  46. <view class="py-12 px-24 mx-12 round-3 border-b-1 grey text">
  47. <text class="text-size-n text-weight-b ">上传封面图片</text>
  48. <text class="text-grey text-size-xs px-10">(最多可以上传1张)</text>
  49. </view>
  50. <view class="py-32 mx-12">
  51. <tm-upload ref="upload" :code="200" :max="1" :grid="1" url="https://cardoa.platomix.net/api/upload"
  52. url-key="data" :auto-upload="true" :header="header" :filelist.sync="editForm.path"></tm-upload>
  53. </view>
  54. </tm-dialog>
  55. </tm-sheet>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. form: {
  63. path: []
  64. },
  65. list: [],
  66. cateList: [],
  67. disabledGrid: true,
  68. editShow: false,
  69. editForm: {
  70. path: [],
  71. name: ''
  72. },
  73. header: {
  74. 'Authorization': uni.getStorageSync('token'),
  75. 'Content-Type': 'multipart/form-data'
  76. }
  77. }
  78. },
  79. onLoad(option) {
  80. this.$tm.request.post('album/cate').then(res => {
  81. this.cateList = res.data
  82. })
  83. if (option.album_id) {
  84. this.album_id = option.album_id
  85. this.init()
  86. this.piclist()
  87. }
  88. },
  89. methods: {
  90. piclist() {
  91. this.$tm.request.post('album/piclist', {
  92. album_id: this.album_id
  93. }).then(res => {
  94. this.list = res.data
  95. })
  96. },
  97. init() {
  98. this.$tm.request.post('album/detail', {
  99. album_id: this.album_id
  100. }).then(res => {
  101. this.form = res.data
  102. this.form.path = [this.form.path]
  103. })
  104. },
  105. del(e) {
  106. let that = this
  107. console.log(this.form);
  108. uni.showModal({
  109. title: '提示',
  110. content: '是否永久删除',
  111. success(res) {
  112. if (res.confirm) {
  113. that.$tm.request.post('album/update', {
  114. id: that.form.id,
  115. isdel: true,
  116. }).then(res => {
  117. uni.navigateBack()
  118. })
  119. } else if (res.cancel) {}
  120. }
  121. });
  122. },
  123. bindPickerChange(o) {
  124. this.form.cate_id = this.cateList[o.detail.value].id
  125. },
  126. changeList(e) {
  127. this.list = e.map(v => {
  128. v.data.sort = v.sort
  129. return v.data
  130. })
  131. },
  132. submit(e) {
  133. this.form.path = this.form.path[0]
  134. this.$tm.request.post('album/update', this.form).then(res => {
  135. uni.navigateBack()
  136. })
  137. this.$tm.request.post('album/batchsort', {
  138. list: this.list,
  139. album_id: this.album_id
  140. }).then(res => {
  141. uni.navigateBack()
  142. })
  143. console.log(this.list);
  144. },
  145. delitem(e) {
  146. let that = this
  147. uni.showModal({
  148. title: '提示',
  149. content: '是否永久删除',
  150. success(res) {
  151. if (res.confirm) {
  152. that.$tm.request.post('album/picupdate', {
  153. isdel: true,
  154. id: e.id,
  155. album_id: that.form.id,
  156. path: e.path
  157. }).then(resdata => {
  158. that.list.splice(that.list.findIndex(v => v.id == e.id), 1)
  159. })
  160. } else if (res.cancel) {}
  161. }
  162. });
  163. },
  164. editImage(e) {
  165. this.editShow = true
  166. this.editForm = e
  167. this.editForm.path = [e.path]
  168. },
  169. saveImage() {
  170. this.$tm.request.post('album/picupdate', {
  171. id: this.editForm.id,
  172. name: this.editForm.name,
  173. album_id: this.form.id,
  174. path: this.editForm.path[0]
  175. }).then(resdata => {
  176. this.piclist()
  177. })
  178. },
  179. addImage() {
  180. let that = this
  181. uni.chooseImage({
  182. count: 9, //默认9
  183. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  184. success: function(res) {
  185. const tempFilePaths = res.tempFilePaths;
  186. tempFilePaths.forEach(item => {
  187. uni.showToast({
  188. title: '上传中',
  189. icon: "none"
  190. });
  191. uni.uploadFile({
  192. url: 'https://cardoa.platomix.net/api/upload', //仅为示例,非真实的接口地址
  193. filePath: item,
  194. name: 'file',
  195. header: that.header,
  196. success: (uploadFileRes) => {
  197. let img = JSON.parse(uploadFileRes.data)
  198. that.$tm.request.post('album/picupdate', {
  199. album_id: that.form.id,
  200. path: img.data
  201. }).then(resdata => {
  202. uni.hideToast();
  203. that.list.push(resdata.data)
  204. })
  205. }
  206. });
  207. })
  208. }
  209. });
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang="scss" scoped>
  215. </style>