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.

437 lines
13 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <script>
  2. import {
  3. generateCustomerNo,
  4. removeCustomer,
  5. saveCustomer,
  6. selectCustomerList, selectCustomerPage,
  7. updateCustomer
  8. } from '../../../api/customer/info'
  9. import dayjs from 'dayjs'
  10. import {getTableDefaultListLanguage, getTableUserListLanguage} from '../../../api/table'
  11. let customer = {
  12. customerNo: '',
  13. customerName: '',
  14. active: '',
  15. }
  16. export default {
  17. name: 'CustomerInfo',
  18. props:{
  19. ofComponents:{
  20. type:Boolean,
  21. default:false
  22. },
  23. height:{
  24. type:Number,
  25. default:730
  26. }
  27. },
  28. data(){
  29. return{
  30. no:1,
  31. size:50,
  32. total:0,
  33. customer:{
  34. ...customer
  35. },
  36. saveCustomer:{
  37. ...customer,
  38. active: 'Y'
  39. },
  40. tableLoading:false,
  41. saveCustomerVisible:false,
  42. customerList:[],
  43. saveCustomerRules:{
  44. customerName: [
  45. { required: true, message: 'Please input Customer Name', trigger: ['blur','change'] }
  46. ],
  47. },
  48. columnList:[
  49. {
  50. userId: this.$store.state.user.name,
  51. functionId: 20002,
  52. serialNumber: '20002TableCustomerNo',
  53. tableId: "20002Table",
  54. tableName: "客户信息表",
  55. columnProp: "customerNo",
  56. headerAlign: "center",
  57. align: "left",
  58. columnLabel: "Customer No",
  59. columnHidden: false,
  60. columnImage: false,
  61. columnSortable: false,
  62. sortLv: 10,
  63. status: true,
  64. fixed: '',
  65. columnWidth: 80
  66. },{
  67. userId: this.$store.state.user.name,
  68. functionId: 20002,
  69. serialNumber: '20002TableCustomerName',
  70. tableId: "20002Table",
  71. tableName: "客户信息表",
  72. columnProp: "customerName",
  73. headerAlign: "center",
  74. align: "left",
  75. columnLabel: "Customer Name",
  76. columnHidden: false,
  77. columnImage: false,
  78. columnSortable: false,
  79. sortLv: 10,
  80. status: true,
  81. fixed: '',
  82. columnWidth: 120
  83. },{
  84. userId: this.$store.state.user.name,
  85. functionId: 20002,
  86. serialNumber: '20002TableActive',
  87. tableId: "20002Table",
  88. tableName: "客户信息表",
  89. columnProp: "active",
  90. headerAlign: "center",
  91. align: "left",
  92. columnLabel: "Active",
  93. columnHidden: false,
  94. columnImage: false,
  95. columnSortable: false,
  96. sortLv: 10,
  97. status: true,
  98. fixed: '',
  99. columnWidth: 80
  100. },{
  101. userId: this.$store.state.user.name,
  102. functionId: 20002,
  103. serialNumber: '20002TableCreateTime',
  104. tableId: "20002Table",
  105. tableName: "客户信息表",
  106. columnProp: "createTime",
  107. headerAlign: "center",
  108. align: "left",
  109. columnLabel: "Created Time",
  110. columnHidden: false,
  111. columnImage: false,
  112. columnSortable: false,
  113. sortLv: 10,
  114. status: true,
  115. fixed: '',
  116. columnWidth: 80
  117. },{
  118. userId: this.$store.state.user.name,
  119. functionId: 20002,
  120. serialNumber: '20002TableCreateBy',
  121. tableId: "20002Table",
  122. tableName: "客户信息表",
  123. columnProp: "createBy",
  124. headerAlign: "center",
  125. align: "left",
  126. columnLabel: "Created By",
  127. columnHidden: false,
  128. columnImage: false,
  129. columnSortable: false,
  130. sortLv: 10,
  131. status: true,
  132. fixed: '',
  133. columnWidth: 80
  134. },
  135. ],
  136. }
  137. },
  138. watch:{
  139. "customer.customerNo"(newVal,oldVal){
  140. this.customer.customerNo = newVal.toUpperCase()
  141. }
  142. },
  143. methods:{
  144. handleSave(){
  145. if (this.saveCustomerVisible){
  146. this.$refs.saveForm.validate((valid,obj) => {
  147. if (valid){
  148. let params = {
  149. ...this.saveCustomer,
  150. site:this.$store.state.user.site,
  151. createBy:this.$store.state.user.name,
  152. createTime:dayjs().format('YYYY-MM-DD HH:mm:ss')
  153. }
  154. saveCustomer(params).then(({data})=>{
  155. if (data && data.code === 0){
  156. this.handleSearch();
  157. this.saveCustomerVisible = false;
  158. this.$message.success(data.msg)
  159. }else {
  160. this.$message.warning(data.msg)
  161. }
  162. }).catch((error)=>{
  163. this.$message.error(error)
  164. })
  165. }else {
  166. Object.keys(obj).forEach(key => {
  167. this.$message.warning(obj[key][0].message)
  168. return
  169. })
  170. }
  171. })
  172. }else {
  173. let params = {
  174. site:this.$store.state.user.site,
  175. }
  176. generateCustomerNo(params).then(({data})=>{
  177. if (data && data.code === 0){
  178. this.saveCustomer.customerNo = data.id;
  179. this.saveCustomerVisible = true;
  180. }else {
  181. this.$message.warning(data.msg)
  182. }
  183. }).catch((error)=>{
  184. this.$message.error(error)
  185. })
  186. }
  187. },
  188. handleSearch(){
  189. let params = {
  190. ...this.customer,
  191. site:this.$store.state.user.site
  192. }
  193. this.tableLoading = true;
  194. selectCustomerList(params).then(({data})=>{
  195. if (data && data.code === 0){
  196. this.customerList = data.rows;
  197. }else {
  198. this.$message.warning(data.msg)
  199. }
  200. this.tableLoading = false;
  201. }).catch((error)=>{
  202. this.tableLoading = false;
  203. this.$message.error(error)
  204. })
  205. },
  206. handleRowClick(row, column, event, index){
  207. if (this.ofComponents){
  208. this.$emit('rowClick', row)
  209. }else {
  210. if (index === 0){
  211. // 处理 点击修改
  212. this.saveCustomer = {
  213. ...row,
  214. }
  215. this.saveCustomerVisible = true;
  216. }
  217. }
  218. },
  219. removeCustomer(row){
  220. removeCustomer(row).then(({data})=>{
  221. if (data && data.code === 0){
  222. this.handleSearch();
  223. this.$message.success(data.msg)
  224. }else {
  225. this.$message.warning(data.msg)
  226. }
  227. }).catch((error)=>{
  228. this.$message.error(error)
  229. })
  230. },
  231. closeSaveForm(){
  232. this.saveCustomer = {
  233. ...customer,
  234. active: 'Y'
  235. }
  236. this.$refs.saveForm.resetFields();
  237. },
  238. handleEdit(){
  239. this.$refs.saveForm.validate((valid,obj) => {
  240. if (valid){
  241. updateCustomer(this.saveCustomer).then(({data})=>{
  242. if (data && data.code === 0){
  243. this.handleSearch();
  244. this.saveCustomerVisible = false;
  245. this.$message.success(data.msg)
  246. }else {
  247. this.$message.warning(data.msg)
  248. }
  249. }).catch((error)=>{
  250. this.$message.error(error)
  251. })
  252. }else {
  253. for (let i = 0; i < Object.keys(obj).length; i++) {
  254. this.$message.warning(obj[Object.keys(obj)[i]][0].message)
  255. break
  256. }
  257. }
  258. })
  259. },
  260. // 动态列开始 获取 用户保存的 格式列
  261. async getTableUserColumn (tableId, columnId) {
  262. let queryTableUser = {
  263. userId: this.$store.state.user.name,
  264. functionId: this.$route.meta.menuId,
  265. tableId: tableId,
  266. status: true,
  267. languageCode: this.$i18n.locale
  268. }
  269. await getTableUserListLanguage(queryTableUser).then(({data}) => {
  270. if (data.rows.length > 0) {
  271. //this.columnList1 = []
  272. switch (columnId) {
  273. case 1:
  274. this.columnList = data.rows
  275. break;
  276. }
  277. } else {
  278. this.getColumnList(tableId, columnId)
  279. }
  280. })
  281. },
  282. // 获取 tableDefault 列
  283. async getColumnList (tableId, columnId) {
  284. let queryTable = {
  285. functionId: this.$route.meta.menuId,
  286. tableId: tableId,
  287. languageCode: this.$i18n.locale
  288. }
  289. await getTableDefaultListLanguage(queryTable).then(({data}) => {
  290. if (!data.rows.length === 0) {
  291. switch (columnId) {
  292. case 1:
  293. this.columnList = data.rows
  294. break;
  295. }
  296. } else {
  297. }
  298. })
  299. },
  300. handleSelectCustomerPage(){
  301. let params = {
  302. ...this.customer,
  303. site:this.$store.state.user.site,
  304. no:this.no,
  305. size:this.size
  306. }
  307. this.tableLoading = true;
  308. selectCustomerPage(params).then(({data})=>{
  309. if (data && data.code === 0){
  310. this.customerList = data.rows;
  311. this.total = data.total;
  312. }else {
  313. this.$message.warning(data.msg)
  314. }
  315. this.tableLoading = false;
  316. }).catch((error)=>{
  317. this.$message.error(error)
  318. this.tableLoading = false;
  319. })
  320. },
  321. handleSizeChange(val){
  322. this.size = val;
  323. this.handleSelectCustomerPage();
  324. },
  325. handleCurrentChange(val){
  326. this.no = val;
  327. this.handleSelectCustomerPage();
  328. }
  329. },
  330. created () {
  331. this.handleSelectCustomerPage();
  332. // this.handleSearch();
  333. this.getTableUserColumn("20002Table", 1)
  334. }
  335. }
  336. </script>
  337. <template>
  338. <div>
  339. <el-form label-position="top" :inline="true" :model="customer" >
  340. <el-form-item label="Customer No">
  341. <el-input v-model="customer.customerNo"></el-input>
  342. </el-form-item>
  343. <el-form-item label="Customer Name">
  344. <el-input v-model="customer.customerName"></el-input>
  345. </el-form-item>
  346. <el-form-item label="Active">
  347. <el-select v-model="customer.active" placeholder="">
  348. <el-option label="All" value=""></el-option>
  349. <el-option label="Active" value="Y"></el-option>
  350. <el-option label="Not Active" value="N"></el-option>
  351. </el-select>
  352. </el-form-item>
  353. <el-form-item label=" ">
  354. <el-button type="primary" v-if="!ofComponents" @click="handleSave">New</el-button>
  355. <!-- <el-button type="primary" @click="handleSearch">Query</el-button>-->
  356. <el-button type="primary" @click="handleSelectCustomerPage">Query</el-button>
  357. </el-form-item>
  358. </el-form>
  359. <el-table
  360. :height="height"
  361. :data="customerList" v-loading="tableLoading"
  362. border @row-dblclick="handleRowClick"
  363. style="width: 100%;margin-top: 5px">
  364. <el-table-column v-if="!ofComponents"
  365. header-align="center"
  366. align="center"
  367. width="100"
  368. fixed="left"
  369. label="Actions">
  370. <template slot-scope="scope">
  371. <el-link style="cursor:pointer;" @click="handleRowClick(scope.row, scope.column, $event,0)">Edit</el-link>
  372. <el-link style="cursor:pointer;" @click="removeCustomer(scope.row)">Delete</el-link>
  373. </template>
  374. </el-table-column>
  375. <el-table-column
  376. v-for="(item,index) in columnList" :key="index"
  377. :sortable="item.columnSortable"
  378. :prop="item.columnProp"
  379. :header-align="item.headerAlign"
  380. :show-overflow-tooltip="item.showOverflowTooltip"
  381. :align="item.align"
  382. :fixed="item.fixed==''?false:item.fixed"
  383. :min-width="item.columnWidth"
  384. :label="item.columnLabel">
  385. <template slot-scope="scope">
  386. <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
  387. <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
  388. style="width: 100px; height: 80px"/></span>
  389. </template>
  390. </el-table-column>
  391. </el-table>
  392. <el-pagination
  393. @size-change="handleSizeChange"
  394. @current-change="handleCurrentChange"
  395. :current-page.sync="no"
  396. :page-sizes="[50,100, 200, 300, 400]"
  397. :page-size="size"
  398. layout="sizes, prev, pager, next,total"
  399. :total="total">
  400. </el-pagination>
  401. <el-dialog v-drag modal-append-to-body :close-on-click-modal="false" :title="`Customer`" @close="closeSaveForm" width="500px" :visible.sync="saveCustomerVisible">
  402. <el-form label-position="top" :model="saveCustomer" :rules="saveCustomerRules" ref="saveForm">
  403. <el-row :gutter="20">
  404. <el-col :span="12">
  405. <el-form-item label="Customer No">
  406. <el-input readonly disabled v-model="saveCustomer.customerNo"></el-input>
  407. </el-form-item>
  408. </el-col>
  409. <el-col :span="12" >
  410. <el-form-item label=" ">
  411. <el-checkbox v-model="saveCustomer.active" true-label="Y" false-label="N">Active</el-checkbox>
  412. </el-form-item>
  413. </el-col>
  414. <el-col :span="24">
  415. <el-form-item label="Customer Name" prop="customerName" :show-message="false">
  416. <el-input v-model="saveCustomer.customerName"></el-input>
  417. </el-form-item>
  418. </el-col>
  419. </el-row>
  420. </el-form>
  421. <div slot="footer" class="dialog-footer">
  422. <el-button type="primary" v-if="saveCustomer.site" @click="handleEdit">Save</el-button>
  423. <el-button type="primary" v-else @click="handleSave">Save</el-button>
  424. <el-button @click="saveCustomerVisible = false">Cancel</el-button>
  425. </div>
  426. </el-dialog>
  427. </div>
  428. </template>
  429. <style scoped>
  430. </style>