addUser.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <div class="addUser app-container">
  3. <el-form
  4. :model="setQuery"
  5. ref="setQuery"
  6. :rules="rules"
  7. label-width="130px"
  8. >
  9. <el-form-item label="商户类型:" prop="accountChildType">
  10. <el-select
  11. v-model="setQuery.accountChildType"
  12. size="small"
  13. clearable
  14. class="item-width-300"
  15. placeholder="请选择"
  16. >
  17. <el-option
  18. v-for="item in options"
  19. :key="item.value"
  20. :label="item.label"
  21. :value="item.value"
  22. >
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="所属平台" prop="platformType">
  27. <el-checkbox-group v-model="setQuery.platformType">
  28. <div class="flex" v-for="(item,index) in masterShopOptions" :key="index" ><el-checkbox :label="item.value">{{item.label}}</el-checkbox>
  29. <el-form-item v-if="setQuery.platformType.includes(item.value)" :prop="'platformShareLists.' + index + '.shareId'" :rules="{required: true, message: '请选择分账规则', trigger: 'change'}">
  30. <el-select
  31. v-model="setQuery.platformShareLists[index].shareId"
  32. class="item-width-300"
  33. size="small"
  34. placeholder="请选择商品分账规则"
  35. >
  36. <el-option
  37. v-for="item in ruleOptions"
  38. :key="item.value"
  39. :label="item.label"
  40. :value="item.value"
  41. >
  42. </el-option>
  43. </el-select>
  44. </el-form-item>
  45. </div>
  46. <!-- <el-checkbox label="1">慧研学惠生活</el-checkbox>
  47. <el-checkbox label="2" >印象贵大</el-checkbox> -->
  48. </el-checkbox-group>
  49. </el-form-item>
  50. <el-form-item label="商户名称:" prop="accountName">
  51. <el-input
  52. v-model="setQuery.accountName"
  53. size="small"
  54. class="item-width-300"
  55. ></el-input>
  56. </el-form-item>
  57. <el-form-item label="所在地区:" prop="district">
  58. <el-select
  59. v-model="setQuery.province"
  60. size="small"
  61. clearable
  62. class="item-width-150"
  63. placeholder="请选择省"
  64. >
  65. <el-option
  66. v-for="item in provinceList"
  67. :key="item.code"
  68. :label="item.name"
  69. :value="item.code"
  70. >
  71. </el-option>
  72. </el-select>
  73. <el-select
  74. v-model="setQuery.city"
  75. size="small"
  76. clearable
  77. class="item-width-150 ml10"
  78. placeholder="请选择市"
  79. >
  80. <el-option
  81. v-for="item in cityList"
  82. :key="item.code"
  83. :label="item.name"
  84. :value="item.code"
  85. >
  86. </el-option>
  87. </el-select>
  88. <el-select
  89. v-model="setQuery.district"
  90. size="small"
  91. clearable
  92. class="item-width-150 ml10"
  93. placeholder="请选择区"
  94. >
  95. <el-option
  96. v-for="item in countyList"
  97. :key="item.code"
  98. :label="item.name"
  99. :value="item.code"
  100. >
  101. </el-option>
  102. </el-select>
  103. </el-form-item>
  104. <el-form-item label="联系人:" prop="contactName">
  105. <el-input
  106. v-model="setQuery.contactName"
  107. size="small"
  108. class="item-width-300"
  109. ></el-input>
  110. </el-form-item>
  111. <el-form-item label="手机号:" prop="phoneNum">
  112. <el-input
  113. v-model="setQuery.phoneNum"
  114. :maxlength="11"
  115. size="small"
  116. class="item-width-300"
  117. :disabled="!!this.$route.query.id"
  118. ></el-input>
  119. </el-form-item>
  120. <!-- <el-form-item label="商品分账规则:" prop="shareId">
  121. <el-select
  122. v-model="setQuery.shareId"
  123. class="item-width-300"
  124. placeholder="请选择商品分账规则"
  125. >
  126. <el-option
  127. v-for="item in ruleOptions"
  128. :key="item.value"
  129. :label="item.label"
  130. :value="item.value"
  131. >
  132. </el-option>
  133. </el-select>
  134. </el-form-item> -->
  135. <el-form-item label="备注:" prop="notes">
  136. <el-input
  137. v-model="setQuery.notes"
  138. class="item-width-300"
  139. type="textarea"
  140. ></el-input>
  141. </el-form-item>
  142. </el-form>
  143. <div class="btn-group">
  144. <el-button>取 消</el-button>
  145. <el-button type="primary" :loading="loading" @click="save"
  146. >确 定</el-button
  147. >
  148. </div>
  149. </div>
  150. </template>
  151. <script>
  152. import { getShopType,addOrUpdateAccount,accountDetail } from "@/api/user";
  153. import {getRegion} from '@/api/payment';
  154. import {debounce} from '@/utils/index';
  155. import {getRuleList} from '@/api/rule'
  156. export default {
  157. data() {
  158. var validatePhone = (rule, value, callback) => {
  159. let reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
  160. if (value && reg.test(value)) {
  161. callback();
  162. }else{
  163. callback(new Error('手机号不合法'));
  164. }
  165. };
  166. return {
  167. loading:false,
  168. setQuery: {
  169. accountChildType: "",
  170. accountId: "",
  171. accountName: "",
  172. accountType: "202",//商户202 渠道201
  173. address: "",
  174. city: "",
  175. contactName: "",
  176. district: "",
  177. mapLat: "",
  178. mapLon: "",
  179. notes: "",
  180. phoneNum: "",
  181. province: "",
  182. shareId:'',
  183. platformType:[],
  184. platformShareLists:[]
  185. },
  186. region:{
  187. "code": "",
  188. "type": "province"
  189. },
  190. rules: {
  191. accountName: [{ required: true, message: "请输入账户名称", trigger: "blur" }],
  192. accountChildType: [
  193. { required: true, message: "请选择账户类型", trigger: "change" },
  194. ],
  195. shareId: [
  196. { required: true, message: "请选择商品分账规则", trigger: "change" },
  197. ],
  198. contactName: [
  199. { required: true, message: "请输入联系人", trigger: "blur" },
  200. ],
  201. phoneNum: [
  202. { required: true, message: "请输入手机号", trigger: "blur" },
  203. { validator: validatePhone, trigger: 'blur' }
  204. ],
  205. platformType: [
  206. { type: 'array', required: true, message: '请至少绑定一个主商户', trigger: 'change' }
  207. ],
  208. // notes: [
  209. // { required: true, message: "请输入备注", trigger: "blur" },
  210. // ],
  211. },
  212. isInit:false,
  213. options: [],
  214. provinceList: [],//省
  215. cityList: [],//市
  216. countyList: [],//区
  217. ruleOptions:[],
  218. };
  219. },
  220. watch: {
  221. 'setQuery.province':debounce(function(val) {
  222. if(val){
  223. this.getRegion('city',val)
  224. }
  225. if(!this.isInit){
  226. console.log(this.isInit);
  227. this.setQuery.city = ''
  228. this.setQuery.district = ''
  229. this.cityList = []
  230. this.countyList = []
  231. }
  232. }),
  233. 'setQuery.city':debounce(function(val) {
  234. if(val){
  235. this.getRegion('county',val)
  236. }
  237. if(!this.isInit){
  238. console.log(this.isInit);
  239. this.setQuery.district = ''
  240. this.countyList = []
  241. }
  242. }),
  243. // 'setQuery.platformType'(val) {
  244. // console.log(123);
  245. // }
  246. },
  247. methods: {
  248. // 获取地区数据
  249. getRegion(type,code=''){
  250. getRegion({type,code}).then(res=>{
  251. if (res.state == "Success") {
  252. this[type+'List'] = res.content
  253. }
  254. })
  255. },
  256. getShopType() {
  257. getShopType().then((res) => {
  258. if (res.state == "Success") {
  259. for (const key in res.content) {
  260. if (Object.hasOwnProperty.call(res.content, key)) {
  261. this.options.push({
  262. value: key,
  263. label: res.content[key],
  264. });
  265. }
  266. }
  267. }
  268. });
  269. },
  270. accountDetail(accountId) {
  271. this.isInit = true
  272. accountDetail({accountId}).then((res) => {
  273. if (res.state == "Success") {
  274. this.setQuery = res.content
  275. this.$set(this.setQuery,'platformShareLists',[])
  276. this.masterShopOptions.map(item=>{
  277. this.setQuery.platformShareLists.push({
  278. shareId:'',
  279. platformType:item.value
  280. })
  281. })
  282. let platformShareLists = JSON.parse(this.setQuery.platformShares)||[]
  283. platformShareLists.map(item=>{
  284. this.setQuery.platformShareLists.map(i=>{
  285. if(item.platformType == i.platformType){
  286. i.shareId = item.shareId
  287. }
  288. })
  289. })
  290. this.setQuery.platformType = this.setQuery.platformType.split(',').map(Number)
  291. setTimeout(() => {
  292. this.isInit = false
  293. }, 1000);
  294. }
  295. });
  296. },
  297. // 规则
  298. getRuleList() {
  299. getRuleList({currentPage:1,pageSize:999}).then((res) => {
  300. if (res.state == "Success") {
  301. res.content.records.map(item=>{
  302. this.ruleOptions.push({
  303. label:item.shareRule,
  304. value:item.id
  305. })
  306. })
  307. }
  308. });
  309. },
  310. save() {
  311. this.$refs.setQuery.validate((v) => {
  312. if (v) {
  313. this.loading = true;
  314. let obj = JSON.parse(JSON.stringify(this.setQuery))
  315. if(this.$route.query.id){
  316. delete obj.phoneNum
  317. }
  318. let platformShareLists = JSON.parse(JSON.stringify(obj.platformShareLists))
  319. obj.platformShareLists = []
  320. platformShareLists.map((item,index)=>{
  321. if(item.shareId&&obj.platformType.includes(item.platformType)){
  322. obj.platformShareLists.push(item)
  323. }
  324. })
  325. obj.platformType = obj.platformType.toString()
  326. addOrUpdateAccount(obj).then((res) => {
  327. this.loading = false;
  328. if (res.state == "Success") {
  329. this.$notify({
  330. title: "成功",
  331. message: "操作成功",
  332. type: "success",
  333. });
  334. this.setQuery = {
  335. accountChildType: "",
  336. accountId: "",
  337. accountName: "",
  338. accountType: "202",
  339. address: "",
  340. city: "",
  341. contactName: "",
  342. district: "",
  343. mapLat: "",
  344. mapLon: "",
  345. notes: "",
  346. phoneNum: "",
  347. province: "",
  348. platformType:[],
  349. platformShareLists:[]
  350. };
  351. this.$router.push("/merchantManage/index");
  352. }
  353. });
  354. }
  355. });
  356. },
  357. },
  358. created() {
  359. this.setQuery.platformShareLists=[]
  360. this.masterShopOptions.map(item=>{
  361. this.setQuery.platformShareLists.push({
  362. shareId:'',
  363. platformType:item.value
  364. })
  365. })
  366. this.getRuleList()
  367. if(this.$route.query.title == '编辑商户'){
  368. // this.setQuery = JSON.parse( sessionStorage.getItem('shopUser') )
  369. this.accountDetail(this.$route.query.id)
  370. }
  371. this.getShopType();
  372. this.getRegion('province');
  373. },
  374. };
  375. </script>
  376. <style lang="scss" scoped>
  377. .addUser {
  378. padding-bottom: 40px;
  379. .flex{
  380. width: 500px;
  381. display: flex;
  382. align-items: center;
  383. justify-content: space-between;
  384. }
  385. .btn-group {
  386. display: flex;
  387. align-items: center;
  388. justify-content: center;
  389. }
  390. }
  391. </style>