demand.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <template>
  2. <div class="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <div class="one_left">
  7. <div class="button" @click="toAdd">发布需求</div>
  8. <div class="button" @click="toExpert">导入数据</div>
  9. <div class="button" @click="toDownload">导出数据</div>
  10. </div>
  11. <div class="one_right">
  12. <el-input v-model="searchForm.name" style="width: 250px" size="large" placeholder="搜索" @change="search" :suffix-icon="Search" />
  13. </div>
  14. </el-col>
  15. <el-col :span="24" class="two">
  16. <el-table :data="list" style="width: 100%" size="large" :header-cell-style="{ backgroundColor: '#edf3ff' }">
  17. <template #empty>
  18. <el-empty description="暂无数据" />
  19. </template>
  20. <el-table-column prop="name" align="center" label="需求名称" />
  21. <el-table-column prop="start_time" align="center" label="开始时间" width="180" />
  22. <el-table-column prop="end_time" align="center" label="结束时间" width="180" />
  23. <el-table-column prop="status" align="center" label="状态" width="180">
  24. <template #default="scope">
  25. <div>{{ getDict(scope.row.status, 'status') }}</div>
  26. </template>
  27. </el-table-column>
  28. <el-table-column align="center" label="操作" width="180">
  29. <template #default="{ row }">
  30. <el-link v-if="row.status == '-2'" :underline="false" type="warning" size="mini" @click="toExam(row)" style="margin-right: 10px">提交审核</el-link>
  31. <el-link :underline="false" type="primary" size="mini" @click="toEdit(row)" style="margin-right: 10px">修改</el-link>
  32. <el-link :underline="false" type="danger" size="mini" @click="toDelete(row)"> 删除 </el-link>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. </el-col>
  37. <el-col :span="24" class="thr">
  38. <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit" v-model:current-page="currentPage" @current-change="changePage" @size-change="sizeChange" />
  39. </el-col>
  40. </el-col>
  41. </el-row>
  42. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose" :width="width">
  43. <el-row>
  44. <el-col :span="24" v-if="dialog.type == '1'">
  45. <custom-form v-model="form" :fields="formFields" :rules="rules" @save="toSave" @draftSave="toDraftSave">
  46. <template #is_use>
  47. <el-radio v-for="i in isUseList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  48. </template>
  49. <template #field>
  50. <el-option v-for="i in fieldList" :key="i.id" :label="i.label" :value="i.label"></el-option>
  51. </template>
  52. <template #industry>
  53. <el-option v-for="i in sectorList" :key="i.id" :label="i.title" :value="i.title"></el-option>
  54. </template>
  55. <template #urgent>
  56. <el-option v-for="i in urgentList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  57. </template>
  58. <template #method>
  59. <el-option v-for="i in methodList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  60. </template>
  61. <template #area>
  62. <el-cascader v-model="form.area" :props="{ value: 'name', label: 'name' }" :options="cityList" style="width: 100%" />
  63. </template>
  64. <template #tags>
  65. <el-select v-model="form.tags" multiple filterable allow-create default-first-option :reserve-keyword="false" placeholder="请选择标签" style="width: 100%">
  66. <el-option v-for="item in tagsList" :key="item.id" :label="item.title" :value="item.title" />
  67. </el-select>
  68. </template>
  69. </custom-form>
  70. </el-col>
  71. <!-- 加载界面 -->
  72. <transition name="why">
  73. <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">
  74. <div class="list" v-for="(item, index) in supplyList" :key="index" @click="toView(item)">
  75. <h2 class="name textMore">
  76. <span>{{ item.name || '暂无' }}</span>
  77. </h2>
  78. <div class="other">
  79. <span class="other_1">{{ getDict(item.urgent, 'urgent') || '暂无' }}</span>
  80. <div class="other_2">
  81. <span>应用行业:</span>
  82. {{ item.field || '暂无' }}
  83. </div>
  84. <div class="other_2">
  85. <span>所属产业:</span>
  86. {{ item.industry || '暂无' }}
  87. </div>
  88. <div class="other_2">
  89. <span>来源:</span>
  90. {{ item.source || '暂无' }}
  91. </div>
  92. </div>
  93. </div>
  94. </el-col>
  95. </transition>
  96. <el-col :span="24" class="dialog_thr" v-if="dialog.type == '3'">
  97. <el-col :span="24" class="one">
  98. <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
  99. </el-col>
  100. <el-col :span="24" class="two">
  101. <el-checkbox-group v-model="checkedExport" @change="checkedExportChange">
  102. <el-checkbox v-for="i in formFields" :label="i" :key="i.model">{{ i.label }}</el-checkbox>
  103. </el-checkbox-group>
  104. </el-col>
  105. <el-col :span="24" class="btn">
  106. <el-button type="primary" size="mini" @click="toFile()">确定导出</el-button>
  107. </el-col>
  108. </el-col>
  109. <el-col :span="24" class="dialog_four" v-if="dialog.type == '4'">
  110. <el-row justify="center">
  111. <el-col :span="16">
  112. <el-steps style="max-width: 600px" :active="importActive" align-center>
  113. <el-step title="下载导入模板">
  114. <template #description v-if="importActive == 0">
  115. <el-button type="primary" size="mini" @click="toTemplate">下载导入模板</el-button>
  116. </template>
  117. </el-step>
  118. <el-step title="上传导入模板" description="上传导入模板">
  119. <template #description v-if="importActive == 1">
  120. <el-upload action="/files/web/cxyy_import/upload" :show-file-list="false" :on-success="onSuccess" accept=".xlsx">
  121. <el-button type="primary" size="mini">上传导入文件</el-button>
  122. </el-upload>
  123. </template>
  124. </el-step>
  125. <el-step title="确定导入" description="确定导入">
  126. <template #description v-if="importActive == 2">
  127. <el-button type="primary" size="mini" @click="onImport">确定</el-button>
  128. </template>
  129. </el-step>
  130. </el-steps>
  131. </el-col>
  132. </el-row>
  133. </el-col>
  134. </el-row>
  135. </el-dialog>
  136. </div>
  137. </template>
  138. <script setup>
  139. import { Search } from '@element-plus/icons-vue'
  140. import { cloneDeep, get } from 'lodash-es'
  141. const $checkRes = inject('$checkRes')
  142. import { UserStore } from '@/store/user'
  143. const userStore = UserStore()
  144. const user = computed(() => userStore.user)
  145. // 接口
  146. import { DemandStore } from '@/store/api/platform/demand'
  147. import { SupplyStore } from '@/store/api/platform/supply'
  148. import { DictDataStore } from '@/store/api/system/dictData'
  149. import { TagsStore } from '@/store/api/system/tags'
  150. import { SectorStore } from '@/store/api/platform/sector'
  151. import { RegionStore } from '@/store/api/system/region'
  152. import { UtilStore } from '@/store/api/util'
  153. const utilStore = UtilStore()
  154. const regionStore = RegionStore()
  155. const store = DemandStore()
  156. const dictDataStore = DictDataStore()
  157. const tagsStore = TagsStore()
  158. const sectorStore = SectorStore()
  159. const supplyStore = SupplyStore()
  160. // 加载中
  161. const loading = ref(false)
  162. const isLoading = ref(false)
  163. const svg = ref(`
  164. <path class="path" d="
  165. M 30 15
  166. L 28 17
  167. M 25.61 25.61
  168. A 15 15, 0, 0, 1, 15 30
  169. A 15 15, 0, 1, 1, 27.99 7.5
  170. L 15 15
  171. " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
  172. `)
  173. const router = useRouter()
  174. const searchForm = ref({})
  175. // 列表
  176. const list = ref([])
  177. let skip = 0
  178. let limit = inject('limit')
  179. const total = ref(0)
  180. const currentPage = ref(1)
  181. // 字典表
  182. const isUseList = ref([])
  183. const statusList = ref([])
  184. const methodList = ref([])
  185. const urgentList = ref([])
  186. const fieldList = ref([])
  187. const cityList = ref([])
  188. const demandList = ref([])
  189. const tagsList = ref([])
  190. const sectorList = ref([])
  191. // 推荐供给列表
  192. const supplyList = ref([])
  193. const width = ref('50%')
  194. const form = ref({ time: [] })
  195. const dialog = ref({ type: '1', show: false, title: '发布需求' })
  196. const formFields = ref([
  197. { label: '需求名称', model: 'name' },
  198. { label: '标签', model: 'tags', custom: true, mark: 'tags' },
  199. { label: '所属产业', model: 'industry', type: 'select' },
  200. { label: '行业领域', model: 'field' },
  201. { label: '需求紧急度', model: 'urgent', type: 'select', mark: 'dict', code: 'urgent' },
  202. { label: '合作方式', model: 'method', type: 'select', mark: 'dict', code: 'method' },
  203. { label: '价格(万元)', model: 'money' },
  204. { label: '所属企业', model: 'company' },
  205. { label: '企业简况', model: 'company_brief', type: 'textarea' },
  206. { label: '联系人', model: 'contacts' },
  207. { label: '联系电话', model: 'tel' },
  208. { label: '年份', model: 'year', type: 'year' },
  209. { label: '月份', model: 'month', type: 'month' },
  210. { label: '技术需求名称', model: 'tec_name' },
  211. { label: '待解决问题', model: 'question', type: 'textarea' },
  212. { label: '需求地区', model: 'area', custom: true, mark: 'area' },
  213. { label: '发布时间', model: 'time', type: 'daterange', mark: 'time' },
  214. { label: '是否公开', model: 'is_use', type: 'radio', mark: 'dict', code: 'isUse' },
  215. { label: '简介', model: 'brief', type: 'textarea' }
  216. ])
  217. const rules = reactive({ name: [{ required: true, message: '请输入需求名称', trigger: 'blur' }] })
  218. // 导出文件
  219. const checkAll = ref(false)
  220. const checkedExport = ref([])
  221. const isIndeterminate = ref(true)
  222. // 导入文件
  223. const importActive = ref(0)
  224. const url = ref('')
  225. // 请求
  226. onMounted(async () => {
  227. loading.value = true
  228. await searchOther()
  229. await search()
  230. loading.value = false
  231. })
  232. const search = async (query = { skip, limit }) => {
  233. skip = query.skip
  234. limit = query.limit
  235. const info = {
  236. skip: query.skip,
  237. limit: query.limit,
  238. user: user.value.id,
  239. ...searchForm.value
  240. }
  241. const res = await store.query(info)
  242. if (res.errcode == '0') {
  243. list.value = res.data
  244. total.value = res.total
  245. }
  246. }
  247. const searchOther = async () => {
  248. let result
  249. // 是否使用
  250. result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  251. if ($checkRes(result)) isUseList.value = result.data
  252. // 状态
  253. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  254. if ($checkRes(result)) statusList.value = result.data
  255. // 合作方式
  256. result = await dictDataStore.query({ code: 'method', is_use: '0' })
  257. if ($checkRes(result)) methodList.value = result.data
  258. // 需求紧急度
  259. result = await dictDataStore.query({ code: 'urgent', is_use: '0' })
  260. if ($checkRes(result)) urgentList.value = result.data
  261. // 技术领域
  262. result = await dictDataStore.query({ code: 'field', is_use: '0' })
  263. if ($checkRes(result)) fieldList.value = result.data
  264. // 需求状态
  265. result = await dictDataStore.query({ code: 'demandStatus', is_use: '0' })
  266. if ($checkRes(result)) demandList.value = result.data
  267. // 标签
  268. result = await tagsStore.query({ is_use: '0' })
  269. if ($checkRes(result)) tagsList.value = result.data
  270. // 行业
  271. result = await sectorStore.query({ is_use: '0' })
  272. if ($checkRes(result)) sectorList.value = result.data
  273. // 城市
  274. result = await regionStore.area({ level: 'province', code: 22 })
  275. if ($checkRes(result)) cityList.value = result.data
  276. }
  277. // 字典数据转换
  278. const getDict = (data, model) => {
  279. if (data) {
  280. let res
  281. if (model == 'status') res = statusList.value.find((f) => f.value == data)
  282. else if (model == 'urgent') res = urgentList.value.find((f) => f.value == data)
  283. return get(res, 'label')
  284. }
  285. }
  286. // 添加
  287. const toAdd = () => {
  288. dialog.value = { type: '1', show: true, title: '发布需求' }
  289. }
  290. // 修改
  291. const toEdit = (data) => {
  292. data.time = [data.start_time, data.end_time]
  293. form.value = data
  294. dialog.value = { type: '1', show: true, title: '修改需求' }
  295. }
  296. // 删除
  297. const toDelete = (data) => {
  298. ElMessageBox.confirm(`您确认删除${data.name}该数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  299. .then(async () => {
  300. const res = await store.del(data.id)
  301. if ($checkRes(res, true)) {
  302. search({ skip, limit })
  303. }
  304. })
  305. .catch(() => {})
  306. }
  307. const toSave = async () => {
  308. const data = cloneDeep(form.value)
  309. const other = { status: '0', user: user.value.id }
  310. if (data.time && data.time.length > 1) {
  311. data.start_time = data.time[0]
  312. data.end_time = data.time[1]
  313. }
  314. delete data.time
  315. let res
  316. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  317. else res = await store.create({ ...data, ...other })
  318. if ($checkRes(res, true)) {
  319. await search({ skip, limit })
  320. await toClose()
  321. await searchSupply()
  322. width.value = '90%'
  323. dialog.value = { type: '2', show: true, title: '相关供给推荐' }
  324. }
  325. }
  326. const toDraftSave = async () => {
  327. const data = cloneDeep(form.value)
  328. const other = { status: '-2', user: user.value.id }
  329. if (data.time && data.time.length > 1) {
  330. data.start_time = data.time[0]
  331. data.end_time = data.time[1]
  332. }
  333. delete data.time
  334. let res
  335. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  336. else res = await store.create({ ...data, ...other })
  337. if ($checkRes(res, true)) {
  338. await search({ skip, limit })
  339. await toClose()
  340. await searchSupply()
  341. width.value = '90%'
  342. dialog.value = { type: '2', show: true, title: '相关供给推荐' }
  343. }
  344. }
  345. // 审核保存
  346. const toExam = async (row) => {
  347. ElMessageBox.confirm(`您确认保存并提交审核该数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  348. .then(async () => {
  349. const data = cloneDeep(row)
  350. let res = await store.update({ id: data.id, status: '0', user: user.value.id })
  351. if ($checkRes(res, true)) {
  352. await search({ skip, limit })
  353. await toClose()
  354. await searchSupply()
  355. width.value = '90%'
  356. dialog.value = { type: '2', show: true, title: '相关供给推荐' }
  357. }
  358. })
  359. .catch(() => {})
  360. }
  361. // 供给列表查询
  362. const searchSupply = async () => {
  363. isLoading.value = true
  364. const info = { skip: 0, limit: 5, is_use: '0', status: '1' }
  365. const res = await supplyStore.query(info)
  366. if (res.errcode == '0') supplyList.value = res.data
  367. setTimeout(() => {
  368. isLoading.value = false
  369. }, 3000) // 假设3秒后加载完成
  370. }
  371. // 查看详情
  372. const toView = (item) => {
  373. router.push({ path: '/supply/detail', query: { id: item.id || item._id } })
  374. }
  375. const toClose = () => {
  376. importActive.value = 0
  377. url.value = ''
  378. checkedExport.value = []
  379. checkAll.value = false
  380. form.value = { time: [] }
  381. width.value = '50%'
  382. dialog.value = { show: false }
  383. }
  384. // 全选
  385. const handleCheckAllChange = (val) => {
  386. checkedExport.value = val ? formFields.value : []
  387. isIndeterminate.value = false
  388. }
  389. // 选择
  390. const checkedExportChange = (value) => {
  391. let checkedCount = value.length
  392. checkAll.value = checkedCount === formFields.value.length
  393. isIndeterminate.value = checkedCount > 0 && checkedCount < formFields.value.length
  394. }
  395. // 导入数据
  396. const toExpert = () => {
  397. dialog.value = { type: '4', show: true, title: '导入数据' }
  398. }
  399. // 导出数据
  400. const toDownload = () => {
  401. dialog.value = { type: '3', show: true, title: '导出数据' }
  402. }
  403. // 下载导入模板
  404. const toTemplate = () => {
  405. importActive.value = importActive.value + 1
  406. window.open('/cxyyWeb/产学研用需求模板.xlsx')
  407. }
  408. // 上传Excel
  409. const onSuccess = async (response, file) => {
  410. importActive.value = importActive.value + 1
  411. url.value = response.uri
  412. }
  413. // 确定导出
  414. const onImport = async () => {
  415. const msgbox = ElMessage({ message: '正在导入中,请稍后...', center: true, duration: 0 })
  416. try {
  417. const res = await utilStore.toImport({ url: url.value })
  418. if (res.errcode == '0') {
  419. if (res.data[0].errorList) {
  420. ElMessageBox.alert(res.data[0].errorList, '错误提示', {
  421. confirmButtonText: 'OK'
  422. })
  423. } else {
  424. ElMessage({ message: '导入成功', type: 'success' })
  425. }
  426. await search({ skip, limit })
  427. await toClose()
  428. }
  429. } catch (error) {
  430. console.error(error)
  431. } finally {
  432. msgbox.close()
  433. }
  434. }
  435. // 导出数据
  436. const toFile = async () => {
  437. if (checkedExport.value.length > 0) {
  438. const reqData = { table: 'demand', config: checkedExport.value, user: user.value.id }
  439. const res = await utilStore.toExport(reqData)
  440. if ($checkRes(res, true)) {
  441. ElMessage({ type: `success`, message: `导出成功` })
  442. window.open(res.data)
  443. }
  444. toClose()
  445. } else {
  446. ElMessage({ type: `warning`, message: `请选择导出信息字段` })
  447. }
  448. }
  449. // 分页
  450. const changePage = (page = currentPage.value) => {
  451. search({ skip: (page - 1) * limit, limit: limit })
  452. }
  453. const sizeChange = (limits) => {
  454. limit = limits
  455. currentPage.value = 1
  456. search({ skip: 0, limit: limit })
  457. }
  458. </script>
  459. <style scoped lang="scss">
  460. .main {
  461. .one {
  462. height: 50px;
  463. display: flex;
  464. justify-content: space-between;
  465. align-items: center;
  466. margin: 0 0 10px 0;
  467. .one_left {
  468. display: flex;
  469. font-size: 16px;
  470. .button {
  471. background: #1875df;
  472. padding: 0 10px;
  473. height: 30px;
  474. color: #fff;
  475. line-height: 30px;
  476. text-align: center;
  477. cursor: default;
  478. margin: 0 10px 0 0;
  479. }
  480. }
  481. }
  482. .thr {
  483. display: flex;
  484. justify-content: center;
  485. margin: 20px 0 0 0;
  486. }
  487. }
  488. .why-enter-from,
  489. .why-leave-to {
  490. opacity: 0;
  491. transform: scale(0.6);
  492. }
  493. .why-enter-to,
  494. .why-leave-from {
  495. opacity: 1;
  496. transform: scale(1);
  497. }
  498. .why-enter-active,
  499. .why-leave-active {
  500. transition: all 2s ease;
  501. }
  502. .dialog {
  503. display: flex;
  504. flex-wrap: wrap;
  505. margin-top: 20px;
  506. .list {
  507. position: relative;
  508. margin-right: 10px;
  509. margin-bottom: 10px;
  510. width: 380px;
  511. height: 233px;
  512. box-shadow: 0 0 13px 0 rgba(5, 88, 219, 0.18);
  513. .name {
  514. padding: 10px 20px;
  515. width: 380px;
  516. height: 71px;
  517. background-color: #dce5ff;
  518. font-size: 16px;
  519. line-height: 24px;
  520. color: #0d0d0d;
  521. display: flex;
  522. align-items: center;
  523. }
  524. .other {
  525. height: 162px;
  526. padding: 10px 20px 0 20px;
  527. .other_1 {
  528. padding: 0 10px;
  529. height: 25px;
  530. background-color: #e6f2fd;
  531. border-radius: 2px;
  532. border: solid 1px #cae0f5;
  533. font-size: $global-font-size-14;
  534. line-height: 25px;
  535. color: #0085f5;
  536. }
  537. .other_2 {
  538. display: flex;
  539. align-items: center;
  540. margin-top: 15px;
  541. font-size: $global-font-size-16;
  542. span {
  543. color: #909090;
  544. }
  545. .state {
  546. position: absolute;
  547. right: 20px;
  548. bottom: 15px;
  549. display: inline-block;
  550. vertical-align: middle;
  551. padding: 0 20px;
  552. height: 30px;
  553. line-height: 30px;
  554. background-image: linear-gradient(90deg, #ff8a00 0, #ff5a00 100%), linear-gradient(#ff7800, #ff7800);
  555. background-blend-mode: normal, normal;
  556. border-radius: 14px;
  557. border: solid 1px #e5e5e5;
  558. color: #fff;
  559. }
  560. }
  561. }
  562. }
  563. .list:hover {
  564. box-shadow: 0 0 5px 0 $global-color-107;
  565. .name {
  566. background-color: $global-color-107;
  567. color: $global-color-fff;
  568. }
  569. }
  570. }
  571. .dialog_thr {
  572. padding: 20px;
  573. .one {
  574. margin: 0 0 10px 0;
  575. }
  576. .two {
  577. margin: 0 0 10px 0;
  578. :deep(.el-checkbox) {
  579. padding: 0 0 20px 0;
  580. }
  581. }
  582. .btn {
  583. text-align: center;
  584. margin: 20px 0 0 0;
  585. }
  586. }
  587. .dialog_four {
  588. padding: 20px;
  589. }
  590. </style>