videoForm.vue 9.9 KB

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