search.vue 2.61 KB
Newer Older
1 2 3
<template>
	<!-- 搜索界面 -->
	<view class="">
阮藤's avatar
阮藤 committed
4
		<u-navbar :is-back="true" :borderBottom="false" :background="{ backgroundColor: '#F5F5F5' }" title="">
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
			<view class="slot-wrap">
				<view class="search-wrap">
					<u-search
						@change="changeCli"
						@search="searchEng"
						bg-color="#fff"
						border-color="#d5aa7a"
						placeholder="请输入名称"
						:show-action="false"
						v-model="value"
					></u-search>
				</view>
			</view>
		</u-navbar>
		<!-- 列表 -->
		<view class="home_con_order u-p-l-30 u-p-r-30">
阮藤's avatar
阮藤 committed
21 22 23
			<view class="u-flex u-m-t-30 hs-height-120 u-border-bottom" @click="searchEng(item.materialName)" v-for="item in fiabricList">
				<image class="hs-img-48 u-m-r-20" src="@/static/images/home/search@2x.png" mode=""></image>
				<text class="u-font-28 u-flex-1 text-cut" v-html="brightenKeyword(item.materialName,value)"></text>
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
import home from '../mixin/index.js';
export default {
	mixins: [home],
	data() {
		return {
			value: '',
			size: 10,
			total: 0,
			state: 1,
			fiabricList: []
		};
	},
	onLoad(option) {
		this.state = option.state;
	},
	methods: {
阮藤's avatar
阮藤 committed
47 48 49 50 51 52 53 54
		brightenKeyword(val, keyword) {
			val = val + '';
			if (val.indexOf(keyword) !== -1 && keyword !== '') {
				return val.replace(keyword, '<font color="#AF8D66">' + keyword + '</font>');
			} else {
				return val;
			}
		},
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
		filterSwitch() {
			const val = this.state;
			switch (val) {
				case 1:
					// 款式
					this.entrustmentPage();
					return;
				case 2:
					// 建模
					return;
				default:
					// 款式
					this.entrustmentPage();
					return;
			}
		},
		changeCli() {
			this.size = 10;
			this.filterSwitch();
		},
		searchEng(item) {
			let data = item || this.value;
			try {
				uni.setStorageSync('styleSearch', data);
				uni.navigateBack({
					delta: 1
				});
			} catch (e) {
				// error
			}
		},
		// 款式委托
		entrustmentPage() {
			this.$http(
				'orderTicket.entrustmentPage',
				{
					size: this.size,
					materialCode: '',
					status: 0,
					materialName: this.value
				},
				'加载中...'
			)
				.then(res => {
					let { code, data } = res;
					if (code == 200) {
						this.fiabricList = data.data;
						this.total = data.total;
						this.$refs.uToast.show({
							title: '操作成功'
						});
					}
				})
				.catch(err => {
					this.$refs.uToast.show({
						title: '操作失败'
					});
				});
		}
	}
};
</script>
<style lang="scss" scoped>
.slot-wrap {
	display: flex;
	align-items: center;
	flex: 1;
}
.search-wrap {
	margin: 0 20rpx;
	flex: 1;
}
阮藤's avatar
阮藤 committed
127 128 129
.ver_middle {
	vertical-align: middle;
}
130
</style>