123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- var app = getApp();
- var util = require('../../utils/util.js');
- var api = require('../../config/api.js');
- var user = require('../../services/user.js');
- Page({
- data: {
- desc: '',
- title: '',
- regionId: 0,
- region: '',
- price: '',
- marketPrice: '',
- isPostageFree: false,
- postage: null,
- ableSelfTake: false,
- ableMeet: false,
- ableExpress: false,
- cateId: 0,
- cateName:''
- },
- onLoad: function(options) {
- var that = this;
- user.checkLoginAndNav()
- },
- onClose() {
- wx.navigateBack({
- delta: 1
- });
- },
- onPost() {
- if (this.data.title.trim() == '') {
- util.showErrorToast('必须填写商品名')
- return;
- }
- if (this.data.desc.trim() == '') {
- util.showErrorToast('必须填写介绍')
- return;
- }
- if (this.data.region.trim() == '') {
- util.showErrorToast('请选择发货地点')
- return;
- }
- if (this.data.cateName.trim() == '') {
- util.showErrorToast('请选择分类')
- return;
- }
- let reg1 = /^[0-9]+(.[0-9]{1,})?$/;
- let reg2 = /^[0-9]+(.[0-9]{1,2})?$/;
- if (this.data.price == '') {
- util.showErrorToast('必须填写价格')
- return;
- }
- let postage = this.data.postage == null ? '0.00' : this.data.postage
- this.setData({
- marketPrice: this.data.marketPrice == '' ? '0' : this.data.marketPrice
- })
- if (!reg1.test(this.data.price) || !reg1.test(this.data.marketPrice) || !reg1.test(postage)) {
- util.showErrorToast('价格必须是数字')
- return;
- }
- if (!reg2.test(this.data.price) || !reg2.test(this.data.marketPrice) || !reg2.test(postage)) {
- util.showErrorToast('小数必须是最大2位')
- return;
- }
- if (parseFloat(this.data.price) >= 100000000 || parseFloat(this.data.marketPrice) >= 100000000) {
- util.showErrorToast("必须在0到1亿元之间")
- return;
- }
- if (parseFloat(postage) > 1000) {
- util.showErrorToast("邮费最大1千元")
- return;
- }
- if (!this.data.ableSelfTake && !this.data.ableMeet && !this.data.ableExpress ){
- util.showErrorToast("请选择交易方式")
- return;
- }
- let that = this
- user.checkLoginAndNav().then(() => {
- util.request(api.GoodsPost, {
- name: this.data.title,
- desc: this.data.desc,
- regionId: this.data.regionId,
- region: this.data.region,
- categoryId: this.data.cateId,
- price: this.data.price,
- marketPrice: this.data.marketPrice,
- postage: postage,
- ableSelfTake: this.data.ableSelfTake,
- ableMeet: this.data.ableMeet,
- ableExpress: this.data.ableExpress
- }, 'POST').then(function(res) {
- if (res.errno === 0) {
- setTimeout(function goback(){
- wx.reLaunch({
- url: '/pages/index/index'
- })
- }, 1000)
- wx.showToast({
- title: '发布成功'
- })
- }
- console.log(res)
- });
- })
- },
- bindInputDesc(event) {
- this.setData({
- desc: event.detail.value,
- })
- console.log(event.detail)
- },
- bindInputTitle(event) {
- this.setData({
- title: event.detail.value,
- })
- console.log(event.detail)
- },
- bindInputPrice(event) {
- this.setData({
- price: event.detail.value,
- })
- console.log(event.detail)
- },
- bindInputMarketPrice(event) {
- this.setData({
- marketPrice: event.detail.value,
- })
- },
- bindInputPostage(event) {
- this.setData({
- postage: event.detail.value,
- })
- },
- postageFree(event) {
- if (event.detail.value[0]) {
- this.setData({
- isPostageFree: true,
- postage: null
- })
- } else {
- this.setData({
- isPostageFree: false,
- })
- }
- console.log(event.detail.value[0])
- },
- trade(event) {
- this.setData({
- ableSelfTake: false,
- ableMeet: false,
- ableExpress: false,
- })
- for (let i in event.detail.value) {
- console.log(event.detail.value[i])
- if (event.detail.value[i] == 'ableSelfTake') {
- this.setData({
- ableSelfTake: true,
- })
- } else if (event.detail.value[i] == 'ableMeet') {
- this.setData({
- ableMeet: true,
- })
- } else if (event.detail.value[i] == 'ableExpress') {
- this.setData({
- ableExpress: true,
- })
- }
- };
- console.log(event.detail)
- },
- onReady: function() {
- },
- onShow: function() {
- // 页面显示
- if (app.post.region.id) {
- this.setData({
- regionId: app.post.region.id,
- region: app.post.region.name
- });
- app.post.region.id = 0;
- app.post.region.name = ''
- }
- if(app.post.cate.id){
- this.setData({
- cateId: app.post.cate.id,
- cateName: app.post.cate.name
- });
- app.post.cate.id = 0;
- app.post.cate.name = ''
- }
- },
- onHide: function() {
- // 页面隐藏
- },
- onUnload: function() {
- // 页面关闭
- //重启
- wx.reLaunch({
- url: '/pages/index/index'
- })
- }
- })
|