plm前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

430 lines
13 KiB

3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div class="mod-config">
  3. <el-form label-position="top" style="margin-top: 1px; margin-left: 0px;">
  4. <el-form :inline="true" label-position="top" style="margin-top: 0px">
  5. <el-button type="primary" @click="searchTable()">查询</el-button>
  6. <el-button type="primary" @click="addModal()">新增</el-button>
  7. <download-excel
  8. :fields="fields()"
  9. :data="exportData"
  10. type="xls"
  11. :name="exportName"
  12. :header="exportHeader"
  13. :footer="exportFooter"
  14. :fetch="createExportData"
  15. :before-generate="startDownload"
  16. :before-finish="finishDownload"
  17. worksheet="导出信息"
  18. class="el-button el-button--primary el-button--medium">
  19. {{ '导出' }}
  20. </download-excel>
  21. </el-form>
  22. </el-form>
  23. <el-table
  24. :data="dataList"
  25. :height="height"
  26. border
  27. v-loading="dataListLoading"
  28. style="width: 100%; ">
  29. <el-table-column
  30. v-for="(item,index) in columnList1" :key="index"
  31. :sortable="item.columnSortable"
  32. :prop="item.columnProp"
  33. :header-align="item.headerAlign"
  34. :show-overflow-tooltip="item.showOverflowTooltip"
  35. :align="item.align"
  36. :fixed="item.fixed==''?false:item.fixed"
  37. :min-width="item.columnWidth"
  38. :label="item.columnLabel">
  39. <template slot-scope="scope">
  40. <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
  41. <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
  42. style="width: 100px; height: 80px"/></span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column
  46. header-align="center"
  47. align="center"
  48. width="150"
  49. fixed="right"
  50. label="操作">
  51. <template slot-scope="scope">
  52. <a type="text" size="small" @click="accessModel(scope.row)">授权</a>
  53. <a type="text" size="small" @click="updateModel(scope.row)">修改</a>
  54. <a type="text" size="small" @click="deleteData(scope.row)">删除</a>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <el-dialog
  59. width="460px"
  60. :title="!dataForm.id ? '添加' :'编辑'"
  61. :close-on-click-modal="false"
  62. :visible.sync="visible">
  63. <el-form label-position="top" label-width="100px" :rules="dataRole">
  64. <el-row :gutter="20">
  65. <el-col :span="8">
  66. <el-form-item :label="'BU编码'" prop="buNo" :rules="dataRole.buNo">
  67. <el-input v-model="dataForm.buNo" :disabled="this.dataForm.id!=0"></el-input>
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="8">
  71. <el-form-item :label="'BU名称'" prop="buDesc" :rules="dataRole.buDesc">
  72. <el-input v-model="dataForm.buDesc" ></el-input>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="8">
  76. <el-form-item label="在用">
  77. <el-select filterable v-model="dataForm.active" >
  78. <el-option label="Y" value="Y"></el-option>
  79. <el-option label="N" value="N"></el-option>
  80. </el-select>
  81. </el-form-item>
  82. </el-col>
  83. </el-row>
  84. <el-row :gutter="20">
  85. <el-col :span="24">
  86. <el-form-item :label="'备注'">
  87. <el-input v-model="dataForm.remark" style="" ></el-input>
  88. </el-form-item>
  89. </el-col>
  90. </el-row>
  91. </el-form>
  92. <span slot="footer" class="dialog-footer">
  93. <el-button type="primary" @click="saveData()">{{'确定'}}</el-button>
  94. <el-button type="primary" @click="visible = false">{{'关闭'}}</el-button>
  95. </span>
  96. </el-dialog>
  97. <el-dialog
  98. style="font-size: 12px"
  99. v-drag
  100. :title="'BU授权'"
  101. :visible.sync="accessModelFlag"
  102. width="518px"
  103. :append-to-body="true">
  104. <el-transfer v-model="accessBuList" class="rq" filterable :props="{
  105. key: 'username',
  106. label: 'userDisplay'
  107. }" :data="userList" :titles="['未选择', '已选择']"></el-transfer>
  108. <span slot="footer" class="dialog-footer">
  109. <div style="margin-top: 5px">
  110. <el-button type="primary" @click="saveAccessBuListForBu()">确定</el-button>
  111. <el-button @click="accessModelFlag = false" type="primary">取消</el-button>
  112. </div>
  113. </span>
  114. </el-dialog>
  115. <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>
  116. </div>
  117. </template>
  118. <script>
  119. import {
  120. getBUList,
  121. saveBU,
  122. deleteBU,
  123. searchAccessBuListForUser,
  124. saveAccessBuListForBu,
  125. } from "@/api/base/site.js"
  126. import Chooselist from '@/views/modules/common/Chooselist'
  127. export default {
  128. components: {
  129. Chooselist
  130. },
  131. data() {
  132. return {
  133. rowBuNo:'',
  134. accessModelFlag:false,
  135. userList:[],
  136. accessBuList:[],
  137. dataList: [],
  138. height:200,
  139. searchData: {
  140. site:this.$store.state.user.site,
  141. username: this.$store.state.user.name,
  142. },
  143. visible:false,
  144. dataListLoading: false,
  145. currentRow:'',
  146. columnList1:[
  147. {
  148. userId: this.$store.state.user.name,
  149. functionId: 100001003,
  150. serialNumber: '100001003Table1BuNo',
  151. tableId: "100001003Table1",
  152. tableName: "BU列表",
  153. columnProp: "buNo",
  154. headerAlign: "center",
  155. align: "left",
  156. columnLabel: "BU编码",
  157. columnHidden: false,
  158. columnImage: false,
  159. columnSortable: false,
  160. sortLv: 0,
  161. status: true,
  162. fixed: '',
  163. columnWidth: 80
  164. },{
  165. userId: this.$store.state.user.name,
  166. functionId: 100001003,
  167. serialNumber: '100001003Table1BuDesc',
  168. tableId: "100001003Table1",
  169. tableName: "BU列表",
  170. columnProp: "buDesc",
  171. headerAlign: "center",
  172. align: "left",
  173. columnLabel: "BU名称",
  174. columnHidden: false,
  175. columnImage: false,
  176. columnSortable: false,
  177. sortLv: 0,
  178. status: true,
  179. fixed: '',
  180. columnWidth: 120
  181. },{
  182. userId: this.$store.state.user.name,
  183. functionId: 100001003,
  184. serialNumber: '100001003Table1Active',
  185. tableId: "100001003Table1",
  186. tableName: "BU列表",
  187. columnProp: "active",
  188. headerAlign: "center",
  189. align: "left",
  190. columnLabel: "是否在用",
  191. columnHidden: false,
  192. columnImage: false,
  193. columnSortable: false,
  194. sortLv: 0,
  195. status: true,
  196. fixed: '',
  197. columnWidth: 80
  198. },{
  199. userId: this.$store.state.user.name,
  200. functionId: 100001003,
  201. serialNumber: '100001003Table1Remark',
  202. tableId: "100001003Table1",
  203. tableName: "BU列表",
  204. columnProp: "remark",
  205. headerAlign: "center",
  206. align: "left",
  207. columnLabel: "备注",
  208. columnHidden: false,
  209. columnImage: false,
  210. columnSortable: false,
  211. sortLv: 0,
  212. status: true,
  213. fixed: '',
  214. columnWidth: 120
  215. },
  216. ],
  217. dataForm:{
  218. id:'',
  219. site: '',
  220. buNo:'',
  221. buDesc:'',
  222. active:'Y',
  223. remark:'',
  224. username:'',
  225. },
  226. dataRole: {
  227. buNo: [
  228. {
  229. required: true,
  230. message: ' ',
  231. trigger: 'change'
  232. }
  233. ],
  234. buDesc: [
  235. {
  236. required: true,
  237. message: ' ',
  238. trigger: 'change'
  239. }
  240. ],
  241. },
  242. // 导出 start
  243. exportData: [],
  244. exportName: 'BU清单'+this.dayjs().format('YYYYMMDDHHmmss'),
  245. exportHeader: ["BU清单"],
  246. exportFooter: [],
  247. // 导出 end
  248. }
  249. },
  250. mounted() {
  251. this.$nextTick(() => {
  252. this.height = window.innerHeight - 140;
  253. })
  254. this.searchTable()
  255. },
  256. watch: {
  257. dataForm: {
  258. deep: true,
  259. handler: function (newV, oldV) {
  260. this.dataForm.buNo = this.dataForm.buNo.toUpperCase()
  261. }
  262. },
  263. },
  264. methods: {
  265. // 获取基础数据列表S
  266. getBaseList (val, type) {
  267. this.tagNo = val
  268. this.tagNo1 = type
  269. this.$nextTick(() => {
  270. let strVal = ''
  271. if (val === 1013) {
  272. if(type==1) {
  273. strVal = this.dataForm.partType
  274. }
  275. }
  276. this.$refs.baseList.init(val, strVal)
  277. })
  278. },
  279. /* 列表方法的回调 */
  280. getBaseData (val) {
  281. if (this.tagNo === 1013) {
  282. if(this.tagNo1==1) {
  283. this.dataForm.partType = val.Base_id
  284. this.dataForm.partTypeDesc = val.Base_desc
  285. }
  286. }
  287. },
  288. searchTable(){
  289. getBUList(this.searchData).then(({data}) => {
  290. //区分请求成功和失败的状况
  291. if (data && data.code == 0) {
  292. this.dataList = data.rows;
  293. } else {
  294. this.dataList = [];
  295. }
  296. });
  297. },
  298. addModal(){
  299. this.dataForm={
  300. id:0,
  301. site: this.$store.state.user.site,
  302. buNo:'',
  303. buDesc:'',
  304. active:'Y',
  305. remark:'',
  306. username:this.$store.state.user.name,
  307. }
  308. this.visible=true;
  309. },
  310. updateModel(row){
  311. this.dataForm={
  312. id:row.id,
  313. site: row.site,
  314. buNo:row.buNo,
  315. buDesc:row.buDesc,
  316. active:row.active,
  317. remark:row.remark,
  318. username:this.$store.state.user.name,
  319. }
  320. this.visible=true;
  321. },
  322. saveData(){
  323. if(this.dataForm.buNo==''||this.dataForm.buNo==null){
  324. this.$alert('请输入BU编码!', '错误', {
  325. confirmButtonText: '确定'
  326. })
  327. return false;
  328. }
  329. if(this.dataForm.buDesc==''||this.dataForm.buDesc==null){
  330. this.$alert('请输入BU名称!', '错误', {
  331. confirmButtonText: '确定'
  332. })
  333. return false;
  334. }
  335. saveBU(this.dataForm).then(({data}) => {
  336. if (data && data.code === 0) {
  337. this.$message.success( '操作成功')
  338. this.visible = false
  339. this.searchTable();
  340. } else {
  341. this.$message.error(data.msg)
  342. }
  343. })
  344. },
  345. deleteData(row){
  346. this.$confirm('确定要删除这条数据?', '提示', {
  347. confirmButtonText: '确定',
  348. cancelButtonText: '取消',
  349. type: 'warning'
  350. }).then(() => {
  351. deleteBU(row).then(({data}) => {
  352. if (data && data.code === 0) {
  353. this.$message.success( '操作成功')
  354. this.searchTable();
  355. } else {
  356. this.$message.error(data.msg)
  357. }
  358. })
  359. }).catch(() => {
  360. })
  361. },
  362. accessModel(row){
  363. searchAccessBuListForUser({site:this.$store.state.user.site,
  364. buNo: row.buNo,
  365. active:'Y'}).then(({data}) => {
  366. this.accessBuList = data.accessBuList
  367. this.userList=data.userList
  368. })
  369. this.rowBuNo=row.buNo
  370. this.accessModelFlag=true
  371. },
  372. saveAccessBuListForBu(){
  373. let inList=[];
  374. for (let i = 0; i < this.accessBuList.length; i++) {
  375. let inData={
  376. site:this.$store.state.user.site,
  377. username:this.accessBuList[i],
  378. buNo:this.rowBuNo
  379. }
  380. inList.push(inData)
  381. }
  382. let saveData={
  383. site:this.$store.state.user.site,
  384. buNo:this.rowBuNo,
  385. accessBuList:inList,
  386. }
  387. saveAccessBuListForBu(saveData).then(({data}) => {
  388. if (data && data.code === 0) {
  389. this.$message.success( '操作成功')
  390. this.accessModelFlag = false
  391. } else {
  392. this.$message.error(data.msg)
  393. }
  394. })
  395. },
  396. //导出excel
  397. async createExportData() {
  398. return this.dataList;
  399. },
  400. startDownload() {
  401. // this.exportData = this.dataList
  402. },
  403. finishDownload() {
  404. },
  405. fields() {
  406. let json = "{"
  407. this.columnList1.forEach((item, index) => {
  408. if (index == this.columnList1.length - 1) {
  409. json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
  410. } else {
  411. json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
  412. }
  413. })
  414. json += "}"
  415. let s = eval("(" + json + ")")
  416. return s
  417. },
  418. },
  419. }
  420. </script>
  421. <style scoped>
  422. </style>