index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div class="h-full flex">
  3. <div class="p-5 w-80 pr-0">
  4. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
  5. <div class="flex-1 p-3 overflow-y-auto">
  6. <el-form :model="filterProductForm" label-width="70px" style="max-width: 600px">
  7. <el-form-item label="产品编号">
  8. <el-input v-model="filterProductForm.productCode" clearable placeholder="请输入"></el-input>
  9. </el-form-item>
  10. <el-form-item label="产品名称">
  11. <el-input v-model="filterProductForm.productName" clearable placeholder="请输入"></el-input>
  12. </el-form-item>
  13. <el-form-item label="产品类别">
  14. <el-select v-model="filterProductForm.productType" placeholder="请选择" clearable filterable>
  15. <el-option v-for="item in fixedData.ProductType" :key="item.id" :label="item.name" :value="item.id" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="状态">
  19. <el-select v-model="filterProductForm.status" placeholder="请选择" filterable clearable>
  20. <el-option v-for="item in SELECTSTATUS" :key="item.value" :label="item.label" :value="item.value" />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="负责人">
  24. <personnel-search v-model="filterProductForm.userId" :size="''" placeholder="请选择"></personnel-search>
  25. <!-- <el-select v-model="filterProductForm.userId" placeholder="请选择" filterable clearable>
  26. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  27. </el-select> -->
  28. </el-form-item>
  29. <el-form-item label="创建时间">
  30. <el-date-picker v-model="filterProductForm.startTime" type="date" placeholder="请选择" :clearable="false"
  31. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  32. </el-form-item>
  33. <el-form-item label="">
  34. <el-date-picker v-model="filterProductForm.endTime" type="date" placeholder="请选择" :clearable="false"
  35. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  36. </el-form-item>
  37. </el-form>
  38. </div>
  39. <div class="w-full flex p-3 shadow-[0_-3px_5px_0px_rgba(0,0,0,0.2)]">
  40. <El-button class="w-full" @click="resetFilter()">重置</El-Button>
  41. <El-button type="primary" class="w-full" @click="getProductTableList()">搜索</El-Button>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="flex-1 p-5 overflow-auto">
  46. <div class="bg-white w-full h-full p-3 shadow-md rounded-md flex flex-col">
  47. <div class="flex justify-end pb-3">
  48. <el-button type="primary" v-permission="['productAdd']" @click="editProduct(false)">新建产品</el-button>
  49. <el-button type="primary" v-permission="['productDelete']" @click="batchDelete()">批量删除</el-button>
  50. <el-button type="primary" v-permission="['productRecycle']" @click="showDeteleProduct(true)">回收站</el-button>
  51. <el-button type="primary" v-permission="['productImport']" @click="dialogVisible.importVisible = true">导入</el-button>
  52. <el-button type="primary" v-permission="['productExport']" @click="exportProductTableList()" :loading="allLoading.exoprtLoading">导出</el-button>
  53. </div>
  54. <div class="flex-1 w-full overflow-hidden">
  55. <el-table ref="productTableRef" :show-overflow-tooltip="tableShowOverflowTooltip" :data="productTableList" border v-loading="allLoading.productTableLading"
  56. style="width: 100%;height: 100%;">
  57. <el-table-column type="selection" width="55" />
  58. <el-table-column prop="productCode" label="产品编号" width="180"></el-table-column>
  59. <el-table-column prop="productName" label="产品名称" width="180">
  60. <template #default="scope">
  61. <!-- <el-button link type="primary" size="large" @click="toProductDetail(scope.row)">{{
  62. scope.row.productName
  63. }}</el-button> -->
  64. <div class="table-text-textnowrap" @click.prevent="toProductDetail(scope.row)">{{ scope.row.productName }}</div>
  65. </template>
  66. </el-table-column>
  67. <el-table-column prop="typeName" label="产品类别" width="180"></el-table-column>
  68. <el-table-column prop="unitName" label="单位" width="180"></el-table-column>
  69. <el-table-column prop="price" label="标准价格(元)" width="180"></el-table-column>
  70. <el-table-column prop="inventory" label="库存" width="180"></el-table-column>
  71. <el-table-column prop="status" label="状态" width="180">
  72. <template #default="scope">
  73. {{ scope.row.status == 1 ? '上架' : '下架' }}
  74. </template>
  75. </el-table-column>
  76. <el-table-column prop="inchargerName" label="负责人" width="190">
  77. <template #default="scope">
  78. <TextTranslation translationTypes="userName" :translationValue="scope.row.inchargerName" v-if="scope.row.inchargerName"></TextTranslation>
  79. </template>
  80. </el-table-column>
  81. <el-table-column prop="creatorName" label="创建人" width="180">
  82. <template #default="scope">
  83. <TextTranslation translationTypes="userName" :translationValue="scope.row.creatorName"></TextTranslation>
  84. </template>
  85. </el-table-column>
  86. <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
  87. <el-table-column label="操作" fixed="right" width="200" v-permission="['productEdit', 'productDelete']">
  88. <template #default="scope">
  89. <el-button link type="primary" size="large" @click.stop="editProduct(scope.row)">编辑</el-button>
  90. <el-button link type="danger" v-permission="['productDelete']" size="large" @click.stop="deteleRow([scope.row])">删除</el-button>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. </div>
  95. <div class="flex justify-end pt-3">
  96. <el-pagination layout="total, prev, pager, next, sizes" :page-size="filterProductForm.pageSize"
  97. @size-change="handleSizeChange" @current-change="handleCurrentChange" :total="productTableTotal"
  98. :hide-on-single-page="true" />
  99. </div>
  100. </div>
  101. </div>
  102. <!-- 弹窗 -->
  103. <el-dialog v-model="dialogVisible.editProductVisible" width="1000" :show-close="false" top="10vh">
  104. <template #header="{ close, titleId, titleClass }">
  105. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  106. <h4 :id="titleId">{{ allText.editClueText }}</h4>
  107. <div>
  108. <el-button type="primary" @click="saveProductRow(true)" v-if="!genereditForm.id":loading="allLoading.saveLoading">保存并新建</el-button>
  109. <el-button type="primary" @click="saveProductRow(false)" :loading="allLoading.saveLoading">保存</el-button>
  110. <el-button @click="dialogVisible.editProductVisible = false">取消</el-button>
  111. </div>
  112. </div>
  113. </template>
  114. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3" v-loading="allLoading.generateFormLading">
  115. <div class="ml-4 mr-4">
  116. <GenerateForm ref="generateForm" :data="productTemplate" :value="genereditForm" :key="generateFormKey" />
  117. </div>
  118. </div>
  119. </el-dialog>
  120. <el-dialog v-model="dialogVisible.importVisible" width="680" :show-close="false" top="10vh">
  121. <template #header="{ close, titleId, titleClass }">
  122. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  123. <h4 :id="titleId">导入产品</h4>
  124. <div class="flex">
  125. <el-upload class="upload-demo mr-3" :limit="1" :show-file-list="false" accept=".xlsx" :http-request="importProducts">
  126. <el-button type="primary" :loading="allLoading.importLoading">导入</el-button>
  127. </el-upload>
  128. <el-button @click="dialogVisible.importVisible = false">取消</el-button>
  129. </div>
  130. </div>
  131. </template>
  132. <div class="p-8">
  133. <div class="ml-4 mr-4">
  134. <div class="flex items-center">1、点击下载 <el-link type="primary" @click="downloadTemplate(MODUCODE, '产品导入模板.xlsx')">产品导入模板.xlsx</el-link></div>
  135. <div class="mt-4">2、填写excel文件、产品编号、产品名称、产品类别、标准价格、库存、状态必填</div>
  136. </div>
  137. </div>
  138. </el-dialog>
  139. <DeteleTables :visibles="dialogVisible.deteleProductDialogVisible" @showDeteleProduct="showDeteleProduct" />
  140. </div>
  141. </template>
  142. <script lang="ts" setup>
  143. import { ref, reactive, onMounted, inject } from "vue";
  144. import { GETSYSFILED, MOD, MODUCODE, GETPERSONNEL, GETTEMPLATE, GETTABLELIST, ADDPRODUCT, ALLDETELE, UPLOADFILE, EXPORTTIME, SELECTSTATUS } from './api'
  145. import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, downloadFile, formatDate, createTaskFromType, confirmAction, downloadTemplate } from '@/utils/tools'
  146. import { FormInstance, FormRules, ElMessageBox, ElTable, UploadRequestOptions } from 'element-plus'
  147. import { tableShowOverflowTooltip } from '@/utils/globalVariables'
  148. import { post, get, uploadFile } from "@/utils/request";
  149. import { useRouter, useRoute } from "vue-router";
  150. import { GenerateForm } from '@zmjs/form-design';
  151. import DeteleTables from "./deteleTables.vue";
  152. import personnelSearch from '@/components/translationComponent/personnelSearch/personnelSearch.vue';
  153. const router = useRouter()
  154. const globalPopup = inject<GlobalPopup>('globalPopup')
  155. const filterProductForm = reactive<filterProductFormType>({ // 筛选条件form
  156. userId: '',
  157. productName: '',
  158. productCode: '',
  159. startTime: getFirstDayOfMonth(new Date()),
  160. endTime: formatDate(new Date()),
  161. pageIndex: 1,
  162. pageSize: 10,
  163. id: '',
  164. productType: '',
  165. status: '',
  166. })
  167. const allLoading = reactive({
  168. productTableLading: false,
  169. generateFormLading: false,
  170. saveLoading: false,
  171. importLoading: false,
  172. exoprtLoading: false
  173. })
  174. const dialogVisible = reactive({
  175. editProductVisible: false,
  176. taskModalVisible: false,
  177. clueDialogVisible: false,
  178. deteleClueDialogVisible: false,
  179. importVisible: false,
  180. deteleProductDialogVisible: false
  181. })
  182. const allText = reactive({
  183. editClueText: '新建产品',
  184. })
  185. const fixedData = reactive({
  186. ProductType: [] as fixedDataInterface[],
  187. Personnel: [] as personnelInterface[]
  188. })
  189. const productTableList = ref([]) // 产品table数据
  190. const productTableTotal = ref(0) // 产品 table 数据总数
  191. const productTableRef = ref<InstanceType<typeof ElTable>>() // 产品table dom
  192. const generateForm: any = ref(null) // 模板
  193. const productTemplate = ref({
  194. list: [],
  195. config: {}
  196. }) // 产品模板
  197. const genereditForm = ref<any>({}) // 编辑表单
  198. const generateFormKey = ref(1)
  199. // 方法定义
  200. function batchDelete() {
  201. const data = productTableRef.value && productTableRef.value.getSelectionRows()
  202. if (!data.length) {
  203. globalPopup?.showWarning('请选择数据')
  204. return
  205. }
  206. deteleRow(data)
  207. }
  208. function showDeteleProduct(flag: boolean) {
  209. if(!flag) {
  210. getProductTableList()
  211. }
  212. dialogVisible.deteleProductDialogVisible = flag
  213. }
  214. function deteleRow(items: any[]) {
  215. let ids = items.map(item => item.id).join(',')
  216. let str = items.map(item => item.productName).join(',')
  217. confirmAction(`确定${items.length > 1 ? '批量删除' : '删除'}【${str}】产品吗?`).then(() => {
  218. post(ALLDETELE, { ids: ids }).then((_res) => {
  219. globalPopup?.showSuccess('删除成功')
  220. getProductTableList()
  221. }).catch((err) => {
  222. globalPopup?.showError(err.msg)
  223. })
  224. })
  225. }
  226. async function saveProductRow(flag: boolean) {
  227. const data = await generateForm.value.getData()
  228. let newData = { ...genereditForm.value, ...data }
  229. delete newData.createTime
  230. allLoading.saveLoading = true
  231. post(ADDPRODUCT, { ...newData }).then(() => {
  232. globalPopup?.showSuccess('保存成功')
  233. if (flag) {
  234. genereditForm.value = {}
  235. generateForm.value && generateForm.value.reset()
  236. }
  237. getProductTableList()
  238. dialogVisible.editProductVisible = flag
  239. }).catch((err) => {
  240. globalPopup?.showError(err.msg)
  241. }).finally(() => {
  242. allLoading.saveLoading = false
  243. })
  244. }
  245. function editProduct(item: any) {
  246. dialogVisible.editProductVisible = true
  247. allLoading.generateFormLading = true
  248. if (item) {
  249. genereditForm.value = { ...item, status: String(item.status) }
  250. allText.editClueText = '编辑产品'
  251. }
  252. if (!item) {
  253. genereditForm.value = {}
  254. allText.editClueText = '新建产品'
  255. }
  256. setTimeout(() => {
  257. generateForm.value && generateForm.value.reset()
  258. generateFormKey.value++
  259. allLoading.generateFormLading = false
  260. }, 500)
  261. }
  262. function getProductTableList() {
  263. allLoading.productTableLading = true
  264. let valueForm = getFromValue(filterProductForm)
  265. post(GETTABLELIST, { ...valueForm }).then((res) => {
  266. if (res.code == 'ok') {
  267. const { record, total } = res.data
  268. productTableList.value = record
  269. productTableTotal.value = total
  270. }
  271. }).finally(() => {
  272. allLoading.productTableLading = false
  273. })
  274. }
  275. async function importProducts(param: UploadRequestOptions) {
  276. allLoading.importLoading = true
  277. const formData = new FormData();
  278. formData.append('multipartFile', param.file)
  279. const res = await uploadFile(UPLOADFILE, formData).finally(() => {
  280. allLoading.importLoading = false
  281. })
  282. allLoading.importLoading = false
  283. if (res.code == 'ok') {
  284. globalPopup?.showSuccess('导入成功' || '')
  285. getProductTableList()
  286. return
  287. }
  288. globalPopup?.showError(res.msg || '')
  289. }
  290. function exportProductTableList() {
  291. allLoading.exoprtLoading = true
  292. let valueForm = getFromValue(filterProductForm)
  293. post(EXPORTTIME, {...valueForm}).then((res) => {
  294. downloadFile(res.data, '产品表导出.xlsx')
  295. }).finally(() => {
  296. allLoading.exoprtLoading = false
  297. })
  298. }
  299. function handleSizeChange(val: number) {
  300. filterProductForm.pageIndex = 1
  301. filterProductForm.pageSize = val
  302. getProductTableList()
  303. }
  304. function handleCurrentChange(val: number) {
  305. filterProductForm.pageIndex = val
  306. getProductTableList()
  307. }
  308. function resetFilter() {
  309. let newResetForm = resetFromValue(filterProductForm, { startTime: getFirstDayOfMonth(new Date()), endTime: formatDate(new Date()), pageIndex: 1, pageSize: 10 })
  310. Object.assign(filterProductForm, newResetForm)
  311. getProductTableList()
  312. }
  313. function toProductDetail(row: any) {
  314. router.push({
  315. path: `${MOD}/detail`,
  316. query: { id: row.id }
  317. })
  318. }
  319. async function getSystemField() {
  320. const systemField = getAllListByCode(['产品类型'])
  321. for (let i in systemField) {
  322. const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  323. for (let key of Object.keys(fixedData)) {
  324. if (systemField[i] == key) {
  325. Object.assign(fixedData, { [key]: data })
  326. }
  327. }
  328. }
  329. const { data } = await post(GETPERSONNEL, {})
  330. fixedData.Personnel = data.map((item: any) => {
  331. const { id, name, phone, jobNumber } = item
  332. return {
  333. id, name, phone, jobNumber
  334. }
  335. })
  336. const res = await get(GETTEMPLATE)
  337. productTemplate.value = JSON.parse(res.data[0].config)
  338. }
  339. onMounted(() => {
  340. getSystemField()
  341. getProductTableList()
  342. })
  343. </script>
  344. <style lang="scss" scoped></style>