添加组件
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-picker": "tdesign-miniprogram/picker/picker",
|
||||
"t-picker-item": "tdesign-miniprogram/picker-item/picker-item",
|
||||
"t-cell": "tdesign-miniprogram/cell/cell"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { post } from '@/utils/https';
|
||||
import { getAuthInfo, toArray } from '@/utils/util';
|
||||
|
||||
Component({
|
||||
options: { multipleSlots: true },
|
||||
/**
|
||||
* 组件的属性列表
|
||||
*/
|
||||
properties: {
|
||||
value: {
|
||||
type: null,
|
||||
},
|
||||
},
|
||||
observers: {
|
||||
value: function () {
|
||||
this.setData({ label: this.data.listToObj[this.data.value]?.label });
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
visible: false,
|
||||
list: [] as any[],
|
||||
listToObj: {} as any,
|
||||
label: '',
|
||||
},
|
||||
lifetimes: {
|
||||
attached() {
|
||||
const auth = getAuthInfo();
|
||||
const SF_ERP_ACCOUNT_VIEW = auth.SF_ERP_ACCOUNT_VIEW;
|
||||
post('ErpAccount/list', { state: 1 }).then((res: any) => {
|
||||
let accountDefaultObj: any = {};
|
||||
const list = toArray(res?.data?.list).map((el) => {
|
||||
if (el.if_default == 2) {
|
||||
accountDefaultObj = el;
|
||||
}
|
||||
const label = `${el.account_name}${
|
||||
SF_ERP_ACCOUNT_VIEW ? `(余额: ${el.current_amount})` : ''
|
||||
}`;
|
||||
el.label = label;
|
||||
this.data.listToObj[el.account_id] = el;
|
||||
return {
|
||||
label: label,
|
||||
value: el.account_id,
|
||||
};
|
||||
});
|
||||
if (!accountDefaultObj) {
|
||||
accountDefaultObj = list[0] || {};
|
||||
}
|
||||
this.setData({ list: list, label: this.data.listToObj[this.data.value]?.label });
|
||||
this.triggerEvent('default', accountDefaultObj);
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
onShowPicker() {
|
||||
this.setData({ visible: true });
|
||||
},
|
||||
onPickerCancel() {
|
||||
this.setData({ visible: false });
|
||||
},
|
||||
onPickerConfirm(e: any) {
|
||||
// console.log(e);
|
||||
const item = this.data.listToObj[e.detail.value[0]];
|
||||
this.triggerEvent('ok', item);
|
||||
this.setData({ visible: false });
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
<t-cell arrow note="{{label}}" hover bind:click="onShowPicker">
|
||||
<view slot="title" class="custom-label">选择账户</view>
|
||||
</t-cell>
|
||||
<t-picker visible="{{visible}}" value="{{value}}" title="选择账户" cancelBtn="取消" confirmBtn="确认"
|
||||
bindconfirm="onPickerConfirm" bindcancel="onPickerCancel">
|
||||
<t-picker-item options="{{list}}">
|
||||
<block wx:for="{{list}}" wx:key="index" wx:for-item="option">
|
||||
<view wx:if="{{option.tag}}" slot="label-suffix--{{index}}" class="label-suffix">
|
||||
<t-tag size="small" theme="primary">{{option.tag}}</t-tag>
|
||||
</view>
|
||||
</block>
|
||||
</t-picker-item>
|
||||
</t-picker>
|
||||
@@ -0,0 +1,10 @@
|
||||
.custom-label {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.custom-label::after {
|
||||
content: '*';
|
||||
color: red;
|
||||
font-size: 32rpx;
|
||||
margin-left: 4rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user