index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.providerName" placeholder="供应商名称" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.getdataListParm.parammaps.providerNumber" placeholder="供应商编号" style="width: 180px;" class="filter-item" clearable />
  6. <el-select v-model="table.getdataListParm.parammaps.enable" filterable :placeholder="$t('formulationEvaluation.sfqy')" class="filter-item" style="width: 120px;" clearable>
  7. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  8. </el-select>
  9. <el-button class="successBorder" @click="form_search">{{$t('common.query')}}</el-button>
  10. <el-button class="successBorder" @click="handleRefresh">{{$t('common.reset')}}</el-button>
  11. </div>
  12. <div class="operation">
  13. <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="handleCreate">{{$t('formulationEvaluation.add')}}</el-button>
  14. <el-button v-if="isRoleEdit" class="danger" icon="el-icon-delete" @click="form_delete">{{$t('formulationEvaluation.del')}}</el-button>
  15. </div>
  16. <div class="table">
  17. <el-table
  18. :key="table.tableKey"
  19. v-loading="table.listLoading"
  20. element-loading-text="给我一点时间"
  21. :data="table.list"
  22. border
  23. fit
  24. highlight-current-row
  25. style="width: 100%;"
  26. :row-style="rowStyle"
  27. :cell-style="cellStyle"
  28. class="elTable table-fixed"
  29. @selection-change="handleSelectionChange"
  30. :max-height="myHeight"
  31. >
  32. <el-table-column type="selection" align="center" width="50" />
  33. <el-table-column :label="$t('formulationEvaluation.xh')" align="center" type="index" width="50px">
  34. <template slot-scope="scope">
  35. <span v-if="table.pageNum">{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  36. <span v-else>1</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="供应商名称" min-width="150px" align="center">
  40. <template slot-scope="scope">
  41. <span v-if="scope.row.NoEdit">{{ scope.row.providerName }}</span>
  42. <el-input v-if="scope.row.Edit" v-model="scope.row.providerName" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="供应商编号" min-width="150px" align="center">
  46. <template slot-scope="scope">
  47. <span v-if="scope.row.NoEdit">{{ scope.row.providerNumber }}</span>
  48. <el-input v-if="scope.row.Edit" v-model="scope.row.providerNumber" placeholder="1-8位数字" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="8" style="width:95%;padding:10px 0;" />
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="联系人" min-width="150px" align="center">
  52. <template slot-scope="scope">
  53. <span v-if="scope.row.NoEdit">{{ scope.row.linkman }}</span>
  54. <el-input v-if="scope.row.Edit" v-model="scope.row.linkman" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="联系方式" min-width="150px" align="center">
  58. <template slot-scope="scope">
  59. <span v-if="scope.row.NoEdit">{{ scope.row.telphone }}</span>
  60. <el-input v-if="scope.row.Edit" v-model="scope.row.telphone" placeholder="11位数字" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="11" style="width:95%;padding:10px 0;" />
  61. </template>
  62. </el-table-column>
  63. <el-table-column :label="$t('formulationEvaluation.remark')" min-width="150px" align="center">
  64. <template slot-scope="scope">
  65. <span v-if="scope.row.NoEdit">{{ scope.row.remark }}</span>
  66. <el-input v-if="scope.row.Edit" v-model="scope.row.remark" placeholder="1-255个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="255" style="width:95%;padding:10px 0;" />
  67. </template>
  68. </el-table-column>
  69. <el-table-column :label="$t('formulationEvaluation.sfqy')" min-width="110px" align="center">
  70. <template slot-scope="scope">
  71. <el-switch v-model="scope.row.enable" :disabled="scope.row.NoEdit==true" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
  72. </template>
  73. </el-table-column>
  74. <el-table-column :label="$t('errorAnalysis.cz')" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  75. <template slot-scope="{row}">
  76. <!-- 新增 -->
  77. <el-button v-if="row.isCreate" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData(row)" />
  78. <span v-if="row.isCreate" class="centerSpan">|</span>
  79. <el-button v-if="row.isCreate" class="minCancel" icon="el-icon-close" @click="createCancel(row)" />
  80. <!-- 编辑 -->
  81. <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  82. <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
  83. <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete(row)" />
  84. <!-- 编辑保存 -->
  85. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData(row)" />
  86. <span v-if="row.isUpdateSave" class="centerSpan">|</span>
  87. <el-button v-if="row.isUpdateSave" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <pagination v-show="table.total>0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  92. </div>
  93. </div>
  94. </template>
  95. <script>
  96. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, checkButtons } from '@/api/common'
  97. import Cookies from 'js-cookie'
  98. import Pagination from '@/components/Pagination'
  99. import { MessageBox } from 'element-ui'
  100. export default {
  101. name: 'Supplier',
  102. components: { Pagination },
  103. data() {
  104. return {
  105. isRoleEdit: [],
  106. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }], // 是否启用
  107. table: {
  108. getdataListParm: {
  109. name: 'getProviderList',
  110. page: 1,
  111. offset: 1,
  112. pagecount: parseInt(Cookies.get('pageCount')),
  113. returntype: 'Map',
  114. parammaps: {
  115. pastureid: Cookies.get('pastureid'),
  116. providerName: '',
  117. providerNumber: '',
  118. enable: ''
  119. }
  120. },
  121. tableKey: 0,
  122. list: [],
  123. total: 0,
  124. listLoading: true,
  125. temp: {}
  126. },
  127. requestParam: {},
  128. isokDisable: false,
  129. selectList: [],
  130. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  131. cellStyle: { padding: 0 + 'px' },
  132. myHeight:document.documentElement.clientHeight - 85- 150-50
  133. }
  134. },
  135. created() {
  136. this.getList()
  137. this.getButtons()
  138. },
  139. methods: {
  140. getButtons() {
  141. const Edit = 'Supplier'
  142. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  143. this.isRoleEdit = isRoleEdit
  144. },
  145. getList() {
  146. this.table.listLoading = true
  147. GetDataByName(this.table.getdataListParm).then(response => {
  148. console.log('table数据', response.data.list)
  149. if (response.data.list !== null) {
  150. for (let i = 0; i < response.data.list.length; i++) {
  151. this.$set(response.data.list[i], 'Edit', false) // 编辑
  152. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  153. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  154. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  155. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  156. }
  157. this.table.list = response.data.list
  158. this.table.pageNum = response.data.pageNum
  159. this.table.pageSize = response.data.pageSize
  160. } else {
  161. this.table.list = []
  162. }
  163. this.table.total = response.data.total
  164. setTimeout(() => {
  165. this.table.listLoading = false
  166. }, 100)
  167. })
  168. },
  169. handleEnableChange() {
  170. console.log('点击了是否启用')
  171. },
  172. form_search() {
  173. console.log('点击了查询')
  174. this.table.getdataListParm.offset = 1
  175. this.getList()
  176. },
  177. handleRefresh() {
  178. console.log('点击了重置')
  179. this.table.getdataListParm.parammaps.providerName = ''
  180. this.table.getdataListParm.parammaps.providerNumber = ''
  181. this.table.getdataListParm.parammaps.enable = ''
  182. this.table.getdataListParm.offset = 1
  183. this.getList()
  184. },
  185. // 新增
  186. handleCreate() {
  187. // 编辑true/不可编辑false
  188. // 新增操true,编辑false,编辑保存false
  189. console.log(11)
  190. for (let i = 0; i < this.table.list.length; i++) {
  191. if (this.table.list[i].Edit === true) {
  192. console.log(123)
  193. this.$message({ type: 'error', message: this.$t('driver.messageNote'), duration: 2000 })
  194. return false
  195. }
  196. }
  197. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'providerName': '', 'providerNumber': '', 'linkman': '', 'telphone': '', 'remark': '' })
  198. },
  199. createData(row) {
  200. console.log('点击了新增保存', row)
  201. this.table.temp.pastureid = Cookies.get('pastureid')
  202. this.table.temp.providerNumber = row.providerNumber
  203. this.table.temp.providerName = row.providerName
  204. this.table.temp.linkman = row.linkman
  205. this.table.temp.telphone = row.telphone
  206. this.table.temp.remark = row.remark
  207. this.table.temp.enable = row.enable
  208. // 检验供应商名称/供应商编号是否为空
  209. if (this.table.temp.providerName == '' && this.table.temp.providerNumber == '') {
  210. this.$message({ type: 'error', message: '供应商名称/供应商编号不能为空', duration: 2000 })
  211. return false
  212. } else if (this.table.temp.providerNumber == '') {
  213. this.$message({ type: 'error', message: '供应商编号不能为空', duration: 2000 })
  214. return false
  215. } else if (this.table.temp.providerName == '') {
  216. this.$message({ type: 'error', message: '供应商名称不能为空', duration: 2000 })
  217. return false
  218. }
  219. const providerNumber = /(^[\-0-9][0-9]*(.[0-9]+)?)$/
  220. if (!providerNumber.test(parseInt(this.table.temp.providerNumber))) {
  221. console.log(this.table.temp.providerNumber)
  222. this.$message({ type: 'error', message: '供应商编号请输入1-8位数字', duration: 2000 })
  223. return false
  224. }
  225. if (this.table.temp.telphone !== '') {
  226. const telphone = /^\d{11}$/
  227. if (!telphone.test(this.table.temp.telphone)) {
  228. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  229. return false
  230. }
  231. }
  232. this.isokDisable = true
  233. setTimeout(() => {
  234. this.isokDisable = false
  235. }, 1000)
  236. this.requestParam.name = 'insertProvider'
  237. this.requestParam.parammaps = this.table.temp
  238. PostDataByName(this.requestParam).then(response => {
  239. console.log('新增保存发送参数', this.requestParam)
  240. if (response.msg !== 'fail') {
  241. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  242. this.getList()
  243. } else {
  244. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  245. }
  246. })
  247. },
  248. createCancel(row) {
  249. console.log('点击了新增取消')
  250. for (let i = 0; i < this.table.list.length; i++) {
  251. if (row.myId === this.table.list[i].myId) {
  252. var listIndex = this.table.list.indexOf(this.table.list[i])
  253. }
  254. if (listIndex > -1) {
  255. this.table.list.splice(listIndex, 1)
  256. return
  257. }
  258. }
  259. },
  260. // 编辑
  261. handleUpdate(row) {
  262. for (let i = 0; i < this.table.list.length; i++) {
  263. if (this.table.list[i].Edit == true) {
  264. this.$message({ type: 'error', message: this.$t('driver.messageNote'), duration: 2000 })
  265. return false
  266. }
  267. }
  268. // 编辑true,不可编辑false
  269. row.Edit = true
  270. row.NoEdit = false
  271. // 新增false,编辑false,编辑保存true
  272. row.isCreate = false
  273. row.isUpdate = false
  274. row.isUpdateSave = true
  275. },
  276. updateData(row) {
  277. console.log('点击了编辑保存', row)
  278. this.table.temp.pastureid = Cookies.get('pastureid')
  279. this.table.temp.providerNumber = row.providerNumber
  280. this.table.temp.providerName = row.providerName
  281. this.table.temp.linkman = row.linkman
  282. this.table.temp.telphone = row.telphone
  283. this.table.temp.remark = row.remark
  284. this.table.temp.enable = row.enable
  285. this.table.temp.id = row.id
  286. // 检验供应商名称/供应商编号是否为空
  287. if (this.table.temp.providerName == '' && this.table.temp.providerNumber == '') {
  288. this.$message({ type: 'error', message: '供应商名称/供应商编号不能为空', duration: 2000 })
  289. return false
  290. } else if (this.table.temp.providerNumber == '') {
  291. this.$message({ type: 'error', message: '供应商编号不能为空', duration: 2000 })
  292. return false
  293. } else if (this.table.temp.providerName == '') {
  294. this.$message({ type: 'error', message: '供应商名称不能为空', duration: 2000 })
  295. return false
  296. }
  297. const providerNumber = /(^[\-0-9][0-9]*(.[0-9]+)?)$/
  298. if (!providerNumber.test(parseInt(this.table.temp.providerNumber))) {
  299. console.log(this.table.temp.providerNumber)
  300. this.$message({ type: 'error', message: '供应商编号请输入1-8位数字', duration: 2000 })
  301. return false
  302. }
  303. if (this.table.temp.telphone !== '') {
  304. const telphone = /^\d{11}$/
  305. if (!telphone.test(this.table.temp.telphone)) {
  306. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  307. return false
  308. }
  309. }
  310. this.isokDisable = true
  311. setTimeout(() => {
  312. this.isokDisable = false
  313. }, 1000)
  314. this.requestParam.name = 'updateProvider'
  315. this.requestParam.parammaps = this.table.temp
  316. PostDataByName(this.requestParam).then(response => {
  317. console.log('编辑保存发送参数', this.requestParam)
  318. if (response.msg !== 'fail') {
  319. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  320. this.getList()
  321. } else {
  322. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  323. }
  324. })
  325. },
  326. updateCancel(row) {
  327. console.log('点击了编辑取消')
  328. // 编辑false,不可编辑true
  329. row.Edit = false
  330. row.NoEdit = true
  331. // 新增false,编辑true,编辑保存false
  332. row.isCreate = false
  333. row.isUpdate = true
  334. row.isUpdateSave = false
  335. this.getList()
  336. },
  337. // 删除
  338. handleRowDelete(row) {
  339. console.log('点击了行内删除')
  340. MessageBox.confirm('是否确认删除此信息?', {
  341. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  342. }).then(() => {
  343. this.selectList = []
  344. this.requestParam = {}
  345. this.requestParam.common = { 'returnmap': '0' }
  346. this.requestParam.data = []
  347. this.requestParam.data[0] = { 'name': 'checkDeleteProv', 'type': 'v', 'parammaps': {
  348. 'pastureid': row.pastureid,
  349. 'id': row.id
  350. }}
  351. this.requestParam.data[1] = { 'name': 'deleteProvider', 'type': 'e', 'parammaps': {
  352. 'pastureid': row.pastureid,
  353. 'id': row.id
  354. }}
  355. ExecDataByConfig(this.requestParam).then(response => {
  356. console.log('删除保存发送参数', this.requestParam)
  357. if (response.msg === 'fail') {
  358. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  359. } else {
  360. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  361. this.getList()
  362. }
  363. })
  364. }).catch(() => {
  365. this.$message({ type: 'info', message: '已取消删除' })
  366. })
  367. },
  368. handleSelectionChange(val) {
  369. console.log('勾选数据', val)
  370. this.selectList = val
  371. },
  372. form_delete() {
  373. console.log('点击了删除')
  374. if (this.selectList.length == 0) {
  375. this.$message({ type: 'error', message: '请选择供应商信息', duration: 2000 })
  376. } else {
  377. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  378. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  379. }).then(() => {
  380. this.requestParam = {}
  381. this.requestParam.common = { 'returnmap': '0' }
  382. this.requestParam.data = []
  383. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  384. this.requestParam.data[0].children = []
  385. this.requestParam.data[0].children[0] = { 'name': 'checkDeleteProv', 'type': 'v', 'parammaps': {
  386. id: '@insertSpotList.id',
  387. pastureid: '@insertSpotList.pastureid'
  388. }}
  389. this.requestParam.data[0].children[1] = { 'name': 'deleteProvider', 'type': 'e', 'parammaps': {
  390. id: '@insertSpotList.id',
  391. pastureid: '@insertSpotList.pastureid'
  392. }}
  393. ExecDataByConfig(this.requestParam).then(response => {
  394. console.log('删除保存发送参数', this.requestParam)
  395. if (response.msg === 'fail') {
  396. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  397. } else {
  398. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  399. this.getList()
  400. }
  401. })
  402. })
  403. }
  404. }
  405. }
  406. }
  407. </script>
  408. <style lang="scss" scoped>
  409. .search{margin-top:10px;}
  410. </style>