123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- import {
- stateConfig,
- stateFormData
- } from "../../utils/orderAddOptions";
- import { httpAdd } from "../../api/serverOrder";
- import { valMobile } from "../../utils/validate";
- import {
- createStoreBindings
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from "../../store/index";
- Page({
- data: {
- phone: "",
- token: "",
- loading: false,
- popupOptions: [],
- popupType: "",
- popupKey: "",
- popupTitle: "",
- popupApi: "",
- show: false,
- config: stateConfig,
- formData: {
- ...stateFormData
- },
- popupValue: '',
- background: [
- 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg',
- 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg',
- 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg',
- 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg',
- ],
- 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();
- },
- onShow() {
- if (typeof this.getTabBar === 'function' &&
- this.getTabBar()) {
- this.getTabBar().setData({
- selected: 0
- })
- }
- },
- async submitTap() {
- const token = this.data.token || ""
- if (token === '') {
- wx.navigateTo({
- url: "../../userLogin/pages/login/index"
- })
- return
- }
- const {
- loading,
- formData,
- phone
- } = this.data
- if (loading) return
- this.setData({
- loading: true
- })
- const {
- city,
- act_time_start,
- act_day_count,
- item_id,
- name,
- // budget,
- participant,
- require_item,
- req_demand,
- } = formData
- const keyMsg = this.valKey()
- if (keyMsg) {
- this.showToastMsg(keyMsg)
- this.setData({
- loading: false
- })
- return
- }
- const msg = valMobile(phone)
- if (msg) {
- this.showToastMsg(msg)
- this.setData({
- loading: false
- })
- return
- }
- const {
- code,
- data,
- msg: ss
- } = await httpAdd({
- city,
- act_time: act_time_start,
- act_day_count,
- item_id,
- name,
- // budget,
- participant,
- require_item,
- req_demand: req_demand.toString(),
- phone
- })
- if (code === 1) {
- this.showToastMsg('会务订单创建成功!')
- wx.navigateTo({
- url: '../../userOrder/pages/order-details/index?id=' + data.reqCode
- })
- this.setData({
- formData: {
- ...formData
- }
- })
- } else if (code === 0) {
- this.showToastMsg(ss)
- } else {
- }
- this.setData({
- loading: false
- })
- },
- valKey() {
- let msg = ""
- const {
- formData,
- config
- } = this.data
- const list = [
- "city",
- "act_time",
- "name",
- // "budget",
- "item_id",
- "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: any) {
- this.setData({
- phone: event.detail.value
- })
- },
- onNameChange(event: any) {
- const {
- formData
- } = this.data
- let model = {
- ...formData,
- name: event.detail.value
- }
- this.setData({
- formData: model
- })
- },
- //输入组件 只读点击选择数据
- onFormChange(event: any) {
- const token = this.data.token || ""
- const key = event.currentTarget.dataset.type
- const type = this.data.config[key].type
- if (token === '') {
- this.showToastMsg("请先登录!")
- 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: any) {
- const {
- label,
- popupKey,
- popupType,
- value,
- count,
- end
- } = e.detail
- 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: string) {
- wx.showToast({
- title: msg,
- icon: 'none',
- duration: 2000
- })
- },
- })
|