7cf169527e31e86d47ce0567775c932bbd63d883.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" 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" :disabled="isokDisable" class="miniSuccess" @click="createData(row)">保存</el-button>
  76. <el-button v-if="row.isCreate" 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" :disabled="isokDisable" class="miniSuccess" @click="updateData(row)">保存</el-button>
  82. <el-button v-if="row.isUpdateSave" 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. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }], // 是否启用
  101. table: {
  102. getdataListParm: {
  103. name: 'getProviderList',
  104. page: 1,
  105. offset: 1,
  106. pagecount: 10,
  107. returntype: 'Map',
  108. parammaps: {
  109. pastureid: Cookies.get('pastureid'),
  110. providerName: '',
  111. providerNumber: '',
  112. enable: ''
  113. }
  114. },
  115. tableKey: 0,
  116. list: [],
  117. total: 0,
  118. listLoading: true,
  119. temp: {}
  120. },
  121. requestParam: {},
  122. isokDisable: false,
  123. selectList: [],
  124. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  125. cellStyle: { padding: 0 + 'px' }
  126. }
  127. },
  128. created() {
  129. this.getList()
  130. this.getButtons()
  131. },
  132. methods: {
  133. getButtons() {
  134. const Edit = 'Supplier'
  135. const isRoleEdit = checkButtons(this.$store.state.user.buttons, Edit)
  136. this.isRoleEdit = isRoleEdit
  137. },
  138. getList() {
  139. this.table.listLoading = true
  140. GetDataByName(this.table.getdataListParm).then(response => {
  141. console.log('table数据', response.data.list)
  142. if (response.data.list !== null) {
  143. for (let i = 0; i < response.data.list.length; i++) {
  144. this.$set(response.data.list[i], 'Edit', false) // 编辑
  145. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  146. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  147. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  148. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  149. }
  150. this.table.list = response.data.list
  151. this.table.pageNum = response.data.pageNum
  152. this.table.pageSize = response.data.pageSize
  153. this.table.total = response.data.total
  154. } else {
  155. this.table.list = []
  156. }
  157. setTimeout(() => {
  158. this.table.listLoading = false
  159. }, 100)
  160. })
  161. },
  162. handleEnableChange() {
  163. console.log('点击了是否启用')
  164. },
  165. handleSearch() {
  166. console.log('点击了查询')
  167. this.table.getdataListParm.offset = 1
  168. this.getList()
  169. },
  170. handleRefresh() {
  171. console.log('点击了重置')
  172. this.table.getdataListParm.parammaps.providerName = ''
  173. this.table.getdataListParm.parammaps.providerNumber = ''
  174. this.table.getdataListParm.parammaps.enable = ''
  175. this.table.getdataListParm.offset = 1
  176. this.getList()
  177. },
  178. // 新增
  179. handleCreate() {
  180. // 编辑true/不可编辑false
  181. // 新增操true,编辑false,编辑保存false
  182. console.log(11)
  183. for (let i = 0; i < this.table.list.length; i++) {
  184. if (this.table.list[i].Edit === true) {
  185. console.log(123)
  186. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  187. return false
  188. }
  189. }
  190. 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': '' })
  191. },
  192. createData(row) {
  193. console.log('点击了新增保存', row)
  194. this.table.temp.pastureid = Cookies.get('pastureid')
  195. this.table.temp.providerNumber = row.providerNumber
  196. this.table.temp.providerName = row.providerName
  197. this.table.temp.linkman = row.linkman
  198. this.table.temp.telphone = row.telphone
  199. this.table.temp.remark = row.remark
  200. this.table.temp.enable = row.enable
  201. // 检验供应商名称/供应商编号是否为空
  202. if (this.table.temp.providerName == '' && this.table.temp.providerNumber == '') {
  203. this.$message({ type: 'error', message: '供应商名称/供应商编号不能为空', duration: 2000 })
  204. return false
  205. } else if (this.table.temp.providerNumber == '') {
  206. this.$message({ type: 'error', message: '供应商编号不能为空', duration: 2000 })
  207. return false
  208. } else if (this.table.temp.providerName == '') {
  209. this.$message({ type: 'error', message: '供应商名称不能为空', duration: 2000 })
  210. return false
  211. }
  212. const providerNumber = /(^[\-0-9][0-9]*(.[0-9]+)?)$/
  213. if (!providerNumber.test(parseInt(this.table.temp.providerNumber))) {
  214. console.log(this.table.temp.providerNumber)
  215. this.$message({ type: 'error', message: '供应商编号请输入1-8位数字', duration: 2000 })
  216. return false
  217. }
  218. if (this.table.temp.telphone !== '') {
  219. const telphone = /^\d{11}$/
  220. if (!telphone.test(this.table.temp.telphone)) {
  221. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  222. return false
  223. }
  224. }
  225. this.isokDisable = true
  226. setTimeout(() => {
  227. this.isokDisable = false
  228. }, 1000)
  229. this.requestParam.name = 'insertProvider'
  230. this.requestParam.parammaps = this.table.temp
  231. PostDataByName(this.requestParam).then(response => {
  232. console.log('新增保存发送参数', this.requestParam)
  233. if (response.msg !== 'fail') {
  234. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  235. this.getList()
  236. } else {
  237. failproccess(response, this.$notify)
  238. }
  239. })
  240. },
  241. createCancel(row) {
  242. console.log('点击了新增取消')
  243. for (let i = 0; i < this.table.list.length; i++) {
  244. if (row.myId === this.table.list[i].myId) {
  245. var listIndex = this.table.list.indexOf(this.table.list[i])
  246. }
  247. if (listIndex > -1) {
  248. this.table.list.splice(listIndex, 1)
  249. return
  250. }
  251. }
  252. },
  253. // 编辑
  254. handleUpdate(row) {
  255. for (let i = 0; i < this.table.list.length; i++) {
  256. if (this.table.list[i].Edit == true) {
  257. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  258. return false
  259. }
  260. }
  261. // 编辑true,不可编辑false
  262. row.Edit = true
  263. row.NoEdit = false
  264. // 新增false,编辑false,编辑保存true
  265. row.isCreate = false
  266. row.isUpdate = false
  267. row.isUpdateSave = true
  268. },
  269. updateData(row) {
  270. console.log('点击了编辑保存', row)
  271. this.table.temp.pastureid = Cookies.get('pastureid')
  272. this.table.temp.providerNumber = row.providerNumber
  273. this.table.temp.providerName = row.providerName
  274. this.table.temp.linkman = row.linkman
  275. this.table.temp.telphone = row.telphone
  276. this.table.temp.remark = row.remark
  277. this.table.temp.enable = row.enable
  278. this.table.temp.id = row.id
  279. // 检验供应商名称/供应商编号是否为空
  280. if (this.table.temp.providerName == '' && this.table.temp.providerNumber == '') {
  281. this.$message({ type: 'error', message: '供应商名称/供应商编号不能为空', duration: 2000 })
  282. return false
  283. } else if (this.table.temp.providerNumber == '') {
  284. this.$message({ type: 'error', message: '供应商编号不能为空', duration: 2000 })
  285. return false
  286. } else if (this.table.temp.providerName == '') {
  287. this.$message({ type: 'error', message: '供应商名称不能为空', duration: 2000 })
  288. return false
  289. }
  290. const providerNumber = /(^[\-0-9][0-9]*(.[0-9]+)?)$/
  291. if (!providerNumber.test(parseInt(this.table.temp.providerNumber))) {
  292. console.log(this.table.temp.providerNumber)
  293. this.$message({ type: 'error', message: '供应商编号请输入1-8位数字', duration: 2000 })
  294. return false
  295. }
  296. if (this.table.temp.telphone !== '') {
  297. const telphone = /^\d{11}$/
  298. if (!telphone.test(this.table.temp.telphone)) {
  299. this.$message({ type: 'error', message: '请输入11位手机号', duration: 2000 })
  300. return false
  301. }
  302. }
  303. this.isokDisable = true
  304. setTimeout(() => {
  305. this.isokDisable = false
  306. }, 1000)
  307. this.requestParam.name = 'updateProvider'
  308. this.requestParam.parammaps = this.table.temp
  309. PostDataByName(this.requestParam).then(response => {
  310. console.log('编辑保存发送参数', this.requestParam)
  311. if (response.msg !== 'fail') {
  312. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  313. this.getList()
  314. } else {
  315. failproccess(response, this.$notify)
  316. }
  317. })
  318. },
  319. updateCancel(row) {
  320. console.log('点击了编辑取消')
  321. // 编辑false,不可编辑true
  322. row.Edit = false
  323. row.NoEdit = true
  324. // 新增false,编辑true,编辑保存false
  325. row.isCreate = false
  326. row.isUpdate = true
  327. row.isUpdateSave = false
  328. },
  329. // 删除
  330. handleRowDelete(row) {
  331. console.log('点击了行内删除')
  332. MessageBox.confirm('是否确认删除此信息?', {
  333. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  334. }).then(() => {
  335. this.requestParam.name = 'deleteProvider'
  336. this.requestParam.parammaps = {}
  337. this.requestParam.parammaps.pastureid = row.pastureid
  338. this.requestParam.parammaps.id = row.id
  339. PostDataByName(this.requestParam).then(response => {
  340. if (response.msg === 'fail') {
  341. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  342. } else {
  343. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  344. this.getList()
  345. }
  346. })
  347. }).catch(() => {
  348. this.$message({ type: 'info', message: '已取消删除' })
  349. })
  350. },
  351. handleSelectionChange(val) {
  352. console.log('勾选数据', val)
  353. this.selectList = val
  354. },
  355. handleDelete() {
  356. console.log('点击了删除')
  357. if (this.selectList.length == 0) {
  358. this.$message({ type: 'error', message: '请选择供应商信息', duration: 2000 })
  359. } else {
  360. MessageBox.confirm('是否确认删除此信息?', {
  361. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  362. }).then(() => {
  363. console.log(this.selectList)
  364. this.requestParam.common = { 'returnmap': '0' }
  365. this.requestParam.data = []
  366. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  367. this.requestParam.data[0].children = []
  368. this.requestParam.data[0].children[0] = { 'name': 'deleteProvider', 'type': 'e', 'parammaps': {
  369. id: '@insertSpotList.id',
  370. pastureid: '@insertSpotList.pastureid'
  371. }}
  372. ExecDataByConfig(this.requestParam).then(response => {
  373. console.log('删除保存发送参数', this.requestParam)
  374. if (response.msg === 'fail') {
  375. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  376. } else {
  377. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  378. this.getList()
  379. }
  380. })
  381. })
  382. }
  383. }
  384. }
  385. }
  386. </script>
  387. <style lang="scss" scoped>
  388. .search{margin-top:10px;}
  389. .table{margin-top:10px;}
  390. </style>