procedureRatio.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <div>
  3. <Toptitle title="工序占比设置">
  4. <slot name="titleButton">
  5. <!-- <Button @click="back"
  6. type='primary'
  7. ghost
  8. style="margin-right:10px;">返回</Button> -->
  9. <Button type="primary"
  10. style="margin-right:10px;"
  11. @click="handleRowClick({},null,1)"
  12. ghost>新增</Button>
  13. </slot>
  14. </Toptitle>
  15. <div style="height:80%;overflow:auto">
  16. <div style="padding-top:20px">
  17. <Form inline :label-width='80'>
  18. <FormItem label="方案名称:">
  19. <Input style="width:150px"
  20. clearable
  21. v-model="search_title"
  22. size="small"
  23. placeholder="请输入方案名称" />
  24. </FormItem>
  25. <FormItem label="启用状态:">
  26. <Select v-model="search_state" style="width:150px" clearable>
  27. <Option value="0">
  28. 未启用
  29. </Option>
  30. <Option value="1">
  31. 已启用
  32. </Option>
  33. </Select>
  34. </FormItem>
  35. <FormItem>
  36. <Button type="primary"
  37. size="small"
  38. @click="init">搜索</Button>
  39. </FormItem>
  40. </Form>
  41. </div>
  42. <div style="padding:20px 0px">
  43. <Table border
  44. ref="refTableData"
  45. draggable
  46. :columns="columns"
  47. :data="tableData"
  48. @on-drag-drop="onDragDrop">
  49. <template slot="op"
  50. slot-scope="{row,index}">
  51. <a @click="startUse(row)" v-show="row.state==0"
  52. style="margin-right:10px">启用</a>
  53. <a @click="handleRowClick(row,index,4)"
  54. style="margin-right:10px">编辑</a>
  55. <a @click="handleRowClick(row,index,2)"
  56. style="margin-right:10px">查看</a>
  57. <a @click="handleRowClick(row,index,3)" :disabled="row.state ==1">删除</a>
  58. </template>
  59. </Table>
  60. </div>
  61. </div>
  62. <div style="text-align:center">
  63. <Page :page-size-opts="[10, 20, 30, 40,100]"
  64. @on-page-size-change='changeSize'
  65. @on-change='changePage'
  66. :current='pageIndex'
  67. show-total
  68. :total="total"
  69. show-sizer
  70. :page-size='pageSize' />
  71. </div>
  72. <Modal class="modal"
  73. :title='modal_title'
  74. v-model='showModal'
  75. :mask-closable="false"
  76. :width="400">
  77. <div><span style="width:100px">方案名称:</span><Input style="width:80%" v-model="scheme_title"/></div>
  78. <span >占比设置:</span>
  79. <Table :data='modalData' :columns="modalColumns" border
  80. :max-height='400' >
  81. </Table>
  82. <span style="margin-top:10px;display:inline-block">合计占比:<span>{{total_scale}}</span></span>
  83. <div class="modal-footer"
  84. slot="footer">
  85. <Button @click="showModal = false">取消</Button>
  86. <Button type="primary"
  87. v-if="modal_title !=='查看' "
  88. @click="handleColorConfirm">确认</Button>
  89. </div>
  90. </Modal>
  91. </div>
  92. </template>
  93. <script>
  94. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  95. // 例如:import 《组件名称》 from '《组件路径》';
  96. export default {
  97. components: {
  98. },
  99. props: {},
  100. // import引入的组件需要注入到对象中才能使用
  101. data () {
  102. // 这里存放数据
  103. return {
  104. search_state:'',
  105. id:'',
  106. scheme_title:'',
  107. modalData:[],
  108. modalColumns:[
  109. {title:'ID',align:'center',type:'index',width:'60'},
  110. {title:'工序',align:'center',key:'title'},
  111. {title:'占比(%)',align:'center',key:'scale',render:(h,params)=>{
  112. const {row,index} = params;
  113. return h('Input',{props:{value:row.scale,disabled:this.modal_title == '查看'?true:false,type:'number'},on:{'on-change':(e)=>{
  114. this.modalData[index].scale = e.target.value;
  115. let total_scale = 0;
  116. this.modalData.forEach(v=>{
  117. total_scale+=v.scale*1
  118. })
  119. this.total_scale = total_scale
  120. }}},row.scale)
  121. }}
  122. ],
  123. pageSize:10,
  124. pageIndex: 1,
  125. total: 0,
  126. total_scale:0,
  127. process_list:[],
  128. band_list:[],
  129. user_list:[],
  130. search_title:'',
  131. modal_title:'',
  132. title: '工序班组权限表',
  133. columns: [
  134. { title:'ID', type:'index', align: 'center' },
  135. { title: '方案名称', key: 'title', align: 'center', },
  136. {title:'启用状态',key:'state',align:'center',render:(h,params)=>{
  137. const {row} = params;
  138. return h('span',{},row.state == 0?'未启用':'已启用')
  139. }},
  140. { title: '操作', key: 'operation', align: 'center', slot: 'op' }
  141. ],
  142. tableData: [],
  143. maxSort: 0,
  144. showModal: false,
  145. //1新增2编辑
  146. addState: 0,
  147. currencyRow: {
  148. id:'',
  149. produce_ids :[],
  150. employee_ids:[]
  151. },
  152. currencyIndex: 0
  153. }
  154. },
  155. // 生命周期 - 创建完成(可以访问当前this实例)
  156. created () {
  157. // this.initData()
  158. //用户列表
  159. // this.axios.get('/api/user').then(res=>{this.user_list = res.data.data});
  160. //工序列表
  161. this.axios.post('/api/ext_produce_list').then(res=>{this.process_list = res.data});
  162. // //班组列表
  163. // this.axios("/api/employee_list").then((res) => (this.band_list = res.data));
  164. },
  165. // 生命周期 - 挂载完成(可以访问DOM元素)
  166. mounted () {
  167. this.init()
  168. },
  169. methods: {
  170. startUse(row){
  171. this.axios.post('/api/ext_produce_scale_switch',{id:row.id}).then(res=>{
  172. if(res.code==200){
  173. this.$Message.success(res.msg);
  174. this.init();
  175. }
  176. })
  177. },
  178. changeSize (e) {
  179. this.pageSize = e;
  180. this.init()
  181. },
  182. changePage (index) {
  183. this.pageIndex = index;
  184. this.init()
  185. },
  186. init () {
  187. // this.$forceUpdate();
  188. this.axios.post('/api/ext_produce_scale_list',
  189. {
  190. title: this.search_title,
  191. page_size:this.pageSize,
  192. page_index:this.pageIndex,
  193. state:this.search_state,
  194. }
  195. ).then(res => {
  196. if (res.code == 200) {
  197. this.tableData = res.data.data;
  198. this.total = res.data.total;
  199. }
  200. }).catch(err => { })
  201. },
  202. back () {
  203. this.$router.go(-1)
  204. },
  205. handleRowClick (row, index, type) {
  206. //1新增 2查看 3删除 4编辑
  207. this.currencyIndex = index
  208. this.addState = type
  209. this.id = row.id||'';
  210. switch (type) {
  211. case 1:
  212. this.modal_title = '新增';
  213. this.scheme_title = '';
  214. this.modalData = [];
  215. this.total_scale = 0;
  216. this.process_list.forEach(v=>{
  217. let obj = {};
  218. obj.title = v.title;
  219. obj.scale = '';
  220. this.modalData.push(obj)
  221. })
  222. this.showModal = true;
  223. break;
  224. case 2:
  225. this.total_scale = 0;
  226. this.modal_title ='查看';
  227. this.modalData = row.json;
  228. this.scheme_title = row.title;
  229. this.modalData.forEach(v=>{
  230. this.total_scale+=v.scale*1
  231. })
  232. this.showModal = true;
  233. break;
  234. case 3:
  235. this.$Modal.confirm({
  236. title: '确认删除?',
  237. content: '此操作确认后无法恢复,请确认此操作!',
  238. onOk: () => {
  239. this.axios({
  240. method: 'post',
  241. url: '/api/ext_user_permission_del',
  242. data: {
  243. id: row.id
  244. }
  245. }).then((res) => {
  246. this.$Message.success(res.msg)
  247. this.init()
  248. }).catch((err) => { });
  249. },
  250. onCancel: () => { }
  251. })
  252. break;
  253. case 4:
  254. this.total_scale = 0;
  255. this.modal_title = '编辑';
  256. this.scheme_title = row.title;
  257. let data = JSON.parse(JSON.stringify(this.process_list));
  258. let title = [];
  259. data.forEach(v=>{
  260. v.scale = 0;
  261. title.push(v.title)
  262. })
  263. row.json.forEach(v=>{
  264. if(title.indexOf(v.title)>=0){
  265. data.forEach(m=>{
  266. if(m.title == v.title ){
  267. m.scale = v.scale;
  268. }
  269. })
  270. }
  271. })
  272. this.modalData = data;
  273. this.modalData.forEach(v=>{
  274. this.total_scale+=v.scale*1
  275. })
  276. console.log(this.modalData);
  277. console.log(row.json)
  278. this.showModal = true;
  279. }
  280. },
  281. handleColorChange (row, index, type) {
  282. this.addState = type
  283. this.showModal = true
  284. },
  285. handleColorConfirm () {
  286. if(this.total_scale!=100){
  287. return this.$Message.warning('合计占比必须是100%!')
  288. }
  289. console.log(this.modalData)
  290. let data = [];
  291. this.modalData.forEach(v=>{
  292. if(v.scale){
  293. data.push(v)
  294. }
  295. })
  296. this.axios({
  297. method: 'post',
  298. url: '/api/ext_produce_scale_edit',
  299. data: {
  300. title:this.scheme_title,
  301. json:{...data},
  302. id:this.id
  303. }
  304. }).then((res) => {
  305. if(res.code == 200){
  306. this.$Message.success(res.msg)
  307. this.showModal = false
  308. this.init()}
  309. }).catch((err) => { });
  310. },
  311. onDragDrop (a, b) {
  312. this.tableData.splice(b, 0, ...this.tableData.splice(a, 1))
  313. }
  314. },
  315. // 监听属性 类似于data概念
  316. computed: {
  317. },
  318. // 监控data中的数据变化
  319. watch: {},
  320. beforeCreate () { }, // 生命周期 - 创建之前
  321. beforeMount () { }, // 生命周期 - 挂载之前
  322. beforeUpdate () { }, // 生命周期 - 更新之前
  323. updated () { }, // 生命周期 - 更新之后
  324. beforeDestroy () { }, // 生命周期 - 销毁之前
  325. destroyed () { }, // 生命周期 - 销毁完成
  326. activated () { }, // 如果页面有keep-alive缓存功能,这个函数会触发
  327. }
  328. </script>
  329. <style lang='scss' scoped>
  330. .modal {
  331. div {
  332. display: flex;
  333. justify-content: center;
  334. align-items: center;
  335. padding: 10px 0;
  336. }
  337. }
  338. /deep/.select_band .ivu-select-selection{
  339. width: 500px;
  340. }
  341. </style>