videoForm.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="container">
  3. <u-cell-group class="form-info" :border="false">
  4. <u-field label="视频名称" placeholder="请输入视频名称" label-width="180" v-model="videoInfo.videoName">
  5. <u-button v-if="type == 'edit'" size="mini" slot="right" type="success" @click="goToVideo">预览</u-button>
  6. </u-field>
  7. <u-cell-item title="请上传视频" :arrow="false" v-if="type == 'add'">
  8. <view slot="label">
  9. <image class="video-img" :src="videoImg" v-show="videoImg" @tap="chooseVideoImage"></image>
  10. <view class="upload-video" @tap="chooseVideoImage" v-if="!videoImg">
  11. <u-icon name="plus" size="40" v-if="!videoInfo.mediaFilePath"></u-icon>
  12. <view class="u-add-tips" style="margin-top: 6px;text-align: center;">{{videoInfo.mediaFilePath ? '上传成功,单击替换视频' : '选择视频'}}</view>
  13. </view>
  14. </view>
  15. </u-cell-item>
  16. <u-cell-item title="请上传视频海报" :arrow="false" v-if="type == 'add'">
  17. <view slot="label">
  18. <u-upload :action="uploadUrl" :file-list="defaultList" :form-data="uploadData" @on-success="uploadSuccess"
  19. @on-error="uploadError" @on-remove="uploadRemove" max-count="1"></u-upload>
  20. </view>
  21. </u-cell-item>
  22. <u-cell-item title="绑定商品(可多选)" @click="popupShow = true" class="good-arrow">
  23. <view slot="label">
  24. <view class="good-card" v-for="(item, index) in goodList.filter(site => site.check)" :key="index">
  25. <image class="goods-img" :src="item.imgPath"></image>
  26. <view class="good-info">
  27. <view class="good-name">{{item.productName}}</view>
  28. <view class="good-text">销量:{{item.sellCount}}</view>
  29. <view class="good-price">
  30. <text class="goods-spec">¥{{item.bizPrice}}/{{item.unit}}</text>
  31. <text class="goods-original">原价:{{item.originalPrice}}</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </u-cell-item>
  37. </u-cell-group>
  38. <view class="form-handle">
  39. <u-button type="success" shape="circle" :ripple="true" @click="submitData" :disabled="getPermit()" class="handle-custom">提交</u-button>
  40. </view>
  41. <u-popup v-model="popupShow" mode="bottom" closeable border-radius="30">
  42. <scroll-view scroll-y="true" class="good-select-box">
  43. <view class="select-good-row" v-for="(item, index) in goodList" :key="index" @click="setCheck(item)">
  44. <view class="good-check">
  45. <view class="iconfont" :class="item.check ? 'iconqueding' : 'iconfeigouxuan'"></view>
  46. </view>
  47. <view class="good-card" style="width: calc(100% - 60px);">
  48. <image class="goods-img" :src="item.imgPath"></image>
  49. <view class="good-info">
  50. <view class="good-name">{{item.productName}}</view>
  51. <view class="good-text">销量:{{item.sellCount}}</view>
  52. <view class="good-price">
  53. <text class="goods-spec">¥{{item.bizPrice}}/{{item.unit}}</text>
  54. <text class="goods-original">原价:{{item.originalPrice}}</text>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </scroll-view>
  60. <view class="good-select-custom-box">
  61. <u-button type="success" shape="circle" :ripple="true" @click="popupShow = false" class="good-select-custom">确认</u-button>
  62. </view>
  63. </u-popup>
  64. <u-top-tips ref="uTips"></u-top-tips>
  65. </view>
  66. </template>
  67. <script>
  68. const NET = require('@/utils/request')
  69. const API = require('@/config/api')
  70. export default {
  71. data() {
  72. return {
  73. type: 'add',
  74. videoId: '',
  75. videoInfo: {
  76. videoName: '',
  77. mediaFilePath: '',
  78. },
  79. productIds: '',
  80. videoImg: '',
  81. uploadData: {
  82. folderId: 0,
  83. },
  84. uploadUrl: '',
  85. fileList: [],
  86. defaultList: [],
  87. goodList: [],
  88. popupShow: false,
  89. }
  90. },
  91. onLoad(options) {
  92. this.uploadUrl = API.uploadFile
  93. this.type = options.type
  94. if (this.type == 'edit') {
  95. this.videoInfo.videoId = options.videoId
  96. this.getDetail()
  97. }
  98. NET.request(API.getVideoGoods, {}, 'GET').then(res => {
  99. res.data.forEach(site => {
  100. site.check = this.productIds && this.productIds.indexOf(site.productId) != -1 ? true : false
  101. })
  102. this.goodList = res.data
  103. }).catch(res => {
  104. this.$refs.uTips.show({
  105. title: '获取可绑定商品失败',
  106. type: 'warning',
  107. })
  108. })
  109. },
  110. onReady() {},
  111. methods: {
  112. // 切换选择状态
  113. setCheck(item) {
  114. item.check = !item.check
  115. },
  116. // 上传视频
  117. chooseVideoImage() {
  118. uni.chooseVideo({
  119. count: 1,
  120. sourceType: ['camera', 'album'],
  121. success: (res) => {
  122. console.log(res)
  123. this.videoImg = res.thumbTempFilePath
  124. uni.uploadFile({
  125. url: API.uploadFile,
  126. filePath: res.tempFilePath,
  127. name: 'file',
  128. formData: this.uploadData,
  129. success: (uploadFileRes) => {
  130. let resData = JSON.parse(uploadFileRes.data)
  131. this.videoInfo.mediaFilePath = resData.data.url
  132. this.$refs.uTips.show({
  133. title: '文件上传成功',
  134. type: 'success',
  135. })
  136. }
  137. });
  138. }
  139. });
  140. },
  141. // 获取详情
  142. getDetail() {
  143. NET.request(API.getVideoDetail, {
  144. videoId: this.videoInfo.videoId
  145. }, 'GET').then(res => {
  146. this.videoInfo.videoName = res.data.videoName
  147. res.data.products = res.data.products.map(site => {
  148. return site.productId
  149. }).join(',')
  150. if (this.goodList.length && res.data.products) {
  151. this.goodList.forEach(site => {
  152. site.check = res.data.products.indexOf(site.productId) != -1
  153. })
  154. } else {
  155. this.productIds = res.data.products ? res.data.products : []
  156. }
  157. }).catch(res => {
  158. this.$refs.uTips.show({
  159. title: '获取详情失败',
  160. type: 'warning',
  161. })
  162. })
  163. },
  164. // 文件上传成功回调
  165. uploadSuccess(res, index, lists, name) {
  166. this.fileList.push(res.data.url)
  167. this.$refs.uTips.show({
  168. title: '文件上传成功',
  169. type: 'success',
  170. })
  171. return true
  172. },
  173. // 文件上传失败回调
  174. uploadError(res, index, lists, name) {
  175. this.$refs.uTips.show({
  176. title: '文件上传失败',
  177. type: 'warning',
  178. })
  179. },
  180. // 移除文件回调
  181. uploadRemove(index, lists, name) {
  182. this.fileList.splice(index, 1)
  183. },
  184. // 检查必填项
  185. getPermit() {
  186. if (!this.videoInfo.videoName || !this.goodList.filter(site => site.check).length) {
  187. return true
  188. }
  189. if (this.type == 'add' && (!this.videoInfo.mediaFilePath || !this.fileList.length)) {
  190. return true
  191. }
  192. return false
  193. },
  194. // 提交
  195. submitData() {
  196. if (this.type == 'add') {
  197. NET.request(API.addVideo, {
  198. ...this.videoInfo,
  199. coverFilePath: this.fileList[0],
  200. coverFileId: 0,
  201. mediaFileId: 0,
  202. productIds: this.goodList.filter(site => site.check).map(site => {
  203. return site.productId
  204. })
  205. }, 'POST').then(res => {
  206. this.$refs.uTips.show({
  207. title: '新增短视频成功',
  208. type: 'success',
  209. })
  210. setTimeout(() => {
  211. uni.navigateBack()
  212. }, 1000)
  213. }).catch(res => {
  214. this.$refs.uTips.show({
  215. title: '新增短视频失败',
  216. type: 'warning',
  217. })
  218. })
  219. } else {
  220. NET.request(API.editVideo, {
  221. ...this.videoInfo,
  222. productIds: this.goodList.filter(site => site.check).map(site => {
  223. return site.productId
  224. })
  225. }, 'POST').then(res => {
  226. this.$refs.uTips.show({
  227. title: '编辑短视频成功',
  228. type: 'success',
  229. })
  230. setTimeout(() => {
  231. uni.navigateBack()
  232. }, 1000)
  233. }).catch(res => {
  234. this.$refs.uTips.show({
  235. title: '编辑短视频失败',
  236. type: 'warning',
  237. })
  238. })
  239. }
  240. },
  241. goToVideo() {
  242. uni.navigateTo({
  243. url: '/pagesMedia/videoDetail?videoId=' + this.videoInfo.videoId
  244. });
  245. }
  246. },
  247. }
  248. </script>
  249. <style lang="less" scoped>
  250. page {
  251. width: 100%;
  252. height: 100%;
  253. }
  254. .container {
  255. width: 100%;
  256. height: 100%;
  257. float: left;
  258. box-sizing: border-box;
  259. padding-bottom: 60px;
  260. overflow-y: auto;
  261. .form-info {
  262. width: 100%;
  263. float: left;
  264. /deep/.u-label-text {
  265. color: #333333;
  266. }
  267. /deep/.u-cell_title {
  268. color: #333333;
  269. }
  270. .video-img {
  271. width: 100px;
  272. height: 100px;
  273. border-radius: 5px;
  274. object-fit: cover;
  275. }
  276. .upload-video {
  277. width: 100px;
  278. height: 100px;
  279. background: #f4f5f6;
  280. margin: 5px;
  281. color: #606266;
  282. display: flex;
  283. justify-content: center;
  284. align-items: center;
  285. flex-direction: column;
  286. }
  287. .good-arrow {
  288. /deep/.u-cell__right-icon-wrap {
  289. position: absolute;
  290. top: 18px;
  291. right: 10px;
  292. }
  293. /deep/.u-cell_title {
  294. width: calc(100% - 10px) !important;
  295. }
  296. }
  297. }
  298. .form-handle {
  299. width: 100%;
  300. height: 60px;
  301. position: fixed;
  302. z-index: 10;
  303. padding: 10px 15px 20px 15px;
  304. box-sizing: border-box;
  305. bottom: 0;
  306. background-color: #FFFFFF;
  307. border-top: 1px solid #EEEEEE;
  308. .handle-custom {
  309. background-color: #51A539;
  310. /deep/button {
  311. background-color: #56a83a;
  312. }
  313. /deep/.u-btn--success--disabled {
  314. background-color: #74bd60 !important;
  315. }
  316. }
  317. }
  318. .good-select-box {
  319. width: 100%;
  320. height: 400px;
  321. float: left;
  322. overflow-y: auto;
  323. padding: 40px 0 10px 0;
  324. }
  325. .good-select-custom-box {
  326. width: calc(100% - 30px);
  327. margin: 10px 15px;
  328. float: left;
  329. .good-select-custom {
  330. background-color: #51A539;
  331. /deep/button {
  332. background-color: #56a83a;
  333. }
  334. }
  335. }
  336. .select-good-row {
  337. width: 100%;
  338. height: 114px;
  339. float: left;
  340. }
  341. .good-check {
  342. width: 30px;
  343. height: 104px;
  344. float: left;
  345. line-height: 104px;
  346. margin-right: 10px;
  347. .iconfont {
  348. font-size: 40px;
  349. text-align: right;
  350. color: #51A539;
  351. }
  352. }
  353. .good-card {
  354. width: 100%;
  355. float: left;
  356. margin: 5px;
  357. background: #FFFFFF;
  358. border-radius: 15px;
  359. box-shadow: 0px 1px 5px 0px rgba(102, 102, 102, 0.43);
  360. padding: 12px;
  361. box-sizing: border-box;
  362. .goods-img {
  363. width: 80px;
  364. height: 80px;
  365. float: left;
  366. border-radius: 10px;
  367. object-fit: cover;
  368. }
  369. .good-info {
  370. width: calc(100% - 86px);
  371. height: 80px;
  372. float: right;
  373. .good-name {
  374. width: 100%;
  375. height: 40px;
  376. float: left;
  377. font-size: 15px;
  378. font-family: PingFang SC;
  379. color: #333333;
  380. line-height: 20px;
  381. overflow: hidden;
  382. text-overflow: ellipsis;
  383. display: -webkit-box;
  384. -webkit-line-clamp: 2;
  385. -webkit-box-orient: vertical;
  386. word-wrap: break-word;
  387. }
  388. .good-price {
  389. width: 100%;
  390. height: 20px;
  391. float: left;
  392. line-height: 20px;
  393. font-family: PingFang SC;
  394. white-space: nowrap;
  395. margin: 3px 0 3px 0;
  396. .goods-spec {
  397. font-size: 15px;
  398. color: #52A63A;
  399. margin-right: 6px;
  400. }
  401. .goods-original {
  402. font-size: 12px;
  403. text-decoration: line-through;
  404. color: #A67954;
  405. }
  406. }
  407. }
  408. }
  409. }
  410. </style>