LiveApplyForm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <seller-base :show="false" class="scroll-view-wrapper">
  3. <view class="scroll-view-wrapper scroll-view div container live-apply-form">
  4. <view class="div common-header-wrap">
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar :title="getTitle" class="common-header" left-icon="back" @clickLeft="goBack">
  10. </uni-nav-bar>
  11. </view>
  12. </view>
  13. <view class="div main-content">
  14. <flex-line class="field-line menu-item" :show-border="true"><text class="span field-name">直播标题</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="live_apply_info.live_apply_name" /></view></flex-line>
  15. <flex-line class="pt-5" :show-border="true">
  16. <text class="span">直播封面</text>
  17. <view class="div" slot="right">
  18. <view class="div user-avatar-wrapper">
  19. <view class="div user-avatar">
  20. <uni-file-picker class="common-avatar" v-model="image" fileMediatype="image" mode="grid" :limit="1"
  21. :auto-upload="false" @select="uploadImage" :image-styles="{
  22. width:'160px',
  23. height:'160px',
  24. }"></uni-file-picker>
  25. </view>
  26. </view>
  27. </view>
  28. </flex-line>
  29. <view class="div">
  30. <flex-line :is-link="true" :show-border="true">
  31. <text class="span line-name">直播时间</text>
  32. <view class="span" slot="right">
  33. <uni-datetime-picker class="common-datetime-picker" type="datetime" v-model="live_apply_info.live_apply_play_time"
  34. :start="$moment().format('YYYY-MM-DD HH:mm')"></uni-datetime-picker>
  35. </view>
  36. </flex-line>
  37. </view>
  38. <view class="div" @click="showPopup('popupSelect')">
  39. <flex-line :is-link="true" :show-border="true"><text class="span line-name">选择商品</text><text class="span" slot="right">{{selectGoodsId.length?('已选' + selectGoodsId.length + '件'):''}}</text></flex-line>
  40. </view>
  41. <flex-line class="field-line menu-item" :show-border="true"><text class="span field-name">申请备注</text><view class="div field-line-right" slot="right"><input class="field-input" type="textarea" rows="4" v-model="live_apply_info.live_apply_remark" /></view></flex-line>
  42. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submit">保存</view></view>
  43. </view>
  44. <uni-popup background-color="#fff" ref="popupSelect" type="right">
  45. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  46. <view class="div common-header-wrap">
  47. <view :style="'height:'+navHeight+'px'"></view>
  48. <view class="common-header-holder"></view>
  49. <view class="common-header-fixed">
  50. <title-header />
  51. <uni-nav-bar title="选择商品" class="common-header" left-icon="back" @clickLeft="hidePopup('popupSelect')">
  52. </uni-nav-bar>
  53. </view>
  54. </view>
  55. <view class="scroll-view-wrapper scroll-view div common-popup-content">
  56. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view div" @scrolltolower="loadMore" scroll-y="true">
  57. <view class="div select-goods" v-if="selectGoodsList">
  58. <view class="ul" v-if="selectGoodsList.length">
  59. <view class="li" v-for="item in selectGoodsList" v-bind:key="item.goods_commonid" :class="{'active':selectGoodsId.indexOf(item.goods_commonid)>-1}" @click="selectedGoods(item)">
  60. <view class="div p-img">
  61. <image mode="aspectFit" class="img" :src="item.goods_image"/>
  62. </view>
  63. <view class="div p-info">
  64. <view class="p name">{{item.goods_name}}</view>
  65. <view class="p price">{{item.goods_price}}</view>
  66. </view>
  67. </view>
  68. </view>
  69. <empty-record v-else></empty-record>
  70. </view>
  71. </scroll-view>
  72. </view>
  73. </view>
  74. </uni-popup>
  75. <tui-picture-cropper v-if="cropperOption.imgUrl" :width="cropperOption.autoCropWidth" :height="cropperOption.autoCropHeight" :imageUrl="cropperOption.img" @ready="cropReady" @cropper="useCrop" @back="cropBack"></tui-picture-cropper>
  76. </view>
  77. </seller-base>
  78. </template>
  79. <script>
  80. import {getFontSize} from '@/util/common'
  81. import TitleHeader from '../../TitleHeader'
  82. import SellerBase from '../SellerBase'
  83. import tuiPictureCropper from "@/components/thorui/tui-picture-cropper/tui-picture-cropper"
  84. import { getLiveApplyInfo, saveLiveApply, uploadInfoFile } from '../../../api/sellerLiveApply'
  85. import { getGoodsList } from '../../../api/sellerGoods'
  86. import EmptyRecord from '../../EmptyRecord'
  87. import flexLine from '../../flexLine'
  88. export default {
  89. components:{
  90. TitleHeader,
  91. SellerBase,
  92. flexLine,
  93. EmptyRecord,
  94. tuiPictureCropper
  95. },
  96. props: {
  97. ifComponent: {
  98. type: Boolean,
  99. default: false
  100. },
  101. query: {
  102. type: Object,
  103. default: function () {
  104. return { action: 'add', live_apply_id: 0 }
  105. }
  106. }
  107. },
  108. computed:{
  109. fontSize(){
  110. return getFontSize()
  111. },
  112. isAddMode () {
  113. let mode = this.ifComponent ? this.query.action : this.action
  114. // add: 添加地址,edit: 编辑地址
  115. if (mode === 'add') {
  116. return true
  117. } else {
  118. return false
  119. }
  120. },
  121. getTitle () {
  122. if (this.isAddMode) {
  123. return '新增直播'
  124. } else {
  125. return '修改直播'
  126. }
  127. }
  128. },
  129. data(){
  130. return {
  131. navHeight: 0,
  132. image:[],
  133. screenWidth:0,
  134. action:'',
  135. cropperOption: {
  136. img: '',
  137. canMove: false,
  138. autoCrop: true,
  139. autoCropWidth: 100,
  140. autoCropHeight: 100,
  141. maxImgSize: 500,
  142. outputType: 'png'
  143. },
  144. live_apply_info: {},
  145. params: { 'page': 0, 'per_page': 10 },
  146. loading: false, // 是否加载更多
  147. isMore: true, // 是否有更多
  148. selectGoodsList: false,
  149. selectGoodsId: [],
  150. keyword: '',
  151. goods_type: '',
  152. search_type: '',
  153. showimage: '',
  154. isshow: false
  155. }
  156. },
  157. onLoad: function (option) {
  158. this.action = option.action
  159. this.initLive()
  160. this.loadMore()
  161. },
  162. watch: {
  163. query: function (val) {
  164. this.live_apply_id = val.live_apply_id
  165. this.initLive()
  166. }
  167. },
  168. mounted(){
  169. // #ifdef MP-WEIXIN
  170. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  171. // #endif
  172. this.screenWidth=uni.getSystemInfoSync().screenWidth
  173. },
  174. methods:{
  175. showPopup(id){
  176. this.$refs[id].open()
  177. },
  178. hidePopup(id){
  179. this.$refs[id].close()
  180. },
  181. goBack () {
  182. if (this.ifComponent) {
  183. this.$emit('closeLiveApplyForm')
  184. } else {
  185. uni.navigateBack({delta:1})
  186. }
  187. },
  188. initLive () {
  189. if (!this.isAddMode) {
  190. getLiveApplyInfo(this.live_apply_id).then(res => {
  191. var live_apply_info = res.result.live_apply_info
  192. this.live_apply_info = live_apply_info
  193. if(this.live_apply_info.live_apply_cover_image){
  194. this.image=[{
  195. name:'live_apply_cover_image',
  196. extname:'jpg',
  197. url:this.live_apply_info.live_apply_cover_image_url
  198. }]
  199. }else if(this.live_apply_info.live_apply_cover_video){
  200. this.image=[{
  201. name:'live_apply_cover_video',
  202. extname:'mp4',
  203. url:this.live_apply_info.live_apply_cover_video_url
  204. }]
  205. }
  206. }).catch(function (error) {
  207. uni.showToast({icon:'none',title: error.message})
  208. })
  209. }
  210. },
  211. submit () {
  212. saveLiveApply(Object.assign({}, this.live_apply_info, { goods_ids: this.selectGoodsId })).then(res => {
  213. if (this.ifComponent) {
  214. this.$emit('saveLiveApply')
  215. } else {
  216. uni.navigateTo({url:'/pages/seller/live_apply/LiveApplyList'})
  217. }
  218. }).catch(error => {
  219. uni.showToast({icon:'none',title: error.message})
  220. })
  221. },
  222. loadMore () {
  223. this.loading = true
  224. this.params.page = ++this.params.page
  225. if (this.isMore) {
  226. this.loading = false
  227. this.getSelectGoodsList(true)
  228. }
  229. },
  230. reload () {
  231. // 重新加载数据
  232. this.params.page = 0
  233. this.isMore = true
  234. this.selectGoodsList = []
  235. this.loadMore()
  236. },
  237. // 获取商品列表 用于设置产品分佣
  238. getSelectGoodsList () {
  239. getGoodsList('Sellergoodsonline', this.params, this.keyword, this.goods_type, this.search_type).then(res => {
  240. if (this.selectGoodsList) {
  241. this.selectGoodsList = this.selectGoodsList.concat(res.result.goods_list)
  242. } else {
  243. this.selectGoodsList = res.result.goods_list
  244. }
  245. if (res.result.hasmore) {
  246. this.isMore = true
  247. } else {
  248. this.isMore = false
  249. }
  250. }).catch(function (error) {
  251. uni.showToast({icon:'none',title: error.message})
  252. })
  253. },
  254. // 选择商品
  255. selectedGoods (item) {
  256. var index = this.selectGoodsId.indexOf(item.goods_commonid)
  257. if (index > -1) {
  258. this.selectGoodsId.splice(index, 1)
  259. } else {
  260. if (this.selectGoodsId.length >= 10) {
  261. uni.showToast({icon:'none',title: '最多选10件商品'})
  262. return
  263. }
  264. this.selectGoodsId.push(item.goods_commonid)
  265. }
  266. },
  267. openImage (src) {
  268. this.showimage = src
  269. this.isshow = true
  270. },
  271. dropImage () {
  272. this.live_apply_info.live_apply_cover_image = ''
  273. this.live_apply_info.live_apply_cover_video = ''
  274. this.$forceUpdate()
  275. },
  276. useCrop (res) {
  277. var formdata={
  278. filePath:res.url,
  279. name:'file',
  280. id:'file'
  281. }
  282. uni.showLoading({ title: '加载中' })
  283. uploadInfoFile(formdata).then(res => {
  284. if (res.result.file_type == 'image') {
  285. this.live_apply_info.live_apply_cover_video = ''
  286. this.live_apply_info.live_apply_cover_video_url = ''
  287. this.live_apply_info.live_apply_cover_image = res.result.file_name
  288. this.live_apply_info.live_apply_cover_image_url = res.result.file_path
  289. this.image=[{
  290. name:'live_apply_cover_image',
  291. extname:'jpg',
  292. url:res.result.file_path
  293. }]
  294. } else {
  295. this.live_apply_info.live_apply_cover_image = ''
  296. this.live_apply_info.live_apply_cover_image_url = ''
  297. this.live_apply_info.live_apply_cover_video = res.result.file_name
  298. this.live_apply_info.live_apply_cover_video_url = res.result.file_path
  299. this.image=[{
  300. name:'live_apply_cover_video',
  301. extname:'mp4',
  302. url:res.result.file_path
  303. }]
  304. }
  305. uni.hideLoading()
  306. this.cropperOption.imgUrl=''
  307. this.$forceUpdate()
  308. }).catch(function (error) {
  309. uni.showToast({icon:'none',title: error.message})
  310. uni.hideLoading()
  311. this.cropperOption.imgUrl=''
  312. this.$forceUpdate()
  313. })
  314. },
  315. cropReady(){
  316. this.cropperOption.img = this.cropperOption.imgUrl
  317. },
  318. cropBack(){
  319. this.cropperOption.imgUrl=''
  320. this.$forceUpdate()
  321. },
  322. uploadImage (event) {
  323. let that = this
  324. let file = event.tempFiles[0]
  325. that.cropperOption.imgUrl = file.path
  326. that.cropperOption.autoCropWidth = uni.getSystemInfoSync().windowWidth
  327. that.cropperOption.autoCropHeight = uni.getSystemInfoSync().windowWidth
  328. that.cropperOption.maxImgSize = uni.getSystemInfoSync().windowHeight - 40
  329. that.$forceUpdate()
  330. }
  331. }
  332. }
  333. </script>
  334. <style lang="scss" scoped>
  335. .scroll-view-wrapper{display: flex;flex-direction: column;}
  336. .scroll-view{flex:1}
  337. .common-header{
  338. .btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
  339. }
  340. .main-content{padding:0 $pageSpace;background: #fff;}
  341. .select-goods .li{height:3rem;padding:.6rem;display:flex;}
  342. .select-goods .li.active{background: rgba(255, 203, 203, 0.5) }
  343. .select-goods .li .p-img{}
  344. .select-goods .li .p-img .img{width:3rem;height: 3rem;}
  345. .select-goods .li .p-info{margin-left:1rem;}
  346. .select-goods .li .p-info .p{line-height:1rem;}
  347. .select-goods .li .p-info .price{font-size:$fontSize;color:$primaryColor;height:2rem;overflow: hidden}
  348. .select-goods .li .p-info .name{font-size:$subFontSize;}
  349. .common-avatar{text-align: right;}
  350. </style>