demand.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div class="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <custom-form v-model="form" :fields="formFields" :rules="rules" @save="toSave" @draftSave="toDraftSave">
  6. <template #is_use>
  7. <el-radio v-for="i in isUseList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  8. </template>
  9. <template #field>
  10. <el-option v-for="i in fieldList" :key="i.id" :label="i.label" :value="i.label"></el-option>
  11. </template>
  12. <template #industry>
  13. <el-option v-for="i in sectorList" :key="i.id" :label="i.title" :value="i.title"></el-option>
  14. </template>
  15. <template #urgent>
  16. <el-option v-for="i in urgentList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  17. </template>
  18. <template #method>
  19. <el-option v-for="i in methodList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  20. </template>
  21. <template #area>
  22. <el-cascader v-model="form.area" :props="{ value: 'name', label: 'name' }" :options="cityList" style="width: 100%" />
  23. </template>
  24. <template #tags>
  25. <el-select v-model="form.tags" multiple filterable allow-create default-first-option :reserve-keyword="false" placeholder="请选择标签" style="width: 100%">
  26. <el-option v-for="item in tagsList" :key="item.id" :label="item.title" :value="item.title" />
  27. </el-select>
  28. </template>
  29. </custom-form>
  30. </el-col>
  31. </el-row>
  32. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose" :width="width">
  33. <el-row>
  34. <transition name="why">
  35. <el-col :span="24" v-if="dialog.type == '2'" class="dialog" v-loading="isLoading" element-loading-text="智能推荐中..." :element-loading-svg="svg" element-loading-svg-view-box="-10,-10,50,50">
  36. <el-empty v-if="supplytotal == 0" description="暂无数据" />
  37. <div class="list" v-for="(item, index) in supplyList" :key="index" @click="toView(item)">
  38. <h2 class="name textMore">
  39. <span>{{ item.name || '暂无' }}</span>
  40. </h2>
  41. <div class="other">
  42. <span class="other_1">{{ getDict(item.urgent, 'urgent') || '暂无' }}</span>
  43. <div class="other_2">
  44. <span>应用行业:</span>
  45. {{ item.field || '暂无' }}
  46. </div>
  47. <div class="other_2">
  48. <span>所属产业:</span>
  49. {{ item.industry || '暂无' }}
  50. </div>
  51. <div class="other_2">
  52. <span>来源:</span>
  53. {{ item.source || '暂无' }}
  54. </div>
  55. <div class="other_2">
  56. <span>推荐指数:</span>
  57. <el-rate size="large" v-model="item._recommend" disabled show-score text-color="#ff9900" :score-template="`${item._recommend} 星`" />
  58. </div>
  59. </div>
  60. </div>
  61. <el-col :span="24" class="page">
  62. <el-pagination background layout="prev, pager, next" :total="supplytotal" :page-size="supplylimit" v-model:current-page="scurrentPage" @current-change="schangePage" @size-change="ssizeChange" />
  63. </el-col>
  64. </el-col>
  65. </transition>
  66. </el-row>
  67. </el-dialog>
  68. </div>
  69. </template>
  70. <script setup>
  71. const router = useRouter()
  72. import { cloneDeep, get } from 'lodash-es'
  73. const $checkRes = inject('$checkRes')
  74. import { UserStore } from '@/store/user'
  75. const userStore = UserStore()
  76. const user = computed(() => userStore.user)
  77. // 接口
  78. import { DemandStore } from '@/store/api/platform/demand'
  79. import { DictDataStore } from '@/store/api/system/dictData'
  80. import { TagsStore } from '@/store/api/system/tags'
  81. import { SectorStore } from '@/store/api/platform/sector'
  82. import { RegionStore } from '@/store/api/system/region'
  83. import { EsStore } from '@/store/api/es'
  84. const esStore = EsStore()
  85. const regionStore = RegionStore()
  86. const store = DemandStore()
  87. const dictDataStore = DictDataStore()
  88. const tagsStore = TagsStore()
  89. const sectorStore = SectorStore()
  90. // 加载中
  91. const loading = ref(false)
  92. // 字典表
  93. const isUseList = ref([])
  94. const statusList = ref([])
  95. const methodList = ref([])
  96. const urgentList = ref([])
  97. const fieldList = ref([])
  98. const cityList = ref([])
  99. const demandList = ref([])
  100. const tagsList = ref([])
  101. const sectorList = ref([])
  102. const form = ref({ time: [] })
  103. const formFields = ref([
  104. { label: '需求名称', model: 'name' },
  105. { label: '标签', model: 'tags', custom: true, mark: 'tags' },
  106. { label: '所属产业', model: 'industry', type: 'select' },
  107. { label: '行业领域', model: 'field' },
  108. { label: '需求紧急度', model: 'urgent', type: 'select', mark: 'dict', code: 'urgent' },
  109. { label: '合作方式', model: 'method', type: 'select', mark: 'dict', code: 'method' },
  110. { label: '价格(万元)', model: 'money' },
  111. { label: '所属企业', model: 'company' },
  112. { label: '企业简况', model: 'company_brief', type: 'textarea' },
  113. { label: '联系人', model: 'contacts' },
  114. { label: '联系电话', model: 'tel' },
  115. { label: '年份', model: 'year', type: 'year' },
  116. { label: '月份', model: 'month', type: 'month' },
  117. { label: '技术需求名称', model: 'tec_name' },
  118. { label: '待解决问题', model: 'question', type: 'textarea' },
  119. { label: '需求地区', model: 'area', custom: true, mark: 'area' },
  120. { label: '发布时间', model: 'time', type: 'daterange', mark: 'time' },
  121. { label: '是否公开', model: 'is_use', type: 'radio', mark: 'dict', code: 'isUse' },
  122. { label: '简介', model: 'brief', type: 'textarea' }
  123. ])
  124. const rules = reactive({ name: [{ required: true, message: '请输入需求名称', trigger: 'blur' }] })
  125. // 推荐供给列表
  126. const supplyList = ref([])
  127. let supplyskip = 0
  128. let supplylimit = 4
  129. const supplytotal = ref(0)
  130. const key = ref('')
  131. const width = ref('50%')
  132. const isLoading = ref(false)
  133. const svg = ref(`
  134. <path class="path" d="
  135. M 30 15
  136. L 28 17
  137. M 25.61 25.61
  138. A 15 15, 0, 0, 1, 15 30
  139. A 15 15, 0, 1, 1, 27.99 7.5
  140. L 15 15
  141. " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
  142. `)
  143. const dialog = ref({ type: '1', show: false, title: '供给智能推荐' })
  144. // 请求
  145. onMounted(async () => {
  146. loading.value = true
  147. await searchOther()
  148. loading.value = false
  149. })
  150. const searchOther = async () => {
  151. let result
  152. // 是否使用
  153. result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  154. if ($checkRes(result)) isUseList.value = result.data
  155. // 状态
  156. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  157. if ($checkRes(result)) statusList.value = result.data
  158. // 合作方式
  159. result = await dictDataStore.query({ code: 'method', is_use: '0' })
  160. if ($checkRes(result)) methodList.value = result.data
  161. // 需求紧急度
  162. result = await dictDataStore.query({ code: 'urgent', is_use: '0' })
  163. if ($checkRes(result)) urgentList.value = result.data
  164. // 技术领域
  165. result = await dictDataStore.query({ code: 'field', is_use: '0' })
  166. if ($checkRes(result)) fieldList.value = result.data
  167. // 需求状态
  168. result = await dictDataStore.query({ code: 'demandStatus', is_use: '0' })
  169. if ($checkRes(result)) demandList.value = result.data
  170. // 标签
  171. result = await tagsStore.query({ is_use: '0' })
  172. if ($checkRes(result)) tagsList.value = result.data
  173. // 行业
  174. result = await sectorStore.query({ is_use: '0' })
  175. if ($checkRes(result)) sectorList.value = result.data
  176. // 城市
  177. result = await regionStore.area({ level: 'province', code: 22 })
  178. if ($checkRes(result)) cityList.value = result.data
  179. }
  180. const toSave = async () => {
  181. const data = cloneDeep(form.value)
  182. const other = { status: '0', user: user.value.id }
  183. if (data.time && data.time.length > 1) {
  184. data.start_time = data.time[0]
  185. data.end_time = data.time[1]
  186. }
  187. delete data.time
  188. let res
  189. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  190. else res = await store.create({ ...data, ...other })
  191. if ($checkRes(res, true)) {
  192. ElMessage({ message: `发布成功可以长历史发布查看`, type: 'success' })
  193. key.value = form.value.name
  194. await toClose()
  195. await searchSupply({ supplyskip, supplylimit })
  196. width.value = '90%'
  197. dialog.value = { type: '2', show: true, title: '相关供给推荐' }
  198. }
  199. }
  200. const toDraftSave = async () => {
  201. const data = cloneDeep(form.value)
  202. const other = { status: '-2', user: user.value.id }
  203. if (data.time && data.time.length > 1) {
  204. data.start_time = data.time[0]
  205. data.end_time = data.time[1]
  206. }
  207. delete data.time
  208. let res
  209. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  210. else res = await store.create({ ...data, ...other })
  211. if ($checkRes(res, true)) {
  212. ElMessage({ message: `发布成功可以长历史发布查看`, type: 'success' })
  213. key.value = form.value.name
  214. await toClose()
  215. await searchSupply({ supplyskip, supplylimit })
  216. width.value = '90%'
  217. dialog.value = { type: '2', show: true, title: '相关供给推荐' }
  218. }
  219. }
  220. // 供给列表查询
  221. const searchSupply = async (query = { supplyskip, supplylimit }) => {
  222. supplyskip = query.supplyskip
  223. supplylimit = query.supplylimit
  224. isLoading.value = true
  225. const info = { skip: supplyskip, limit: supplylimit, keyword: key.value }
  226. const res = await esStore.supply(info)
  227. if (res.errcode == '0') {
  228. supplyList.value = res.data
  229. supplytotal.value = res.total
  230. }
  231. setTimeout(() => {
  232. isLoading.value = false
  233. }, 3000) // 假设3秒后加载完成
  234. }
  235. const scurrentPage = ref(1)
  236. // 分页
  237. const schangePage = (page = scurrentPage.value) => {
  238. searchSupply({ supplyskip: (page - 1) * supplylimit, supplylimit: supplylimit })
  239. }
  240. const ssizeChange = (limits) => {
  241. supplylimit = limits
  242. scurrentPage.value = 1
  243. searchSupply({ supplyskip: 0, supplylimit: supplylimit })
  244. }
  245. // 字典数据转换
  246. const getDict = (data, model) => {
  247. if (data) {
  248. let res
  249. if (model == 'status') res = statusList.value.find((f) => f.value == data)
  250. else if (model == 'urgent') res = urgentList.value.find((f) => f.value == data)
  251. return get(res, 'label')
  252. }
  253. }
  254. // 查看详情
  255. const toView = (item) => {
  256. router.push({ path: '/supply/detail', query: { id: item.id || item._id } })
  257. }
  258. const toClose = () => {
  259. form.value = {}
  260. width.value = '50%'
  261. dialog.value = { show: false }
  262. }
  263. </script>
  264. <style scoped lang="scss">
  265. .why-enter-from,
  266. .why-leave-to {
  267. opacity: 0;
  268. transform: scale(0.6);
  269. }
  270. .why-enter-to,
  271. .why-leave-from {
  272. opacity: 1;
  273. transform: scale(1);
  274. }
  275. .why-enter-active,
  276. .why-leave-active {
  277. transition: all 2s ease;
  278. }
  279. .dialog {
  280. display: flex;
  281. flex-wrap: wrap;
  282. margin-top: 20px;
  283. .list {
  284. position: relative;
  285. margin-right: 10px;
  286. margin-bottom: 10px;
  287. width: 380px;
  288. box-shadow: 0 0 13px 0 rgba(5, 88, 219, 0.18);
  289. .name {
  290. padding: 10px 20px;
  291. width: 380px;
  292. height: 71px;
  293. background-color: #dce5ff;
  294. font-size: 16px;
  295. line-height: 24px;
  296. color: #0d0d0d;
  297. display: flex;
  298. align-items: center;
  299. }
  300. .other {
  301. padding: 10px 20px 20px;
  302. .other_1 {
  303. padding: 0 10px;
  304. height: 25px;
  305. background-color: #e6f2fd;
  306. border-radius: 2px;
  307. border: solid 1px #cae0f5;
  308. font-size: $global-font-size-14;
  309. line-height: 25px;
  310. color: #0085f5;
  311. }
  312. .other_2 {
  313. display: flex;
  314. justify-content: space-between;
  315. align-items: center;
  316. margin-top: 15px;
  317. font-size: $global-font-size-16;
  318. span {
  319. color: #909090;
  320. }
  321. .state {
  322. position: absolute;
  323. right: 20px;
  324. bottom: 15px;
  325. display: inline-block;
  326. vertical-align: middle;
  327. padding: 0 20px;
  328. height: 30px;
  329. line-height: 30px;
  330. background-image: linear-gradient(90deg, #ff8a00 0, #ff5a00 100%), linear-gradient(#ff7800, #ff7800);
  331. background-blend-mode: normal, normal;
  332. border-radius: 14px;
  333. border: solid 1px #e5e5e5;
  334. color: #fff;
  335. }
  336. }
  337. }
  338. }
  339. .list:hover {
  340. box-shadow: 0 0 5px 0 $global-color-107;
  341. .name {
  342. background-color: $global-color-107;
  343. color: $global-color-fff;
  344. }
  345. }
  346. .page {
  347. margin: 10px 0;
  348. display: flex;
  349. justify-content: center;
  350. }
  351. }
  352. </style>