videoForm.vue 9.8 KB

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