supply.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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" @click="toAdd">发布供给</div>
  7. <div class="one_right">
  8. <el-input v-model="searchForm.name" style="width: 250px" size="large" placeholder="搜索" @change="search" :suffix-icon="Search" />
  9. </div>
  10. </el-col>
  11. <el-col :span="24" class="two">
  12. <el-table :data="list" style="width: 100%" size="large" :header-cell-style="{ backgroundColor: '#edf3ff' }">
  13. <template #empty>
  14. <el-empty description="暂无数据" />
  15. </template>
  16. <el-table-column prop="name" align="center" label="供给名称" />
  17. <el-table-column prop="start_time" align="center" label="开始时间" width="180" />
  18. <el-table-column prop="end_time" align="center" label="结束时间" width="180" />
  19. <el-table-column prop="status" align="center" label="状态" width="180">
  20. <template #default="scope">
  21. <div>{{ getDict(scope.row.status, 'status') }}</div>
  22. </template>
  23. </el-table-column>
  24. <el-table-column align="center" label="操作" width="180">
  25. <template #default="{ row }">
  26. <el-link v-if="row.status == '-2'" :underline="false" type="warning" size="mini" @click="toExam(row)" style="margin-right: 10px">提交审核</el-link>
  27. <el-link :underline="false" type="primary" size="mini" @click="toEdit(row)" style="margin-right: 10px">修改</el-link>
  28. <el-link :underline="false" type="danger" size="mini" @click="toDelete(row)"> 删除 </el-link>
  29. </template>
  30. </el-table-column>
  31. </el-table>
  32. </el-col>
  33. <el-col :span="24" class="thr">
  34. <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit" v-model:current-page="currentPage" @current-change="changePage" @size-change="sizeChange" />
  35. </el-col>
  36. </el-col>
  37. </el-row>
  38. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose" :width="width">
  39. <el-row>
  40. <el-col :span="24" v-if="dialog.type == '1'">
  41. <custom-form v-model="form" :fields="formFields" :rules="rules" @save="toSave" @draftSave="toDraftSave">
  42. <template #is_use>
  43. <el-radio v-for="i in isUseList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  44. </template>
  45. <template #field>
  46. <el-option v-for="i in fieldList" :key="i.id" :label="i.label" :value="i.label"></el-option>
  47. </template>
  48. <template #urgent>
  49. <el-option v-for="i in urgentList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  50. </template>
  51. <template #method>
  52. <el-option v-for="i in methodList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  53. </template>
  54. <template #industry>
  55. <el-option v-for="i in sectorList" :key="i.id" :label="i.title" :value="i.title"></el-option>
  56. </template>
  57. <template #area>
  58. <el-cascader v-model="form.area" :props="{ value: 'name', label: 'name' }" :options="cityList" style="width: 100%" />
  59. </template>
  60. <template #tags>
  61. <el-select v-model="form.tags" multiple filterable allow-create default-first-option :reserve-keyword="false" placeholder="请选择标签" style="width: 100%">
  62. <el-option v-for="item in tagsList" :key="item.id" :label="item.title" :value="item.title" />
  63. </el-select>
  64. </template>
  65. </custom-form>
  66. </el-col>
  67. <el-col :span="24" v-if="dialog.type == '2'" class="dialog">
  68. <div class="list" v-for="(item, index) in demandList" :key="index" @click="toView(item)">
  69. <h2 class="name textMore">
  70. <span>{{ item.name || '暂无' }}</span>
  71. </h2>
  72. <div class="other">
  73. <span class="other_1">{{ getDict(item.urgent, 'urgent') || '暂无' }}</span>
  74. <div class="other_2">
  75. <span>应用行业:</span>
  76. {{ item.field || '暂无' }}
  77. </div>
  78. <div class="other_2">
  79. <span>资金预算:</span>
  80. {{ item.money || '面议' }}
  81. </div>
  82. <div class="other_2 textOne">
  83. <el-icon color="#0085f5"><Location /></el-icon>
  84. {{ getArea(item.area) }}
  85. <span class="state">{{ getDict(item.status, 'status') || '未解决' }}</span>
  86. </div>
  87. </div>
  88. </div>
  89. </el-col>
  90. </el-row>
  91. </el-dialog>
  92. </div>
  93. </template>
  94. <script setup>
  95. import { Search } from '@element-plus/icons-vue'
  96. import { cloneDeep, get } from 'lodash-es'
  97. const $checkRes = inject('$checkRes')
  98. import { UserStore } from '@/store/user'
  99. const userStore = UserStore()
  100. const user = computed(() => userStore.user)
  101. // 接口
  102. import { SupplyStore } from '@/store/api/platform/supply'
  103. import { DemandStore } from '@/store/api/platform/demand'
  104. import { DictDataStore } from '@/store/api/system/dictData'
  105. import { TagsStore } from '@/store/api/system/tags'
  106. import { SectorStore } from '@/store/api/platform/sector'
  107. import { RegionStore } from '@/store/api/system/region'
  108. const regionStore = RegionStore()
  109. const store = SupplyStore()
  110. const dictDataStore = DictDataStore()
  111. const tagsStore = TagsStore()
  112. const sectorStore = SectorStore()
  113. const demandStore = DemandStore()
  114. // 加载中
  115. const loading = ref(false)
  116. const router = useRouter()
  117. const searchForm = ref({})
  118. // 列表
  119. const list = ref([])
  120. let skip = 0
  121. let limit = inject('limit')
  122. const total = ref(0)
  123. const currentPage = ref(1)
  124. // 字典表
  125. const isUseList = ref([])
  126. const statusList = ref([])
  127. const methodList = ref([])
  128. const urgentList = ref([])
  129. const fieldList = ref([])
  130. const cityList = ref([])
  131. const supplyList = ref([])
  132. const tagsList = ref([])
  133. const sectorList = ref([])
  134. // 推荐需求列表
  135. const demandList = ref([])
  136. const width = ref('50%')
  137. const form = ref({ time: [] })
  138. const dialog = ref({ type: '1', show: false, title: '发布供给' })
  139. const formFields = ref([
  140. { label: '供给名称', model: 'name' },
  141. { label: '标签', model: 'tags', custom: true },
  142. { label: '所属产业', model: 'industry', type: 'select' },
  143. { label: '行业领域', model: 'field' },
  144. { label: '供给紧急度', model: 'urgent', type: 'select' },
  145. { label: '合作方式', model: 'method', type: 'select' },
  146. { label: '价格(万元)', model: 'money' },
  147. { label: '项目来源', model: 'source' },
  148. { label: '供给地区', model: 'area', custom: true },
  149. { label: '发布时间', model: 'time', type: 'daterange' },
  150. { label: '是否公开', model: 'is_use', type: 'radio' },
  151. { label: '简介', model: 'brief', type: 'textarea' }
  152. ])
  153. const rules = reactive({ name: [{ required: true, message: '请输入供给名称', trigger: 'blur' }] })
  154. // 请求
  155. onMounted(async () => {
  156. loading.value = true
  157. await searchOther()
  158. await search()
  159. loading.value = false
  160. })
  161. const search = async (query = { skip, limit }) => {
  162. skip = query.skip
  163. limit = query.limit
  164. const info = {
  165. skip: query.skip,
  166. limit: query.limit,
  167. user: user.value.id,
  168. ...searchForm.value
  169. }
  170. const res = await store.query(info)
  171. if (res.errcode == '0') {
  172. list.value = res.data
  173. total.value = res.total
  174. }
  175. }
  176. const searchOther = async () => {
  177. let result
  178. // 是否使用
  179. result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  180. if ($checkRes(result)) isUseList.value = result.data
  181. // 状态
  182. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  183. if ($checkRes(result)) statusList.value = result.data
  184. // 合作方式
  185. result = await dictDataStore.query({ code: 'method', is_use: '0' })
  186. if ($checkRes(result)) methodList.value = result.data
  187. // 需求紧急度
  188. result = await dictDataStore.query({ code: 'urgent', is_use: '0' })
  189. if ($checkRes(result)) urgentList.value = result.data
  190. // 技术领域
  191. result = await dictDataStore.query({ code: 'field', is_use: '0' })
  192. if ($checkRes(result)) fieldList.value = result.data
  193. // 需求状态
  194. result = await dictDataStore.query({ code: 'supplyStatus', is_use: '0' })
  195. if ($checkRes(result)) supplyList.value = result.data
  196. // 标签
  197. result = await tagsStore.query({ is_use: '0' })
  198. if ($checkRes(result)) tagsList.value = result.data
  199. // 行业
  200. result = await sectorStore.query({ is_use: '0' })
  201. if ($checkRes(result)) sectorList.value = result.data
  202. // 城市
  203. result = await regionStore.area({ level: 'province', code: 22 })
  204. if ($checkRes(result)) cityList.value = result.data
  205. }
  206. // 字典数据转换
  207. const getDict = (data, model) => {
  208. if (data) {
  209. let res
  210. if (model == 'status') res = statusList.value.find((f) => f.value == data)
  211. else if (model == 'urgent') res = urgentList.value.find((f) => f.value == data)
  212. return get(res, 'label')
  213. }
  214. }
  215. // 添加
  216. const toAdd = () => {
  217. dialog.value = { type: '1', show: true, title: '发布供给' }
  218. }
  219. // 修改
  220. const toEdit = (data) => {
  221. data.time = [data.start_time, data.end_time]
  222. form.value = data
  223. dialog.value = { type: '1', show: true, title: '修改供给' }
  224. }
  225. // 删除
  226. const toDelete = (data) => {
  227. ElMessageBox.confirm(`您确认删除${data.name}该数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  228. .then(async () => {
  229. const res = await store.del(data.id)
  230. if ($checkRes(res, true)) {
  231. search({ skip, limit })
  232. }
  233. })
  234. .catch(() => {})
  235. }
  236. const toSave = async () => {
  237. const data = cloneDeep(form.value)
  238. const other = { status: '0', user: user.value.id }
  239. if (data.time && data.time.length > 1) {
  240. data.start_time = data.time[0]
  241. data.end_time = data.time[1]
  242. }
  243. delete data.time
  244. let res
  245. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  246. else res = await store.create({ ...data, ...other })
  247. if ($checkRes(res, true)) {
  248. await search({ skip, limit })
  249. await toClose()
  250. await searchDemand()
  251. width.value = '90%'
  252. dialog.value = { type: '2', show: true, title: '相关需求推荐' }
  253. }
  254. }
  255. const toDraftSave = async () => {
  256. const data = cloneDeep(form.value)
  257. const other = { status: '-2', user: user.value.id }
  258. if (data.time && data.time.length > 1) {
  259. data.start_time = data.time[0]
  260. data.end_time = data.time[1]
  261. }
  262. delete data.time
  263. let res
  264. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  265. else res = await store.create({ ...data, ...other })
  266. if ($checkRes(res, true)) {
  267. await search({ skip, limit })
  268. await toClose()
  269. await searchDemand()
  270. width.value = '90%'
  271. dialog.value = { type: '2', show: true, title: '相关需求推荐' }
  272. }
  273. }
  274. // 审核保存
  275. const toExam = async (row) => {
  276. ElMessageBox.confirm(`您确认保存并提交审核该数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  277. .then(async () => {
  278. const data = cloneDeep(row)
  279. let res = await store.update({ id: data.id, status: '0', user: user.value.id })
  280. if ($checkRes(res, true)) {
  281. await search({ skip, limit })
  282. await toClose()
  283. await searchDemand()
  284. width.value = '90%'
  285. dialog.value = { type: '2', show: true, title: '相关需求推荐' }
  286. }
  287. })
  288. .catch(() => {})
  289. }
  290. // 需求列表查询
  291. const searchDemand = async () => {
  292. const info = { skip: 0, limit: 5, is_use: '0', status: '1' }
  293. const res = await demandStore.query(info)
  294. if (res.errcode == '0') demandList.value = res.data
  295. }
  296. // 查看详情
  297. const toView = (item) => {
  298. router.push({ path: '/demand/detail', query: { id: item.id || item._id } })
  299. }
  300. // 地区
  301. const getArea = (data) => {
  302. if (data) return data.join('-')
  303. else return '暂无地区'
  304. }
  305. const toClose = () => {
  306. form.value = { time: [] }
  307. width.value = '50%'
  308. dialog.value = { show: false }
  309. }
  310. // 分页
  311. const changePage = (page = currentPage.value) => {
  312. search({ skip: (page - 1) * limit, limit: limit })
  313. }
  314. const sizeChange = (limits) => {
  315. limit = limits
  316. currentPage.value = 1
  317. search({ skip: 0, limit: limit })
  318. }
  319. </script>
  320. <style scoped lang="scss">
  321. .main {
  322. .one {
  323. height: 50px;
  324. display: flex;
  325. justify-content: space-between;
  326. align-items: center;
  327. margin: 0 0 10px 0;
  328. .one_left {
  329. background: #1875df;
  330. padding: 0 10px;
  331. height: 30px;
  332. color: #fff;
  333. line-height: 30px;
  334. text-align: center;
  335. font-size: 16px;
  336. cursor: default;
  337. }
  338. }
  339. .thr {
  340. display: flex;
  341. justify-content: center;
  342. margin: 20px 0 0 0;
  343. }
  344. }
  345. .dialog {
  346. display: flex;
  347. flex-wrap: wrap;
  348. margin-top: 20px;
  349. .list {
  350. position: relative;
  351. margin-right: 10px;
  352. margin-bottom: 10px;
  353. width: 380px;
  354. height: 233px;
  355. box-shadow: 0 0 13px 0 rgba(5, 88, 219, 0.18);
  356. .name {
  357. padding: 10px 20px;
  358. width: 380px;
  359. height: 71px;
  360. background-color: #dce5ff;
  361. font-size: 16px;
  362. line-height: 24px;
  363. color: #0d0d0d;
  364. display: flex;
  365. align-items: center;
  366. }
  367. .other {
  368. height: 162px;
  369. padding: 10px 20px 0 20px;
  370. .other_1 {
  371. padding: 0 10px;
  372. height: 25px;
  373. background-color: #e6f2fd;
  374. border-radius: 2px;
  375. border: solid 1px #cae0f5;
  376. font-size: $global-font-size-14;
  377. line-height: 25px;
  378. color: #0085f5;
  379. }
  380. .other_2 {
  381. display: flex;
  382. align-items: center;
  383. margin-top: 15px;
  384. font-size: $global-font-size-16;
  385. span {
  386. color: #909090;
  387. }
  388. .state {
  389. position: absolute;
  390. right: 20px;
  391. bottom: 15px;
  392. display: inline-block;
  393. vertical-align: middle;
  394. padding: 0 20px;
  395. height: 30px;
  396. line-height: 30px;
  397. background-image: linear-gradient(90deg, #ff8a00 0, #ff5a00 100%), linear-gradient(#ff7800, #ff7800);
  398. background-blend-mode: normal, normal;
  399. border-radius: 14px;
  400. border: solid 1px #e5e5e5;
  401. color: #fff;
  402. }
  403. }
  404. }
  405. }
  406. .list:hover {
  407. box-shadow: 0 0 5px 0 $global-color-107;
  408. .name {
  409. background-color: $global-color-107;
  410. color: $global-color-fff;
  411. }
  412. }
  413. }
  414. </style>