videoForm.vue 10 KB

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