VerifyContract.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <script setup lang="ts">
  2. import { GlobalStore } from '@/stores/index'
  3. import { ref, reactive, nextTick } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import Drawer from '@/components/Drawer/index.vue'
  6. import { ElMessage } from 'element-plus'
  7. import TableBase from '@/components/TableBase/index.vue'
  8. import { Edit, View } from '@element-plus/icons-vue'
  9. import type { ColumnProps } from '@/components/TableBase/interface/index'
  10. import type { FormInstance, FormRules } from 'element-plus'
  11. import {
  12. Storehouse_VerifyContract_Add_Customer,
  13. Storehouse_VerifyContract_Customer_List,
  14. Storehouse_VerifyContract_Update_Customer
  15. } from '@/api/storehouse/index'
  16. const isNew = ref(true)
  17. const router = useRouter()
  18. const globalStore = GlobalStore()
  19. const ruleFormRef = ref<FormInstance>()
  20. const drawerRef = ref<InstanceType<typeof Drawer> | null>(null)
  21. const TableRef = ref<InstanceType<typeof TableBase> | null>(null)
  22. const columns: ColumnProps[] = [
  23. { type: 'index', label: '序号', width: 80 },
  24. { prop: 'T_customer', label: '客户名称' },
  25. { prop: 'T_start_date', label: '起始时间' },
  26. { prop: 'T_end_date', label: '终止时间' },
  27. { prop: 'T_State', label: '状态', name: 'T_State' },
  28. { prop: 'T_sign_times', label: '签约次数' },
  29. { prop: 'operation', label: '操作', width: 260, fixed: 'right' }
  30. ]
  31. const options = reactive([
  32. { name: '已签约', id: 3 },
  33. { name: '已作废', id: 2 },
  34. { name: '未签约', id: 1 },
  35. { name: '即将到期', id: 4 }
  36. ])
  37. const initParam = reactive({
  38. User_tokey: globalStore.GET_User_tokey,
  39. T_name: '',
  40. T_state: ''
  41. })
  42. const openContract = (type: string, row?: any) => {
  43. isNew.value = type === 'new' ? true : false
  44. if (type === 'edit') {
  45. form.value = { ...row }
  46. }
  47. drawerRef.value?.openDrawer()
  48. }
  49. const updateOnTableList = () => TableRef.value?.getTableList()
  50. const processContract = (id: string) => router.push({ name: 'VerifyContractDetail', params: { id } })
  51. const searchHandle = () => TableRef.value?.searchTable()
  52. const callbackDrawer = (done: () => void) => {
  53. resetForm(ruleFormRef.value)
  54. done()
  55. }
  56. const form = ref({
  57. T_customer: '',
  58. T_customer_id: ''
  59. })
  60. const rules = reactive<FormRules>({
  61. T_customer: [{ required: true, message: '请输入客户名称', trigger: 'blur' }]
  62. })
  63. const AddContract = (formEl: FormInstance | undefined) => {
  64. if (!formEl) return
  65. formEl.validate(async valid => {
  66. if (valid) {
  67. let res: any = {}
  68. if (isNew.value) {
  69. res = await Storehouse_VerifyContract_Add_Customer({ User_tokey: globalStore.GET_User_tokey, ...form.value })
  70. } else {
  71. res = await Storehouse_VerifyContract_Update_Customer({ User_tokey: globalStore.GET_User_tokey, ...form.value })
  72. }
  73. if (res.Code === 200) {
  74. ElMessage.success('添加客户成功!!')
  75. nextTick(() => {
  76. updateOnTableList()
  77. isNew.value = true
  78. resetForm(ruleFormRef.value)
  79. drawerRef.value?.closeDrawer()
  80. })
  81. }
  82. } else {
  83. return false
  84. }
  85. })
  86. }
  87. const resetForm = (formEl: FormInstance | undefined) => {
  88. if (!formEl) return
  89. formEl.resetFields()
  90. }
  91. </script>
  92. <template>
  93. <div class="verify-contract">
  94. <TableBase
  95. ref="TableRef"
  96. :columns="columns"
  97. :requestApi="Storehouse_VerifyContract_Customer_List"
  98. :initParam="initParam"
  99. >
  100. <template #table-header>
  101. <el-row :gutter="20" style="margin-bottom: 0" class="input-suffix">
  102. <el-col :xl="6" :lg="8" :md="8" class="d-flex">
  103. <span class="inline-flex items-center">客户名称:</span>
  104. <el-input
  105. v-model="initParam.T_name"
  106. type="text"
  107. class="w-50 m-2"
  108. placeholder="按产品名称搜索"
  109. @change="searchHandle"
  110. />
  111. </el-col>
  112. <el-col :xl="6" :md="8" class="d-flex">
  113. <span class="inline-flex items-center">状态:</span>
  114. <el-select v-model="initParam.T_state" class="w-50" clearable placeholder="请选择状态~">
  115. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id" />
  116. </el-select>
  117. <el-button type="primary" @click="searchHandle">搜索</el-button>
  118. </el-col>
  119. <el-col :xl="6" :md="2" :offset="4" class="btn"
  120. ><el-button type="primary" @click="openContract('new')">添加</el-button></el-col
  121. >
  122. </el-row>
  123. </template>
  124. <template #T_State="{ row }">
  125. <el-tag v-if="row.T_State === 1" type="warning" effect="dark"> 未签约 </el-tag>
  126. <el-tag v-else-if="row.T_State === 2" type="info" effect="dark"> 已作废 </el-tag>
  127. <el-tag v-else-if="row.T_State === 3" type="danger" effect="dark"> 已签约 </el-tag>
  128. <el-tag v-else type="danger" effect="dark"> 即将到期 </el-tag>
  129. </template>
  130. <template #right="{ row }">
  131. <el-button link type="primary" size="small" :icon="Edit" @click="openContract('edit', row)">编辑</el-button>
  132. <el-button link type="success" size="small" :icon="View" @click="processContract(row.T_customer_id)"
  133. >明细</el-button
  134. >
  135. </template>
  136. </TableBase>
  137. <Drawer ref="drawerRef" :handleClose="callbackDrawer">
  138. <template #header="{ params }">
  139. <h4 :id="params.titleId" :class="params.titleClass">{{ isNew ? '添加' : '编辑' }} - 客户名称</h4>
  140. </template>
  141. <el-form ref="ruleFormRef" :model="form" :rules="rules">
  142. <el-form-item label="客户名称:" label-width="100px" prop="T_customer">
  143. <el-input v-model="form.T_customer" type="text" autocomplete="off" placeholder="请输入仓库名称" />
  144. </el-form-item>
  145. <el-form-item label-width="100px">
  146. <el-button v-if="isNew" color="#626aef" @click="AddContract(ruleFormRef)">提交</el-button>
  147. <el-button v-else color="#626aef" @click="AddContract(ruleFormRef)">修改</el-button>
  148. </el-form-item>
  149. </el-form>
  150. </Drawer>
  151. </div>
  152. </template>
  153. <style scoped lang="scss">
  154. @import '@/styles/var.scss';
  155. .verify-contract {
  156. @include f-direction;
  157. :deep(.el-drawer__header) {
  158. margin-bottom: 0;
  159. }
  160. .input-suffix {
  161. width: 100%;
  162. .inline-flex {
  163. white-space: nowrap;
  164. }
  165. .btn {
  166. display: flex;
  167. justify-content: end;
  168. }
  169. .w-50 {
  170. flex: 0 0 50%;
  171. }
  172. }
  173. }
  174. </style>