index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <!-- 添加供应商 -->
  3. <div class="article-manager video-icon form-submit" id="shopp-manager">
  4. <div class="i-layout-page-header">
  5. <PageHeader class="product_tabs" hidden-breadcrumb>
  6. <div slot="title" class="acea-row row-middle">
  7. <router-link :to="{ path: `${roterPre}/supplier/menu/list` }">
  8. <div class="font-sm after-line">
  9. <span class="iconfont iconfanhui"></span>
  10. <span class="pl10">返回</span>
  11. </div>
  12. </router-link>
  13. <span
  14. v-text="$route.params.id ? '编辑供应商' : '添加供应商'"
  15. class="mr20 ml16"
  16. ></span>
  17. </div>
  18. </PageHeader>
  19. </div>
  20. <Card :bordered="false" dis-hover class="ivu-mt">
  21. <Form
  22. class="formValidate mt20"
  23. ref="formValidate"
  24. :rules="ruleValidate"
  25. :model="formValidate"
  26. :label-width="width"
  27. :label-position="labelPosition"
  28. @submit.native.prevent
  29. >
  30. <Row :gutter="24" type="flex">
  31. <Col span="24">
  32. <FormItem label="供应商名称:" prop="supplier_name">
  33. <Input
  34. v-model="formValidate.supplier_name"
  35. placeholder="请输入供应商名称"
  36. v-width="460"
  37. />
  38. </FormItem>
  39. </Col>
  40. <!-- <Row :gutter="24" type="flex"> -->
  41. <Col span="24">
  42. <FormItem label="联系人姓名:" prop="name">
  43. <Input
  44. v-model="formValidate.name"
  45. placeholder="请输入联系人姓名"
  46. v-width="460"
  47. />
  48. </FormItem>
  49. </Col>
  50. <!-- </Row> -->
  51. <Col span="24">
  52. <FormItem label="联系电话:" prop="phone">
  53. <Input
  54. v-model="formValidate.phone"
  55. placeholder="请输入联系电话"
  56. v-width="460"
  57. />
  58. </FormItem>
  59. </Col>
  60. <Col span="24">
  61. <FormItem label="省市区地址" prop="addressSelect">
  62. <Cascader
  63. :data="addresData"
  64. :load-data="loadData"
  65. v-model="formValidate.addressSelect"
  66. @on-change="addchack"
  67. v-width="460"
  68. ></Cascader>
  69. </FormItem>
  70. </Col>
  71. <Col span="24">
  72. <FormItem label="供应商地址:" prop="detailed_address">
  73. <Input
  74. v-model="formValidate.detailed_address"
  75. placeholder="请输入供应商地址"
  76. v-width="460"
  77. />
  78. </FormItem>
  79. </Col>
  80. <Col span="24">
  81. <FormItem label="供应商邮箱:" prop="email">
  82. <Input
  83. v-model="formValidate.email"
  84. placeholder="请输入供应商邮箱"
  85. v-width="460"
  86. />
  87. </FormItem>
  88. </Col>
  89. <Col span="24">
  90. <FormItem label="备注:" prop="mark">
  91. <Input
  92. type="textarea"
  93. v-model="formValidate.mark"
  94. placeholder="请输入..."
  95. v-width="460"
  96. />
  97. </FormItem>
  98. </Col>
  99. <Col span="24">
  100. <FormItem label="供应商登录用户名:" prop="account">
  101. <Input
  102. v-model="formValidate.account"
  103. placeholder="请输入登录名称"
  104. v-width="460"
  105. />
  106. </FormItem>
  107. </Col>
  108. <Col span="24">
  109. <FormItem label="供应商登录密码 :" prop="pwd">
  110. <Input
  111. v-model="formValidate.pwd"
  112. placeholder="请输入登录密码"
  113. v-width="460"
  114. />
  115. </FormItem>
  116. </Col>
  117. <Col span="24">
  118. <FormItem label="确认登录密码 :" prop="conf_pwd">
  119. <Input
  120. v-model="formValidate.conf_pwd"
  121. placeholder="请确认登录密码"
  122. v-width="460"
  123. />
  124. </FormItem>
  125. </Col>
  126. <Col span="24">
  127. <FormItem label="派单限额:">
  128. <InputNumber
  129. v-width="460"
  130. :min="0"
  131. v-model="formValidate.dispatch_total"
  132. placeholder="请输入派单限额"
  133. />
  134. </FormItem>
  135. </Col>
  136. <Col span="24">
  137. <FormItem label="排序:">
  138. <InputNumber
  139. v-width="460"
  140. :min="0"
  141. :max="999999"
  142. v-model="formValidate.sort"
  143. placeholder="请输入排序"
  144. />
  145. </FormItem>
  146. </Col>
  147. <Col span="24">
  148. <FormItem label="是否开启:">
  149. <i-switch
  150. v-model="formValidate.is_show"
  151. :true-value="1"
  152. :false-value="0"
  153. size="large"
  154. >
  155. <span slot="open">开启</span>
  156. <span slot="close">关闭</span>
  157. </i-switch>
  158. </FormItem>
  159. </Col>
  160. </Row>
  161. </Form>
  162. </Card>
  163. <Card
  164. :bordered="false"
  165. dis-hover
  166. class="fixed-card"
  167. :style="{ left: `${!menuCollapse ? '200px' : isMobile ? '0' : '80px'}` }"
  168. >
  169. <Form>
  170. <FormItem>
  171. <Button
  172. type="primary"
  173. class="submission"
  174. @click="handleSubmit('formValidate')"
  175. >保存</Button
  176. >
  177. </FormItem>
  178. </Form>
  179. </Card>
  180. </div>
  181. </template>
  182. <script>
  183. import { mapState, mapMutations } from 'vuex'
  184. import { getSupplier, addSupplier, putSupplier } from '@/api/supplier'
  185. import { cityApi } from '@/api/store'
  186. import Setting from "@/setting";
  187. export default {
  188. name: '',
  189. components: {},
  190. props: {},
  191. data() {
  192. return {
  193. roterPre: Setting.roterPre,
  194. width: 150,
  195. addresData: [],
  196. formValidate: {
  197. supplier_name: '',
  198. name: '',
  199. phone: '',
  200. detailed_address: '',
  201. address: '',
  202. addressSelect: [],
  203. email: '',
  204. mark: '',
  205. account: '',
  206. pwd: '',
  207. conf_pwd: '',
  208. is_show: 0,
  209. province: 0,
  210. city: 0,
  211. area: 0,
  212. street: 0,
  213. },
  214. ruleValidate: {
  215. supplier_name: [
  216. {
  217. required: true,
  218. message: '供应商不能为空',
  219. trigger: 'blur',
  220. },
  221. ],
  222. phone: [
  223. { required: true, message: '联系电话不能为空', trigger: 'blur' },
  224. {
  225. pattern: /^1[3456789]\d{9}$/,
  226. message: '手机号码格式不正确',
  227. trigger: 'blur',
  228. },
  229. ],
  230. account: [
  231. {
  232. required: true,
  233. message: '请输入用户名',
  234. trigger: 'blur',
  235. },
  236. ],
  237. address: [
  238. {
  239. required: true,
  240. message: '请填写具体地址',
  241. trigger: 'blur',
  242. },
  243. ],
  244. addressSelect: [
  245. {
  246. required: true,
  247. message: '请选择省市区',
  248. trigger: 'blur',
  249. },
  250. ],
  251. pwd: [
  252. {
  253. required: true,
  254. message: '请输入密码',
  255. trigger: 'blur',
  256. },
  257. ],
  258. conf_pwd: [
  259. {
  260. required: true,
  261. message: '密码不能为空',
  262. trigger: 'blur',
  263. },
  264. ],
  265. },
  266. }
  267. },
  268. computed: {
  269. ...mapState('admin/layout', ['isMobile', 'menuCollapse']),
  270. labelPosition() {
  271. return this.isMobile ? 'top' : 'right'
  272. },
  273. },
  274. watch: {},
  275. created() {
  276. let data = { pid: 0 }
  277. this.cityInfo(data)
  278. if (this.$route.params.id) {
  279. this.getSupplier()
  280. }
  281. },
  282. mounted() {},
  283. methods: {
  284. // 获取省市区
  285. cityInfo(data) {
  286. cityApi(data).then((res) => {
  287. this.addresData = res.data
  288. })
  289. },
  290. loadData(item, callback) {
  291. item.loading = true
  292. cityApi({ pid: item.value }).then((res) => {
  293. item.children = res.data
  294. item.loading = false
  295. callback()
  296. })
  297. },
  298. // 选择省市区
  299. addchack(e, selectedData) {
  300. e.forEach((i, index) => {
  301. if (index == 0) {
  302. this.formValidate.province = i
  303. } else if (index == 1) {
  304. this.formValidate.city = i
  305. } else if (index == 2) {
  306. this.formValidate.area = i
  307. } else {
  308. this.formValidate.street = i
  309. }
  310. })
  311. (this.formValidate.addressSelect)
  312. this.formValidate.address = selectedData.map((o) => o.label).join('')
  313. },
  314. // 添加供应商
  315. handleSubmit() {
  316. if (this.$route.params.id) {
  317. putSupplier(this.$route.params.id,this.formValidate)
  318. .then(async (res) => {
  319. this.$Message.success(res.msg)
  320. this.$router.push({ path: this.roterPre + '/supplier/menu/list' })
  321. })
  322. .catch((res) => {
  323. this.$Message.error(res.msg)
  324. })
  325. } else {
  326. addSupplier(this.formValidate)
  327. .then(async (res) => {
  328. this.$Message.success(res.msg)
  329. this.$router.push({ path: this.roterPre + '/supplier/menu/list' })
  330. })
  331. .catch((res) => {
  332. this.$Message.error(res.msg)
  333. })
  334. }
  335. },
  336. // 获取供应商信息
  337. getSupplier() {
  338. getSupplier(this.$route.params.id)
  339. .then(async (res) => {
  340. this.formValidate = res.data
  341. let addressSelect = []
  342. if (res.data.province) {
  343. addressSelect.push(res.data.province)
  344. }
  345. if (res.data.city) {
  346. addressSelect.push(res.data.city)
  347. }
  348. if (res.data.area) {
  349. addressSelect.push(res.data.area)
  350. }
  351. if (res.data.street) {
  352. addressSelect.push(res.data.street)
  353. }
  354. this.formValidate.addressSelect = addressSelect
  355. })
  356. .catch((res) => {
  357. this.$Message.error(res.msg)
  358. })
  359. },
  360. },
  361. }
  362. </script>
  363. <style scoped lang="less">
  364. .fixed-card {
  365. position: fixed;
  366. right: 0;
  367. bottom: 0;
  368. left: 200px;
  369. z-index: 99;
  370. box-shadow: 0 -1px 2px rgb(240, 240, 240);
  371. }
  372. .submission {
  373. margin-left: 50%;
  374. }
  375. </style>