commissionFormList.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view class="commission-form-list">
  3. <!-- 头部按钮组 -->
  4. <view class="commission-header">
  5. <u-button type="primary" size="mini" icon="plus" @click="handleAdd">新增分成</u-button>
  6. </view>
  7. <!-- 分成信息卡片列表 -->
  8. <view v-if="loading" class="loading_wrap">
  9. <u-loading-icon text="加载中" textSize="18"></u-loading-icon>
  10. </view>
  11. <view v-else-if="commissionList.length === 0" class="empty_wrap">
  12. <u-empty text="暂无分成数据"></u-empty>
  13. </view>
  14. <view v-else class="card_list">
  15. <view class="card_item" v-for="(row, index) in commissionList" :key="row.id">
  16. <view class="card_header">
  17. <view class="card_title">{{ row.userName || '-' }}</view>
  18. <view class="card_actions">
  19. <u-button size="mini" type="text" @click="handleEdit(row)">编辑</u-button>
  20. <u-button size="mini" type="text" @click="handleDelete(row.id)" style="color: #f56c6c">删除</u-button>
  21. </view>
  22. </view>
  23. <view class="card_body">
  24. <view class="info_row">
  25. <view class="info_label">公司:</view>
  26. <view class="info_value">{{ row.orgName || '-' }}</view>
  27. </view>
  28. <view class="info_row">
  29. <view class="info_label">账户类型:</view>
  30. <view class="info_value">{{ row.accountType === '1' ? '前端' : '后端' }}</view>
  31. </view>
  32. <view class="info_row">
  33. <view class="info_label">分成比例:</view>
  34. <view class="info_value highlight">{{ row.commissionRate || '0' }}%</view>
  35. </view>
  36. <view class="info_row">
  37. <view class="info_label">创建时间:</view>
  38. <view class="info_value">{{ formatTime(row.createTime) }}</view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 分页组件 -->
  44. <u-pagination
  45. v-if="total > 0"
  46. :total="total"
  47. :current="queryParams.pageNum"
  48. :page-size="queryParams.pageSize"
  49. @change="handlePageChange"
  50. :page-sizes="[10, 20, 50, 100]"
  51. :show-total="true"
  52. ></u-pagination>
  53. <!-- 新增/编辑对话框 -->
  54. <u-popup v-model="dialogVisible" mode="center" width="500rpx" border-radius="16">
  55. <view class="dialog_header">{{ dialogTitle }}</view>
  56. <view class="dialog_body">
  57. <u-form :model="commissionForm" ref="commissionFormRef" label-width="120rpx">
  58. <u-form-item label="账户类型" prop="accountType" :required="true">
  59. <u-radio-group v-model="commissionForm.accountType" :disabled="!isEdit">
  60. <u-radio name="1" label="前端"></u-radio>
  61. <u-radio name="2" label="后端"></u-radio>
  62. </u-radio-group>
  63. </u-form-item>
  64. <u-form-item label="分成人" prop="userName" :required="true">
  65. <u-input v-model="commissionForm.userName" placeholder="请选择分成人" :disabled="!isEdit" />
  66. </u-form-item>
  67. <u-form-item label="分成比例(%)" prop="commissionRate" :required="true">
  68. <u-input v-model.number="commissionForm.commissionRate" type="number" placeholder="请输入分成比例(0-100)" />
  69. </u-form-item>
  70. </u-form>
  71. </view>
  72. <view class="dialog_footer">
  73. <u-button @click="handleClose">取消</u-button>
  74. <u-button type="primary" @click="handleSubmit">确定</u-button>
  75. </view>
  76. </u-popup>
  77. </view>
  78. </template>
  79. <script>
  80. export default {
  81. name: 'CommissionFormList',
  82. props: {
  83. sendFormId: {
  84. type: [Number, String],
  85. required: true
  86. },
  87. clueId: {
  88. type: [Number, String],
  89. required: true
  90. }
  91. },
  92. data() {
  93. return {
  94. commissionList: [],
  95. total: 0,
  96. loading: false,
  97. queryParams: {
  98. pageNum: 1,
  99. pageSize: 10
  100. },
  101. dialogVisible: false,
  102. dialogTitle: '新增分成',
  103. isEdit: true,
  104. commissionForm: {
  105. id: null,
  106. sendFormId: null,
  107. clueId: null,
  108. accountType: '1',
  109. userName: null,
  110. userId: null,
  111. commissionRate: 0
  112. },
  113. rules: {
  114. accountType: [{ required: true, message: '请选择账户类型', trigger: 'change' }],
  115. userName: [{ required: true, message: '请选择分成人', trigger: 'blur' }],
  116. commissionRate: [
  117. { required: true, message: '请输入分成比例', trigger: 'blur' },
  118. { type: 'number', min: 0, max: 100, message: '分成比例必须在0-100之间', trigger: 'blur' }
  119. ]
  120. }
  121. }
  122. },
  123. methods: {
  124. async getList() {
  125. this.loading = true
  126. try {
  127. const params = {
  128. ...this.queryParams,
  129. sendFormId: this.sendFormId,
  130. }
  131. const res = await uni.$u.api.clueCommissionForm.list(params)
  132. this.commissionList = res.rows || []
  133. this.total = res.total || 0
  134. } catch (error) {
  135. uni.$u.toast('获取分成列表失败')
  136. } finally {
  137. this.loading = false
  138. }
  139. },
  140. // 格式化时间
  141. formatTime(time) {
  142. if (!time) return '-'
  143. const date = new Date(time)
  144. const year = date.getFullYear()
  145. const month = String(date.getMonth() + 1).padStart(2, '0')
  146. const day = String(date.getDate()).padStart(2, '0')
  147. const hours = String(date.getHours()).padStart(2, '0')
  148. const minutes = String(date.getMinutes()).padStart(2, '0')
  149. const seconds = String(date.getSeconds()).padStart(2, '0')
  150. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  151. },
  152. handleAdd() {
  153. this.dialogTitle = '新增分成'
  154. this.commissionForm = {
  155. id: null,
  156. sendFormId: this.sendFormId,
  157. clueId: this.clueId,
  158. accountType: '1',
  159. userName: null,
  160. userId: null,
  161. commissionRate: 0
  162. }
  163. this.$nextTick(() => {
  164. if (this.$refs.commissionFormRef) {
  165. this.$refs.commissionFormRef.clearValidate()
  166. }
  167. })
  168. this.dialogVisible = true
  169. },
  170. handleEdit(row) {
  171. this.dialogTitle = '编辑分成'
  172. // 深拷贝对象,避免直接修改原数据
  173. this.commissionForm = JSON.parse(JSON.stringify(row))
  174. this.dialogVisible = true
  175. },
  176. handleDelete(id) {
  177. uni.showModal({
  178. title: '警告',
  179. content: '确定要删除这条分成记录吗?删除后将无法恢复!',
  180. confirmButtonText: '确定删除',
  181. cancelButtonText: '取消',
  182. success: (res) => {
  183. if (res.confirm) {
  184. this.deleteRow(id)
  185. }
  186. }
  187. })
  188. },
  189. async deleteRow(id) {
  190. try {
  191. await uni.$u.api.clueCommissionForm.remove([id])
  192. uni.$u.toast('删除成功')
  193. this.getList()
  194. } catch (error) {
  195. uni.$u.toast('删除失败,请稍后重试')
  196. }
  197. },
  198. handleSubmit() {
  199. this.$refs.commissionFormRef.validate(async (valid) => {
  200. if (valid) {
  201. // 显示加载状态
  202. const loading = uni.showLoading({
  203. title: this.commissionForm.id ? '编辑中...' : '新增中...',
  204. mask: true
  205. })
  206. try {
  207. if (this.commissionForm.id) {
  208. await uni.$u.api.clueCommissionForm.update(this.commissionForm)
  209. uni.$u.toast('编辑成功')
  210. } else {
  211. await uni.$u.api.clueCommissionForm.add(this.commissionForm)
  212. uni.$u.toast('新增成功')
  213. }
  214. this.dialogVisible = false
  215. this.getList()
  216. } catch (error) {
  217. uni.$u.toast('操作失败,请重试')
  218. } finally {
  219. uni.hideLoading(loading)
  220. }
  221. }
  222. })
  223. },
  224. handleClose() {
  225. this.dialogVisible = false
  226. // 关闭对话框后重置表单
  227. this.$nextTick(() => {
  228. if (this.$refs.commissionFormRef) {
  229. this.$refs.commissionFormRef.clearValidate()
  230. }
  231. })
  232. },
  233. handlePageChange(page) {
  234. this.queryParams.pageNum = page
  235. this.getList()
  236. },
  237. // 外部调用获取列表
  238. getListByExternal() {
  239. this.getList()
  240. }
  241. },
  242. created() {
  243. this.getList()
  244. }
  245. }
  246. </script>
  247. <style lang="scss" scoped>
  248. .commission-form-list {
  249. padding: 0 20px 20px;
  250. }
  251. .commission-header {
  252. margin-bottom: 16px;
  253. }
  254. .card_list {
  255. display: flex;
  256. flex-direction: column;
  257. gap: 16px;
  258. }
  259. .card_item {
  260. background-color: #fff;
  261. border-radius: 12px;
  262. padding: 20px;
  263. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  264. }
  265. .card_header {
  266. display: flex;
  267. justify-content: space-between;
  268. align-items: center;
  269. margin-bottom: 16px;
  270. padding-bottom: 12px;
  271. border-bottom: 1px solid #f0f0f0;
  272. }
  273. .card_title {
  274. font-size: 18px;
  275. font-weight: bold;
  276. color: #202020;
  277. }
  278. .card_actions {
  279. display: flex;
  280. gap: 8px;
  281. }
  282. .card_body {
  283. display: flex;
  284. flex-direction: column;
  285. gap: 12px;
  286. }
  287. .info_row {
  288. display: flex;
  289. align-items: center;
  290. font-size: 14px;
  291. }
  292. .info_label {
  293. color: #666;
  294. min-width: 80px;
  295. font-weight: 500;
  296. }
  297. .info_value {
  298. color: #202020;
  299. flex: 1;
  300. &.highlight {
  301. color: #108cff;
  302. font-weight: bold;
  303. font-size: 16px;
  304. }
  305. }
  306. .loading_wrap,
  307. .empty_wrap {
  308. padding: 40px 20px;
  309. text-align: center;
  310. }
  311. .dialog_header {
  312. padding: 20px;
  313. font-size: 32rpx;
  314. font-weight: bold;
  315. text-align: center;
  316. border-bottom: 1px solid #e9ecef;
  317. }
  318. .dialog_body {
  319. padding: 20px;
  320. }
  321. .dialog_footer {
  322. padding: 20px;
  323. display: flex;
  324. justify-content: space-around;
  325. border-top: 1px solid #e9ecef;
  326. }
  327. </style>