collectionEdit.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="es-pt-24 es-pl-24 es-pr-24 es-pb-24">
  3. <u--form ref="uForm" :rules="rules" :model="form" labelPosition="top" labelWidth="auto" errorType="toast">
  4. <view class="box">
  5. <u-form-item required label="合集图片" prop="name">
  6. <view class="upload" @tap="chooseImage">
  7. <u-icon class="upload-icon" name="plus" size="40" v-if="!form.coverUrl"></u-icon>
  8. <image :src="form.coverUrl" v-else mode=""></image>
  9. </view>
  10. </u-form-item>
  11. </view>
  12. <view class="box">
  13. <u-form-item required label="合集名称" prop="name">
  14. <u--textarea style="padding: 9px 0;" v-model="form.title" border="none"
  15. placeholder="一个好的合集名称,更能吸引人哦~" autoHeight count maxlength="20"></u--textarea>
  16. </u-form-item>
  17. </view>
  18. <view class="box">
  19. <u-form-item label="合集简介" prop="desc">
  20. <u--textarea style="padding: 9px 0;" v-model="form.description" placeholder="简单介绍下你的合集" count
  21. maxlength="50" border="none"></u--textarea>
  22. </u-form-item>
  23. </view>
  24. <view class="box">
  25. <u-form-item label="合集标签" prop="desc">
  26. <u--textarea style="padding: 9px 0;" v-model="form.tags" placeholder="请填写标签,多个用英文逗号隔开" count
  27. maxlength="50" border="none"></u--textarea>
  28. </u-form-item>
  29. </view>
  30. </u--form>
  31. <button class="del-btn" @tap="collectionDel" v-if="form.collectionId">删除合集</button>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. videoCollectionAdd,
  37. videoCollectionUpd,
  38. deleteCollection
  39. } from "@/api/expert.js"
  40. export default {
  41. data() {
  42. return {
  43. form: {
  44. collectionId: '',
  45. title: '',
  46. description: '',
  47. coverUrl: '',
  48. talentId: uni.getStorageSync('expertInfo').talentId || '',
  49. status: 1,
  50. tags: ''
  51. },
  52. rules: {},
  53. }
  54. },
  55. onLoad(option) {
  56. uni.setNavigationBarTitle({
  57. title: '创建合集'
  58. });
  59. const collectionData = uni.getStorageSync('collectionData')
  60. if (collectionData) {
  61. uni.setNavigationBarTitle({
  62. title: '编辑合集'
  63. });
  64. this.form.collectionId = collectionData.collectionId
  65. this.form.title = collectionData.title
  66. this.form.description = collectionData.description || ''
  67. this.form.coverUrl = collectionData.coverUrl || ''
  68. this.form.talentId = collectionData.talentId
  69. this.form.tags = collectionData.tags || ''
  70. }
  71. },
  72. async onNavigationBarButtonTap(e) {
  73. await this.collectionAdd()
  74. },
  75. methods: {
  76. async collectionDel() {
  77. uni.showModal({
  78. title: "删除合集",
  79. content: "合集删除后,合集将不存在,确定要删除吗?",
  80. confirmText: "确定",
  81. confirmColor: "#ff5c03",
  82. success: async (result) => {
  83. console.log(222,this.form.collectionId);
  84. const res = await deleteCollection(this.form.collectionId)
  85. if (res.code == 200) {
  86. uni.showToast({
  87. title: '删除成功!',
  88. })
  89. setTimeout(() => {
  90. uni.navigateBack()
  91. }, 1000)
  92. }
  93. },
  94. })
  95. },
  96. async collectionAdd() {
  97. if (!this.form.coverUrl) {
  98. return uni.showToast({
  99. title: '请上传合集图片!',
  100. icon: 'none'
  101. })
  102. }
  103. if (!this.form.title) {
  104. return uni.showToast({
  105. title: '请填写合集名称!',
  106. icon: 'none'
  107. })
  108. }
  109. let res = ''
  110. if (this.form.collectionId) {
  111. res = await videoCollectionUpd(this.form)
  112. } else {
  113. res = await videoCollectionAdd(this.form)
  114. }
  115. if (res.code == 200) {
  116. uni.showToast({
  117. title: '添加成功!',
  118. })
  119. setTimeout(() => {
  120. uni.navigateBack()
  121. }, 1000)
  122. }else{
  123. uni.showToast({
  124. icon:'none',
  125. title: res.msg,
  126. })
  127. }
  128. },
  129. async chooseImage() {
  130. uni.chooseImage({
  131. count: 1,
  132. sizeType: ['original', 'compressed'],
  133. sourceType: ['album', 'camera'],
  134. success: (res) => {
  135. uni.uploadFile({
  136. url: uni.getStorageSync('requestPath') + '/app/common/uploadOSS',
  137. filePath: res.tempFilePaths[0],
  138. name: 'file',
  139. formData: {
  140. 'user': 'test'
  141. },
  142. success: (uploadFileRes) => {
  143. let data = JSON.parse(uploadFileRes.data)
  144. this.form.coverUrl = data.url;
  145. }
  146. });
  147. }
  148. });
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped lang="scss">
  154. .box {
  155. background-color: #fff;
  156. border-radius: 16rpx;
  157. overflow: hidden;
  158. padding: 0 24rpx 24rpx 42rpx;
  159. margin-bottom: 24rpx;
  160. }
  161. .del-btn {
  162. margin-top: 50rpx;
  163. height: 92rpx;
  164. color: #FF5C03 !important;
  165. border-radius: 12rpx;
  166. font-weight: 400;
  167. font-size: 34rpx;
  168. border: 1px solid #FF5C03;
  169. line-height: 92rpx;
  170. text-align: center;
  171. background-color: transparent !important;
  172. &::after {
  173. border: none;
  174. }
  175. }
  176. .upload {
  177. width: 160rpx;
  178. height: 160rpx;
  179. image {
  180. width: 100%;
  181. height: 100%;
  182. border-radius: 16rpx;
  183. }
  184. }
  185. .upload-icon {
  186. width: 160rpx;
  187. height: 160rpx;
  188. border: 1rpx dashed #999999;
  189. display: flex;
  190. align-items: center;
  191. justify-content: center;
  192. }
  193. </style>