index.jsx 11.3 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 设备供应商
 * @Author: Li Hanlin
 * @Date: 2022-11-09 14:44:44
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2022-12-08 15:09:50
TZW's avatar
TZW committed
6 7
 */

wuhao's avatar
wuhao committed
8
import * as React from 'react';
TZW's avatar
TZW committed
9
import { useState, useMemo, useEffect, useRef } from 'react';
wuhao's avatar
wuhao committed
10 11 12 13
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
TZW's avatar
TZW committed
14 15
import InitForm from '@/components/InitForm';
import ExtendField from '@/components/ExtendField';
TZW's avatar
TZW committed
16
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
17 18
import { Image, message, Divider } from 'antd';
import { ProDescriptions } from '@ant-design/pro-components';
wuhao's avatar
wuhao committed
19 20 21 22

function Supplier(props) {
  const actionRef = useRef(),
    formRef = useRef();
TZW's avatar
TZW committed
23
  const [drawer, setDrawer] = useState({
wuhao's avatar
wuhao committed
24 25 26
    visible: false,
  });

TZW's avatar
TZW committed
27 28 29 30 31 32 33 34
  const urlParams = {
    save: '/asset/equipmentSupplier/save',
    remove: '/asset/equipmentSupplier/deleteById',
    list: '/asset/equipmentSupplier/queryList',
    detail: '/asset/equipmentSupplier/query/detail',
    detail_nocp: '/asset/equipmentSupplier/queryById',
  };

wuhao's avatar
wuhao committed
35 36 37 38 39 40
  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
TZW's avatar
TZW committed
41
            setDrawer((s) => ({
wuhao's avatar
wuhao committed
42 43
              ...s,
              visible: true,
TZW's avatar
TZW committed
44
              detailpath: urlParams.detail,
TZW's avatar
TZW committed
45
              params: { id: row?.id },
wuhao's avatar
wuhao committed
46
              title: '编辑',
TZW's avatar
TZW committed
47 48
              val: 'only',
              type: 'add',
TZW's avatar
TZW committed
49
              onFinish: async (vals) => {
TZW's avatar
TZW committed
50
                let equipmentSupplierCharReqList = [];
TZW's avatar
TZW committed
51
                //console.log('id:', row.id);
TZW's avatar
TZW committed
52 53 54 55 56 57 58 59 60
                for (let i in vals) {
                  if (!isNaN(Number(i))) {
                    equipmentSupplierCharReqList.push({
                      fieldId: i,
                      fieldRealValue: vals[i],
                    });
                    delete vals[i];
                  }
                }
TZW's avatar
TZW committed
61 62
                let params = {
                  ...vals,
TZW's avatar
TZW committed
63 64 65
                  id: row?.id,
                  shopIdList: vals.shopId,
                  equipmentSupplierCharReqList,
TZW's avatar
TZW committed
66
                };
TZW's avatar
TZW committed
67
                delete params.shopId;
TZW's avatar
TZW committed
68 69 70 71 72 73 74 75 76 77 78 79 80
                let res = await doFetch({
                  url: urlParams.save,
                  params,
                });
                if (res.code === '0000') {
                  message.success('编辑成功!');
                  setDrawer((s) => ({
                    ...s,
                    visible: false,
                  }));
                  actionRef.current.reload();
                }
              },
wuhao's avatar
wuhao committed
81 82 83 84 85 86 87 88 89 90 91 92 93
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
TZW's avatar
TZW committed
94
          title: '是否删除该供应商?',
wuhao's avatar
wuhao committed
95 96
          okText: '确认',
          cancelText: '取消',
TZW's avatar
TZW committed
97 98 99 100 101 102 103 104 105 106
          onConfirm: async () => {
            let res = await doFetch({ url: urlParams.remove, params: { id: row.id } });
            if (res.code === '0000') {
              message.success('删除成功!');
              setDrawer((s) => ({
                ...s,
                visible: false,
              }));
              actionRef.current.reload();
            }
wuhao's avatar
wuhao committed
107 108 109 110 111 112 113 114 115 116 117
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };
TZW's avatar
TZW committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  const Details = () => {
    const columns = [
      {
        title: '供应商编号',
        dataIndex: 'supplierNo',
        key: 'supplierNo',
      },
      {
        title: '供应商名称',
        dataIndex: 'supplierName',
        key: 'supplierName',
      },
      { title: '公司官网', dataIndex: 'officialWebsite', key: 'officialWebsite' },
      {
        title: '联系电话',
        dataIndex: 'telephone',
        key: 'telephone',
      },
      {
        title: '公司邮箱',
        dataIndex: 'email',
        key: 'email',
      },
      {
        title: '地址',
        dataIndex: 'address',
        key: 'address',
      },
      {
        title: '状态',
        dataIndex: 'status',
        key: 'status',
      },
      {
        title: '评分',
        dataIndex: 'score',
        key: 'score',
      },
      {
        title: '备注',
        dataIndex: 'remark',
        key: 'remark',
      },
    ];
wuhao's avatar
wuhao committed
162

TZW's avatar
TZW committed
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
    const [newfieldscolumns, setnewfieldscolumns] = useState([]);
    const selectValueType = (type, options) => {
      switch (type) {
        case 1:
          return {
            valueType: 'input',
          };
        case 2:
          return {
            valueType: 'select',
            options,
          };
        case 3:
          return {
            valueType: 'radio',
            options,
          };
        case 4:
          return {
            valueType: 'select',
            options,
          };
        default:
          break;
      }
    };
    const [request, setrequest] = useState();
    useEffect(() => {
      const fn = async () => {
          let res = await doFetch({
            url: '/base/paFormField/queryList',
            params: {
              formId: '3',
            },
          });
          if (res?.data?.dataList) {
            let column = [];
            res?.data?.dataList?.forEach((el) => {
              column.push({
                ...selectValueType(el.fieldChar, el.valueList),
                title: el.fieldName,
                dataIndex: el.id,
                key: el.id,
              });
            });
            setnewfieldscolumns(column);
          }
        },
        fn2 = async () => {
          const res = await doFetch({
            url: urlParams.detail,
            params: { id: drawer?.item?.id },
          });
TZW's avatar
TZW committed
216
          //console.log(res?.data?.data);
TZW's avatar
TZW committed
217 218 219 220
          let obj = {};
          res?.data?.data['equipmentSupplierCharReqList']?.forEach((it) => {
            obj[it?.fieldId] = it?.fieldRealValue;
          });
TZW's avatar
TZW committed
221 222 223 224
          // console.log('drawerpro:', {
          //   ...(res?.data?.data ?? {}),
          //   ...obj,
          // });
TZW's avatar
TZW committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
          setrequest(
            {
              ...(res?.data?.data ?? {}),
              ...obj,
            } ?? {},
          );
        };
      fn();
      fn2();
    }, []);
    return (
      <>
        <ProDescriptions dataSource={request} columns={columns} />
        <AutoTable
          pagetitle="联系信息"
          columns={[
            {
              title: '联系人',
              dataIndex: 'userName',
              key: 'userName',
              formItemProps: {
                rules: [
                  {
                    required: true,
                    message: '此项为必填项',
                  },
                ],
              },
            },
            {
              title: '手机号码',
              dataIndex: 'telephone',
              key: 'telephone',
              formItemProps: {
                rules: [
                  {
                    required: true,
                    message: '此项为必填项',
                  },
                ],
              },
            },
            {
              title: '邮箱',
              dataIndex: 'email',
              key: 'email',
            },
            {
              title: '职务',
              dataIndex: 'title',
              key: 'title',
              fieldProps: {
                placeholder: '请选择',
              },
              formItemProps: {
                rules: [
                  {
                    required: false,
                    message: '此项为必填项',
                  },
                ],
              },
            },
          ]}
          dataSource={request?.supplierUserList}
          resizeable={false}
          pagination={false}
        />
        <Divider />
        <h3 className="page-title" style={{ marginBottom: 16 }}>
          扩展字段
        </h3>
        <ProDescriptions dataSource={request} columns={newfieldscolumns} />
      </>
    );
  };
wuhao's avatar
wuhao committed
301
  const columns = useMemo(() => {
TZW's avatar
TZW committed
302
    let defcolumn = getcolumns(setDrawer);
TZW's avatar
TZW committed
303 304 305 306 307 308 309
    defcolumn[1].render = (text, row) => {
      return (
        <a
          onClick={() => {
            setDrawer((s) => ({
              ...s,
              visible: true,
TZW's avatar
TZW committed
310 311 312 313
              type: 'detail',
              item: row,
              val: 'only',
              title: row.supplierName + '的详细信息',
TZW's avatar
TZW committed
314 315 316 317 318 319 320
            }));
          }}
        >
          {row.supplierName}
        </a>
      );
    };
wuhao's avatar
wuhao committed
321 322 323 324
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
TZW's avatar
TZW committed
325
      render: (text, row, _, action) => [edit(text, row, _, action), remove(text, row, _, action)],
wuhao's avatar
wuhao committed
326 327 328
    });
  }, []);

TZW's avatar
TZW committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
  const selectMoreDrawerType = (type) => {
    switch (type) {
      case 'detail':
        return <Details />;
      case 'add':
        return (
          <ExtendField
            setDrawer={setDrawer}
            drawer={drawer}
            actionRef={actionRef}
            columns={columns}
            formId={'3'}
            urlParams={urlParams}
            onFinish={async (vals) => {
              let equipmentSupplierCharReqList = [];
              for (let i in vals) {
                if (!isNaN(Number(i))) {
                  equipmentSupplierCharReqList.push({
                    fieldId: i,
                    fieldRealValue: vals[i],
                  });
                  delete vals[i];
                }
              }
              let params = {
                ...vals,
                id: drawer?.title == '编辑' ? drawer?.item?.id : '',
                equipmentSupplierCharReqList,
              };
              delete params.shopId;
              let res = await doFetch({
                url: urlParams.save,
                params,
              });
              if (res.code === '0000') {
                if (drawer?.title == '编辑') {
                  message.success('编辑成功!');
                } else {
                  message.success('新增成功!');
                }
                setDrawer((s) => ({
                  ...s,
                  visible: false,
                }));
                actionRef.current.reload();
              }
            }}
          />
        );
      default:
        return null;
    }
  };
wuhao's avatar
wuhao committed
382 383 384
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
TZW committed
385
        pagetitle={<h3 className="page-title">设备供应商</h3>}
wuhao's avatar
wuhao committed
386
        columns={columns}
TZW's avatar
TZW committed
387
        path={urlParams.list}
wuhao's avatar
wuhao committed
388 389
        actionRef={actionRef}
        pageextra={'add'}
TZW's avatar
TZW committed
390
        resizeable={false}
wuhao's avatar
wuhao committed
391 392 393 394
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
TZW's avatar
TZW committed
395
            type: 'primary',
wuhao's avatar
wuhao committed
396
            onClick: () => {
TZW's avatar
TZW committed
397
              setDrawer((s) => ({
wuhao's avatar
wuhao committed
398 399
                ...s,
                visible: true,
TZW's avatar
TZW committed
400 401 402
                item: {
                  status: 1,
                },
wuhao's avatar
wuhao committed
403
                title: '新增',
TZW's avatar
TZW committed
404
                detailpath: null,
TZW's avatar
TZW committed
405 406
                type: 'add',
                val: 'only',
wuhao's avatar
wuhao committed
407 408 409 410 411 412 413 414
              }));
            },
          },
        }}
      />

      <DrawerPro
        fields={columns}
TZW's avatar
TZW committed
415
        defaultFormValue={drawer?.item ?? {}}
wuhao's avatar
wuhao committed
416 417 418
        formRef={formRef}
        placement="right"
        onClose={() => {
TZW's avatar
TZW committed
419
          setDrawer((s) => ({
wuhao's avatar
wuhao committed
420 421 422
            ...s,
            visible: false,
          }));
TZW's avatar
TZW committed
423
          actionRef.current.reload();
wuhao's avatar
wuhao committed
424 425
        }}
        {...drawer}
TZW's avatar
TZW committed
426 427 428
      >
        {selectMoreDrawerType(drawer?.type)}
      </DrawerPro>
wuhao's avatar
wuhao committed
429 430 431 432
    </div>
  );
}

TZW's avatar
TZW committed
433
export default Supplier;