liveDrawer.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. <template>
  2. <BasicDrawer
  3. v-bind="$attrs"
  4. @register="registerDrawer"
  5. showFooter
  6. :title="getTitle"
  7. :showDetailBack="false"
  8. width="60%"
  9. @ok="handleSubmit"
  10. @close="handleClose"
  11. >
  12. <div class="entry-x">
  13. <BasicForm @register="registerForm">
  14. <template #map>
  15. <!-- <Card style="width: 300px; height: 300px"> -->
  16. <div ref="wrapRef" style="width: 100%; height: 400px"></div>
  17. <!-- </Card> -->
  18. </template>
  19. <!-- ="{ model, field }" -->
  20. <template #detailAddr>
  21. <a-input
  22. class="live-drawer"
  23. v-bind="$attrs"
  24. v-model:value="detailAddr"
  25. :allowClear="true"
  26. placeholder=""
  27. >
  28. <template #addonAfter>
  29. <a-button type="primary" class="mr-10px" @click="handleMapSearch">
  30. {{ t('common.queryText') }}
  31. </a-button>
  32. <a-button @click="handleMapReset"> {{ t('common.resetText') }}</a-button>
  33. </template>
  34. </a-input>
  35. </template>
  36. <template #sceneNum="{ model, field }">
  37. <Select
  38. :disabled="isUpdate"
  39. v-bind="$attrs"
  40. v-model:value="model[field]"
  41. @change="handleChange"
  42. @search="handleSearch"
  43. showSearch
  44. placeholder="请选择场景链接"
  45. :options="getOptions"
  46. :filterOption="filterOption"
  47. />
  48. </template>
  49. </BasicForm>
  50. </div>
  51. </BasicDrawer>
  52. </template>
  53. <script lang="ts">
  54. import { defineComponent, ref, computed, unref, nextTick, reactive, watch } from 'vue';
  55. import { BasicForm, useForm, FormSchema } from '/@/components/Form/index';
  56. // import { Card } from 'ant-design-vue';
  57. import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  58. import { useMessage } from '/@/hooks/web/useMessage';
  59. import { useI18n } from '/@/hooks/web/useI18n';
  60. import { useUserStore } from '/@/store/modules/user';
  61. import type { UserInfo } from '/#/store';
  62. import { data as CascaderData, getCode } from '/@/utils/cascaderData';
  63. import { ListApi } from '/@/api/scene/list';
  64. import { Select } from 'ant-design-vue';
  65. import {
  66. brandTypeListApi,
  67. uploadLiveApi,
  68. getAllSceneApi,
  69. // uploadLiveVideoApi,
  70. addSave,
  71. getLiveInfoApi,
  72. brandUpdateApi,
  73. // LiveSceneDeleteApi,
  74. } from '/@/api/scene/live';
  75. import { useScript } from '/@/hooks/web/useScript';
  76. import { staffListApi } from '/@/api/staff/list';
  77. import { SceneLiveItem } from '/@/api/scene/model';
  78. import { isBoolean } from '/@/utils/is';
  79. // import cascaderOptions, { DivisionUtil } from '@pansy/china-division';
  80. // const divisionUtil = new DivisionUtil(cascaderOptions);
  81. // let ProvincesData = divisionUtil.getProvinces();
  82. // ProvincesData.map((n) => {
  83. // const cities = divisionUtil.getChildrenByCode(n.value);
  84. // n.children = cities;
  85. // });
  86. // console.log('ProvincesData', ProvincesData);
  87. const A_MAP_URL = 'https://webapi.amap.com/maps?v=2.0&key=e661b00bdf2c44cccf71ef6070ef41b8';
  88. // const A_MAP_URL = 'https://webapi.amap.com/maps?v=2.0&key=5a2d384532ae531bf99bd8487c4f03d2';
  89. // const A_MAP_URL = 'https://webapi.amap.com/maps?v=1.4.10&key=e661b00bdf2c44cccf71ef6070ef41b8';
  90. //webapi.amap.com/maps?v=1.4.10&key=e661b00bdf2c44cccf71ef6070ef41b8
  91. // Card
  92. export default defineComponent({
  93. name: 'MenuDrawer',
  94. components: { BasicDrawer, BasicForm, Select },
  95. emits: ['success', 'register'],
  96. setup(_, { emit }) {
  97. const isUpdate = ref(true);
  98. const detailAddr = ref('');
  99. const userStore = useUserStore();
  100. const token = userStore.getToken;
  101. const userinfo = computed(() => userStore.getUserInfo);
  102. const wrapRef = ref<HTMLDivElement | null>(null);
  103. const isDeaultContactUser = ref<UserInfo | false>(false);
  104. const editRecord = ref<SceneLiveItem | boolean>(false);
  105. const sceneNumOption = reactive({
  106. list: [],
  107. allList: [],
  108. });
  109. const getOptions = computed(() => {
  110. return sceneNumOption.list;
  111. });
  112. interface AddressComponentType {
  113. city: string;
  114. district: string;
  115. province: string;
  116. }
  117. interface GeocodesType {
  118. adcode: string;
  119. addressComponent: AddressComponentType;
  120. formattedAddress: string;
  121. location: {
  122. lng: number;
  123. lat: number;
  124. };
  125. }
  126. interface infoItem {
  127. province?: string;
  128. city?: string;
  129. address?: string;
  130. district?: string;
  131. picList?: string[];
  132. appListPicUrl?: string[];
  133. introduceVideo?: string[];
  134. location?: string[];
  135. }
  136. let map;
  137. // Lat(120.262337, 30.178285),
  138. const myData = reactive({
  139. sceneUrl: '',
  140. id: '',
  141. introduceVideoCover: '',
  142. });
  143. const filterOption = (input, option) => {
  144. return option.sceneName.includes(input.toLowerCase());
  145. };
  146. const defaultAddress = reactive({
  147. address: '山阴路688号恒隆广场B座1217',
  148. // address: '权晖花园21栋',
  149. lng: 120.262337,
  150. lat: 30.178285,
  151. location: ['浙江省', '杭州市', '滨江区'],
  152. province: '浙江省',
  153. city: '杭州市',
  154. district: '萧山区',
  155. });
  156. const { toPromise } = useScript({ src: A_MAP_URL });
  157. const { t } = useI18n();
  158. const { createMessage } = useMessage();
  159. const schemas: FormSchema[] = [
  160. {
  161. field: 'type',
  162. label: t('routes.scenes.liveType'),
  163. component: 'ApiSelect',
  164. required: true,
  165. itemProps: {
  166. validateTrigger: 'blur',
  167. },
  168. componentProps: {
  169. api: brandTypeListApi,
  170. resultField: 'list',
  171. labelField: 'name',
  172. valueField: 'brandType',
  173. params: {
  174. page: 1,
  175. limit: 1000,
  176. },
  177. },
  178. },
  179. {
  180. field: 'name',
  181. component: 'Input',
  182. label: t('routes.scenes.liveName'),
  183. required: true,
  184. helpMessage: '仅能输入 英文大小写和中文,最多可输入50个字',
  185. componentProps: {
  186. maxLength: 25,
  187. },
  188. },
  189. {
  190. field: 'appListPicUrl',
  191. label: t('routes.scenes.appListPicUrl'),
  192. component: 'Upload',
  193. helpMessage: '推荐大小:400 * 400 像素',
  194. required: true,
  195. colProps: {
  196. span: 10,
  197. },
  198. componentProps: {
  199. accept: ['jpg', 'jpeg', 'gif', 'png'],
  200. maxSize: 5,
  201. maxNumber: 1,
  202. api: uploadLiveApi,
  203. onChange: async () => {
  204. await validateFields(['appListPicUrl']);
  205. },
  206. maxgoodsNumber: 1,
  207. afterFetch: function (data) {
  208. Reflect.set(data, 'url', data.message.url);
  209. return data;
  210. },
  211. },
  212. },
  213. {
  214. field: 'simpleDesc',
  215. component: 'InputTextArea',
  216. label: t('routes.scenes.simpleDesc'),
  217. required: true,
  218. },
  219. {
  220. field: 'sceneNum',
  221. label: t('routes.scenes.sceneUrl'),
  222. component: 'Input',
  223. colProps: {
  224. span: 10,
  225. },
  226. itemProps: {
  227. validateTrigger: 'blur',
  228. },
  229. required: true,
  230. helpMessage: '直播间绑定后,将无法修改',
  231. slot: 'sceneNum',
  232. // componentProps: {
  233. // api: getAllSceneApi,
  234. // immediate: true,
  235. // resultField: 'list',
  236. // labelField: 'sceneName',
  237. // valueField: 'num',
  238. // onChange: function (_, item) {
  239. // console.log('onChange', item);
  240. // myData.sceneUrl = item.webSite || item.sceneUrl || item.liveRoomUrl;
  241. // },
  242. // onSearch:function(vale,item) {
  243. // console.log('onChange', vale,item);
  244. // },
  245. // params: {
  246. // page: 1,
  247. // limit: 100,
  248. // },
  249. // },
  250. },
  251. {
  252. field: 'location',
  253. label: '直播间位置',
  254. component: 'ApiCascader',
  255. itemProps: {
  256. validateTrigger: 'blur',
  257. },
  258. componentProps: {
  259. api: () => {
  260. // return ProvincesData;
  261. return CascaderData;
  262. },
  263. apiParamKey: 'provinceCode',
  264. dataField: 'children',
  265. labelField: 'name',
  266. valueField: 'name',
  267. // numberToString: true,
  268. isLeaf: (record) => {
  269. return !(record.levelType < 3);
  270. },
  271. onChange: (data) => {
  272. try {
  273. console.log('data', data);
  274. let location: string[] = data;
  275. // [a,b,c].map(ele => {
  276. // return ele && ele.code
  277. // } ),
  278. let province = data[0],
  279. city = data[1],
  280. district = data[2];
  281. defaultAddress.location = location;
  282. defaultAddress.province = province;
  283. defaultAddress.city = city;
  284. defaultAddress.district = district;
  285. } catch (error) {
  286. console.error('error', error);
  287. }
  288. },
  289. },
  290. colProps: {
  291. span: 20,
  292. },
  293. },
  294. {
  295. field: 'detailAddr',
  296. label: t('routes.scenes.detailAddr'),
  297. component: 'Input',
  298. slot: 'detailAddr',
  299. colProps: {
  300. span: 10,
  301. },
  302. },
  303. {
  304. field: 'map',
  305. label: '地图位置',
  306. component: 'Input',
  307. slot: 'map',
  308. colProps: {
  309. span: 20,
  310. },
  311. },
  312. {
  313. field: 'picList',
  314. label: '直播间图片',
  315. component: 'Upload',
  316. helpMessage: '推荐大小:400 * 400 像素',
  317. componentProps: {
  318. api: uploadLiveApi,
  319. maxSize: 5,
  320. emptyHidePreview: true,
  321. maxNumber: 15,
  322. accept: ['jpg', 'jpeg', 'gif', 'png'],
  323. afterFetch: function (data) {
  324. Reflect.set(data, 'url', data.message.url);
  325. return data;
  326. },
  327. },
  328. colProps: {
  329. span: 20,
  330. },
  331. },
  332. // {
  333. // field: 'introduceVideo',
  334. // label: '视频',
  335. // component: 'Upload',
  336. // componentProps: {
  337. // api: uploadLiveVideoApi,
  338. // maxSize: 100,
  339. // emptyHidePreview: true,
  340. // maxNumber: 1,
  341. // accept: ['video/*'],
  342. // afterFetch: function (data) {
  343. // Reflect.set(data, 'url', data.message.video);
  344. // myData.introduceVideoCover = data.message.image;
  345. // return data;
  346. // },
  347. // },
  348. // colProps: {
  349. // span: 20,
  350. // },
  351. // },
  352. {
  353. field: 'sortOrder',
  354. component: 'InputNumber',
  355. label: t('routes.scenes.sortOrder'),
  356. // required: true,
  357. defaultValue: 1,
  358. componentProps: {
  359. min: 0,
  360. },
  361. },
  362. {
  363. field: 'livestreamStatus',
  364. component: 'RadioGroup',
  365. label: t('routes.scenes.livestream'),
  366. required: true,
  367. defaultValue: 0,
  368. componentProps: {
  369. options: [
  370. {
  371. label: '是',
  372. value: 1,
  373. key: 1,
  374. },
  375. {
  376. label: '否',
  377. value: 0,
  378. key: 0,
  379. },
  380. ],
  381. },
  382. },
  383. // {
  384. // field: 'contractPhone',
  385. // component: 'Input',
  386. // label: t('routes.scenes.contractPhone'),
  387. // required: true,
  388. // helpMessage: ['支持填写400(400-xxx-xxxx)热线、手机号等联系方式'],
  389. // },
  390. {
  391. field: 'contactId',
  392. component: 'ApiSelect',
  393. label: '场景联系人',
  394. required: true,
  395. componentProps: {
  396. api: staffListApi,
  397. resultField: 'list',
  398. labelField: 'nickName',
  399. valueField: 'id',
  400. immediate: true,
  401. showSearch: true,
  402. optionFilterProp: 'label',
  403. onOptionsChange: async (data) => {
  404. const isDeaultUser = data.find((i) => i.value === Number(userinfo.value.id));
  405. if (isDeaultUser && !isDeaultContactUser.value) {
  406. isDeaultUser.id = Number(isDeaultUser.value);
  407. isDeaultContactUser.value = isDeaultUser;
  408. }
  409. },
  410. onChange: function (model, opt) {
  411. console.log('model', model);
  412. console.log('opt', opt);
  413. // Reflect.set(modalRecord, 'shippingName', opt.label);
  414. },
  415. params: {
  416. page: 1,
  417. limit: 1000,
  418. },
  419. required: true,
  420. },
  421. itemProps: {
  422. validateFirst: true,
  423. validateTrigger: 'select',
  424. },
  425. },
  426. ];
  427. // updateSchema, validate
  428. const [
  429. registerForm,
  430. { resetFields, setFieldsValue, updateSchema, validate, validateFields },
  431. ] = useForm({
  432. labelWidth: 120,
  433. schemas: schemas,
  434. showActionButtonGroup: false,
  435. baseColProps: { lg: 24, md: 24 },
  436. });
  437. const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
  438. resetFields();
  439. setDrawerProps({ confirmLoading: false });
  440. isUpdate.value = !!data?.isUpdate;
  441. const { record } = data;
  442. let Option = await getAllSceneApi({
  443. page: 1,
  444. limit: 100,
  445. sceneNum: record && record.sceneNum,
  446. });
  447. // @ts-ignore
  448. sceneNumOption.list = Option.list.map((ele) => {
  449. return {
  450. ...ele,
  451. label: ele.sceneName,
  452. // @ts-ignore
  453. value: ele.num,
  454. };
  455. });
  456. sceneNumOption.allList = sceneNumOption.list;
  457. console.log('isUpdate', isUpdate.value, data);
  458. await updateSchema({
  459. field: 'sceneNum',
  460. componentProps: {
  461. api: getAllSceneApi,
  462. disabled: isUpdate.value,
  463. immediate: true,
  464. resultField: 'list',
  465. labelField: 'sceneName',
  466. valueField: 'num',
  467. onChange: function (_, item) {
  468. myData.sceneUrl = item.webSite || item.sceneUrl || item.liveRoomUrl;
  469. },
  470. params: {
  471. page: 1,
  472. limit: 100,
  473. sceneNum: record && record.sceneNum,
  474. },
  475. },
  476. });
  477. // console.log('isDeaultContactUser', isDeaultContactUser.value?.id);
  478. if (unref(isUpdate)) {
  479. try {
  480. const res = await getLiveInfoApi({ id: record.id, token });
  481. // console.log('edit', res);
  482. let setDAta = reactive<infoItem>({
  483. province: '',
  484. city: '',
  485. district: '',
  486. address: '',
  487. picList: [],
  488. appListPicUrl: [],
  489. introduceVideo: [],
  490. });
  491. let ssq = res.address?.split(' ');
  492. try {
  493. let ssqlist = ssq[0].split(',');
  494. setDAta.province = ssqlist[0];
  495. setDAta.city = ssqlist[1];
  496. setDAta.district = ssqlist[2];
  497. setDAta.address = ssq[1];
  498. setDAta.location = ssqlist;
  499. setDAta.picList = res.picList?.split('#$#') || [];
  500. setDAta.appListPicUrl = [res.appListPicUrl];
  501. setDAta.introduceVideo = [res.introduceVideo];
  502. defaultAddress.address = ssq[1];
  503. defaultAddress.province = ssqlist[0];
  504. defaultAddress.city = ssqlist[1];
  505. defaultAddress.district = ssqlist[2];
  506. defaultAddress.location = ssqlist;
  507. defaultAddress.lng = res.longitude;
  508. defaultAddress.lat = res.latitude;
  509. detailAddr.value = ssq[2];
  510. } catch (error) {
  511. console.warn('edit-error', error);
  512. }
  513. myData.introduceVideoCover = res.introduceVideoCover || '';
  514. myData.sceneUrl = res.sceneUrl;
  515. await setFieldsValue({
  516. ...res,
  517. ...setDAta,
  518. });
  519. myData.introduceVideoCover = res.introduceVideoCover;
  520. editRecord.value = res;
  521. } catch (error) {
  522. console.error(error);
  523. }
  524. } else {
  525. editRecord.value = false;
  526. }
  527. myData.id = (record && record.id) || false;
  528. // if (isDeaultContactUser.value?.id) {
  529. // console.log('hey');
  530. // await setFieldsValue({
  531. // contactId: isDeaultContactUser.value.id,
  532. // });
  533. // }
  534. initMap();
  535. });
  536. watch(
  537. () => [editRecord, isDeaultContactUser],
  538. async ([edit, user]) => {
  539. console.log('update', edit.value);
  540. // if (!edit.value && user.value) {
  541. // await setFieldsValue({
  542. // contactId: user.value.id,
  543. // });
  544. // }
  545. //
  546. if (!isBoolean(edit.value) && !isBoolean(user.value)) {
  547. if (user.value.contactId === '') {
  548. await setFieldsValue({
  549. contactId: user.value.id,
  550. });
  551. }
  552. }
  553. //新增
  554. if (isBoolean(edit.value) && !isBoolean(user.value)) {
  555. await setFieldsValue({
  556. contactId: user.value.id,
  557. });
  558. }
  559. },
  560. {
  561. deep: true,
  562. immediate: true,
  563. },
  564. );
  565. async function initMap() {
  566. console.log('initMap');
  567. await toPromise();
  568. await nextTick();
  569. const wrapEl = unref(wrapRef);
  570. if (!wrapEl) return;
  571. // center: [this.longitude || 120.262337, this.latitude || 30.178285],
  572. // const geocoder = new AMap.Geocoder({});
  573. let searchCity = getCode(defaultAddress.location);
  574. const AMap = (window as any).AMap;
  575. let center = [defaultAddress.lng, defaultAddress.lat];
  576. map = new AMap.Map(wrapEl, {
  577. zoom: 18,
  578. center: center,
  579. viewMode: '3D',
  580. resizeEnable: true,
  581. floorControl: true,
  582. showIndoorMap: true,
  583. });
  584. AMap.plugin('AMap.Geocoder', function () {
  585. var geocoder = new AMap.Geocoder({
  586. // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
  587. city: searchCity[2] || searchCity[1] || searchCity[0],
  588. });
  589. geocoder.getLocation(defaultAddress.address, async function (status, result) {
  590. if (status === 'complete' && result.info === 'OK') {
  591. // result中对应详细地理坐标信息
  592. const { geocodes } = result;
  593. if (geocodes?.length > 0) {
  594. const { addressComponent } = geocodes[0] as any as GeocodesType;
  595. defaultAddress.location = getCodeArray(addressComponent);
  596. await updateSchema({
  597. field: 'location',
  598. componentProps: {
  599. displayRenderArray: [
  600. addressComponent.province,
  601. addressComponent.city,
  602. addressComponent.district,
  603. ],
  604. },
  605. });
  606. await setFieldsValue({
  607. location: defaultAddress.location,
  608. // detailAddr: defaultAddress.address,
  609. });
  610. detailAddr.value = defaultAddress.address;
  611. }
  612. } else {
  613. createMessage.error('查询地址异常');
  614. }
  615. });
  616. // const marker = new AMap.Marker({
  617. // position: new AMap.LngLat(defaultAddress.lng, defaultAddress.lat),
  618. // title: 'lala',
  619. // });
  620. // map && map.add(marker);
  621. });
  622. }
  623. function handleChange(value, item) {
  624. console.log('handleChange', value, item);
  625. console.log('myData.sceneUrl', myData.sceneUrl);
  626. setFieldsValue({
  627. sceneNum: value,
  628. });
  629. }
  630. async function handleSearch(value) {
  631. if (!value) {
  632. return (sceneNumOption.list = sceneNumOption.allList);
  633. }
  634. let { list } = await ListApi({
  635. sceneName: value,
  636. limit: 100,
  637. page: 1,
  638. });
  639. // @ts-ignore
  640. sceneNumOption.list = list.map((ele) => {
  641. return {
  642. ...ele,
  643. // @ts-ignore
  644. value: ele.num,
  645. label: ele.sceneName,
  646. };
  647. });
  648. console.log('handleSearch', value, list);
  649. }
  650. function getCodeArray(addressComponent) {
  651. let { province, city, district } = addressComponent;
  652. return [province, city, district];
  653. }
  654. const getTitle = computed(() => (!unref(isUpdate) ? '新增直播间' : '编辑直播间'));
  655. async function handleMapSearch() {
  656. console.log('handleMapSearch');
  657. console.log('detailAddr', detailAddr.value, defaultAddress);
  658. if (detailAddr.value?.length > 0) {
  659. let searchCity = getCode(defaultAddress.location);
  660. const AMap = (window as any).AMap;
  661. AMap.plugin('AMap.Geocoder', function () {
  662. const geocoder = new AMap.Geocoder({
  663. // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
  664. city: searchCity[2] || searchCity[1] || searchCity[0],
  665. // adcode: defaultAddress.location[2],
  666. // citycode: '0571',
  667. });
  668. geocoder.getLocation(detailAddr.value, async function (status, result) {
  669. if (status === 'complete' && result.info === 'OK') {
  670. // result中对应详细地理坐标信息
  671. const { geocodes } = result;
  672. if (geocodes?.length > 0) {
  673. // map.setCenter([lng, lat]);
  674. const { addressComponent, formattedAddress, location } =
  675. geocodes[0] as any as GeocodesType;
  676. map.setCenter(location);
  677. const marker = new AMap.Marker({
  678. position: new AMap.LngLat(location.lng, location.lat),
  679. title: formattedAddress,
  680. });
  681. map.add(marker);
  682. defaultAddress.lng = location.lng;
  683. defaultAddress.lat = location.lat;
  684. defaultAddress.location = getCodeArray(addressComponent);
  685. await updateSchema({
  686. field: 'location',
  687. componentProps: {
  688. displayRenderArray: [
  689. addressComponent.province,
  690. addressComponent.city,
  691. addressComponent.district,
  692. ],
  693. },
  694. });
  695. await setFieldsValue({
  696. location: defaultAddress.location,
  697. // detailAddr: defaultAddress.address,
  698. });
  699. // detailAddr.value = defaultAddress.address;
  700. }
  701. } else {
  702. createMessage.error('查询地址异常');
  703. }
  704. });
  705. });
  706. }
  707. }
  708. async function handleMapReset() {
  709. defaultAddress.location = ['33', '3301', '330109'];
  710. detailAddr.value = '山阴路688号恒隆广场B座1217';
  711. handleMapSearch();
  712. }
  713. async function handleSubmit() {
  714. const { companyId, id } = userinfo.value;
  715. const { lng, lat } = defaultAddress;
  716. let requestApi = isUpdate.value ? brandUpdateApi : addSave;
  717. try {
  718. map && map.destroy();
  719. const values = await validate();
  720. const { location, picList, appListPicUrl = [], introduceVideo = [] } = values;
  721. let address = unref(location);
  722. let apiData = {
  723. ...values,
  724. // contractPhone:phone,
  725. createUserDeptId: companyId,
  726. latitude: lat,
  727. longitude: lng,
  728. createUserId: id,
  729. address: address.join(',') + ' ' + detailAddr.value,
  730. picList: picList && picList.join('#$#'),
  731. appListPicUrl: appListPicUrl[0],
  732. introduceVideo: introduceVideo[0],
  733. sceneUrl: myData.sceneUrl,
  734. introduceVideoCover: myData.introduceVideoCover,
  735. };
  736. if (myData.id) {
  737. apiData.id = myData.id;
  738. }
  739. await requestApi(apiData);
  740. resetFields();
  741. closeDrawer();
  742. createMessage.success(t('common.optSuccess'));
  743. emit('success');
  744. } catch (error) {
  745. console.error(error);
  746. }
  747. }
  748. async function handleClose() {
  749. map && map.destroy();
  750. resetFields();
  751. isDeaultContactUser.value = false;
  752. editRecord.value = false;
  753. closeDrawer();
  754. }
  755. return {
  756. detailAddr,
  757. myData,
  758. registerDrawer,
  759. registerForm,
  760. getTitle,
  761. handleSubmit,
  762. wrapRef,
  763. handleMapSearch,
  764. handleMapReset,
  765. handleClose,
  766. t,
  767. token,
  768. sceneNumOption,
  769. isUpdate,
  770. handleChange,
  771. handleSearch,
  772. getOptions,
  773. filterOption,
  774. };
  775. },
  776. });
  777. </script>
  778. <style lang="less">
  779. .live-drawer {
  780. .ant-input-group-addon {
  781. padding-right: 0;
  782. background-color: transparent;
  783. border: none;
  784. button {
  785. font-size: 14px;
  786. }
  787. }
  788. }
  789. </style>