contract.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div id="contract">
  3. <el-row>
  4. <el-col :span="24" class="container">
  5. <el-col :span="24" class="top">
  6. <el-button type="primary" size="mini" @click="dialog = true">添加</el-button>
  7. </el-col>
  8. <el-col :span="24" class="info">
  9. <!-- :select="true"在前面加上复选框 @handleSelect="toSelect"给复选框添加点击事件,如果想要点击事件好用的话列表必须给一个id要不然点击区分不了是不是同一个数据-->
  10. <data-table
  11. :fields="fields"
  12. :data="list"
  13. :opera="opera"
  14. :total="total"
  15. :size="50"
  16. :step="10"
  17. :select="true"
  18. @editor="editor"
  19. @delete="toDelete"
  20. @see="see"
  21. @query="searchTreaty"
  22. @handleSelect="toSelect"
  23. :toFormat="roleSelect"
  24. >
  25. <template #options="{item}">
  26. <template v-if="item.model == 'client'">
  27. <el-option v-for="(item, index) in nameList" :key="index" :value="item.id" :label="item.name"></el-option>
  28. </template>
  29. </template>
  30. <template #filterEnd>
  31. <el-button v-if="selected.length <= 0" type="primary" :disabled="true">未选择任何合同</el-button>
  32. <el-button v-else type="primary" @click="toExport">导出选中合同</el-button>
  33. </template>
  34. </data-table>
  35. </el-col>
  36. </el-col>
  37. </el-row>
  38. <el-dialog :visible.sync="dialog" title="客户合同详情" @close="toClose" width="50%">
  39. <!-- 物流里面的:data要换成v-model -->
  40. <data-form v-model="form" :fields="fields" @save="turnSave" :rules="rules">
  41. <template #options="{item}">
  42. <template v-if="item.model == 'client'">
  43. <el-option v-for="(item, index) in nameList" :key="index" :value="item.id" :label="item.name"></el-option>
  44. </template>
  45. <template v-if="item.model == 'status'">
  46. <el-option v-for="(item, index) in item.list" :key="index" :value="item.value" :label="item.label"></el-option>
  47. </template>
  48. </template>
  49. </data-form>
  50. </el-dialog>
  51. </div>
  52. </template>
  53. <script>
  54. import { mapState, createNamespacedHelpers } from 'vuex';
  55. const { mapActions: treaty } = createNamespacedHelpers('treaty');
  56. const { mapActions: client } = createNamespacedHelpers('client');
  57. export default {
  58. metaInfo() {
  59. return { title: this.$route.meta.title };
  60. },
  61. name: 'contract',
  62. props: {},
  63. components: {},
  64. data: function() {
  65. return {
  66. fields: [
  67. { label: '客户', model: 'client', filter: 'select', type: 'select', format: true },
  68. { label: '合同编号', model: 'number', filter: 'input' },
  69. { label: '甲方', model: 'jf' },
  70. { label: '乙方', model: 'yf' },
  71. { label: '合同周期', model: 'period' },
  72. { label: '结算方式', model: 'settle_up' },
  73. { label: '结算周期', model: 'settle_up_period' },
  74. {
  75. label: '状态',
  76. model: 'status',
  77. filter: 'select',
  78. type: 'select',
  79. formact: i => (i === '0' ? '使用' : '禁用'),
  80. list: [
  81. { label: '使用', value: '0' },
  82. { label: '禁用', value: '1' },
  83. ],
  84. },
  85. { label: '创始人', model: 'owner', notable: true, noform: true },
  86. ],
  87. list: [],
  88. total: 0,
  89. opera: [
  90. { label: '编辑', method: 'editor' },
  91. { label: '查看项目', method: 'see' },
  92. { label: '删除', method: 'delete' },
  93. ],
  94. dialog: false,
  95. form: {},
  96. rules: {
  97. client: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  98. number: [{ required: true, message: '请输入合同编号', trigger: 'blur' }],
  99. jf: [{ required: true, message: '请输入甲方名称', trigger: 'blur' }],
  100. yf: [{ required: true, message: '请输入乙方名称', trigger: 'blur' }],
  101. period: [{ required: true, message: '请输入合同周期', trigger: 'blur' }],
  102. settle_up: [{ required: true, message: '请输入结算方式', trigger: 'blur' }],
  103. settle_up_period: [{ required: true, message: '请输入结算周期', trigger: 'blur' }],
  104. status: [{ required: true, message: '请选择状态', trigger: 'blur' }],
  105. },
  106. //客户列表
  107. nameList: [],
  108. selected: [],
  109. };
  110. },
  111. created() {
  112. this.search();
  113. },
  114. methods: {
  115. ...treaty(['query', 'create', 'update', 'delete']),
  116. ...client({ cQuery: 'query', cCreate: 'create', cUpdate: 'update', cDelete: 'delete' }),
  117. async search() {
  118. //查客户
  119. const res = await this.cQuery({ type: '客户' });
  120. if (this.$checkRes(res)) {
  121. this.$set(this, `nameList`, res.data);
  122. }
  123. },
  124. // 查合同 其他参数是...info,都包括在里面,可以输出看看
  125. async searchTreaty({ skip = 0, limit = 10, ...info } = {}) {
  126. const res = await this.query({ skip, limit, ...info });
  127. if (this.$checkRes(res)) {
  128. const { data, total } = res;
  129. this.$set(this, `list`, data);
  130. this.$set(this, `total`, total);
  131. }
  132. },
  133. //关闭
  134. toClose() {
  135. this.form = {};
  136. this.dialog = false;
  137. },
  138. //保存
  139. async turnSave({ data }) {
  140. let client = data.client;
  141. if (data.id) {
  142. const res = await this.update(data);
  143. if (this.$checkRes(res, '修改成功', res.errmsg || '修改失败')) {
  144. this.searchTreaty({ client });
  145. this.toClose();
  146. }
  147. } else {
  148. //谁登陆owner就是谁,把id赋予上面就行
  149. data.owner = this.user.id;
  150. const res = await this.create(data);
  151. if (this.$checkRes(res, '创建成功', res.errmsg || '创建失败')) {
  152. this.searchTreaty({ client });
  153. this.toClose();
  154. }
  155. }
  156. },
  157. //编辑
  158. editor({ data }) {
  159. this.$set(this, `form`, data);
  160. this.dialog = true;
  161. },
  162. //刪除
  163. async toDelete({ data }) {
  164. let client = data.client;
  165. const res = await this.delete(data.id);
  166. if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) {
  167. this.searchTreaty({ client });
  168. }
  169. },
  170. //查看項目
  171. see() {
  172. this.$router.push({ path: '/client/project' });
  173. },
  174. toSelect(data) {
  175. this.selected = data;
  176. },
  177. toExport() {
  178. console.log('导出');
  179. },
  180. roleSelect({ model, value }) {
  181. if (model == 'client') {
  182. let arr = this.nameList.find(i => i.id === value);
  183. if (arr) return arr.name;
  184. }
  185. },
  186. },
  187. computed: {
  188. ...mapState(['user']),
  189. },
  190. };
  191. </script>
  192. <style lang="less" scoped>
  193. .container {
  194. .top {
  195. text-align: right;
  196. margin: 15px 0;
  197. }
  198. }
  199. </style>