index.vue 19 KB

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