vlogList.vue 8.54 KB
Newer Older
zhoucong's avatar
zhoucong committed
1
<template>
zhoucong's avatar
zhoucong committed
2 3
	<view class="content">
		<view style="padding-top: 30rpx;">
zhoucong's avatar
zhoucong committed
4
			<view class="item" v-for="(item,index) in myVlogList" :key="index">
5
				<video class="video" :src="item.productUrl" :poster="item.thumbImageUrl" @error="error" object-fit="fill"
zhoucong's avatar
zhoucong committed
6 7
					play-btn-position="center" :id="index" @play="playing(index)"></video>
				<view class="">
qipeng's avatar
qipeng committed
8 9 10 11
					<!-- <button v-if="item.shareNumber===0" :data-productUrl="item.productUrl" :data-productId="item.productId" class="btnn"
						open-type="share">分享下载</button> -->
					<!-- 	v-else -->
					<button class="btnn" @click="handPayment(item.productUrl,item.isPay,item.sellingPrice)">下载视频</button>
qipeng's avatar
qipeng committed
12
					<text class="price">¥<text>{{item.sellingPrice}}</text></text>
zhoucong's avatar
zhoucong committed
13 14
				</view>
				<view style="clear: both;"></view>
zhoucong's avatar
zhoucong committed
15 16
			</view>
		</view>
zhoucong's avatar
zhoucong committed
17 18 19 20
	</view>
</template>

<script>
qipeng's avatar
qipeng committed
21
export default {
zhoucong's avatar
zhoucong committed
22

qipeng's avatar
qipeng committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  data() {
    return {
      openid:'',
      myVlogList: [], //我的视频列表
      merchantId: '', //景区id
      merchantIdOrder:'',//下单用merchantId
      merchantMessage:[],//景区基础参数
    }
  },
  onLoad(options) {
    this.merchantId = options.merchantId
    this.merchantIdOrder=options.merchantIdOrder||'z0015605022691a5945bbe463141668c'
    this.openid = uni.getStorageSync('openid') //获取openid
    this.getMyVlogList()
    this.mearchLoadList()//调用参数
  },
  onShow() {
zhoucong's avatar
zhoucong committed
40

qipeng's avatar
qipeng committed
41 42
  },
  onUnload() { //退出页面
zhoucong's avatar
zhoucong committed
43

qipeng's avatar
qipeng committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  },
  onHide() {},
  onReady() {},
  onShareAppMessage(res) { //分享
    let productId = res.target.dataset.productid
    let productUrl= res.target.dataset.producturl
    if (res.from === 'button') {
      this.$request('wechatUser/myPage/updateVlogRecord', {
        productId,
        openid: uni.getStorageSync('openid')
      }).then(res => {
        if (res.code === '00') {
          this.getMyVlogList()
        }
      })
      return {
        title: '胖丁旅行',
        type: 4,
        path: '/pages/vlog/share/share?url='+productUrl,
      }
    }else{
      return {
        title: '胖丁旅行',
        type: 4,
        path: '/pages/vlog/vlogIndex/vlogIndex',
      }
    }
  },
  methods: {
    getMyVlogList() { //获取景区vlog列表
      this.$request('wechatUser/myPage/getVlogRecord', {
        openid: uni.getStorageSync('openid'),
        productType:0
      }).then(res => {
        if (res.code === '00') {
          res.data.forEach(item => { //获取当前景区视频列表
            if (this.merchantId === item.merchantId) {
              this.myVlogList = item.vlogList
            }
          })
        }
      })
    },
    playing(e) { //控制只播放当前video
      this.myVlogList.forEach((item, index) => {
        if (e !== index) {
          uni.createVideoContext(index.toString()).pause()
        }
      })
    },
    handPayment(productUrl,isPay,sellingPrice){//当前视频是否需要支付下载费用
      //isPay 0为未支付  1为已支付
      if(isPay==0){//originalPrice 原价   sellingPrice售价  settlementPrice结算价
qipeng's avatar
qipeng committed
97
        this.upLoad(sellingPrice,productUrl)
qipeng's avatar
qipeng committed
98
      }else{
qipeng's avatar
qipeng committed
99
        this.handleDownload(productUrl)
qipeng's avatar
qipeng committed
100 101
      }
    },
qipeng's avatar
qipeng committed
102
    upLoad(sellingPrice,productUrl){//下单
qipeng's avatar
qipeng committed
103 104 105 106 107
		  var data = {
		    companyId:this.merchantMessage[0].companyId||'',//公司ID
			  orderMoney:sellingPrice,//订单总价
		    userId:this.openid,
		    orderProductVo:{},//下单信息
108
		    orderType:12,// vlogTYPE值
qipeng's avatar
qipeng committed
109 110 111 112 113
		    orderProductList:[],//景区下单信息
		  }
		  var orderProductListData = {
		    buyNum:1,//购买数量
		    merchantId:this.merchantMessage[0].merchantId||'',
114
		    orderType:12,// 12vlog
qipeng's avatar
qipeng committed
115 116 117 118 119 120 121
		    productId:this.merchantMessage[0].merchantExtendProjectId||'',
		    productName:this.merchantMessage[0].merchantExtendProjectName||'',
		    extendContent:'',
		    unitPrice:sellingPrice,//产品单价
		    orderImgList:[],////订单图片
		    couponList:[],//券信息
		  }
qipeng's avatar
qipeng committed
122
      var imgList = {
123 124
			  imgUrl:productUrl,
        imgType:1,
qipeng's avatar
qipeng committed
125 126
      }
		  orderProductListData.orderImgList.push(imgList)
qipeng's avatar
qipeng committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
		  var extendContentData={
		    openid:this.openid,
		    projectAddress:this.merchantMessage[0].projectAddress||'',
		    projectPhone:this.merchantMessage[0].projectPhone||'',
		  }
		  orderProductListData.extendContent = JSON.stringify(extendContentData)
		  data.orderProductList.push(orderProductListData)
		  //data.orderProductVo = orderProductVo
		  this.$request('orderc/photo/photoCreateOrder',data).then((res)=>{
		    if(res.code=='00'){
		      uni.navigateTo({
		        url:'../../payment/orderPayment/orderPayment?orderId='+res.data.id+'&albumOrderdetail=1'
		      })
		    }else{
		      uni.showToast({
					  title: res.message,
					  icon: 'none'
		      })
		    }
		  })
    },
    mearchLoadList(){//调用参数
		  var merchantIds = []
		  merchantIds.push(this.merchantIdOrder)
		  this.$request('scenic/merchantExtendProject/loadList',{
		    merchantIds:merchantIds,
        merchantExtendProjectName:'vlog'
		  }).then((res)=>{
		    if(res.code=='00'){
		      this.merchantMessage = res.data
		    }else{
		      uni.showToast({
		        title: res.message,
		        icon: 'none'
		      })
		    }
		  })
    },
    handleDownload(url) { // 下载功能
      uni.showLoading({
        title: '下载中',
        mask: true
      })
      let fileName = new Date().valueOf() //获取时间戳
      uni.downloadFile({ //下载文件资源到本地
        url,
        filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4', //filePath指定文件下载后存储的路径,wx.env.USER_DATA_PATH,时间戳为文件名
        success: res => { //下载到本地成功
          let filePath = res.filePath
          uni.saveVideoToPhotosAlbum({ //保存视频到系统相册。
            filePath,
            success: file => { //保存成功
              //删除本地缓存
              let fileMgr = uni.getFileSystemManager()
              fileMgr.unlink({
                filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
              })
              uni.showToast({
                title: '下载成功',
                icon: 'success',
                mask: true
              })
            },
            fail: err => {
              uni.hideLoading()
              //拒绝授权时显示
              if (err.errMsg === 'saveVideoToPhotosAlbum:fail auth deny') {
                uni.showModal({
                  title: '提示',
                  content: '需要您授权保存相册',
                  showCancel: false,
                  success: data => {
                    //打开权限设置
                    uni.openSetting({
                      success: setting => {
                        if (setting.authSetting['scope.writePhotosAlbum']) {
                          uni.showModal({
                            title: '提示',
                            content: '获取权限成功,再次点击下载即可保存',
                            showCancel: false,
                          })
                        } else {
                          uni.showModal({
                            title: '提示',
                            ontent: '获取权限失败,将无法保存到相册哦',
                            showCancel: false
                          })
                        }
                      },
                    })
                  }
                })
              }
            }
          })
        },
        fail: err => { //下载失败
          uni.hideLoading()
          if (err.errMsg == 'downloadFile:fail createDownloadTask:fail url not in domain list') {
            uni.showToast({
              title: '服务器错误,请联系相关管理员',
              icon: 'none',
              mask: true
            })
          }
        }
      })
    },
    error(e) { //视频播放出错触发函数
      uni.showModal({
        content: e.target.errMsg,
        showCancel: false
      })
    },
  }
}
zhoucong's avatar
zhoucong committed
243 244
</script>

zhoucong's avatar
zhoucong committed
245
<style lang="scss" scoped>
zhoucong's avatar
zhoucong committed
246 247 248 249 250 251 252
	.content {
		padding: 0 20rpx;
		min-height: 100%;
		width: 100%;
		text-align: center;
		background-color: #192033;

zhoucong's avatar
zhoucong committed
253 254 255 256
		.item {
			padding: 0 10rpx;
			border-radius: 10rpx;
			background-color: #192033;
zhoucong's avatar
zhoucong committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
			padding-bottom: 40rpx;

			.video {
				height: 350rpx;
				border-radius: 10rpx;
				width: 100%;
			}

			view {
				margin: 20rpx 0;

				.btnn {
					float: left;
					width: 150rpx;
					background-color: #FFE600;
					font-weight: bold;
					border-radius: 30rpx;
					line-height: 30rpx;
					font-size: 24rpx;
					padding: 10rpx 15rpx;
				}

				.price {
					float: right;
					color: #DE6F26;
					font-size: 22rpx;

					text {
						font-size: 32rpx;
						margin-left: 5rpx;
						font-weight: bold;
cc_inu's avatar
cc_inu committed
288 289
					}
				}
zhoucong's avatar
zhoucong committed
290
			}
zhoucong's avatar
zhoucong committed
291 292
		}
	}
zhoucong's avatar
zhoucong committed
293
</style>