demand.vue 19 KB

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