123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- const columns = require("./columns");
- const orderHttps = require("../../../utils/serverOrder");
- const validate = require("../../../utils/validate");
- import {
- createStoreBindings
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from "../../../store/index";
- Page({
- data: {
- loading: false,
- popupOptions: [],
- popupType: "",
- popupKey: "",
- popupTitle: "",
- popupApi: "",
- show: false,
- config: columns.config,
- formData: {
- ...columns.formData
- },
- popupValue: '',
- show: false,
- indicatorDots: true,
- vertical: false,
- autoplay: true,
- interval: 3000,
- duration: 500,
- date: '',
- },
- onLoad() {
- this.storeBindings = createStoreBindings(this, {
- store,
- fields: ["token", "phone"],
- actions: ["setPhone"],
- });
- },
- onUnload() {
- this.storeBindings.destroyStoreBindings();
- },
- onClickLeft() {
- wx.navigateBack({
- data: 1
- })
- },
- async submitTap() {
- const token = this.data.token ?? ""
- if (token === '') {
- wx.navigateTo({
- url: "../login/index"
- })
- return
- }
- const {
- loading,
- formData,
- phone
- } = this.data
- if (loading) return
- this.setData({
- loading: true
- })
- const {
- city,
- act_time,
- act_day_count,
- budget,
- participant,
- require_item,
- req_demand,
- } = formData
- const keyMsg = this.valKey()
- if (keyMsg) {
- this.showToastMsg(keyMsg)
- this.setData({
- loading: false
- })
- return
- }
- const msg = validate.valMobile(phone)
- if (msg) {
- this.showToastMsg(msg)
- this.setData({
- loading: false
- })
- return
- }
- const {
- code,
- data,
- msg: ss
- } = await orderHttps.orderAdd({
- city,
- act_time,
- act_day_count,
- budget,
- participant,
- require_item,
- req_demand: req_demand.toString(),
- phone
- })
- if (code === 1) {
- this.showToastMsg('会务订单创建成功!')
- wx.redirectTo({
- url: '../order-details/index?id=' + data.reqCode
- })
- this.setData({
- formData: {
- ...columns.formData
- }
- })
- } else if (code === 0) {
- this.showToastMsg(ss)
- } else {
- }
- this.setData({
- loading: false
- })
- },
- async orderAdd(model) {
- return {
- code,
- reqCode: data.reqCode,
- msg
- }
- },
- valKey() {
- let msg = ""
- const {
- formData,
- config
- } = this.data
- const list = [
- "city",
- "act_time",
- "budget",
- "participant",
- "require_item",
- "req_demand"
- ]
- list.forEach((key) => {
- if (config[key] === 'checkbox') {
- if (formData[key].length === 0) {
- msg = `至少选择一个${config[key].title}!`
- }
- } else {
- if (!formData[key]) {
- msg = `${config[key].title}不能为空!`
- }
- }
- })
- return msg
- },
- onPhoneChange(event) {
- this.setData({
- phone: event.detail.value
- })
- },
- //输入组件 只读点击选择数据
- onFormChange(event) {
- const token = this.data.token ?? ""
- const key = event.currentTarget.dataset.type
- const type = this.data.config[key].type
- if (token === '' && (type === "city" || type === "radio" || type === 'checkbox')) {
- wx.navigateTo({
- url: "../login/index"
- })
- return
- }
- const {
- act_time_start,
- act_time_end
- } = this.data.formData
- this.setData({
- popupValue: type !== 'time' ? this.data.formData[key] : act_time_start ? [act_time_start, act_time_end] : [],
- popupType: type,
- popupTitle: this.data.config[key].title,
- popupApi: this.data.config[key].api,
- popupKey: key,
- show: true,
- popupOptions: []
- });
- },
- tapItemClick(e) {
- const {
- label,
- popupKey,
- popupType,
- value,
- count,
- end
- } = e.detail
- // console.log(e);
- let form = {
- ...this.data.formData
- }
- form[popupKey] = value
- form[popupKey + '_name'] = label
- if (popupType === 'time') {
- form.act_day_count = count;
- form.act_time_start = value;
- form.act_time_end = end
- }
- this.setData({
- show: false,
- formData: form
- });
- },
- popupLeft() {
- this.setData({
- show: false,
- });
- },
- showToastMsg(msg) {
- wx.showToast({
- title: msg,
- icon: 'none',
- duration: 2000
- })
- }
- })
|