|
|
@@ -9,7 +9,7 @@
|
|
|
</tui-list-cell>
|
|
|
<tui-list-cell class="line-cell" :arrow="true">
|
|
|
<div class="tui-title required">开始时间</div>
|
|
|
- <picker mode="date" :value="form.startTime" @change="startTimeFn" class="tui-input">
|
|
|
+ <picker mode="date" :value="form.startTime" @change="startTimeFn" class="tui-input">
|
|
|
<input v-model="form.startTime" name="startTime" type="text" hidden />
|
|
|
<div v-if="form.startTime">{{ form.startTime }}</div>
|
|
|
<div class="tui-placeholder" v-else>请选择</div>
|
|
|
@@ -89,191 +89,209 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import TuiListCell from '@/components/plugin/list-cell'
|
|
|
-import AppUploader from '@/components/app-uploader'
|
|
|
-import AppDatePicker from '@/components/app-date-picker'
|
|
|
-const form = require('@/utils/formValidation.js')
|
|
|
-// api
|
|
|
-import { getDet, add, update } from '@/api/ad'
|
|
|
-import { getDetailB as getGoodsDet } from '@/api/goods'
|
|
|
-export default {
|
|
|
- name: 'ad-add',
|
|
|
- components: {
|
|
|
- TuiListCell,
|
|
|
- AppUploader,
|
|
|
- AppDatePicker
|
|
|
- },
|
|
|
- data() {
|
|
|
- return {
|
|
|
- form: {
|
|
|
- adName: '',
|
|
|
- adImg: [],
|
|
|
- status: 0,
|
|
|
- inTurn: '1',
|
|
|
- type: 0,
|
|
|
- style: 0,
|
|
|
- url: '',
|
|
|
- goodsId: '',
|
|
|
- startTime: 0,
|
|
|
- endTime: 0
|
|
|
- },
|
|
|
- // imgList: [],
|
|
|
- goodsData: {}
|
|
|
- }
|
|
|
- },
|
|
|
- computed: {
|
|
|
- adImgStr() {
|
|
|
- // let img = JSON
|
|
|
- return this.form.adImg.join()
|
|
|
- }
|
|
|
- },
|
|
|
- onLoad(option) {
|
|
|
- this.setPageTitle()
|
|
|
- // this.init()
|
|
|
- },
|
|
|
- methods: {
|
|
|
- init() {
|
|
|
- this.type = this.option.type
|
|
|
-
|
|
|
- let data = uni.getStorageSync('addAdData')
|
|
|
- if (data) {
|
|
|
- uni.removeStorageSync('addAdData')
|
|
|
- setTimeout(() => {
|
|
|
- this.form = data.form
|
|
|
- // this.imgList = data.imgList
|
|
|
- })
|
|
|
- this.goodsData = data.goodsData
|
|
|
- }
|
|
|
- let goodsData = uni.getStorageSync('adSelGoods')
|
|
|
- if (goodsData) {
|
|
|
- uni.removeStorageSync('adSelGoods')
|
|
|
- this.goodsData = goodsData
|
|
|
- this.goodsId = goodsData.id
|
|
|
+ import TuiListCell from '@/components/plugin/list-cell'
|
|
|
+ import AppUploader from '@/components/app-uploader'
|
|
|
+ import AppDatePicker from '@/components/app-date-picker'
|
|
|
+ const form = require('@/utils/formValidation.js')
|
|
|
+ // api
|
|
|
+ import { getDet, add, update } from '@/api/ad'
|
|
|
+ import { getDetailB as getGoodsDet } from '@/api/goods'
|
|
|
+ export default {
|
|
|
+ name: 'ad-add',
|
|
|
+ components: {
|
|
|
+ TuiListCell,
|
|
|
+ AppUploader,
|
|
|
+ AppDatePicker
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ form: {
|
|
|
+ adName: '',
|
|
|
+ adImg: [],
|
|
|
+ status: 0,
|
|
|
+ inTurn: '1',
|
|
|
+ type: 0,
|
|
|
+ style: 0,
|
|
|
+ url: '',
|
|
|
+ goodsId: '',
|
|
|
+ startTime: 0,
|
|
|
+ endTime: 0
|
|
|
+ },
|
|
|
+ // imgList: [],
|
|
|
+ goodsData: {}
|
|
|
}
|
|
|
-
|
|
|
- if (this.option.id && !data) {
|
|
|
- this._getDet()
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ adImgStr() {
|
|
|
+ // let img = JSON
|
|
|
+ if (this.$util.isArray(this.form.adImg)) {
|
|
|
+ return this.form.adImg.join()
|
|
|
+ } else {
|
|
|
+ return this.form.adImg
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
- setPageTitle() {
|
|
|
- if (this.option.id) {
|
|
|
- uni.setNavigationBarTitle({
|
|
|
- title: this.option.type == 0 ? '修改门店轮播图' : '修改商城首页轮播图'
|
|
|
+ onLoad(option) {
|
|
|
+ this.setPageTitle()
|
|
|
+ // this.init()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ init() {
|
|
|
+ this.type = this.option.type
|
|
|
+
|
|
|
+ let data = uni.getStorageSync('addAdData')
|
|
|
+ if (data) {
|
|
|
+ uni.removeStorageSync('addAdData')
|
|
|
+ setTimeout(() => {
|
|
|
+ this.form = data.form
|
|
|
+ // this.imgList = data.imgList
|
|
|
+ })
|
|
|
+ this.goodsData = data.goodsData
|
|
|
+ this.getFormAdImg(data.goodsData)
|
|
|
+ }
|
|
|
+ let goodsData = uni.getStorageSync('adSelGoods')
|
|
|
+ if (goodsData) {
|
|
|
+ uni.removeStorageSync('adSelGoods')
|
|
|
+ this.goodsData = goodsData
|
|
|
+ this.goodsId = goodsData.id
|
|
|
+ this.getFormAdImg(data.goodsData)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.option.id && !data) {
|
|
|
+ this._getDet()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setPageTitle() {
|
|
|
+ if (this.option.id) {
|
|
|
+ uni.setNavigationBarTitle({
|
|
|
+ title: this.option.type == 0 ? '修改门店轮播图' : '修改商城首页轮播图'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.setNavigationBarTitle({
|
|
|
+ title: this.option.type == 0 ? '添加门店轮播图' : '添加商城首页轮播图'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getFormAdImg(data) {
|
|
|
+ if (this.$util.isArray(data.adImg)) {
|
|
|
+ this.form.adImg = data.adImg
|
|
|
+ } else {
|
|
|
+ this.form.adImg = [data.adImg]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // api
|
|
|
+ _getDet() {
|
|
|
+ getDet({ id: this.option.id }).then(res => {
|
|
|
+ if (this.$util.isEmpty(res.data)) return
|
|
|
+ Object.keys(this.form).forEach((i, index) => {
|
|
|
+ if (i == 'adImg') {
|
|
|
+ this.form.adImg = [res.data.adImgUrl]
|
|
|
+ } else {
|
|
|
+ this.form[i] = res.data[i]
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ this.form.startTime = this.$util.$formatDate(this.form.startTime, 'YYYY-MM-DD')
|
|
|
+ this.form.endTime = this.$util.$formatDate(this.form.endTime, 'YYYY-MM-DD')
|
|
|
+
|
|
|
+ if (this.form.style && this.form.style != '0') {
|
|
|
+ this._getGoodsDet()
|
|
|
+ }
|
|
|
})
|
|
|
- } else {
|
|
|
- uni.setNavigationBarTitle({
|
|
|
- title: this.option.type == 0 ? '添加门店轮播图' : '添加商城首页轮播图'
|
|
|
+ },
|
|
|
+ // 获取商品详情
|
|
|
+ _getGoodsDet() {
|
|
|
+ getGoodsDet({ id: this.form.goodsId }).then(res => {
|
|
|
+ if (this.$util.isEmpty(res.data)) return
|
|
|
+ this.goodsData = res.data
|
|
|
})
|
|
|
- }
|
|
|
- },
|
|
|
- // api
|
|
|
- _getDet() {
|
|
|
- getDet({ id: this.option.id }).then(res => {
|
|
|
- if (this.$util.isEmpty(res.data)) return
|
|
|
- Object.keys(this.form).forEach((i, index) => {
|
|
|
- this.form[i] = res.data[i]
|
|
|
+ },
|
|
|
+ // 操作
|
|
|
+ // 选择商品
|
|
|
+ selGoodsFn() {
|
|
|
+ let data = {
|
|
|
+ form: this.form,
|
|
|
+ // imgList: this.imgList,
|
|
|
+ goodsData: this.goodsData
|
|
|
+ }
|
|
|
+ uni.setStorageSync('addAdData', data)
|
|
|
+ this.$util.pageTo({
|
|
|
+ url: '/admin/ad/sel-goods',
|
|
|
+ query: {
|
|
|
+ ...this.option
|
|
|
+ }
|
|
|
})
|
|
|
- this.form.startTime = this.$util.$formatDate(this.form.startTime, 'YYYY-MM-DD')
|
|
|
- this.form.endTime = this.$util.$formatDate(this.form.endTime, 'YYYY-MM-DD')
|
|
|
-
|
|
|
- if (this.form.style) {
|
|
|
- this._getGoodsDet()
|
|
|
+ },
|
|
|
+ startTimeFn(e) {
|
|
|
+ console.log(e)
|
|
|
+ this.form.startTime = e.detail.value
|
|
|
+ },
|
|
|
+ endTimeFn(e) {
|
|
|
+ this.form.endTime = e.detail.value
|
|
|
+ },
|
|
|
+ switchChangeFn(e) {
|
|
|
+ this.form.status = e.target.value ? 1 : 0
|
|
|
+ },
|
|
|
+ radioChange(e) {
|
|
|
+ this.form.style = e.detail.value
|
|
|
+ },
|
|
|
+ confirmFn() {
|
|
|
+ let hostFn = this.option.id ? update : add
|
|
|
+ let form = JSON.parse(JSON.stringify(this.form))
|
|
|
+ console.log(form)
|
|
|
+ form.adImg = this.$util.imgSubstr(form.adImg)
|
|
|
+ form.adImg = form.adImg.join()
|
|
|
+ if (this.option.id) {
|
|
|
+ form.id = this.option.id
|
|
|
}
|
|
|
- })
|
|
|
- },
|
|
|
- // 获取商品详情
|
|
|
- _getGoodsDet() {
|
|
|
- getGoodsDet({ id: this.form.goodsId }).then(res => {
|
|
|
- if (this.$util.isEmpty(res.data)) return
|
|
|
- this.goodsData = res.data
|
|
|
- })
|
|
|
- },
|
|
|
- // 操作
|
|
|
- // 选择商品
|
|
|
- selGoodsFn() {
|
|
|
- let data = {
|
|
|
- form: this.form,
|
|
|
- // imgList: this.imgList,
|
|
|
- goodsData: this.goodsData
|
|
|
- }
|
|
|
- uni.setStorageSync('addAdData', data)
|
|
|
- this.$util.pageTo({
|
|
|
- url: '/admin/ad/sel-goods',
|
|
|
- query: {
|
|
|
- ...this.option
|
|
|
+ if (form.style == 0) {
|
|
|
+ delete form.goodsId
|
|
|
+ } else {
|
|
|
+ // form.url = ''
|
|
|
+ delete form.url
|
|
|
}
|
|
|
- })
|
|
|
- },
|
|
|
- startTimeFn(e) {
|
|
|
- console.log(e)
|
|
|
- this.form.startTime = e.detail.value
|
|
|
- },
|
|
|
- endTimeFn(e) {
|
|
|
- this.form.endTime = e.detail.value
|
|
|
- },
|
|
|
- switchChangeFn(e) {
|
|
|
- this.form.status = e.target.value ? 1 : 0
|
|
|
- },
|
|
|
- radioChange(e) {
|
|
|
- this.form.style = e.detail.value
|
|
|
- },
|
|
|
- confirmFn() {
|
|
|
- let hostFn = this.option.id ? update : add
|
|
|
- let form = JSON.parse(JSON.stringify(this.form))
|
|
|
- console.log(form)
|
|
|
- form.adImg = this.$util.imgSubstr(form.adImg)
|
|
|
- form.adImg = form.adImg.join()
|
|
|
- if (this.option.id) {
|
|
|
- form.id = this.option.id
|
|
|
- }
|
|
|
- if (form.style == 0) {
|
|
|
- delete form.goodsId
|
|
|
- } else {
|
|
|
- // form.url = ''
|
|
|
- delete form.url
|
|
|
- }
|
|
|
- hostFn(form).then(res => {
|
|
|
- let promptText = this.option.id ? '修改成功!' : '添加成功!'
|
|
|
- this.$msg(promptText)
|
|
|
- })
|
|
|
- },
|
|
|
- // 表单验证
|
|
|
- formSubmit(e) {
|
|
|
- // 表单规则
|
|
|
- let rules = [
|
|
|
- {
|
|
|
- name: 'adName',
|
|
|
- rule: ['required'],
|
|
|
- msg: ['请输入名称']
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'startTime',
|
|
|
- rule: ['required'],
|
|
|
- msg: ['请选择开始时间']
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'endTime',
|
|
|
- rule: ['required'],
|
|
|
- msg: ['请选择结束时间']
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'adImgStr',
|
|
|
- rule: ['required'],
|
|
|
- msg: ['请先上传图片']
|
|
|
+ hostFn(form).then(res => {
|
|
|
+ let promptText = this.option.id ? '修改成功!' : '添加成功!'
|
|
|
+ this.$msg(promptText)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 表单验证
|
|
|
+ formSubmit(e) {
|
|
|
+ // 表单规则
|
|
|
+ let rules = [
|
|
|
+ {
|
|
|
+ name: 'adName',
|
|
|
+ rule: ['required'],
|
|
|
+ msg: ['请输入名称']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'startTime',
|
|
|
+ rule: ['required'],
|
|
|
+ msg: ['请选择开始时间']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'endTime',
|
|
|
+ rule: ['required'],
|
|
|
+ msg: ['请选择结束时间']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'adImgStr',
|
|
|
+ rule: ['required'],
|
|
|
+ msg: ['请先上传图片']
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ // 进行表单检查
|
|
|
+ let formData = e.detail.value
|
|
|
+ let checkRes = form.validation(formData, rules)
|
|
|
+ // 验证通过!
|
|
|
+ if (!checkRes) {
|
|
|
+ this.confirmFn()
|
|
|
+ } else {
|
|
|
+ this.$msg(checkRes)
|
|
|
}
|
|
|
- ]
|
|
|
- // 进行表单检查
|
|
|
- let formData = e.detail.value
|
|
|
- let checkRes = form.validation(formData, rules)
|
|
|
- // 验证通过!
|
|
|
- if (!checkRes) {
|
|
|
- this.confirmFn()
|
|
|
- } else {
|
|
|
- this.$msg(checkRes)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|