AddModal.jsx 9.19 KB
Newer Older
1 2
/* eslint-disable default-case */
/* eslint-disable no-undef */
皮倩雯's avatar
皮倩雯 committed
3
import React, { useState, useEffect } from 'react';
4
import SiteModal from '@/components/Modal/SiteModa';
皮倩雯's avatar
皮倩雯 committed
5
import { Form, Input, notification, Select, Row, Col } from 'antd';
6 7

const { Item } = Form;
mayongxin's avatar
mayongxin committed
8
const { TextArea } = Input;
9

皮倩雯's avatar
皮倩雯 committed
10
const AddModal = props => {
11
  const { option, messageVersion, visible } = props;
shaoan123's avatar
shaoan123 committed
12

皮倩雯's avatar
皮倩雯 committed
13 14 15 16 17 18 19 20
  const [form] = Form.useForm();
  const [loading, setLoading] = useState(false);
  const [templateName, setTemplateName] = useState([]);
  const onSubmit = () => {
    form.submit();
  };
  const onSubmitSuccess = () => {
    const result = form.getFieldValue();
21 22 23 24 25 26 27
    if (result.type == 'APP' || result.type == 'WEB') {
      delete result.third_id;
      delete result.third_name;
      delete result.weixin;
    }
    console.log(result.type);
    console.log(result);
皮倩雯's avatar
皮倩雯 committed
28 29 30 31
    props.onSubmit & props.onSubmit({ Id: props.template.Id, ...result });
    form.resetFields();
  };
  useEffect(() => {
32 33 34 35 36 37 38 39
    if (visible) {
      console.log(option);
      if (option) {
        setTemplateName(option.filter(item => item.Type === '公众号'));
        form.setFieldsValue({
          type: '公众号',
        });
      }
shaoan123's avatar
shaoan123 committed
40
    }
皮倩雯's avatar
皮倩雯 committed
41 42 43 44 45 46 47 48 49 50
  }, [props]);
  const layout = {
    layout: 'horizontal',
    labelCol: {
      span: 4,
    },
    wrapperCol: {
      span: 19,
    },
  };
皮倩雯's avatar
皮倩雯 committed
51

皮倩雯's avatar
皮倩雯 committed
52 53 54 55 56 57 58
  const onChange = (value, option) => {
    form.setFieldsValue({
      third_id: option.code,
    });
    // setTemplateName(option.filter(item => item.Type === value))
  };
  const onChangeType = value => {
59
    form.setFieldsValue({ third_name: '', third_id: '', weixin: '' });
皮倩雯's avatar
皮倩雯 committed
60 61 62
    setTemplateName(option.filter(item => item.Type === value));
    console.log(option.filter(item => item.Type === value));
  };
63

皮倩雯's avatar
皮倩雯 committed
64 65 66 67 68
  const onChangeType1 = value => {
    form.setFieldsValue({
      third_id: value,
    });
  };
69

皮倩雯's avatar
皮倩雯 committed
70 71 72
  return (
    <SiteModal
      {...props}
73 74 75 76 77 78 79 80 81
      title={
        <span>
          <span style={{ marginRight: '20px' }}>
            <span>模板添加</span>
          </span>
          <span style={{ fontSize: '14px' }}>当前解析版本规则</span>
          <span style={{ color: 'rgb(24, 144, 255)' }}>{messageVersion}</span>
        </span>
      }
皮倩雯's avatar
皮倩雯 committed
82 83 84
      style={{ top: 200, borderRadius: '20px' }}
      width="820px"
      destroyOnClose
85 86 87
      afterClose={() => {
        form.resetFields();
      }}
皮倩雯's avatar
皮倩雯 committed
88 89 90 91 92
      cancelText="取消"
      okText="确认"
      onOk={() => onSubmit()}
      confirmLoading={loading}
    >
93
      <div style={{ height: '500px', overflowY: 'scroll', overflowX: 'hidden' }}>
皮倩雯's avatar
皮倩雯 committed
94
        <Form form={form} {...layout} onFinish={onSubmitSuccess}>
95 96 97
          <Row>
            <Col span={3} />
            <Col span={12}>
皮倩雯's avatar
皮倩雯 committed
98
              <Item
99
                label="模板名称"
皮倩雯's avatar
皮倩雯 committed
100
                name="name"
101 102
                labelCol={{ span: 6 }}
                wrapperCol={{ span: 18 }}
皮倩雯's avatar
皮倩雯 committed
103 104 105 106 107 108 109
                rules={[
                  {
                    required: true,
                    message: '请输入模板名称',
                  },
                ]}
              >
110
                <Input style={{ width: '80%' }} placeholder="请输入模板名称" />
皮倩雯's avatar
皮倩雯 committed
111
              </Item>
112 113
            </Col>
            <Col span={9}>
皮倩雯's avatar
皮倩雯 committed
114 115 116
              <Item
                label="模板类型"
                name="type"
117 118
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 16 }}
皮倩雯's avatar
皮倩雯 committed
119 120 121 122 123 124 125
                rules={[
                  {
                    required: true,
                    message: '请选择模板类型',
                  },
                ]}
              >
126
                <Select style={{ width: '85%' }} onChange={value => onChangeType(value)}>
皮倩雯's avatar
皮倩雯 committed
127 128
                  <Select.Option value="公众号">公众号</Select.Option>
                  <Select.Option value="短信">短信</Select.Option>
129 130
                  <Select.Option value="APP">APP</Select.Option>
                  <Select.Option value="WEB">WEB</Select.Option>
皮倩雯's avatar
皮倩雯 committed
131 132 133
                  <Select.Option value="企业微信">企业微信</Select.Option>
                </Select>
              </Item>
134 135
            </Col>
          </Row>
136

137 138
          {form.getFieldsValue().type === 'APP' || form.getFieldsValue().type === 'WEB' ? (
            <></>
皮倩雯's avatar
皮倩雯 committed
139 140
          ) : (
            <>
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
              {form.getFieldsValue().type !== '企业微信' ? (
                <>
                  <Row>
                    <Col span={12}>
                      <Item
                        label="第三方模板名称"
                        name="third_name"
                        wrapperCol={{ span: 12 }}
                        labelCol={{ span: 12 }}
                        rules={[
                          {
                            required: true,
                            message: '请选择第三方模板名称',
                          },
                        ]}
                      >
                        {/* <Input placeholder="请输入模板名称" /> */}
                        <Select
                          placeholder="请选择模板名称"
                          style={{ width: '120%' }}
                          onChange={(value, option) => onChange(value, option)}
                        >
                          {templateName &&
                            templateName.length > 0 &&
                            templateName.map((item, index) => (
                              <Select.Option value={item.Name} key={index} code={item.Code}>
                                {item.Name}
                              </Select.Option>
                            ))}
                        </Select>
                      </Item>
                    </Col>
                    <Col span={12}>
                      <Item
                        label="第三方模板编号"
                        name="third_id"
                        wrapperCol={{ span: 12 }}
                        labelCol={{ span: 12 }}
                        rules={[
                          {
                            required: true,
                            message: '请输入第三方模板编号',
                          },
                        ]}
                      >
                        <Input placeholder="请输入第三方模板编号" style={{ width: '85%' }} />
                      </Item>
                    </Col>
                  </Row>
                </>
              ) : (
                <>
                  <Row>
                    <Col span={12}>
                      <Item
                        label="第三方模板名称"
                        wrapperCol={{ span: 12 }}
                        labelCol={{ span: 12 }}
                        name="third_name"
                        rules={[
                          {
                            required: true,
                            message: '请选择第三方模板名称',
                          },
                        ]}
                      >
                        <Select
                          style={{ width: '120%' }}
                          onChange={value => onChangeType1(value)}
                          placeholder="请选择模板名称"
                        >
                          <Select.Option value="普通文本">普通文本</Select.Option>
                          <Select.Option value="文字卡片">文字卡片</Select.Option>
                          <Select.Option value="图片消息">图片消息</Select.Option>
                          <Select.Option value="图片">图片</Select.Option>
                        </Select>
                      </Item>
                    </Col>
                    <Col span={12}>
                      <Item
                        label="企业微信应用id"
                        wrapperCol={{ span: 12 }}
                        labelCol={{ span: 12 }}
                        name="weixin"
                        rules={[
                          {
                            required: true,
                            message: '请输入企业微信号',
                          },
                        ]}
                      >
                        <Input placeholder="请输入企业微信号" style={{ width: '160px' }} />
                      </Item>
                    </Col>
                  </Row>
                </>
              )}
皮倩雯's avatar
皮倩雯 committed
238 239
            </>
          )}
240

241
          <Item label="模板参数(仅针对2.0规则)" labelCol={{ span: 6 }} name="params">
242
            <TextArea rows={2} style={{ width: '95%' }} placeholder="first|Second|Third|Four" />
皮倩雯's avatar
皮倩雯 committed
243
          </Item>
244
          <Item label="API解析参数(仅针对2.0规则)" labelCol={{ span: 6 }} name="param1">
245
            <TextArea rows={2} style={{ width: '95%' }} placeholder="first|Second|Third|Four" />
皮倩雯's avatar
皮倩雯 committed
246 247 248
          </Item>
          <Item label="参数说明" name="desc" labelCol={{ span: 6 }}>
            <TextArea
249
              style={{ width: '95%' }}
皮倩雯's avatar
皮倩雯 committed
250 251 252 253
              rows={4}
              placeholder="first: 标题信息|Second: 展示内容|Third: 时间|Four: 备注信息"
            />
          </Item>
254
          <Item label="解析规则版本(仅针对1.0规则)" name="analysis_params" labelCol={{ span: 6 }}>
255
            <TextArea rows={2} style={{ width: '95%' }} placeholder="param1|param2|param3|param4" />
皮倩雯's avatar
皮倩雯 committed
256 257 258 259 260 261 262
          </Item>
        </Form>
      </div>
    </SiteModal>
  );
};
export default AddModal;