index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <div class="page-box">
  3. <moduleView :propConfig="config" ref="view" v-loading="load" @pagination="pagination" @onRefresh="getList" @resert="queryList" @search="queryList" @modalHandle="modalHandle" @clickHandle="clickHandle" @detail="detail" />
  4. </div>
  5. </template>
  6. <script setup>
  7. import { computed,getCurrentInstance,ref } from "vue";
  8. const { proxy } = getCurrentInstance();
  9. import {list,del,add,update} from '@/api/base/merchantManage'
  10. import upload from "./components/upload.vue";
  11. import tableImg from "./components/tableImg.vue";
  12. import stateRadio from "./components/stateRadio.vue";
  13. const config = ref({
  14. attr:{
  15. calculateH:true
  16. },
  17. search:{
  18. attr:{
  19. size:'mini',
  20. rules:{
  21. name:[{
  22. required: true, message: '请输入名称', trigger: 'blur'
  23. }]
  24. }
  25. },
  26. columns:[
  27. [{
  28. span:8,
  29. // label:'设备名称',
  30. labelWidth:16,
  31. prop:'searchText',
  32. component:'by-input',
  33. compConfig:{
  34. attr:{
  35. placeholder:'请输入商户名称、联系人、联系方式',
  36. prefixIcon:'vxe-icon-search'
  37. }
  38. }
  39. }]
  40. ]
  41. },
  42. tool:{
  43. tools:{
  44. export:true,
  45. add:true,
  46. // delete:true,
  47. search:true,
  48. refresh:true
  49. }
  50. },
  51. table:{
  52. attr:{
  53. size:'mini',
  54. seq:true,
  55. align:'center',
  56. // checkbox:true
  57. },
  58. columns:[
  59. // {
  60. // title:'商户ID',
  61. // field:'commercialId',
  62. // },
  63. {
  64. isDetail:true,
  65. title:'商户名称',
  66. field:'commercialName',
  67. },
  68. {
  69. title:'营业执照',
  70. field:'prove1',
  71. component:shallowRef(tableImg)
  72. },
  73. {
  74. title:'状态',
  75. field:'state',
  76. component:'textChange',
  77. compConfig:{
  78. attr:{
  79. data:[{
  80. label:'启用',
  81. value:1,
  82. backgroundColor:'#f0f9eb',
  83. color:'#67c23a'
  84. },{
  85. label:'禁用',
  86. value:0,
  87. backgroundColor:'#fef0f0',
  88. color:'#f56c6c'
  89. }]
  90. }
  91. }
  92. },
  93. {
  94. title:'关联小程序',
  95. field:'apps',
  96. formatField: row => {
  97. let n = ''
  98. if(row.apps && row.apps.length > 0){
  99. for(const item of row.apps){
  100. n = n ? n + ',' + item : item
  101. }
  102. }
  103. return n;
  104. }
  105. },
  106. {
  107. title:'联系人',
  108. field:'principalName'
  109. },
  110. {
  111. title:'联系人手机',
  112. field:'principalTelephone'
  113. },
  114. {
  115. title:'地址',
  116. field:'addrCodeInfo'
  117. },
  118. {
  119. title:'社会统一信用代码',
  120. field:'code'
  121. },
  122. {
  123. title:'创建时间',
  124. field:'createTime'
  125. }]
  126. },
  127. modal:{
  128. tool:{
  129. tools:{
  130. return:true,
  131. add:true
  132. }
  133. },
  134. form:{
  135. attr:{
  136. width:'1000px',
  137. size:'small',
  138. labelWidth:'130px',
  139. rules:{
  140. commercialName:[
  141. {required: true, message: '请输入商户名称', trigger: 'blur'}
  142. ],
  143. code:[
  144. {required: true, message: '请输入统一信用代码', trigger: 'blur'}
  145. ],
  146. principalName:[
  147. {required: true, message: '请选择负责人', trigger: 'blur'},
  148. ],
  149. addrCode:[
  150. {required: true, message: '请选择位置', trigger: 'blur'}
  151. ],
  152. addrInfo:[
  153. {required: true, message: '请输入详细地址', trigger: 'blur'}
  154. ],
  155. principalTelephone:[
  156. {required: true, message: '请输入负责人电话', trigger: 'blur'},
  157. { validator: (rule, value, callback) => {
  158. if (value) {
  159. if(!/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value)) {
  160. callback(new Error('手机号格式不正确!'));
  161. }else{
  162. callback();
  163. }
  164. } else {
  165. callback();
  166. }
  167. }, trigger: 'blur' }
  168. ]
  169. }
  170. },
  171. columns:[
  172. [{
  173. label:'商户名称',
  174. prop:'commercialName',
  175. component:'by-input',
  176. compConfig:{
  177. attr:{}
  178. }
  179. }],
  180. [{
  181. label:'营业执照',
  182. prop:'prove1',
  183. component:shallowRef(upload)
  184. }],
  185. [{
  186. label:'状态',
  187. prop:'state',
  188. component:shallowRef(stateRadio)
  189. }],
  190. [{
  191. label:'统一信用代码',
  192. prop:'code',
  193. component:'by-input',
  194. compConfig:{
  195. attr:{}
  196. }
  197. }],
  198. [{
  199. label:'负责人',
  200. prop:'principalName',
  201. component:'by-input'
  202. },{
  203. label:'负责人电话',
  204. prop:'principalTelephone',
  205. component:'by-input'
  206. }],
  207. [{
  208. label:'位置',
  209. prop:'addrCode',
  210. component:'by-area',
  211. compConfig:{
  212. attr:{
  213. // area:'addrCodeInfo',
  214. areaCode:'addrCode'
  215. }
  216. }
  217. }],
  218. [{
  219. label:'详细地址',
  220. prop:'addrInfo',
  221. component:'by-input'
  222. }]
  223. ]
  224. }
  225. }
  226. })
  227. const load = ref(false)
  228. const isSearch = ref(false)
  229. const timeNum = ref(0);
  230. const detail = () => {
  231. config.value.modal.tool.tools.save = true;
  232. delete config.value.modal.tool.tools.add;
  233. proxy.$refs.view.initFormTool();
  234. }
  235. const clickHandle = n => {
  236. if(n == 'onAdd'){
  237. config.value.modal.tool.tools.add = true;
  238. delete config.value.modal.tool.tools.save;
  239. proxy.$refs.view.initFormTool();
  240. }
  241. if(n == 'onDelete'){
  242. delHandle()
  243. }
  244. }
  245. const modalHandle = n =>{
  246. if(n == 'onAdd'){
  247. proxy.$refs.view.getFormValidate(addData)
  248. }
  249. if(n == 'onSave'){
  250. proxy.$refs.view.getFormValidate(onSave)
  251. }
  252. }
  253. const delHandle = () => {
  254. let data = proxy.$refs.view.getSelectData();
  255. let ids = []
  256. if(!data && data.lenght == 0) {
  257. proxy.$message('请选择数据')
  258. return
  259. }
  260. for(const item of data) {
  261. ids.push(item.equipmentId)
  262. }
  263. proxy.$confirm('此操作将永久删除数据, 是否继续?', '提示', {
  264. confirmButtonText: '确定',
  265. cancelButtonText: '取消',
  266. type: 'warning'
  267. }).then(() => {
  268. load.value = true;
  269. del({
  270. commercialIds:ids,
  271. }).then(()=>{
  272. proxy.$message({message:'删除成功!',type:'success'})
  273. load.value = false;
  274. getList();
  275. }).catch(()=>{
  276. load.value = false;
  277. })
  278. }).catch(()=>{})
  279. }
  280. //添加
  281. const addData = () => {
  282. let value = proxy.$refs.view.getFormValue();
  283. if(value){
  284. load.value = true;
  285. add(value).then(res =>{
  286. load.value = false;
  287. proxy.$message({
  288. message:res.msg,
  289. type:'success'
  290. });
  291. proxy.$refs.view.closeModal();
  292. getList();
  293. }).catch(()=>{
  294. load.value = false;
  295. })
  296. }
  297. }
  298. //保存
  299. const onSave = () => {
  300. let data = proxy.$refs.view.getFormValue();
  301. load.value = true;
  302. update(data).then(res => {
  303. proxy.$message({
  304. message:res.msg,
  305. type:'success'
  306. });
  307. load.value = false;
  308. proxy.$refs.view.closeModal();
  309. pagination();
  310. }).catch(() => {
  311. load.value = false;
  312. })
  313. }
  314. const pagination = () => {
  315. if(isSearch.value){
  316. queryList();
  317. }else{
  318. getList()
  319. }
  320. }
  321. //列表请求(包含分页和搜素条件)
  322. const queryList = () => {
  323. isSearch.value = true;
  324. let data = proxy.$refs.view.getQuery();
  325. requestList(data);
  326. }
  327. const getList = () => {
  328. if(!proxy.$refs.view){
  329. if(timeNum.value > 5){
  330. return
  331. }
  332. setTimeout(()=>{
  333. getList()
  334. },500)
  335. timeNum.value ++;
  336. return
  337. }
  338. timeNum.value = 0;
  339. isSearch.value = false;
  340. let data = proxy.$refs.view.getPage();
  341. requestList(data);
  342. }
  343. const requestList = data => {
  344. load.value = true;
  345. list(data).then(res => {
  346. load.value = false;
  347. proxy.$refs.view.setTableValue(res.data.data);
  348. let page = {
  349. pageNo: res.data.page.current, //当前页
  350. pageSize: data.pageSize, //每页条数
  351. total: res.data.page.total //总条数
  352. };
  353. proxy.$refs.view.setPage(page)
  354. }).catch(()=>{
  355. load.value = false;
  356. })
  357. }
  358. nextTick(()=>{
  359. getList()
  360. })
  361. </script>
  362. <style lang="scss" scoped>
  363. </style>