liveOption.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. res.data.liveWeek.split(',').forEach(site => {
  140. this.checkList[parseInt(site) - 1].checked = true
  141. })
  142. }).catch(res => {
  143. this.$refs.uTips.show({
  144. title: '获取直播设置参数失败',
  145. type: 'warning',
  146. })
  147. })
  148. },
  149. // 文件上传成功回调
  150. uploadSuccess(res, index, lists, name) {
  151. this.fileList.push(res.data.url)
  152. this.$refs.uTips.show({
  153. title: '文件上传成功',
  154. type: 'success',
  155. })
  156. return true
  157. },
  158. // 文件上传失败回调
  159. uploadError(res, index, lists, name) {
  160. this.$refs.uTips.show({
  161. title: '文件上传失败',
  162. type: 'warning',
  163. })
  164. },
  165. // 移除文件回调
  166. uploadRemove(index, lists, name) {
  167. this.fileList.splice(index, 1)
  168. },
  169. // 设置时间
  170. setDate1(data) {
  171. // this.videoInfo.liveStartTime = data.year + '-' + data.month + '-' + data.day + ' ' + data.hour + ':' + data.minute +
  172. // ':' + data.second
  173. this.videoInfo.liveStartTime = data.hour + ':' + data.minute + ':' + data.second
  174. },
  175. // 设置时间
  176. setDate2(data) {
  177. // this.videoInfo.liveEndTime = data.year + '-' + data.month + '-' + data.day + ' ' + data.hour + ':' + data.minute +
  178. // ':' + data.second
  179. console.log('时间:', data)
  180. this.videoInfo.liveEndTime = data.hour + ':' + data.minute + ':' + data.second
  181. },
  182. // 检查必填项
  183. getPermit() {
  184. if (!this.videoInfo.liveName || !this.videoInfo.liveStartTime || !this.videoInfo.liveEndTime || !this.fileList.length ||
  185. !this.checkList.filter(site => site.checked).length) {
  186. return true
  187. }
  188. return false
  189. },
  190. // 提交
  191. submitData() {
  192. if (this.type == 'add') {
  193. NET.request(API.setLiveData, {
  194. ...this.videoInfo,
  195. imgUrl: this.fileList[0],
  196. liveWeek: this.checkList.filter(site => site.checked).map(site => {
  197. return site.value
  198. }).join(',')
  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: res.data.msg,
  210. type: 'warning',
  211. })
  212. })
  213. } else {
  214. NET.request(API.editLiveData, {
  215. ...this.videoInfo,
  216. imgUrl: this.fileList[0],
  217. liveWeek: this.checkList.filter(site => site.checked).map(site => {
  218. return site.value
  219. }).join(',')
  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: res.data.msg,
  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: 70px;
  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. .good-img {
  261. float: left;
  262. margin: 5px;
  263. }
  264. }
  265. .form-handle {
  266. width: calc(100% - 30px);
  267. height: 40px;
  268. position: fixed;
  269. bottom: 20px;
  270. left: 15px;
  271. background-color: #FFFFFF;
  272. .handle-custom {
  273. background-color: #51A539;
  274. /deep/button {
  275. background-color: #56a83a;
  276. }
  277. /deep/.u-btn--success--disabled {
  278. background-color: #74bd60 !important;
  279. }
  280. }
  281. }
  282. }
  283. </style>