| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <template>
- <div class="container add_edit">
- <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px">
- <el-form-item label="轮播图片">
- <uni-file-picker v-model="imageValue" fileMediatype="image" returnType="object"
- :image-styles="imageStyle" @select="imgUpload" @delete="imgDelete" />
-
-
- </el-form-item>
- <el-form-item label="跳转类型">
- <el-radio-group v-model="form.type">
- <el-radio label="2">网页</el-radio>
- <el-radio label="1">页面</el-radio>
- <el-radio label="0">不跳转</el-radio>
- </el-radio-group>
- </el-form-item>
- <!-- <el-form-item label="地址">
- <el-select v-model="mpPageUrl" placeholder="请选择" class="sele" @change="urlChange">
- <el-option v-for="(item, idx) in urlOptions" :key="idx" :label="item.name + ' ' + item.url"
- :value="item._id"></el-option>
- </el-select>
- </el-form-item> -->
- <el-form-item label="跳转地址">
- <el-input v-model="form.url" placeholder="自动获取上面选中的值"></el-input>
- <div class="remark_txt">{{ remark }}</div>
- </el-form-item>
- <el-form-item label="排序">
- <el-input type="number" v-model.number="form.sort" min="0" placeholder="请输入排序"></el-input>
- </el-form-item>
- <el-form-item label="备注">
- <el-input v-model="form.remark" placeholder="请输入备注"></el-input>
- </el-form-item>
- <el-form-item label="状态">
- <el-switch v-model="form.state" active-color="#ff6a6c" inactive-color="#bbb" active-value="1"
- inactive-value="0"></el-switch>
- </el-form-item>
- <el-form-item>
- <el-button class="confirm_btn" @click="submitForm('ruleForm')">确 定</el-button>
- <el-button @click="returnPage">返回列表</el-button>
- </el-form-item>
- </el-form>
- </div>
- </template>
- <script>
- import bus from '@/common/bus';
- const __name = 'usemall-app-carousel';
- const __mpPage = 'usemall-app-wxmini-page';
- import { cos } from '@/util/cos.js'
- export default {
- data() {
- return {
- dataId: '',
- form: {
- img: '',
- type: '0',
- url: '',
- sort: 0,
- remark: '',
- state: '1',//0禁用1启用
- createTime:'',
- createBy:''
- },
- imageValue: null,
- imageStyle: {
- height: '200px',
- width: '500px'
- },
- urlOptions: [],
- remark: '',
- mpPageUrl: '',
- rules: {},
- now_date:'',//当前时间
- };
- },
- methods: {
- loadData() {
- if (!this.dataId) {
- return;
- }else{
-
- }
- //轮播信息
- this.$axios.post("/carousel/admin/info/"+this.dataId,
- {
-
- },
- {
- headers:{
- 'Mall-Token': uni.getStorageSync("token")
- }
- }).then(response => {
- let res = response
- console.log(res)
- if (res.success) {
- for (let item in this.form) {
- this.form[item] = res.data[item];
- }
- console.log(this.form)
- if (this.form.img) {
- this.imageValue = {};
- this.imageValue.url = this.form.img;
- }
- } else {
- }
- }).catch(res =>{
- });
- // await this.$db[__name].tofirst(this.dataId).then(res => {
- // if (res.code == 200) {
- // for (let item in this.form) {
- // this.form[item] = res.datas[item];
- // }
- // if (this.form.img) {
- // this.imageValue = {};
- // this.imageValue.url = this.form.img;
- // }
- // }
- // });
- },
- submitForm(formName) {
- console.log(this.form)
- console.log(this.imageValue)
- this.getNowDate()
-
- if(this.form.type!=0 &&this.form.url==''){
- alert('跳转地址不能为空!')
- }else if(this.form.img==''){
- alert('图片不能为空!')
- }else{
- console.log('触发')
- if (!this.dataId) {
- this.$axios.post("/carousel/admin/add",
- {
- 'createBy':uni.getStorageSync("nickName"),//创建人
- 'createTime':this.now_date,//创建时间
- 'img':this.form.img,//图片地址
- 'remark':this.form.remark,//备注
- 'sort':this.form.sort,//排序
- 'state':this.form.state,//状态0禁用1启用
- 'type':this.form.type,//跳转类型0不跳转 1跳转页面 2跳转网页
- 'url':this.form.url,//跳转地址type不为0时不能为空
- },
- {
- headers:{
- 'Mall-Token': uni.getStorageSync("token")
- }
- }).then(response => {
- let res = response
- console.log(res)
- if (res.success) {
- this.getOpenerEventChannel().emit('loadData');
- this.returnPage();
- } else {
- }
- }).catch(res =>{
- });
- }else{//编辑
- this.$axios.put("/carousel/admin/update",
- {
- 'createBy':this.form.createBy,//创建人
- 'createTime':this.form.createTime,//创建时间
- 'updateBy':uni.getStorageSync("nickName"),//更新人
- 'updateTime':this.now_date,//更新时间
- 'img':this.form.img,//图片地址
- 'remark':this.form.remark,//备注
- 'sort':this.form.sort,//排序
- 'state':this.form.state,//状态0禁用1启用
- 'type':this.form.type,//跳转类型0不跳转 1跳转页面 2跳转网页
- 'url':this.form.url,//跳转地址type不为0时不能为空
- 'id':this.dataId
- },
- {
- headers:{
- 'Mall-Token': uni.getStorageSync("token")
- }
- }).then(response => {
- let res = response
- if (res.success) {
- this.getOpenerEventChannel().emit('loadData');
- this.returnPage();
- } else {
- alert(res.message)
- }
- }).catch(res =>{
- });
- }
- }
-
- },
- //获取当前时间
- getNowDate() {
- var _this = this;
- // this.timer = setInterval(function() {
- var aData = new Date();
- var month = aData.getMonth() < 9 ? "0" + (aData.getMonth() + 1) : aData.getMonth() + 1;
- var date = aData.getDate() <= 9 ? "0" + aData.getDate() : aData.getDate();
- var date2 = aData.getDate() <= 9 ? "0" + (aData.getDate()-1) : (aData.getDate()-1);
- var Hour = aData.getHours() <= 9 ? "0" + (aData.getHours()) : aData.getHours();
- var Miunte = aData.getMinutes() <= 9 ? "0" + (aData.getMinutes()) : aData.getMinutes();
- var Seconds = aData.getSeconds() <= 9 ? "0" + (aData.getSeconds()) : aData.getSeconds();
- // console.log(aData.getTime())
- _this.now_date = aData.getFullYear() + "-" + month + "-" + date + ' '+ Hour +":"+ Miunte +":"+ Seconds;
- // console.log(aData.getFullYear() + "-" + month + "-" + date2)昨天
- // }, 86400000);
- },
- imgUpload(e) {
- this.form.img = e.tempFilePaths[0]
- const file = this.form.img;
- let Key = e.tempFiles[0].name
- cos.postObject(
- {
- Bucket: 'jinganminsu-1320402385',
- Region: 'ap-nanjing',
- Key: Key,
- FilePath: file,
- onProgress: (info) => {
- // console.log(info)
- }
- },
- (err, data) => {
- if (err) {
- console.log('上传失败', err)
- } else {
- console.log('上传成功', data)
-
- uni.hideLoading()
- let imgUrl = 'https://' + data.Location
- this.form.img =imgUrl
-
- }
- }
- )
- // //文件上传
- // this.$axios.post("/file/open/",formData,
- // {
- // headers:{
- // 'Content-type' : 'multipart/form-data'
- // }
- // }).then(response => {
- // let res = response
- // if (res.success) {
- // this.form.img =res.data
- // } else {
- // uni.showToast({
- // icon:'error',
- // title: '请重新上传!'
- // });
- // this.form.img =''
- // this.imageValue = null;
- // }
- // }).catch(res =>{
- // uni.showToast({
- // icon:'error',
- // title: '请重新上传!'
- // });
- // this.form.img =''
- // this.imageValue = null;
- // });
- },
- imgDelete() {
- this.imageValue = null;
- this.form.img = '';
- },
- returnPage() {
- bus.$emit('tab-close');
- this.$router.push('/pages/shop/home/page');
- },
- // urlChange(data) {
- // let obj = this.urlOptions.find(x => x._id == data);
- // this.form.url = obj.url;
- // this.remark = obj.remark;
- // }
- },
- created() {
- this.dataId = this.$route.query.id || '';
- this.loadData();
- }
- };
- </script>
- <style></style>
|