| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- <?php
- use common\helpers\ComponentHelper;
- ComponentHelper::loadComponentView('com-select-cat');
- ComponentHelper::loadComponentView('com-dialog-select');
- ComponentHelper::loadComponentView('com-rich-text');
- ComponentHelper::loadComponentView('com-image');
- ComponentHelper::loadComponentView('com-rich-text');
- ?>
- <script src="/resources/js/Sortable.min.js"></script>
- <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
- <div id="app" v-cloak>
- <el-card class="box-card" shadow="never" style="border:0;min-width: 1200px;"
- body-style="background-color: #f3f3f3;padding: 10px 0 0;">
- <div slot="header">
- <el-breadcrumb separator="/">
- <el-breadcrumb-item>
- <span style="color: #409EFF;cursor: pointer"
- @click="$navigate({r:'business-card/material/index'})">
- 素材中心
- </span>
- </el-breadcrumb-item>
- <el-breadcrumb-item>{{titleName}}</el-breadcrumb-item>
- </el-breadcrumb>
- </div>
- <div class="form-body" v-loading="loading">
- <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;">
- <el-form-item label="素材标题" prop="title" style="margin-bottom: 20px;" label-width="100px">
- <el-input placeholder="请输入素材标题" type="text" v-model="submitData.title"></el-input>
- </el-form-item>
- <el-form-item prop="intro" label="素材简介" style="margin-bottom: 20px;" label-width="100px">
- <el-input placeholder="请输入素材简介" type="textarea" v-model="submitData.intro"></el-input>
- </el-form-item>
- <el-form-item label="分类" style="margin-bottom: 20px" required label-width="100px">
- <el-select v-model="submitData.cate_id" placeholder="请选择分类">
- <el-option v-for="(item, index) in cateList" :label="item.name" :value="item.id" :key="index"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="是否展示" style="margin-bottom: 20px" label-width="100px">
- <el-switch
- v-model="submitData.is_show"
- :active-value="1"
- :inactive-value="0"
- >
- </el-switch>
- </el-form-item>
- <el-form-item label="素材格式" style="margin-bottom: 20px" label-width="100px">
- <el-radio v-model="submitData.ext_type" v-for="(type, keys) in material_ext_type" :label="keys" :key="keys">{{type}}</el-radio>
- </el-form-item>
- <el-form-item label="分享标题" prop="share_title" style="margin-bottom: 20px;" label-width="100px">
- <el-input placeholder="请输入分享标题" type="text" v-model="submitData.share_title"></el-input>
- </el-form-item>
- <el-form-item label="分享描述" prop="share_desc" style="margin-bottom: 20px;padding: 10px;" label-width="100px">
- <el-input placeholder="请输入分享描述" type="textarea" v-model="submitData.share_desc" maxlength="80"></el-input>
- </el-form-item>
- <el-form-item prop="cover_img" label-width="100px" >
- <label slot="label">
- <span>封面图片</span>
- <!-- <el-tooltip effect="dark" content="展示封面,建议尺寸比例 1:1" placement="top">-->
- <!-- <i class="el-icon-info"></i>-->
- <!-- </el-tooltip>-->
- </label>
- <com-attachment @input="getSelImg" :multiple="true" :max="1">
- <el-button size="mini">选择图片</el-button> <span style="color: #BBBBBB;margin-left: 5px;">建议尺寸比例 100px*100px</span>
- </com-attachment>
- <div class="customize-share-title" v-if="submitData.cover_img">
- <com-image mode="aspectFill" width='80px' height='80px' :src="submitData.cover_img"></com-image>
- <!-- <el-button class="del-btn" size="mini" type="danger" icon="el-icon-close" circle @click="delSelImg()"></el-button>-->
- </div>
- </el-form-item>
- <el-form-item v-if="submitData.ext_type == 'video'" label="素材视频" prop="material_link" style="margin-bottom: 20px" required label-width="100px">
- <com-attachment :multiple="false" :max="1" @selected="videoUrl" type="videos">
- <el-tooltip class="item" effect="dark" content="支持格式mp4,支持编码H.264" placement="top">
- <el-button size="mini">选择视频</el-button>
- </el-tooltip>
- </com-attachment>
- <video v-if="submitData.material_link" :src="submitData.material_link" controls="controls" width="200" style="margin-top: 10px;"></video>
- <el-input type="text" placeholder="请输入视频链接" v-model="submitData.material_link" maxlength="200"></el-input>
- </el-form-item>
- <el-form-item v-if="submitData.ext_type == 'pdf'" label="素材文件" prop="material_link" style="margin-bottom: 20px" required label-width="100px">
- <com-attachment :multiple="false" :max="1" @selected="pdfUrl" type="files">
- <el-tooltip class="item" effect="dark" content="支持格式PDF" placement="top">
- <el-button size="mini">选择素材文件</el-button>
- </el-tooltip>
- </com-attachment>
- <a :href="submitData.material_link" v-if="submitData.material_link" target="_blank">点击查看: {{link_title}}</a>
- </el-form-item>
- <!-- <el-form-item v-if="submitData.ext_type == 'pdf'" label="PDF文件" prop="material_link" style="margin-bottom: 20px" required label-width="100px">-->
- <!-- <input ref="input" type="file" accept="application/pdf"-->
- <!-- @change="handleUploadPdf" style="display: none;" id="uploadpdf"/>-->
- <!-- <el-button @click="uploadpdf">上传文件</el-button>-->
- <!-- <div><a v-if="submitData.material_cont" @click="previewPdf">点击预览</a></div>-->
- <!-- </el-form-item>-->
- <el-form-item v-if="submitData.ext_type == 'link'" label="连接地址" prop="material_link" style="margin-bottom: 20px" required label-width="100px">
- <el-input v-model="submitData.material_link" style="margin-top: 10px;" placeholder="请输入连接地址"></el-input>
- </el-form-item>
- <el-form-item v-show="submitData.ext_type == 'pic_text'" label="内容编辑" label-width="100px" required>
- <com-rich-text style="width: 750px" :simple-attachment="true" v-model="submitData.material_cont"></com-rich-text>
- </el-form-item>
- </div>
- <el-button class="button-item" :loading="btnLoading" type="primary" @click="saveFun"
- size="small">保存
- </el-button>
- </el-card>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- return {
- diy_img_prefix: '<?= Yii::getAlias('@attachurl') ?>',
- titleName:"添加名片素材",
- loading:false,
- foundLoading:false,
- keyword_name: '',
- keyword_id: '',
- keyword_mobile: '',
- video_type:[".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
- ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"],
- submitData:{
- id: null,
- user_id: 0,
- title: "",
- intro: "",
- cate_id: null,
- is_show: 1,
- ext_type: 'pic_text',
- share_title: '',
- share_desc: '',
- cover_img: '',
- material_link: '',
- material_cont: '',
- },
- rules: {
- title:[
- { required: true, message: '请标题必填', trigger: 'blur' }
- ],
- intro:[
- { required: true, message: '请输入素材简介', trigger: 'blur' }
- ],
- // share_title:[
- // { required: true, message: '请输入分享标题', trigger: 'blur' }
- // ],
- // share_desc:[
- // { required: true, message: '请输入分享描述', trigger: 'blur' }
- // ],
- cover_img:[
- { required: true, message: '请选择封面图片', trigger: 'blur' }
- ],
- cate_id: [
- { required: true, message: '请选择分类1', trigger: 'blur' }
- ],
- },
- btnLoading:false,
- cateList: [],
- material_ext_type: [],
- pdfBase64: null
- };
- },
- mounted() {
- // this.submitData.updated_at = Date.parse(new Date()) / 1000; // 新建数据的更新时间
- if (getQuery('id')) {
- this.titleName="编辑名片素材";
- this.loadData(getQuery('id'));
- } else {
- // this.submitData.created_at = Date.parse(new Date()) / 1000; // 新建数据的创建时间
- }
- this.getExtType();
- this.getCate();
- },
- watch:{
- },
- computed:
- {
- link_title() {
- let arr = this.submitData.material_link.split('/');
- let title = arr.pop();
- return title ? title : '';
- }
- },
- methods: {
- uploadpdf() {
- $('#uploadpdf').click();
- },
- handleUploadPdf(e) {
- let file = e.target.files[0];
- console.log('file', file)
- let that = this;
- let reader = new FileReader();
- reader.readAsDataURL(file);
- reader.onload = (event) => {
- console.log('event', event)
- let base64 = event.target.result;
- that.pdfBase64 = base64;
- that.submitData.material_cont = base64;
- }
- },
- previewPdf() {
- const blob = this.base64ToBlob(this.submitData.material_cont);
- const file = this.blobToFile(blob, 'pdf预览');
- let url = URL.createObjectURL(file);
- window.open(url);
- },
- base64ToBlob(base64Data) {
- let arr = base64Data.split(','),
- fileType = arr[0].match(/:(.*?);/)[1],
- bstr = atob(arr[1]),
- l = bstr.length,
- u8Arr = new Uint8Array(l);
- while (l--) {
- u8Arr[l] = bstr.charCodeAt(l);
- }
- return new Blob([u8Arr], {
- type: fileType
- });
- },
- blobToFile(newBlob, fileName) {
- newBlob.lastModifiedDate = new Date();
- newBlob.name = fileName;
- return newBlob;
- },
- getCate() {
- request({
- params: {
- r: 'business-card/material/cate-list'
- }
- }).then(e=>{
- if (e.data.code == 0) {
- this.cateList = e.data.data;
- }
- }).catch(e=>{
- })
- },
- getSelImg(val){
- console.info(val);
- this.submitData.cover_img = val[0];
- },
- delSelImg(){
- //this.submitData.cover_img.splice(index, 1);
- this.submitData.cover_img = '';
- },
- videoUrl(e) {
- if (e.length) {
- //this.submitData.material_link = e[0].url;
- this.$set(this.submitData, 'material_link', e[0].url);
- }
- console.log(e[0]);
- // console.log(this.submitData);
- this.$forceUpdate();
- },
- pdfUrl(e) {
- console.log(e[0]);
- if (e.length) {
- //this.submitData.material_link = e[0].url;
- this.$set(this.submitData, 'material_link', e[0].url);
- // console.log(this.submitData.material_link)
- }
- },
- viewPdf() {
- window.open(
- this.submitData.material_link
- )
- },
- getUser() {
- let self = this;
- self.userDialog.loading = true;
- request({
- params: {
- r: 'business-bonus/default/search-user',
- page: self.userDialog.page,
- keyword_name: this.keyword_name,
- keyword_id: this.keyword_id,
- keyword_mobile: this.keyword_mobile,
- type:this.userDialog.index,
- },
- method: 'get',
- }).then(e => {
- self.userDialog.loading = false;
- self.userDialog.list = e.data.data.list;
- self.userDialog.pagination = e.data.data.pagination;
- }).catch(e => {
- console.log(e);
- });
- },
- addUser()
- {
- if (this.userDialog.selectedList && this.userDialog.selectedList.length > 1) {
- this.$message.error('只能选择一个用户!');
- return false;
- }
- this.submitData.nickname = this.userDialog.selectedList[0].nickname;
- this.submitData.user_id = this.userDialog.selectedList[0].id;
- this.submitData.mobile = this.userDialog.selectedList[0].mobile;
- this.submitData.avatar_url = this.userDialog.selectedList[0].avatar_url;
- this.userDialog.visible = false;
- },
- userSelectionChange(e) {
- if (e.length > 1) {
- this.$message.error('只能选择一个用户!');
- }
- this.userDialog.selectedList = e;
- },
- userDialogPageChange(page) {
- this.userDialog.page = page;
- this.getUser();
- },
- showUserDialog(index) {
- this.userDialog.visible = true;
- this.userDialog.index = index;
- },
- //检验必填选项
- check_centent(){
- if (!this.submitData.cate_id) {
- this.$message.error('请选择分类!');
- return false;
- }
- if(this.submitData.ext_type == 'pic_text'){
- if(!this.submitData.material_cont){
- this.$message.error('请输入内容!');
- return false;
- }
- }else if(this.submitData.ext_type == 'video'){
- if(!this.submitData.material_link){
- this.$message.error('请上传视频!');
- return false;
- }
- //console.log(this.video_type.lenght(),6666666);
- for(var i=0; i<this.video_type.length;i++){
- console.log(this.video_type[i],6666666);
- if(this.submitData.material_link.indexOf(this.video_type[i])>-1){
- return true;
- }
- }
- this.$message.error('视频格式不对,请上传视频!');
- return false;
- }else if(this.submitData.ext_type == 'pdf'){
- if(!this.submitData.material_link){
- this.$message.error('请上传PDF!');
- }else if(this.submitData.material_link.indexOf('.pdf')>-1){
- return true;
- }else{
- this.$message.error('文件格式不对,请上传PDF文件!');
- }
- /*if(!this.submitData.material_cont){
- this.$message.error('请上传PDF!');
- }else if(this.submitData.material_cont.indexOf('data:application/pdf;')>-1){
- return true;
- }else{
- this.$message.error('文件格式不对,请上传PDF文件!');
- }*/
- return false;
- }else if(this.submitData.ext_type == 'link'){
- if(!this.submitData.material_link){
- this.$message.error('请填写连接!');
- }else if(this.submitData.material_link.indexOf('http://')>-1){
- return true;
- }else if(this.submitData.material_link.indexOf('https://')>-1){
- return true;
- }else{
- this.$message.error('连接格式不对,请填写连接!');
- }
- return false;
- }
- return true;
- },
- saveFun(){
- this.$refs['ruleForm'].validate((valid) => {
- if (valid) {
- if(!this.check_centent()){
- return false;
- }
- let data =JSON.parse(JSON.stringify(this.submitData));
- this.btnLoading = true;
- let url = 'business-card/material/edit';
- request({
- params: {
- r:url,
- },
- method: 'post',
- data: data
- }).then(e => {
- this.btnLoading = false;
- if (e.data.code == 0) {
- this.$message.success(e.data.msg);
- setTimeout(function () {
- navigateTo({
- r: 'business-card/material/index',
- });
- }, 1500);
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- this.$message.error(e);
- this.btnLoading = false;
- })
- } else {
- this.$message.error('请填写必要的参数!');
- return false;
- }
- });
- },
- picUrl(e) {
- if (e.length) {
- this.submitData.pic = e[0].url;
- }
- },
- delPic(index) {
- /* this.pic_url.splice(index, 1) */
- this.submitData.pic = '';
- },
- receiveDatetimeChange(){
- if(this.receive_datetime){
- this.submitData.receive_begin_time = Date.parse(new Date(this.receive_datetime[0]).toString())/1000;
- this.submitData.receive_end_time = Date.parse(new Date(this.receive_datetime[1]).toString())/1000;
- }
- },
- useDatetimeChange() {
- if(this.use_datetime){
- this.submitData.use_begin_time = Date.parse(new Date(this.use_datetime[0]).toString())/1000;
- this.submitData.use_end_time = Date.parse(new Date(this.use_datetime[1]).toString())/1000;
- }
- },
- addPrize(){
- this.submitData.prize.push(JSON.parse(JSON.stringify(this.prizeObj)));
- },
- delPrize(index){
- this.submitData.prize.splice(index,1)
- },
- formatTime(timeStamp) {
- var date = new Date();
- date.setTime(timeStamp * 1000);
- var y = date.getFullYear();
- var m = date.getMonth() + 1;
- m = m < 10 ? ('0' + m) : m;
- var d = date.getDate();
- d = d < 10 ? ('0' + d) : d;
- var h = date.getHours();
- h = h < 10 ? ('0' + h) : h;
- var minute = date.getMinutes();
- var second = date.getSeconds();
- minute = minute < 10 ? ('0' + minute) : minute;
- second = second < 10 ? ('0' + second) : second;
- return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
- },
- loadData(id){
- this.loading = true;
- request({
- params: {
- r:'business-card/material/info',
- id: id
- },
- method: 'get',
- }).then(e => {
- this.loading = false;
- if (e.data.code == 0) {
- if (e.data.data.is_null == 0) {
- this.submitData = e.data.data.info;
- }
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- this.loading = false;
- });
- },
- getExtType() {
- request({
- params: {
- r:'business-card/material/ext-type',
- },
- method: 'post',
- }).then(e => {
- if (e.data.code == 0) {
- this.material_ext_type = e.data.data;
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- });
- }
- }
- });
- </script>
- <style>
- .form-body {
- padding: 20px;
- background-color: #fff;
- margin-bottom: 20px;
- padding-right: 20%;
- min-width: 900px;
- }
- .form-body .el-form-item {
- padding-right: 25%;
- min-width: 850px;
- }
- .form-button {
- margin: 0;
- }
- .form-button .el-form-item__content {
- margin-left: 0 !important;
- }
- .button-item {
- padding: 9px 25px;
- }
- .check-group {
- font-size: 14px !important;
- }
- .check-group .el-col {
- display: flex;
- }
- .check-group .el-input {
- margin: 0 5px;
- }
- .check-group .el-col .el-checkbox {
- display: flex;
- align-items: center;
- }
- .check-group .el-col .el-input {
- width: 100px;
- }
- .check-group .el-col .el-input .el-input__inner {
- height: 30px;
- width: 100px;
- }
- .el-checkbox-group .el-col {
- margin-bottom: 10px;
- }
- .add-image-btn {
- width: 100px;
- height: 100px;
- color: #419EFB;
- border: 1px solid #e2e2e2;
- cursor: pointer;
- }
- .remark {
- color: #cccccc;
- }
- .user-info img {
- width: 60px;
- border-radius: 50%;
- margin-top: 10px;
- }
- /*批量上传图片*/
- .pic-url-remark {
- font-size: 13px;
- color: #c9c9c9;
- margin-bottom: 12px;
- }
- .add-image-btn {
- width: 100px;
- height: 100px;
- color: #419EFB;
- border: 1px solid #e2e2e2;
- cursor: pointer;
- }
- .del-btn-pro{
- position: absolute;
- top: 28%;
- left: 57px;
- }
- .del-btn{
- position: absolute;
- top: -10%;
- right: -12%;
- z-index: 10;
- }
- .el-button--mini.is-circle{
- padding: 4px;
- }
- .priview-title{
- margin-bottom: 16px;
- font-size: 20px;
- font-weight: bold;
- color: #000000;
- }
- .priview-center{
- margin: 16px 11px;
- height: 86%;
- overflow-y: auto;
- }
- .preview-model{
- margin-right: 15px;
- background: #FFF;
- min-width: 375px;
- max-width: 375px;
- height: 78vh;
- overflow-wrap: anywhere;
- border-radius: 5px;
- }
- .form-right{
- flex: 1;
- overflow: auto;
- height: 78vh;
- }
- .card-model{
- border: 0;
- margin-bottom: 10px;
- }
- .customize-share-title{
- position: relative;
- display: inline-block;
- margin: 10px 10px 0 0;
- }
- .dp-header-placeholder {
- width: 100%;
- height: 44px;
- background-size: 100% 100%;
- z-index: 99;
- background: url("resources/img/decorate/nav/light1.png") no-repeat;
- }
- .preview-top-title{
- width: 100%;
- height: 24px;
- text-align: center;
- line-height: 24px;
- font-size: 16px;
- font-weight: 600;
- }
- /* 富文本表格样式 */
- .rich-text .note-app table {
- border-top: 1px solid #ccc;
- border-left: 1px solid #ccc;
- }
- .rich-text .note-app table th {
- background-color: #f1f1f1;
- }
- .rich-text .note-app table th,
- .rich-text .note-app table td {
- border-bottom: 1px solid #ccc;
- text-align: center;
- border-right: 1px solid #ccc;
- padding: 3px 5px;
- min-height: 30px;
- height: 30px;
- }
- .form-right::-webkit-scrollbar-thumb,.priview-center::-webkit-scrollbar-thumb{
- width: 4px;
- }
- textarea {
- padding: 8px !important;
- }
- </style>
|