liveOption.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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.liveName"></u-field>
  5. <u-cell-item title="请上传直播海报" :arrow="false">
  6. <view slot="label">
  7. <u-upload :action="uploadUrl" :file-list="defaultList" :form-data="uploadData" @on-success="uploadSuccess"
  8. @on-error="uploadError" @on-remove="uploadRemove" max-count="1"></u-upload>
  9. </view>
  10. </u-cell-item>
  11. <u-cell-item title="直播起始时间" :value="videoInfo.liveStartTime" @click="dateShow1 = true"></u-cell-item>
  12. <u-cell-item title="直播结束时间" :value="videoInfo.liveEndTime" @click="dateShow2 = true"></u-cell-item>
  13. <u-cell-item title="日期选择(可多选)" :arrow="false">
  14. <view slot="label" @click.stop="">
  15. <u-checkbox-group @click.stop="">
  16. <u-checkbox size="40" v-model="item.checked" v-for="(item, index) in checkList" :key="index" :name="item.value" shape="circle"
  17. active-color="#51A539" @click.stop="">{{item.name}}</u-checkbox>
  18. </u-checkbox-group>
  19. </view>
  20. </u-cell-item>
  21. </u-cell-group>
  22. <view class="form-handle">
  23. <u-button type="success" shape="circle" :ripple="true" @click="submitData" :disabled="getPermit()" class="handle-custom">提交</u-button>
  24. </view>
  25. <u-picker mode="time" v-model="dateShow1" :start-year="startYear" :params="params1" @confirm="setDate1"></u-picker>
  26. <u-picker mode="time" v-model="dateShow2" :start-year="startYear" :params="params2" @confirm="setDate2"></u-picker>
  27. <u-top-tips ref="uTips"></u-top-tips>
  28. </view>
  29. </template>
  30. <script>
  31. const NET = require('@/utils/request')
  32. const API = require('@/config/api')
  33. export default {
  34. data() {
  35. return {
  36. type: 'add',
  37. videoInfo: {
  38. liveName: '',
  39. liveStartTime: '',
  40. liveEndTime: '',
  41. },
  42. checkList: [{
  43. name: '星期一',
  44. value: '1',
  45. checked: true,
  46. disabled: false
  47. },
  48. {
  49. name: '星期二',
  50. value: '2',
  51. checked: true,
  52. disabled: false
  53. },
  54. {
  55. name: '星期三',
  56. value: '3',
  57. checked: true,
  58. disabled: false
  59. },
  60. {
  61. name: '星期四',
  62. value: '4',
  63. checked: true,
  64. disabled: false
  65. },
  66. {
  67. name: '星期五',
  68. value: '5',
  69. checked: true,
  70. disabled: false
  71. },
  72. {
  73. name: '星期六',
  74. value: '6',
  75. checked: true,
  76. disabled: false
  77. },
  78. {
  79. name: '星期天',
  80. value: '7',
  81. checked: true,
  82. disabled: false
  83. }
  84. ],
  85. dateShow1: false,
  86. dateShow2: false,
  87. params1: {
  88. // year: true,
  89. // month: true,
  90. // day: true,
  91. hour: true,
  92. minute: true,
  93. second: true
  94. },
  95. params2: {
  96. hour: true,
  97. minute: true,
  98. second: true
  99. },
  100. startYear: '',
  101. uploadData: {
  102. folderId: 0,
  103. },
  104. uploadUrl: '',
  105. fileList: [],
  106. defaultList: [],
  107. }
  108. },
  109. onLoad(options) {
  110. this.uploadUrl = API.uploadFile
  111. this.startYear = new Date().getFullYear()
  112. NET.request(API.getLiveId, {}, 'GET').then(res => {
  113. if (res.data && res.data != 0) {
  114. this.type = 'edit'
  115. this.videoInfo.liveId = res.data
  116. this.getLiveDetail()
  117. }
  118. }).catch(res => {
  119. this.$refs.uTips.show({
  120. title: '获取直播ID失败',
  121. type: 'warning',
  122. })
  123. })
  124. },
  125. methods: {
  126. // 直播详情
  127. getLiveDetail() {
  128. NET.request(API.getLiveData + this.videoInfo.liveId, {}, 'POST').then(res => {
  129. this.videoInfo = {
  130. liveId: res.data.liveId,
  131. liveName: res.data.liveName,
  132. liveStartTime: res.data.liveStartTime,
  133. liveEndTime: res.data.liveEndTime,
  134. }
  135. this.fileList = [res.data.imgUrl]
  136. this.defaultList = [{
  137. url: res.data.imgUrl
  138. }]
  139. this.checkList.forEach(v=>v.checked = false)
  140. res.data.liveWeek.split(',').forEach(site => {
  141. this.checkList[parseInt(site) - 1].checked = true
  142. })
  143. }).catch(res => {
  144. this.$refs.uTips.show({
  145. title: '获取直播设置参数失败',
  146. type: 'warning',
  147. })
  148. })
  149. },
  150. // 文件上传成功回调
  151. uploadSuccess(res, index, lists, name) {
  152. this.fileList.push(res.data.url)
  153. this.$refs.uTips.show({
  154. title: '文件上传成功',
  155. type: 'success',
  156. })
  157. return true
  158. },
  159. // 文件上传失败回调
  160. uploadError(res, index, lists, name) {
  161. this.$refs.uTips.show({
  162. title: '文件上传失败',
  163. type: 'warning',
  164. })
  165. },
  166. // 移除文件回调
  167. uploadRemove(index, lists, name) {
  168. this.fileList.splice(index, 1)
  169. },
  170. // 设置时间
  171. setDate1(data) {
  172. // this.videoInfo.liveStartTime = data.year + '-' + data.month + '-' + data.day + ' ' + data.hour + ':' + data.minute +
  173. // ':' + data.second
  174. this.videoInfo.liveStartTime = data.hour + ':' + data.minute + ':' + data.second
  175. },
  176. // 设置时间
  177. setDate2(data) {
  178. // this.videoInfo.liveEndTime = data.year + '-' + data.month + '-' + data.day + ' ' + data.hour + ':' + data.minute +
  179. // ':' + data.second
  180. console.log('时间:', data)
  181. this.videoInfo.liveEndTime = data.hour + ':' + data.minute + ':' + data.second
  182. },
  183. // 检查必填项
  184. getPermit() {
  185. if (!this.videoInfo.liveName || !this.videoInfo.liveStartTime || !this.videoInfo.liveEndTime || !this.fileList.length ||
  186. !this.checkList.filter(site => site.checked).length) {
  187. return true
  188. }
  189. return false
  190. },
  191. // 提交
  192. submitData() {
  193. if (this.type == 'add') {
  194. NET.request(API.setLiveData, {
  195. ...this.videoInfo,
  196. imgUrl: this.fileList[0],
  197. liveWeek: this.checkList.filter(site => site.checked).map(site => {
  198. return site.value
  199. }).join(',')
  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: res.data.msg,
  211. type: 'warning',
  212. })
  213. })
  214. } else {
  215. NET.request(API.editLiveData, {
  216. ...this.videoInfo,
  217. imgUrl: this.fileList[0],
  218. liveWeek: this.checkList.filter(site => site.checked).map(site => {
  219. return site.value
  220. }).join(',')
  221. }, 'POST').then(res => {
  222. this.$refs.uTips.show({
  223. title: '编辑直播设置成功',
  224. type: 'success',
  225. })
  226. setTimeout(() => {
  227. uni.navigateBack()
  228. }, 1000)
  229. }).catch(res => {
  230. this.$refs.uTips.show({
  231. title: res.data.msg,
  232. type: 'warning',
  233. })
  234. })
  235. }
  236. },
  237. },
  238. }
  239. </script>
  240. <style lang="less" scoped>
  241. page {
  242. width: 100%;
  243. height: 100%;
  244. }
  245. .container {
  246. width: 100%;
  247. height: 100%;
  248. float: left;
  249. box-sizing: border-box;
  250. padding-bottom: 70px;
  251. overflow-y: auto;
  252. .form-info {
  253. width: 100%;
  254. float: left;
  255. /deep/.u-label-text {
  256. color: #333333;
  257. }
  258. /deep/.u-cell_title {
  259. color: #333333;
  260. }
  261. .good-img {
  262. float: left;
  263. margin: 5px;
  264. }
  265. }
  266. .form-handle {
  267. width: calc(100% - 30px);
  268. height: 40px;
  269. position: fixed;
  270. bottom: 20px;
  271. left: 15px;
  272. background-color: #FFFFFF;
  273. .handle-custom {
  274. background-color: #51A539;
  275. /deep/button {
  276. background-color: #56a83a;
  277. }
  278. /deep/.u-btn--success--disabled {
  279. background-color: #74bd60 !important;
  280. }
  281. }
  282. }
  283. }
  284. </style>