supply.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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 #urgent>
  53. <el-option v-for="i in urgentList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  54. </template>
  55. <template #method>
  56. <el-option v-for="i in methodList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  57. </template>
  58. <template #industry>
  59. <el-option v-for="i in sectorList" :key="i.id" :label="i.title" :value="i.title"></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. <transition name="why">
  72. <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">
  73. <div class="list" v-for="(item, index) in demandList" :key="index" @click="toView(item)">
  74. <h2 class="name textMore">
  75. <span>{{ item.name || '暂无' }}</span>
  76. </h2>
  77. <div class="other">
  78. <span class="other_1">{{ getDict(item.urgent, 'urgent') || '暂无' }}</span>
  79. <div class="other_2">
  80. <span>应用行业:</span>
  81. {{ item.field || '暂无' }}
  82. </div>
  83. <div class="other_2">
  84. <span>资金预算:</span>
  85. {{ item.money || '面议' }}
  86. </div>
  87. <div class="other_2 textOne">
  88. <el-icon color="#0085f5"><Location /></el-icon>
  89. {{ getArea(item.area) }}
  90. <span class="state">{{ getDict(item.status, 'status') || '未解决' }}</span>
  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 { SupplyStore } from '@/store/api/platform/supply'
  147. import { DemandStore } from '@/store/api/platform/demand'
  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 = SupplyStore()
  156. const dictDataStore = DictDataStore()
  157. const tagsStore = TagsStore()
  158. const sectorStore = SectorStore()
  159. const demandStore = DemandStore()
  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 supplyList = ref([])
  189. const tagsList = ref([])
  190. const sectorList = ref([])
  191. // 推荐需求列表
  192. const demandList = 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: 'source' },
  205. { label: '供给地区', model: 'area', custom: true, mark: 'area' },
  206. { label: '发布时间', model: 'time', type: 'daterange', mark: 'time' },
  207. { label: '是否公开', model: 'is_use', type: 'radio', mark: 'dict', code: 'isUse' },
  208. { label: '简介', model: 'brief', type: 'textarea' }
  209. ])
  210. const rules = reactive({ name: [{ required: true, message: '请输入供给名称', trigger: 'blur' }] })
  211. // 导出文件
  212. const checkAll = ref(false)
  213. const checkedExport = ref([])
  214. const isIndeterminate = ref(true)
  215. // 导入文件
  216. const importActive = ref(0)
  217. const url = ref('')
  218. // 请求
  219. onMounted(async () => {
  220. loading.value = true
  221. await searchOther()
  222. await search()
  223. loading.value = false
  224. })
  225. const search = async (query = { skip, limit }) => {
  226. skip = query.skip
  227. limit = query.limit
  228. const info = {
  229. skip: query.skip,
  230. limit: query.limit,
  231. user: user.value.id,
  232. ...searchForm.value
  233. }
  234. const res = await store.query(info)
  235. if (res.errcode == '0') {
  236. list.value = res.data
  237. total.value = res.total
  238. }
  239. }
  240. const searchOther = async () => {
  241. let result
  242. // 是否使用
  243. result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  244. if ($checkRes(result)) isUseList.value = result.data
  245. // 状态
  246. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  247. if ($checkRes(result)) statusList.value = result.data
  248. // 合作方式
  249. result = await dictDataStore.query({ code: 'method', is_use: '0' })
  250. if ($checkRes(result)) methodList.value = result.data
  251. // 需求紧急度
  252. result = await dictDataStore.query({ code: 'urgent', is_use: '0' })
  253. if ($checkRes(result)) urgentList.value = result.data
  254. // 技术领域
  255. result = await dictDataStore.query({ code: 'field', is_use: '0' })
  256. if ($checkRes(result)) fieldList.value = result.data
  257. // 需求状态
  258. result = await dictDataStore.query({ code: 'supplyStatus', is_use: '0' })
  259. if ($checkRes(result)) supplyList.value = result.data
  260. // 标签
  261. result = await tagsStore.query({ is_use: '0' })
  262. if ($checkRes(result)) tagsList.value = result.data
  263. // 行业
  264. result = await sectorStore.query({ is_use: '0' })
  265. if ($checkRes(result)) sectorList.value = result.data
  266. // 城市
  267. result = await regionStore.area({ level: 'province', code: 22 })
  268. if ($checkRes(result)) cityList.value = result.data
  269. }
  270. // 字典数据转换
  271. const getDict = (data, model) => {
  272. if (data) {
  273. let res
  274. if (model == 'status') res = statusList.value.find((f) => f.value == data)
  275. else if (model == 'urgent') res = urgentList.value.find((f) => f.value == data)
  276. return get(res, 'label')
  277. }
  278. }
  279. // 添加
  280. const toAdd = () => {
  281. dialog.value = { type: '1', show: true, title: '发布供给' }
  282. }
  283. // 修改
  284. const toEdit = (data) => {
  285. data.time = [data.start_time, data.end_time]
  286. form.value = data
  287. dialog.value = { type: '1', show: true, title: '修改供给' }
  288. }
  289. // 删除
  290. const toDelete = (data) => {
  291. ElMessageBox.confirm(`您确认删除${data.name}该数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  292. .then(async () => {
  293. const res = await store.del(data.id)
  294. if ($checkRes(res, true)) {
  295. search({ skip, limit })
  296. }
  297. })
  298. .catch(() => {})
  299. }
  300. const toSave = async () => {
  301. const data = cloneDeep(form.value)
  302. const other = { status: '0', user: user.value.id }
  303. if (data.time && data.time.length > 1) {
  304. data.start_time = data.time[0]
  305. data.end_time = data.time[1]
  306. }
  307. delete data.time
  308. let res
  309. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  310. else res = await store.create({ ...data, ...other })
  311. if ($checkRes(res, true)) {
  312. await search({ skip, limit })
  313. await toClose()
  314. await searchDemand()
  315. width.value = '90%'
  316. dialog.value = { type: '2', show: true, title: '相关需求推荐' }
  317. }
  318. }
  319. const toDraftSave = async () => {
  320. const data = cloneDeep(form.value)
  321. const other = { status: '-2', user: user.value.id }
  322. if (data.time && data.time.length > 1) {
  323. data.start_time = data.time[0]
  324. data.end_time = data.time[1]
  325. }
  326. delete data.time
  327. let res
  328. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  329. else res = await store.create({ ...data, ...other })
  330. if ($checkRes(res, true)) {
  331. await search({ skip, limit })
  332. await toClose()
  333. await searchDemand()
  334. width.value = '90%'
  335. dialog.value = { type: '2', show: true, title: '相关需求推荐' }
  336. }
  337. }
  338. // 审核保存
  339. const toExam = async (row) => {
  340. ElMessageBox.confirm(`您确认保存并提交审核该数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  341. .then(async () => {
  342. const data = cloneDeep(row)
  343. let res = await store.update({ id: data.id, status: '0', user: user.value.id })
  344. if ($checkRes(res, true)) {
  345. await search({ skip, limit })
  346. await toClose()
  347. await searchDemand()
  348. width.value = '90%'
  349. dialog.value = { type: '2', show: true, title: '相关需求推荐' }
  350. }
  351. })
  352. .catch(() => {})
  353. }
  354. // 需求列表查询
  355. const searchDemand = async () => {
  356. isLoading.value = true
  357. const info = { skip: 0, limit: 5, is_use: '0', status: '1' }
  358. const res = await demandStore.query(info)
  359. if (res.errcode == '0') demandList.value = res.data
  360. setTimeout(() => {
  361. isLoading.value = false
  362. }, 3000) // 假设3秒后加载完成
  363. }
  364. // 查看详情
  365. const toView = (item) => {
  366. router.push({ path: '/supply/detail', query: { id: item.id || item._id } })
  367. }
  368. // 地区
  369. const getArea = (data) => {
  370. if (data) return data.join('-')
  371. else return '暂无地区'
  372. }
  373. const toClose = () => {
  374. checkedExport.value = []
  375. checkAll.value = false
  376. form.value = { time: [] }
  377. width.value = '50%'
  378. dialog.value = { show: false }
  379. }
  380. // 全选
  381. const handleCheckAllChange = (val) => {
  382. checkedExport.value = val ? formFields.value : []
  383. isIndeterminate.value = false
  384. }
  385. // 选择
  386. const checkedExportChange = (value) => {
  387. let checkedCount = value.length
  388. checkAll.value = checkedCount === formFields.value.length
  389. isIndeterminate.value = checkedCount > 0 && checkedCount < formFields.value.length
  390. }
  391. // 导入数据
  392. const toExpert = () => {
  393. dialog.value = { type: '4', show: true, title: '导入数据' }
  394. }
  395. // 导出数据
  396. const toDownload = () => {
  397. dialog.value = { type: '3', show: true, title: '导出数据' }
  398. }
  399. // 下载导入模板
  400. const toTemplate = () => {
  401. importActive.value = importActive.value + 1
  402. window.open('/cxyyWeb/产学研用供给模板.xlsx')
  403. }
  404. // 上传Excel
  405. const onSuccess = async (response, file) => {
  406. importActive.value = importActive.value + 1
  407. url.value = response.uri
  408. }
  409. // 确定导出
  410. const onImport = async () => {
  411. const msgbox = ElMessage({ message: '正在导入中,请稍后...', center: true, duration: 0 })
  412. try {
  413. const res = await utilStore.toImport({ url: url.value })
  414. if (res.errcode == '0') {
  415. if (res.data[0].errorList) {
  416. ElMessageBox.alert(res.data[0].errorList, '错误提示', {
  417. confirmButtonText: 'OK'
  418. })
  419. } else {
  420. ElMessage({ message: '导入成功', type: 'success' })
  421. }
  422. await search({ skip, limit })
  423. await toClose()
  424. }
  425. } catch (error) {
  426. console.error(error)
  427. } finally {
  428. msgbox.close()
  429. }
  430. }
  431. // 导出数据
  432. const toFile = async () => {
  433. if (checkedExport.value.length > 0) {
  434. const reqData = { table: 'supply', config: checkedExport.value, user: user.value.id }
  435. const res = await utilStore.toExport(reqData)
  436. if ($checkRes(res, true)) {
  437. ElMessage({ type: `success`, message: `导出成功` })
  438. window.open(res.data)
  439. }
  440. toClose()
  441. } else {
  442. ElMessage({ type: `warning`, message: `请选择导出信息字段` })
  443. }
  444. }
  445. // 分页
  446. const changePage = (page = currentPage.value) => {
  447. search({ skip: (page - 1) * limit, limit: limit })
  448. }
  449. const sizeChange = (limits) => {
  450. limit = limits
  451. currentPage.value = 1
  452. search({ skip: 0, limit: limit })
  453. }
  454. </script>
  455. <style scoped lang="scss">
  456. .main {
  457. .one {
  458. height: 50px;
  459. display: flex;
  460. justify-content: space-between;
  461. align-items: center;
  462. margin: 0 0 10px 0;
  463. .one_left {
  464. display: flex;
  465. font-size: 16px;
  466. .button {
  467. background: #1875df;
  468. padding: 0 10px;
  469. height: 30px;
  470. color: #fff;
  471. line-height: 30px;
  472. text-align: center;
  473. cursor: default;
  474. margin: 0 10px 0 0;
  475. }
  476. }
  477. }
  478. .thr {
  479. display: flex;
  480. justify-content: center;
  481. margin: 20px 0 0 0;
  482. }
  483. }
  484. .why-enter-from,
  485. .why-leave-to {
  486. opacity: 0;
  487. transform: scale(0.6);
  488. }
  489. .why-enter-to,
  490. .why-leave-from {
  491. opacity: 1;
  492. transform: scale(1);
  493. }
  494. .why-enter-active,
  495. .why-leave-active {
  496. transition: all 2s ease;
  497. }
  498. .dialog {
  499. display: flex;
  500. flex-wrap: wrap;
  501. margin-top: 20px;
  502. .list {
  503. position: relative;
  504. margin-right: 10px;
  505. margin-bottom: 10px;
  506. width: 380px;
  507. height: 233px;
  508. box-shadow: 0 0 13px 0 rgba(5, 88, 219, 0.18);
  509. .name {
  510. padding: 10px 20px;
  511. width: 380px;
  512. height: 71px;
  513. background-color: #dce5ff;
  514. font-size: 16px;
  515. line-height: 24px;
  516. color: #0d0d0d;
  517. display: flex;
  518. align-items: center;
  519. }
  520. .other {
  521. height: 162px;
  522. padding: 10px 20px 0 20px;
  523. .other_1 {
  524. padding: 0 10px;
  525. height: 25px;
  526. background-color: #e6f2fd;
  527. border-radius: 2px;
  528. border: solid 1px #cae0f5;
  529. font-size: $global-font-size-14;
  530. line-height: 25px;
  531. color: #0085f5;
  532. }
  533. .other_2 {
  534. display: flex;
  535. align-items: center;
  536. margin-top: 15px;
  537. font-size: $global-font-size-16;
  538. span {
  539. color: #909090;
  540. }
  541. .state {
  542. position: absolute;
  543. right: 20px;
  544. bottom: 15px;
  545. display: inline-block;
  546. vertical-align: middle;
  547. padding: 0 20px;
  548. height: 30px;
  549. line-height: 30px;
  550. background-image: linear-gradient(90deg, #ff8a00 0, #ff5a00 100%), linear-gradient(#ff7800, #ff7800);
  551. background-blend-mode: normal, normal;
  552. border-radius: 14px;
  553. border: solid 1px #e5e5e5;
  554. color: #fff;
  555. }
  556. }
  557. }
  558. }
  559. .list:hover {
  560. box-shadow: 0 0 5px 0 $global-color-107;
  561. .name {
  562. background-color: $global-color-107;
  563. color: $global-color-fff;
  564. }
  565. }
  566. }
  567. .dialog_thr {
  568. padding: 20px;
  569. .one {
  570. margin: 0 0 10px 0;
  571. }
  572. .two {
  573. margin: 0 0 10px 0;
  574. :deep(.el-checkbox) {
  575. padding: 0 0 20px 0;
  576. }
  577. }
  578. .btn {
  579. text-align: center;
  580. margin: 20px 0 0 0;
  581. }
  582. }
  583. .dialog_four {
  584. padding: 20px;
  585. }
  586. </style>