uniapp 微信小程序 请求接口并同步选择数据弹窗

uniapp yekong

微信小程序 请求接口并同步选择数据弹窗

/**
* @Author: 858834013@qq.com
* @Name: GetUionCustomers
* @Date: 2022-04-27
* @Desc: 获取关联客户
*/
<template>
	<div>
		<div @click="getshow">
			<div class="selectbody1 ml28">
				<text>客户:{{name}}</text>
				<image src="https://images.wanjunshijie.com/mini/buildingMaterialsCloud/static/icon_down.png" mode="">
				</image>
			</div>
		</div>
		<u-picker :title="title" :show="show" @cancel="show=false" @confirm="getConfirm" :columns="list"></u-picker>
	</div>
</template>

<script>
	import {
		GetUionCustomers
	} from '@/config/api.js'
	export default {
		name: 'CommodityType',
		props: {
			value: {
				type: Object | String,
				default () {
					return {}
				}
			},
			title: {
				type: String,
				default () {
					return ''
				}
			},
		},
		data() {
			return {
				show: false,
				BelongId: '',
				AccountId: '',
				datalist: [],
				list: [
					[]
				]
			};
		},
		computed: {
			name: function() {
				var name = '请选择'
				this.datalist.forEach((type) => {
					if (this.value == type.Id) {
						name = type.CustomerName
					}
				});
				return name
			}
		},
		mounted() {
			this.BelongId = JSON.parse(uni.getStorageSync('userData')).BelongId
			this.getdata()
		},
		methods: {
			getshow() {
				this.show = true
			},
			getConfirm(e) {
				var that = this;
				that.$emit("update:value", that.datalist[e.indexs[0]].Id);
				this.show = false
			},
			getdata() {
				var that = this;
				that.list[0] = [];
				that.datalist = []
				GetUionCustomers({
					params: {
						CompanyId: that.BelongId,
						pageIndex: 1,
						pageSize: 1000
					},
					custom: {
						auth: true
					}
				}).then(res => {
					if (res.Code == 200) {
						that.datalist = res.Data
						that.datalist.forEach((type) => {
							that.list[0].push(type.CustomerName)
						});
					}
				}).catch(err => {

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.selectbody1 {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: nowrap;
		flex-direction: row;
		align-content: flex-start;
		height: 60rpx;
		background: #F5F6FC;
		border-radius: 8rpx;
		margin-right: 20rpx;

		text {
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #151852;
			margin-left: 10rpx;
			width: 200rpx;
			// margin-right: 18rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		image {
			width: 21rpx;
			height: 13rpx;
			margin-left: 18rpx;
			margin-right: 16rpx;
		}
	}

	.ml28 {
		margin-left: 28rpx;
	}
</style>

使用

<GetUionCustomers title="选择客户" :value.sync="CustomerId"></GetUionCustomers>
喜欢