4e91d972544f552337fac235432ec6b8e42885a2.svn-base 17 KB

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