searchFilter.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <u-popup mode="bottom" :round="10" :show="show" @close="close" @open="open" closeable>
  3. <u--form labelPosition="left" :model="formData" ref="uForm">
  4. <u-form-item label="品牌" @click="showBrandList" labelWidth="70">
  5. <Cell :val="formData.dictLabel" :isDelete="true" :border="true" @handleClear="clear('dictLabel')"></Cell>
  6. <BrandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></BrandList>
  7. </u-form-item>
  8. <u-form-item label="实价范围" labelWidth="70">
  9. <u-input v-model="formData.minPrice" placeholder="最小价格" fontSize="14" border="bottom" clearable></u-input>
  10. &nbsp;&nbsp;——&nbsp;&nbsp;
  11. <u-input v-model="formData.maxPrice" placeholder="最大价格" fontSize="14" border="bottom" clearable></u-input>
  12. </u-form-item>
  13. <u-form-item label="位置" labelWidth="70">
  14. <u-input v-model="formData.location" fontSize="14" clearable border="bottom"></u-input>
  15. </u-form-item>
  16. <u-form-item label="回收时间" labelWidth="70" @click="openTimePicker">
  17. <Cell :val="time" :isDelete="true" :border="true" @handleClear="clear('time')"> </Cell>
  18. <JTimePicker :isShowShortTimeList="true" shortTimeTitle="快捷时间" :shortTimeList="shortTimeList"
  19. :isShowSeletTimeTitle="true" seletTimeTitle="时间选择" cancelText="取消" confirmText="确认"
  20. :endSelectMonth="-1" :endSelectDay="-1" beginTimePlaceHolder='开始时间' endTimePlaceHolder="结束时间"
  21. :isDateTypeRange="true" :isShowSelectedTimeEcho="true" @confirm="getSelectTime" :defaultSelect="0"
  22. ref="jtimePickerPopupRef">
  23. </JTimePicker>
  24. </u-form-item>
  25. <u-form-item label="回收人员" labelWidth="70" @click="recyclePersonClick">
  26. <Cell :val="formData.recyclePerson" :isDelete="true" :border="true" @handleClear="clear('recyclePerson')"></Cell>
  27. <PersonPicker ref="recyclePersonPickerRef" title="请选择回收人员" @selectPerson="handleSelectRecyclePerson"></PersonPicker>
  28. </u-form-item>
  29. <u-form-item label="鉴定人员" labelWidth="70" @click="identifyingPersonClick">
  30. <Cell :val="formData.identifyingPerson" :isDelete="true" :border="true" @handleClear="clear('identifyingPerson')"></Cell>
  31. <PersonPicker ref="identifyingPersonPickerRef" title="请选择鉴定人员" @selectPerson="handleSelectIdentifyingPerson"></PersonPicker>
  32. </u-form-item>
  33. <u-form-item label="商品属性" labelWidth="70">
  34. <TabSelect :tabList="productAttributeList" :colNum="3" :echoInfo="formData.productAttribute" mode="multiple" @tabChange="handleTabChangeProductAttribute"></TabSelect>
  35. </u-form-item>
  36. <u-form-item label="是否入库" labelWidth="70">
  37. <TabSelect :tabList="stockStatusListAll" :colNum="4" :echoInfo="formData.stockStatus" mode="single" @tabChange="handleTabChangeStockStatus"></TabSelect>
  38. </u-form-item>
  39. <u-form-item label="排序方式" labelWidth="70" @click="openSortPicker">
  40. <Cell :val="curSortType.label" :isDelete="false" :border="true"></Cell>
  41. <u-picker ref="sortPicker" :show="sortPickerShow" :columns="sortColumns" keyName="label" @confirm="handleSortChange"
  42. @cancel="sortPickerShow = false"></u-picker>
  43. </u-form-item>
  44. </u--form>
  45. <view class="btns">
  46. <u-button text="重置" @click="resetForm"></u-button>
  47. <u-button type="primary" text="确定" @click="handleSearch"></u-button>
  48. </view>
  49. </u-popup>
  50. </template>
  51. <script>
  52. import Cell from '@/components/custom-cell/index.vue'
  53. import BrandList from '@/components/brand-list/index.vue'
  54. import PersonPicker from '@/components/person-picker/index.vue'
  55. import TabSelect from '@/components/custom-tab-select/index.vue'
  56. import JTimePicker from '@/uni_modules/jtime-picker-popup/components/JTimePicker/JTimePicker.vue'
  57. import { productAttributeList, stockStatusListAll,shortTimeList } from '../js/public.js'
  58. export default {
  59. components: {
  60. Cell,
  61. BrandList,
  62. PersonPicker,
  63. TabSelect,
  64. JTimePicker,
  65. },
  66. name: 'searchFilter',
  67. emits: ['confirm'],
  68. data() {
  69. return {
  70. show: false,
  71. formData: {
  72. dictLabel: '',
  73. dictValue: '',
  74. minPrice: '',
  75. maxPrice: '',
  76. location: '',
  77. startTime: '',
  78. endTime: '',
  79. recyclePerson:'',
  80. recyclePersonId: '',
  81. identifyingPerson:'',
  82. identifyingPersonId: '',
  83. productAttribute: [],
  84. stockStatus: '',
  85. },
  86. time:'',
  87. shortTimeList: shortTimeList,
  88. recyclePersonList: [],
  89. // 将导入的变量在data中重新定义,确保模板能够访问
  90. productAttributeList: productAttributeList,
  91. stockStatusListAll: stockStatusListAll,
  92. curSortType: {
  93. id: 4,
  94. label: '按入库最新',
  95. },
  96. sortPickerShow: false,
  97. sortColumns: [[
  98. {
  99. label: '按最久未下载',
  100. id: 1
  101. },
  102. {
  103. label: '按最近更新',
  104. id: 2
  105. },
  106. {
  107. label: '按最久更新',
  108. id: 3
  109. },
  110. {
  111. label: '按入库最新',
  112. id: 4
  113. },
  114. {
  115. label: '按入库最久',
  116. id: 5
  117. },
  118. {
  119. label: '按价格最高',
  120. id: 6
  121. },
  122. {
  123. label: '按价格最低',
  124. id: 7
  125. },
  126. ]],
  127. }
  128. },
  129. props: {
  130. },
  131. emits: [],
  132. methods: {
  133. handleSearch() {
  134. const filters = { ...this.formData, sortType: this.curSortType.id };
  135. const text = this.generateSelectText(filters);
  136. this.$emit('confirm', { filters, text });
  137. this.close();
  138. },
  139. resetForm() {
  140. this.formData = {
  141. dictLabel: '',
  142. dictValue: '',
  143. minPrice: '',
  144. maxPrice: '',
  145. location: '',
  146. startTime: '',
  147. endTime: '',
  148. recyclePerson:'',
  149. recyclePersonId: '',
  150. identifyingPerson:'',
  151. identifyingPersonId: '',
  152. productAttribute: [],
  153. stockStatus: '',
  154. };
  155. this.time = '';
  156. this.$emit('confirm', { filters: this.formData, text: '' });
  157. },
  158. open() {
  159. this.show = true
  160. setTimeout(() => {
  161. this.$refs.jtimePickerPopupRef.handleInit();
  162. }, 300)
  163. },
  164. openTimePicker() {
  165. this.$nextTick(()=>{
  166. this.$refs.jtimePickerPopupRef.pickerShow();
  167. })
  168. },
  169. close() {
  170. this.show = false
  171. },
  172. showBrandList() {
  173. this.$refs.brandListRef.showBrandList();
  174. },
  175. handleSelectedBrand(info) {
  176. this.formData.dictLabel = info.dictLabel;
  177. this.formData.dictValue = info.dictValue;
  178. },
  179. // 处理清空事件
  180. clear(field) {
  181. // 品牌
  182. if(field == 'dictLabel'){
  183. this.formData.dictLabel = '';
  184. this.formData.dictValue = '';
  185. return;
  186. }
  187. // 回收人
  188. if(field == 'recyclePerson'){
  189. this.formData.recyclePerson = '';
  190. this.formData.recyclePersonId = '';
  191. return;
  192. }
  193. // 鉴定人
  194. if(field == 'identifyingPerson'){
  195. this.formData.identifyingPerson = '';
  196. this.formData.identifyingPersonId = '';
  197. return;
  198. }
  199. // 回收时间
  200. if(field == 'time'){
  201. this.time = '';
  202. this.formData.startTime = '';
  203. this.formData.endTime = '';
  204. return;
  205. }
  206. this.formData[field] = '';
  207. },
  208. getSelectTime(val) {
  209. this.formData.startTime = this.$dayjs(val.beginTime).format('YYYY-MM-DD');
  210. this.formData.endTime = this.$dayjs(val.endTime).format('YYYY-MM-DD');
  211. this.time = this.$dayjs(val.beginTime).format('YYYY-MM-DD') + ' 至 ' + this.$dayjs(val.endTime).format('YYYY-MM-DD');
  212. },
  213. recyclePersonClick() {
  214. this.$refs.recyclePersonPickerRef.open();
  215. },
  216. handleSelectRecyclePerson(info) {
  217. this.formData.recyclePerson = info.label;
  218. this.formData.recyclePersonId = info.id;
  219. },
  220. identifyingPersonClick() {
  221. this.$refs.identifyingPersonPickerRef.open();
  222. },
  223. handleSelectIdentifyingPerson(info) {
  224. this.formData.identifyingPerson = info.label;
  225. this.formData.identifyingPersonId = info.id;
  226. },
  227. handleTabChangeProductAttribute(e) {
  228. this.formData.productAttribute = e;
  229. },
  230. handleTabChangeStockStatus(e) {
  231. this.formData.stockStatus = e;
  232. },
  233. openSortPicker() {
  234. this.sortPickerShow = true;
  235. const selectedIndex = this.sortColumns[0].findIndex(item => item.id === this.curSortType.id);
  236. this.$nextTick(() => {
  237. this.$refs.sortPicker.setIndexs(selectedIndex > -1 ? [selectedIndex] : [0]);
  238. });
  239. },
  240. handleSortChange(e) {
  241. this.curSortType = e.value[0];
  242. this.sortPickerShow = false;
  243. },
  244. generateSelectText(filters) {
  245. let parts = [];
  246. if (filters.dictLabel) parts.push(`品牌: ${filters.dictLabel}`);
  247. if (filters.minPrice || filters.maxPrice) parts.push(`实价范围: ${filters.minPrice || '不限'} - ${filters.maxPrice || '不限'}`);
  248. if (filters.location) parts.push(`位置: ${filters.location}`);
  249. if (filters.startTime || filters.endTime) parts.push(`回收时间: ${filters.startTime || ''} 至 ${filters.endTime || ''}`);
  250. if (filters.recyclePerson) parts.push(`回收人员: ${filters.recyclePerson}`);
  251. if (filters.identifyingPerson) parts.push(`鉴定人员: ${filters.identifyingPerson}`);
  252. if (filters.productAttribute && filters.productAttribute.length > 0) {
  253. const attrNames = filters.productAttribute.map(val => {
  254. const item = this.productAttributeList.find(i => i.value === val);
  255. return item ? item.name : '';
  256. }).filter(Boolean).join(', ');
  257. if (attrNames) parts.push(`商品属性: ${attrNames}`);
  258. }
  259. if (filters.stockStatus) {
  260. const status = this.stockStatusListAll.find(i => i.value === filters.stockStatus);
  261. if (status) parts.push(`是否入库: ${status.name}`);
  262. }
  263. return parts.join(' | ');
  264. },
  265. }
  266. }
  267. </script>
  268. <style lang="scss" scoped>
  269. @import "../styles/searchFilter.scss";
  270. </style>