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.

436 lines
13 KiB

3 years ago
3 years ago
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. activated() {
  265. this.$store.commit("sift/commitSearchFunction",this.getBuDemo)
  266. },
  267. methods: {
  268. getBuDemo(params){
  269. this.$message.success("这里是BU")
  270. },
  271. // 获取基础数据列表S
  272. getBaseList (val, type) {
  273. this.tagNo = val
  274. this.tagNo1 = type
  275. this.$nextTick(() => {
  276. let strVal = ''
  277. if (val === 1013) {
  278. if(type==1) {
  279. strVal = this.dataForm.partType
  280. }
  281. }
  282. this.$refs.baseList.init(val, strVal)
  283. })
  284. },
  285. /* 列表方法的回调 */
  286. getBaseData (val) {
  287. if (this.tagNo === 1013) {
  288. if(this.tagNo1==1) {
  289. this.dataForm.partType = val.Base_id
  290. this.dataForm.partTypeDesc = val.Base_desc
  291. }
  292. }
  293. },
  294. searchTable(){
  295. getBUList(this.searchData).then(({data}) => {
  296. //区分请求成功和失败的状况
  297. if (data && data.code == 0) {
  298. this.dataList = data.rows;
  299. } else {
  300. this.dataList = [];
  301. }
  302. });
  303. },
  304. addModal(){
  305. this.dataForm={
  306. id:0,
  307. site: this.$store.state.user.site,
  308. buNo:'',
  309. buDesc:'',
  310. active:'Y',
  311. remark:'',
  312. username:this.$store.state.user.name,
  313. }
  314. this.visible=true;
  315. },
  316. updateModel(row){
  317. this.dataForm={
  318. id:row.id,
  319. site: row.site,
  320. buNo:row.buNo,
  321. buDesc:row.buDesc,
  322. active:row.active,
  323. remark:row.remark,
  324. username:this.$store.state.user.name,
  325. }
  326. this.visible=true;
  327. },
  328. saveData(){
  329. if(this.dataForm.buNo==''||this.dataForm.buNo==null){
  330. this.$alert('请输入BU编码!', '错误', {
  331. confirmButtonText: '确定'
  332. })
  333. return false;
  334. }
  335. if(this.dataForm.buDesc==''||this.dataForm.buDesc==null){
  336. this.$alert('请输入BU名称!', '错误', {
  337. confirmButtonText: '确定'
  338. })
  339. return false;
  340. }
  341. saveBU(this.dataForm).then(({data}) => {
  342. if (data && data.code === 0) {
  343. this.$message.success( '操作成功')
  344. this.visible = false
  345. this.searchTable();
  346. } else {
  347. this.$message.error(data.msg)
  348. }
  349. })
  350. },
  351. deleteData(row){
  352. this.$confirm('确定要删除这条数据?', '提示', {
  353. confirmButtonText: '确定',
  354. cancelButtonText: '取消',
  355. type: 'warning'
  356. }).then(() => {
  357. deleteBU(row).then(({data}) => {
  358. if (data && data.code === 0) {
  359. this.$message.success( '操作成功')
  360. this.searchTable();
  361. } else {
  362. this.$message.error(data.msg)
  363. }
  364. })
  365. }).catch(() => {
  366. })
  367. },
  368. accessModel(row){
  369. searchAccessBuListForUser({site:this.$store.state.user.site,
  370. buNo: row.buNo,
  371. active:'Y'}).then(({data}) => {
  372. this.accessBuList = data.accessBuList
  373. this.userList=data.userList
  374. })
  375. this.rowBuNo=row.buNo
  376. this.accessModelFlag=true
  377. },
  378. saveAccessBuListForBu(){
  379. let inList=[];
  380. for (let i = 0; i < this.accessBuList.length; i++) {
  381. let inData={
  382. site:this.$store.state.user.site,
  383. username:this.accessBuList[i],
  384. buNo:this.rowBuNo
  385. }
  386. inList.push(inData)
  387. }
  388. let saveData={
  389. site:this.$store.state.user.site,
  390. buNo:this.rowBuNo,
  391. accessBuList:inList,
  392. }
  393. saveAccessBuListForBu(saveData).then(({data}) => {
  394. if (data && data.code === 0) {
  395. this.$message.success( '操作成功')
  396. this.accessModelFlag = false
  397. } else {
  398. this.$message.error(data.msg)
  399. }
  400. })
  401. },
  402. //导出excel
  403. async createExportData() {
  404. return this.dataList;
  405. },
  406. startDownload() {
  407. // this.exportData = this.dataList
  408. },
  409. finishDownload() {
  410. },
  411. fields() {
  412. let json = "{"
  413. this.columnList1.forEach((item, index) => {
  414. if (index == this.columnList1.length - 1) {
  415. json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
  416. } else {
  417. json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
  418. }
  419. })
  420. json += "}"
  421. let s = eval("(" + json + ")")
  422. return s
  423. },
  424. },
  425. }
  426. </script>
  427. <style scoped>
  428. </style>