123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <view>
- <view>
- <uni-search-bar :radius="100" @confirm="search" @input="input" @cancel="cancel"></uni-search-bar>
- </view>
- <uni-forms ref="form" @submit="submitForm">
- <uni-list>
- <checkbox-group @change="checkboxChange">
- <uni-list-item v-for="(item,index) in contractList" :key="index">
- <!-- 自定义 header -->
- <view slot="header" class="slot-box">
- <checkbox :value="item.contractCode" />
- </view>
- <!-- 自定义 body -->
- <view slot="body" class="slot-box">
- {{item.contractID}}
- </view>
- <!-- 自定义 footer-->
- <view slot="footer" class="slot-box">
- {{item.contractName}}
- </view>
- </uni-list-item>
- </checkbox-group>
- </uni-list>
- <view class="uni-btn-v uni-column">
- <button type="primary" form-type="submit" style="border-radius: 15px;">选择成功,确认</button>
- </view>
- </uni-forms>
- </view>
- </template>
- <script>
- import {
- GetRelationContract
- } from "@/common/api/requisitionApi.js";
- export default {
- data() {
- return {
- contractList: [],
- checkboxValues: [],
- searchVal: ''
- }
- },
- onLoad: function() {
- //console.info('授权');
- //console.info(this.$auth);
- this.$util.persistLogin(this);
- },
- created: function() {
- this.getcontractList();
- },
- methods: {
- getcontractList: function() {
- var that = this;
- var projectCode = this.$util.getState(this,"projectCode");
- let searchValue = this.searchVal;
- uni.showLoading({
- title: "页面努力加载中,请稍候...",
- mask: true
- });
- console.info("projectCode",projectCode);
- if(this.$util.isEmpty(projectCode)){
- uni.showToast({
- title:'项目编号丢失,请重新登录',
- duration:4000,
- icon:'none'
- });
- return;
- }
- GetRelationContract(projectCode, searchValue).then((res) => {
- uni.hideLoading();
- console.info('getcontractList');
- //console.info(projectCode);
- console.info(res);
- //return;
- res.forEach(function(item, index, array) {
- that.$set(that.contractList, index, item);
- });
- //console.info(that.contractList);
- });
- },
- checkboxChange: function(e) {
- var items = this.contractList,
- values = e.detail.value;
- this.checkboxValues = values.join(',');
- console.info("values");
- console.info(values);
- console.info(this.checkboxValues);
- for (var i = 0, lenI = items.length; i < lenI; ++i) {
- const item = items[i]
- if (values.includes(item.value)) {
- this.$set(item, 'checked', true)
- } else {
- this.$set(item, 'checked', false)
- }
- }
- },
- submitForm(e) {
- console.info(this.checkboxValues);
- //先记录值,下面this指向会不一样
- let relationContractCodes = this.checkboxValues;
- let arr=relationContractCodes.split(',');
- let selectChecked=[];
- this.contractList.forEach(function(item,index,array){
- arr.forEach(function(item1,index1,array1){
- if(item.contractCode==item1){
- selectChecked.push({contractCode:item.contractCode,contractID:item.contractID,contractName:item.contractName,estimateCash:0.00});
-
- }
- });
- });
- //将数据发射到父级监听事件中
- uni.$emit('fire', selectChecked);
- //关闭当前窗口
- uni.navigateBack({});
- },
- search(res) { //回车搜索
- this.searchvalue = res.value; //赋值
- this.contractList=[];
- this.getcontractList(); //调用搜索方法
- },
- input(res) {
- this.searchVal = res.value
- },
- cancel(res) {
- console.info('点击取消,输入值为:' + res.value);
-
- },
-
- }
- }
- </script>
- <style scoped>
- .slot-box {
- margin: 5px 5px;
- }
- .uni-btn-v {
- position: fixed;
- bottom: 0;
- width: 100%;
- }
- uni-view{
- font-size:15px;
- }
- </style>
|