123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <template>
- <view>
- <cu-custom bgColor="bg-blue" :isBack="true">
- <block slot="backText"></block>
- <block slot="content">选择关联工程部位</block>
- <block slot="right">
- <text @click="preservation">保存</text>
- </block>
- </cu-custom>
- <view class="hc-tree-box">
- <ly-tree ref="ptree" lazy showCheckbox checkStrictly accordion
- nodeKey="id" :load="getTreeData"
- :defaultCheckedKeys="defaultChecked"
- :defaultExpandedKeys="defaultExpanded"
- />
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- project: {},
- userid: '',
- defaultExpanded: [],//默认展开
- defaultChecked: [],//默认选中
- }
- },
- onLoad() {
- const {id} = uni.getStorageSync("userInfo")
- this.project = uni.getStorageSync(`porject_${id}`);
- this.userid = id;
- this.setTreeChecked();
- },
- methods: {
- setTreeChecked() {
- this.defaultChecked = [];
- let selects = getApp().globalData.relationId;
- if (selects) {
- let relationIds = selects ? selects.split(',') : []
- this.defaultChecked = relationIds;
- this.$refs?.ptree?.setCheckedKeys(relationIds)
- }
- },
- async getTreeData(node, resolve) {
- let form = {type: 0, id: ''};
- if (node.level === 0) {
- form = {type: 0, id: ''};
- } else {
- form.id = (node && node.data) ? node.data.id : '';
- }
- //发起请求
- this.http.request('/app/qualityModifyInfo/getDataByparantId', {
- ...form,
- projectId: this.project.id,
- contractId: this.project.contractId,
- }).then((result) => {
- if (result.datas != null) {
- resolve(result.datas);
- } else {
- resolve([]);
- }
- })
- },
- //设置保存
- preservation() {
- uni.showLoading({title: '处理数据中...', mask: true})
- let relation = '', relationId = ''
- const nodes = this.$refs?.ptree?.getCheckedNodes()
- for (let i = 0; i < nodes.length; i++) {
- const { id, name } = nodes[i]
- relation = relation ? relation + ',' + name : name;
- relationId = relationId ? relationId + ',' + id : id;
- }
- //返回数据
- uni.$emit("relation", {
- relation,
- relationId,
- })
- uni.hideLoading()
- //返回上级
- uni.navigateBack({
- delta:1
- })
- },
- }
- }
- </script>
- <style>
- page{
- background-color: white;
- }
- .hc-tree-box {
- position: relative;
- overflow: auto;
- }
- </style>
|