DeliveryerManage1.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <div class="page-wrap">
  3. <div class="crumbs">
  4. <el-breadcrumb separator="/">
  5. <i class="el-icon-eleme"></i> 新配送员管理
  6. </el-breadcrumb>
  7. </div>
  8. <div class="background">
  9. <div class="topbox">
  10. <div class="topbox-left">
  11. <span class="page-title">新配送员管理</span>
  12. </div>
  13. <div class="topbox-right">
  14. <el-button type="primary" icon="el-icon-plus" size="mini" @click="openCreate">新增配送员</el-button>
  15. </div>
  16. </div>
  17. <div class="searchbox">
  18. <div class="filter-group">
  19. <span>姓名</span>
  20. <el-input v-model="filters.name" size="small" style="width:150px" clearable placeholder="配送员姓名"></el-input>
  21. </div>
  22. <div class="filter-group">
  23. <span>手机号</span>
  24. <el-input v-model="filters.phone" size="small" style="width:150px" clearable placeholder="手机号"></el-input>
  25. </div>
  26. <div class="filter-group">
  27. <span>类型</span>
  28. <el-select v-model="filters.type" size="small" style="width:140px" clearable placeholder="配送员类型">
  29. <el-option label="平台配送员" :value="1"></el-option>
  30. <el-option label="商家配送员" :value="2"></el-option>
  31. </el-select>
  32. </div>
  33. <div class="filter-group">
  34. <span>状态</span>
  35. <el-select v-model="filters.accountStatus" size="small" style="width:110px" clearable placeholder="账号状态">
  36. <el-option label="正常" :value="1"></el-option>
  37. <el-option label="冻结" :value="0"></el-option>
  38. </el-select>
  39. </div>
  40. <span style="flex:1"></span>
  41. <el-button type="primary" icon="el-icon-search" size="small" @click="search">查询</el-button>
  42. <el-button size="small" @click="resetSearch">重置</el-button>
  43. </div>
  44. <div class="tablebox">
  45. <dptable
  46. :columns="columns"
  47. :dataSource="tableData"
  48. :options="options"
  49. :fetch="getDataList"
  50. :pagination="pagination"
  51. />
  52. </div>
  53. </div>
  54. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="640px" :close-on-click-modal="false">
  55. <el-form :model="form" label-width="120px">
  56. <el-form-item label="配送员姓名" required>
  57. <el-input v-model="form.name" maxlength="50" placeholder="请输入配送员姓名"></el-input>
  58. </el-form-item>
  59. <el-form-item label="手机号" required>
  60. <el-input v-model="form.phone" maxlength="20" placeholder="请输入手机号" autocomplete="off"></el-input>
  61. </el-form-item>
  62. <el-form-item label="密码" :required="!form.id">
  63. <el-input v-model="form.password" maxlength="128" :placeholder="form.id ? '不填写则不修改密码' : '请输入登录密码'" show-password autocomplete="new-password"></el-input>
  64. </el-form-item>
  65. <el-form-item label="配送员类型" required>
  66. <el-radio-group v-model="form.type" @change="handleTypeChange">
  67. <el-radio :label="1">平台配送员</el-radio>
  68. <el-radio :label="2">商家配送员</el-radio>
  69. </el-radio-group>
  70. </el-form-item>
  71. <el-form-item v-if="form.type === 2" label="所属商家ID" required>
  72. <el-select v-model="form.merchantId" filterable placeholder="请选择所属商家" style="width:100%">
  73. <el-option
  74. v-for="item in merchantList"
  75. :key="getStoreId(item)"
  76. :label="getStoreName(item)"
  77. :value="getStoreId(item)"
  78. ></el-option>
  79. </el-select>
  80. </el-form-item>
  81. <el-form-item label="工作状态">
  82. <el-radio-group v-model="form.workStatus">
  83. <el-radio :label="1">可接单</el-radio>
  84. <el-radio :label="0">暂停接单</el-radio>
  85. </el-radio-group>
  86. </el-form-item>
  87. <el-form-item label="账号状态">
  88. <el-radio-group v-model="form.accountStatus">
  89. <el-radio :label="1">正常</el-radio>
  90. <el-radio :label="0">冻结</el-radio>
  91. </el-radio-group>
  92. </el-form-item>
  93. <template v-if="form.type === 1">
  94. <el-form-item label="平台权限">
  95. <el-checkbox v-model="form.pickup" :true-label="1" :false-label="0">取餐</el-checkbox>
  96. <el-checkbox v-model="form.delivery" :true-label="1" :false-label="0">配送</el-checkbox>
  97. <el-checkbox v-model="form.climbStairs" :true-label="1" :false-label="0">爬楼</el-checkbox>
  98. </el-form-item>
  99. </template>
  100. <el-form-item v-if="form.type === 2" label="不能接单时间">
  101. <el-time-picker v-model="form.noOrderStartTimeStr" value-format="HH:mm" format="HH:mm" placeholder="开始时间" style="width:140px" editable clearable></el-time-picker>
  102. <span class="time-separator">至</span>
  103. <el-time-picker v-model="form.noOrderEndTimeStr" value-format="HH:mm" format="HH:mm" placeholder="结束时间" style="width:140px" editable clearable></el-time-picker>
  104. </el-form-item>
  105. </el-form>
  106. <span slot="footer">
  107. <el-button @click="dialogVisible = false">取消</el-button>
  108. <el-button type="primary" :loading="saving" @click="save">保存</el-button>
  109. </span>
  110. </el-dialog>
  111. </div>
  112. </template>
  113. <script>
  114. import dptable from '@/components/common/Dptable.vue'
  115. const baseUrl = '/deliveryRiderManage1'
  116. export default {
  117. name: 'DeliveryerManage1',
  118. components: { dptable },
  119. data() {
  120. return {
  121. filters: this.createFilters(),
  122. tableData: [],
  123. pagination: {
  124. resultCount: 0,
  125. currentPage: 1,
  126. pageSize: 20
  127. },
  128. options: {
  129. mutiSelect: false,
  130. index: false,
  131. initTable: true,
  132. height: '520'
  133. },
  134. dialogVisible: false,
  135. dialogTitle: '',
  136. saving: false,
  137. form: this.createForm(),
  138. merchantList: [],
  139. columns: [
  140. { prop: 'name', label: '姓名', width: 140 },
  141. { prop: 'phone', label: '手机号', width: 150 },
  142. {
  143. prop: 'type',
  144. label: '类型',
  145. width: 130,
  146. formatter: row => row.type == 1 ? '平台配送员' : '商家配送员'
  147. },
  148. {
  149. prop: 'workStatus',
  150. label: '工作状态',
  151. width: 110,
  152. render: row => row.workStatus == 1
  153. ? <el-tag size="small" type="success" style="cursor:pointer" onClick={() => this.updateWorkStatus(row)}>可接单</el-tag>
  154. : <el-tag size="small" type="warning" style="cursor:pointer" onClick={() => this.updateWorkStatus(row)}>暂停接单</el-tag>
  155. },
  156. {
  157. prop: 'accountStatus',
  158. label: '账号状态',
  159. width: 100,
  160. render: row => row.accountStatus == 1
  161. ? <el-tag size="small" style="cursor:pointer" onClick={() => this.updateAccountStatus(row)}>正常</el-tag>
  162. : <el-tag size="small" type="danger" style="cursor:pointer" onClick={() => this.updateAccountStatus(row)}>冻结</el-tag>
  163. },
  164. {
  165. prop: 'pickup',
  166. label: '取餐',
  167. width: 75,
  168. switch: true,
  169. switchHide: (value, row) => row.type == 2,
  170. onChange: (value, row) => this.updatePermission(row, 'pickup', value)
  171. },
  172. {
  173. prop: 'delivery',
  174. label: '配送',
  175. width: 75,
  176. switch: true,
  177. switchHide: (value, row) => row.type == 2,
  178. onChange: (value, row) => this.updatePermission(row, 'delivery', value)
  179. },
  180. {
  181. prop: 'climbStairs',
  182. label: '爬楼',
  183. width: 75,
  184. switch: true,
  185. switchHide: (value, row) => row.type == 2,
  186. onChange: (value, row) => this.updatePermission(row, 'climbStairs', value)
  187. },
  188. {
  189. prop: 'noOrderStartTimeStr',
  190. label: '不能接单时间',
  191. width: 140,
  192. formatter: row => row.type == 2 && row.noOrderStartTimeStr && row.noOrderEndTimeStr
  193. ? row.noOrderStartTimeStr + ' - ' + row.noOrderEndTimeStr
  194. : row.type == 1 ? '—' : ''
  195. },
  196. {
  197. prop: 'createTime',
  198. label: '创建时间',
  199. width: 150,
  200. formatter: row => row.createTime ? this.$moment(row.createTime).format('YYYY-MM-DD HH:mm:ss') : '—'
  201. },
  202. {
  203. prop: 'updateTime',
  204. label: '修改时间',
  205. width: 150,
  206. formatter: row => row.updateTime ? this.$moment(row.updateTime).format('YYYY-MM-DD HH:mm:ss') : '—'
  207. },
  208. {
  209. label: '操作',
  210. width: 220,
  211. fixed: 'right',
  212. button: true,
  213. group: [
  214. {
  215. name: '编辑',
  216. type: 'primary',
  217. plain: true,
  218. buttonCode: 'edit',
  219. onClick: row => this.openEdit(row)
  220. },
  221. {
  222. name: '删除',
  223. type: 'danger',
  224. plain: true,
  225. buttonCode: 'delete',
  226. onClick: row => this.deleteRider(row)
  227. }
  228. ]
  229. }
  230. ]
  231. }
  232. },
  233. methods: {
  234. createFilters() {
  235. return {
  236. name: '',
  237. phone: '',
  238. type: '',
  239. accountStatus: ''
  240. }
  241. },
  242. createForm() {
  243. return {
  244. id: '',
  245. phone: '',
  246. password: '',
  247. name: '',
  248. type: 1,
  249. merchantId: '',
  250. workStatus: 1,
  251. accountStatus: 1,
  252. pickup: 1,
  253. delivery: 1,
  254. climbStairs: 0,
  255. noOrderStartTimeStr: '',
  256. noOrderEndTimeStr: ''
  257. }
  258. },
  259. search() {
  260. this.pagination.currentPage = 1
  261. this.getDataList()
  262. },
  263. resetSearch() {
  264. this.filters = this.createFilters()
  265. this.search()
  266. },
  267. getDataList() {
  268. const querystring = require('querystring')
  269. this.options.loading = true
  270. this.$axios.post(baseUrl + '/list', querystring.stringify({
  271. name: this.filters.name,
  272. phone: this.filters.phone,
  273. type: this.filters.type,
  274. accountStatus: this.filters.accountStatus,
  275. pageSize: this.pagination.pageSize,
  276. currentPage: this.pagination.currentPage
  277. })).then(res => {
  278. this.tableData = res.data.list || []
  279. if (res.data.page) {
  280. this.pagination.resultCount = res.data.page.resultCount
  281. this.pagination.currentPage = res.data.page.currentPage
  282. }
  283. }).finally(() => {
  284. this.options.loading = false
  285. })
  286. },
  287. openCreate() {
  288. this.dialogTitle = '新增配送员'
  289. this.form = this.createForm()
  290. this.getMerchantList()
  291. this.dialogVisible = true
  292. },
  293. getMerchantList() {
  294. if (this.merchantList.length > 0) return
  295. const querystring = require('querystring')
  296. this.$axios.post('/storeManage/getStoreList', querystring.stringify({})).then(res => {
  297. this.merchantList = res.data.list || []
  298. })
  299. },
  300. getStoreId(item) {
  301. return item.storeId || item.STORE_ID
  302. },
  303. getStoreName(item) {
  304. return item.storeName || item.STORE_NAME || item.name || item.NAME
  305. },
  306. openEdit(row) {
  307. this.dialogTitle = '编辑配送员'
  308. this.form = this.createForm()
  309. this.form.id = row.id
  310. this.getMerchantList()
  311. this.dialogVisible = true
  312. const querystring = require('querystring')
  313. this.$axios.post(baseUrl + '/getById', querystring.stringify({ id: row.id })).then(res => {
  314. if (!this.handleResult(res, false, true)) {
  315. this.dialogVisible = false
  316. return
  317. }
  318. this.form = Object.assign(this.createForm(), res.data.obj || {})
  319. this.form.password = ''
  320. })
  321. },
  322. handleTypeChange() {
  323. if (this.form.type === 1) {
  324. this.form.merchantId = ''
  325. this.form.noOrderStartTimeStr = ''
  326. this.form.noOrderEndTimeStr = ''
  327. return
  328. }
  329. this.form.pickup = 0
  330. this.form.delivery = 0
  331. this.form.climbStairs = 0
  332. },
  333. updatePermission(row, field, value) {
  334. if (field === 'pickup' && value == 1 && row.climbStairs == 1) {
  335. this.$message.error('取餐权限和爬楼权限不能同时存在')
  336. this.getDataList()
  337. return
  338. }
  339. if (field === 'climbStairs' && value == 1 && row.pickup == 1) {
  340. this.$message.error('取餐权限和爬楼权限不能同时存在')
  341. this.getDataList()
  342. return
  343. }
  344. const querystring = require('querystring')
  345. this.$axios.post(baseUrl + '/updatePermission', querystring.stringify({
  346. id: row.id,
  347. field: field,
  348. value: value
  349. })).then(res => this.handleResult(res, true))
  350. },
  351. updateWorkStatus(row) {
  352. const querystring = require('querystring')
  353. this.$axios.post(baseUrl + '/updateWorkStatus', querystring.stringify({
  354. id: row.id,
  355. workStatus: row.workStatus == 1 ? 0 : 1
  356. })).then(res => this.handleResult(res, true))
  357. },
  358. deleteRider(row) {
  359. this.$confirm('确定要删除该配送员吗?', '提示', {
  360. confirmButtonText: '确定',
  361. cancelButtonText: '取消',
  362. type: 'warning'
  363. }).then(() => {
  364. const querystring = require('querystring')
  365. this.$axios.post(baseUrl + '/delete', querystring.stringify({ id: row.id })).then(res => {
  366. this.handleResult(res, true)
  367. })
  368. }).catch(() => {})
  369. },
  370. updateAccountStatus(row) {
  371. const querystring = require('querystring')
  372. this.$axios.post(baseUrl + '/updateAccountStatus', querystring.stringify({
  373. id: row.id,
  374. accountStatus: row.accountStatus == 1 ? 0 : 1
  375. })).then(res => this.handleResult(res, true))
  376. },
  377. save() {
  378. if (!this.validateForm()) {
  379. return
  380. }
  381. const querystring = require('querystring')
  382. this.saving = true
  383. this.$axios.post(baseUrl + '/save', querystring.stringify(this.buildSaveParams())).then(res => {
  384. if (this.handleResult(res, false)) {
  385. this.dialogVisible = false
  386. this.getDataList()
  387. }
  388. }).finally(() => {
  389. this.saving = false
  390. })
  391. },
  392. buildSaveParams() {
  393. return {
  394. id: this.form.id,
  395. phone: this.form.phone,
  396. password: this.form.password,
  397. name: this.form.name,
  398. type: this.form.type,
  399. merchantId: this.form.type === 2 ? this.form.merchantId : '',
  400. workStatus: this.form.workStatus,
  401. accountStatus: this.form.accountStatus,
  402. pickup: this.form.type === 1 ? this.form.pickup : 0,
  403. delivery: this.form.type === 1 ? this.form.delivery : 0,
  404. climbStairs: this.form.type === 1 ? this.form.climbStairs : 0,
  405. noOrderStartTimeStr: this.form.type === 2 ? this.form.noOrderStartTimeStr : '',
  406. noOrderEndTimeStr: this.form.type === 2 ? this.form.noOrderEndTimeStr : ''
  407. }
  408. },
  409. validateForm() {
  410. if (!this.form.name || !this.form.phone) {
  411. this.$message.error('请填写姓名和手机号')
  412. return false
  413. }
  414. if (!this.form.id && !this.form.password) {
  415. this.$message.error('新增配送员必须填写密码')
  416. return false
  417. }
  418. if (!/^1\d{10}$/.test(this.form.phone)) {
  419. this.$message.error('请输入正确的手机号')
  420. return false
  421. }
  422. if (this.form.type === 2 && !this.form.merchantId) {
  423. this.$message.error('商家配送员必须填写所属商家ID')
  424. return false
  425. }
  426. if (this.form.type === 1 && this.form.pickup == 1 && this.form.climbStairs == 1) {
  427. this.$message.error('取餐权限和爬楼权限不能同时存在')
  428. return false
  429. }
  430. return true
  431. },
  432. handleResult(res, refresh, silent) {
  433. if (res.data.rtnBean && res.data.rtnBean.rtnCode != 0) {
  434. this.$message.error(res.data.rtnBean.rtnMsg)
  435. if (refresh) this.getDataList()
  436. return false
  437. }
  438. if (!silent) this.$message.success('操作成功')
  439. if (refresh) this.getDataList()
  440. return true
  441. }
  442. }
  443. }
  444. </script>
  445. <style scoped>
  446. .page-wrap{
  447. height: 100%;
  448. display: flex;
  449. flex-direction: column;
  450. overflow: hidden;
  451. }
  452. .crumbs{
  453. color: #666;
  454. flex-shrink: 0;
  455. }
  456. .background{
  457. flex: 1;
  458. min-height: 0;
  459. display: flex;
  460. flex-direction: column;
  461. gap: 10px;
  462. padding: 0 10px 10px;
  463. }
  464. .topbox{
  465. background: white;
  466. box-shadow: 0 12px 20px -8px rgba(22, 50, 62, 0.3);
  467. border-radius: 10px;
  468. min-height: 52px;
  469. display: flex;
  470. align-items: center;
  471. justify-content: space-between;
  472. padding: 10px 16px;
  473. flex-shrink: 0;
  474. }
  475. .topbox-left{ flex-shrink: 0; }
  476. .page-title{
  477. font-size: 14px;
  478. color: #409EFF;
  479. font-weight: 600;
  480. }
  481. .topbox-right{
  482. flex-shrink: 0;
  483. display: flex;
  484. gap: 8px;
  485. }
  486. .searchbox{
  487. background: white;
  488. box-shadow: 0 12px 20px -8px rgba(22, 50, 62, 0.3);
  489. border-radius: 10px;
  490. padding: 12px 16px;
  491. display: flex;
  492. align-items: center;
  493. gap: 8px;
  494. flex-shrink: 0;
  495. font-size: 13px;
  496. color: #606266;
  497. }
  498. .searchbox > span{ flex: 1; }
  499. .filter-group{
  500. display: flex;
  501. align-items: center;
  502. gap: 6px;
  503. }
  504. .filter-group > span{
  505. white-space: nowrap;
  506. color: #606266;
  507. }
  508. .tablebox{
  509. flex: 1;
  510. min-height: 0;
  511. background: white;
  512. box-shadow: 0 12px 20px -8px rgba(22, 50, 62, 0.3);
  513. border-radius: 10px;
  514. padding: 16px;
  515. overflow: hidden;
  516. }
  517. .time-separator{ margin: 0 8px; color: #909399; }
  518. </style>
  519. <style>
  520. .tablebox .el-table{ width: 100% !important; table-layout: auto !important; }
  521. .tablebox .el-table__header-wrapper table,
  522. .tablebox .el-table__body-wrapper table{ width: 100% !important; }
  523. .tablebox th{
  524. background: #409EFF !important;
  525. color: #fff !important;
  526. font-weight: 500 !important;
  527. font-size: 13px !important;
  528. padding: 10px 8px !important;
  529. border: none !important;
  530. }
  531. .tablebox td{
  532. padding: 8px !important;
  533. font-size: 13px;
  534. border-left: 1px solid #ebeef5 !important;
  535. }
  536. .tablebox td:first-child{ border-left: none !important; }
  537. .tablebox tr:hover td{ background: #f6faff; }
  538. /* 弹窗样式优化 */
  539. .el-dialog__title{ font-weight: 600; }
  540. .el-dialog__footer .el-button{ padding: 8px 24px; }
  541. </style>