index.vue 6.58 KB
<!--
 * @Date: 2022-09-21 16:04:10
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2022-09-22 14:47:45
 * @FilePath: /swx/src/pages/createActivity/index.vue
 * @Description: 创建活动页面
-->
<template>
  <view>
    <van-cell-group inset>
      <van-field
        :value="value1"
        label-class="label-class"
        input-class="input-class"
        label="主办方"
        right-icon="arrow-down"
        placeholder="请选择活动主办方"
        placeholder-style="color: #999;"
        :required="true"
        :disabled="true" />
      <view class="divide-line"></view>
      <van-field
        :value="message"
        label-class="label-class"
        input-class="input-class"
        label="活动主题"
        type="textarea"
        placeholder="请输入活动主题(最多30个字)"
        placeholder-style="color: #999;"
        autosize
        :required="true"
        :maxlength="30"
        :border="false"
        @change="onChange"
      />
      <view class="divide-line"></view>
      <view class="form-item">
        <view class="form-item-title required">活动封面图<text class="sub">(图片比例16:9展示最佳)</text></view>
        <van-uploader v-if="!has_image" @after-read="afterRead">
          <view class="upload-box" :style="uploaderStyle">
            <van-icon :name="icon_upload" size="5rem" class="upload-icon" />
          </view>
        </van-uploader>
        <view v-else class="upload-box" :style="uploaderStyle">
          <van-image fit="contain" :width="uploader_width" height="12rem" :src="uploader_image" />
          <van-icon name="clear" size="1.5rem" color="#000" class="upload-close" @tap="removeUploadImage" />
        </view>
      </view>
      <view class="divide-line"></view>
      <view class="form-item">
        <view class="form-item-title border">活动详情</view>
        <van-field
          :value="message"
          input-class="input-class"
          label=""
          type="textarea"
          placeholder="开始输入活动详情介绍"
          :autosize="{ maxHeight: 200, minHeight: 100 }"
          custom-style="padding-left: 0;"
        />
      </view>
      <view class="divide-line"></view>
      <view class="form-item">
        <view class="form-item-title">报名信息<text class="sub">( <text style="color: red;">*</text>为必填项,单击启用,长按修改)</text></view>
      </view>
      <view class="sign-box">
        <view @tap="onTapSign(item)" @longpress="onLongPressSign(item)" v-for="(item, index) in signInfo" :key="index" class="sign-item" :class="{ 'checked': item.checked }"><text class="required">{{ item.label }}</text></view>
        <!-- <view class="sign-item"><text class="">推荐人</text></view> -->
        <view class="sign-item"><van-icon name="plus" /></view>
      </view>
    </van-cell-group>
  </view>
  <view @tap="onSubmit">确定发布</view>
  <van-overlay :show="show_edit_sign" z-index="999">
    <view class="wrapper">
      <view class="block">
        <view style="padding: 1rem 1rem 0.5rem 1rem; text-align: center;">
          <text class="bg-gradient" style="font-size: 1.15rem;">报名信息</text>
        </view>
        <!-- <view>
          <AtInput
            name='value1'
            title='标准五个字'
            type='text'
            placeholder='使用 v-model:value 更新 value 值'
            v-model:value="value1"
          />
        </view> -->
        <view style="width: 22rem;">
          <van-field
            :value="message"
            label-class="label-class"
            input-class="input-class"
            rows="1"
            autosize
            label="字段名称"
            type="textarea"
            placeholder="请输入字段名称(6个字以内)"
            placeholder-style="color: #999;"
            :required="true"
            :maxlength="6"
            :border="true"
            @change="onChange"
          />
          <view class="form-item" style="overflow: auto; border-bottom: 1px solid #F2F2F2;">
            <view class="form-item-title" style="float: left; padding-top: 0.5rem;">是否必填</view>
            <van-switch
              style="float: right; padding-top: 0.5rem;"
              :checked="checked"
              @change="onChangeEdit"
              size="1.5rem"
              active-color="#199A74"
              inactive-color="#FFFFFF"
            />
          </view>
          <view style="padding: 1rem 0; margin: 1rem; text-align: center;">
            <view @tap="closeEditSign" style="color: #FFFFFF; background-color: #199A74; padding: 0.5rem 1rem; border-radius: 1rem;">确定</view>
          </view>
        </view>
      </view>
    </view>
  </van-overlay>
</template>

<script setup>
import { ref, onMounted, nextTick } from "vue";
// import icon_home1 from '@/images/icon/home01@2x.png'
import icon_upload from '@/images/icon/upload@2x.png'

const value1 = ref('');
const message = ref('');
const checked = ref(false);

const onSubmit = () => {
  console.warn(message.value);
}

const onChange = ({ detail }) => {
  console.warn(detail);
  message.value = detail
}

/**************** 上传模块 ******************/
const uploader_width = ref('')
const uploaderStyle = ref({})
const has_image = ref(false)
const uploader_image = ref('')
const afterRead = (event) => {
  const { file } = event.detail;
  console.warn(file);
  has_image.value = true;
  uploader_image.value = file.url
}
const removeUploadImage = () => {
  has_image.value = false;
  uploader_image.value = ''
}
/**********************************/

onMounted(() => {
  nextTick(() => {
    setTimeout(() => {
      // 获取元素宽度
      wx.createSelectorQuery().selectAll('.form-item-title').boundingClientRect(function (rect) {
        uploaderStyle.value = {
          width: rect[0].width - 8 + 'px'
        }
        uploader_width.value = rect[0].width - 8 + 'px';
      }).exec()
    }, 100)
  })
});

const signInfo = ref([{
  key: 'name',
  label: '姓名',
  checked: 1,
  required: 1
}, {
  key: 'phone',
  label: '手机号',
  checked: 1,
  required: 1
}, {
  key: 'sex',
  label: '性别',
  checked: 1,
  required: 1
}, {
  key: 'age',
  label: '年龄段',
  checked: 1,
  required: 1
}]);

const onTapSign = (item) => {
  item.checked = !item.checked
}

const onLongPressSign = (item) => {
  console.warn(item);
  show_edit_sign.value = true;
}

const show_edit_sign = ref(false)

const onChangeEdit = ({ detail }) => {
  console.warn(detail);
  checked.value = detail;
}

const closeEditSign = () => {
  show_edit_sign.value = false;
}

</script>

<script>
import "./index.less";

export default {
  name: "createActivityPage",
};
</script>