edit.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. <template>
  2. <div v-loading="isLoading" class="addSupplier">
  3. <el-form ref="submitFormRef" :model="submitForm" :rules="formDataRules" label-width="120px" class="addForm">
  4. <el-form-item label="供应商类型:" prop="shopType">
  5. <el-select
  6. v-model="submitForm.shopType"
  7. placeholder="请选择供应商类型"
  8. style="width: 100%"
  9. :disabled="editType === 'edit'"
  10. @change="handleTypeChange"
  11. >
  12. <el-option label="品牌方" :value="1" />
  13. <el-option label="代理商" :value="2" />
  14. </el-select>
  15. </el-form-item>
  16. <!-- 供应商名称 -->
  17. <el-form-item v-if="submitForm.shopType === 2" label="供应商名称:" prop="shopName">
  18. <el-input
  19. v-model="submitForm.shopName"
  20. placeholder="请输入供应商名称"
  21. maxlength="50"
  22. show-word-limit
  23. :disabled="editType === 'edit'"
  24. />
  25. </el-form-item>
  26. <el-form-item v-if="submitForm.shopType === 1" clearable label="供应商名称:" prop="brandId">
  27. <el-select
  28. v-if="editType === 'add'"
  29. v-model="submitForm.brandId"
  30. placeholder="请选择品牌"
  31. style="width: 100%"
  32. filterable
  33. @change="handleBrandChange"
  34. >
  35. <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" />
  36. </el-select>
  37. <el-input
  38. v-else
  39. v-model="submitForm.shopName"
  40. placeholder="请输入供应商名称"
  41. maxlength="50"
  42. show-word-limit
  43. :disabled="editType === 'edit'"
  44. />
  45. </el-form-item>
  46. <!-- 供应商名称END -->
  47. <el-form-item label="手机号:" prop="mobile">
  48. <el-input
  49. v-model="submitForm.mobile"
  50. placeholder="请输入手机号"
  51. maxlength="11"
  52. show-word-limit
  53. @input="handleMobileInput"
  54. />
  55. </el-form-item>
  56. <el-form-item label="联系人:" prop="linkMan">
  57. <el-input v-model="submitForm.linkMan" placeholder="请输入联系人" />
  58. </el-form-item>
  59. <!-- 代理商logo -->
  60. <transition name="fade">
  61. <el-form-item v-if="submitForm.shopType === 2" label="代理商logo:" prop="logo">
  62. <el-input v-show="false" v-model="submitForm.logo" />
  63. <upload-image
  64. :limit="1"
  65. tip="建议尺寸:200px * 200px"
  66. :image-list="logoList"
  67. @success="uploadLogoImageSuccess"
  68. @remove="handleLogoImageRemove"
  69. />
  70. </el-form-item>
  71. </transition>
  72. <transition name="fade">
  73. <el-form-item v-if="submitForm.shopType === 2" label="代理品牌:" prop="shopInfo" class="brand-list">
  74. <template v-if="supplierBrands !== []">
  75. <el-tag
  76. v-for="(brand, index) in supplierBrands"
  77. :key="index"
  78. closable
  79. type="success"
  80. @close="handleRemoveBrand(brand)"
  81. @click="handleEditBrand(brand)"
  82. >{{ brand.brandName }}</el-tag>
  83. </template>
  84. <el-tag type="primary" @click="handleAddBrand">添加品牌<span class="el-icon-plus" /></el-tag>
  85. <el-input v-show="false" v-model="submitForm.shopInfo" />
  86. </el-form-item>
  87. </transition>
  88. <template v-if="submitForm.shopType === 1">
  89. <el-form-item label="产地:" prop="countryId">
  90. <el-select v-model="submitForm.countryId" placeholder="产地" style="width: 100%" filterable>
  91. <el-option
  92. v-for="item in countryList"
  93. :key="item.countryId"
  94. :label="item.countryName"
  95. :value="item.countryId"
  96. />
  97. </el-select>
  98. </el-form-item>
  99. <el-form-item label="品牌logo:" class="no-input" prop="brandAuthLogo">
  100. <upload-image
  101. tip="建议尺寸:200px * 200px"
  102. :image-list="brandAuthLogoList"
  103. @success="uploadBrandAuthSuccess"
  104. @remove="handleRemoveBrandAuthLogo"
  105. />
  106. <el-input v-show="false" v-model="submitForm.brandAuthLogo" />
  107. </el-form-item>
  108. <el-form-item label="官网认证链接:">
  109. <el-input v-model="submitForm.securityLink" placeholder="请输入官网认证链接" />
  110. </el-form-item>
  111. </template>
  112. <!-- 公众号信息 -->
  113. <el-form-item label="微信公众号:">
  114. <el-select v-model="submitForm.wxAccountType" placeholder="请选择微信公众号类型" style="width: 100%">
  115. <el-option label="请选择" :value="0" />
  116. <el-option label="服务号" :value="2" />
  117. <el-option label="订阅号" :value="1" />
  118. </el-select>
  119. </el-form-item>
  120. <transition-group name="fade">
  121. <template v-if="submitForm.wxAccountType !== 0">
  122. <el-form-item key="appID" label="appID:">
  123. <el-input v-model="submitForm.appId" placeholder="微信公众号appID" />
  124. </el-form-item>
  125. <el-form-item v-if="submitForm.wxAccountType === 2" key="appSecret" label="appSecret:">
  126. <el-input v-model="submitForm.appSecret" placeholder="微信公众号appsecret" />
  127. </el-form-item>
  128. <el-form-item key="qrCodeImage" label="公众号二维码:" prop="qrCodeImage">
  129. <upload-image
  130. tip="建议尺寸:200px * 200px"
  131. :image-list="qrCodeImageList"
  132. @success="uploadQrCodeImageSuccess"
  133. @remove="handleRemoveQrCodeImage"
  134. />
  135. <el-input v-show="false" v-model="submitForm.qrCodeImage" />
  136. </el-form-item>
  137. </template>
  138. </transition-group>
  139. <!-- 公众号信息END -->
  140. <el-form-item label="供应商状态:">
  141. <el-select v-model="submitForm.shopStatus" placeholder="请选择供应商状态" style="width: 100%">
  142. <el-option label="启用" :value="1" />
  143. <el-option label="禁用" :value="0" />
  144. </el-select>
  145. </el-form-item>
  146. </el-form>
  147. <div class="submit-btn">
  148. <el-button type="primary" @click="submit">保存</el-button>
  149. <el-button type="warning" @click="$_back()">返回</el-button>
  150. </div>
  151. <!-- 供应商添加品牌的对话框 -->
  152. <el-dialog :title="editBrandText" :visible.sync="dialogAddBrand" width="width" @close="handleDialogAddBrandClosed">
  153. <el-form ref="subFormRef" :model="subForm" label-width="120px" :rules="formDataRules">
  154. <el-form-item label="选择品牌:" prop="brandId">
  155. <el-select
  156. v-model="subForm.brandId"
  157. placeholder="请选择品牌"
  158. style="width: 100%"
  159. filterable
  160. @change="handleBrandChange"
  161. >
  162. <el-option v-for="item in otherBrandList" :key="item.id" :label="item.name" :value="item.id" />
  163. </el-select>
  164. </el-form-item>
  165. <el-form-item label="产地:" prop="countryId">
  166. <el-select v-model="subForm.countryId" placeholder="产地" style="width: 100%" filterable>
  167. <el-option
  168. v-for="item in countryList"
  169. :key="item.countryId"
  170. :label="item.countryName"
  171. :value="item.countryId"
  172. />
  173. </el-select>
  174. </el-form-item>
  175. <el-form-item label="品牌logo:" class="no-input" prop="brandAuthLogo">
  176. <upload-image
  177. tip="建议尺寸:200px * 200px"
  178. :image-list="brandAuthLogoList"
  179. @success="uploadBrandAuthSuccess"
  180. @remove="handleRemoveBrandAuthLogo"
  181. />
  182. <el-input v-show="false" v-model="subForm.brandAuthLogo" />
  183. </el-form-item>
  184. <el-form-item label="代理声明:" prop="statementType">
  185. <el-radio-group v-model="subForm.statementType" @change="handleStatementChange">
  186. <el-radio :label="1">弹窗</el-radio>
  187. <el-radio :label="2">链接</el-radio>
  188. <el-radio :label="3">图片</el-radio>
  189. <el-radio :label="4">文件</el-radio>
  190. </el-radio-group>
  191. </el-form-item>
  192. <el-form-item v-if="subForm.statementType === 1" ref="statement" label="弹窗:" prop="statementContent">
  193. <el-input v-model="subForm.statementContent" type="textarea" />
  194. </el-form-item>
  195. <el-form-item v-else-if="subForm.statementType === 2" ref="statement" label="链接:" prop="statementLink">
  196. <el-input v-model="subForm.statementLink" />
  197. </el-form-item>
  198. <el-form-item
  199. v-else-if="subForm.statementType === 3"
  200. ref="statement"
  201. label="图片:"
  202. class="no-input"
  203. prop="statementImage"
  204. >
  205. <upload-image
  206. tip="建议尺寸:200px * 200px"
  207. :image-list="statementImageList"
  208. @success="uploadStatementImageSuccess"
  209. @remove="handleRemoveStatementImage"
  210. />
  211. <el-input v-show="false" v-model="subForm.statementImage" />
  212. </el-form-item>
  213. <el-form-item v-else ref="statement" label="文件:" prop="statementFileId">
  214. <upload-file
  215. ref="fileUpload"
  216. :auto-upload="false"
  217. :data="uploadParams"
  218. :file-list="statementFileList"
  219. :before-upload="beforeUploadStatementFile"
  220. @success="uploadStatementFileSuccess"
  221. @remove="removeStatementFile"
  222. @change="changeStatementFile"
  223. />
  224. <el-input v-show="false" v-model="subForm.statementFileId" />
  225. </el-form-item>
  226. <el-form-item label="官网认证链接:" prop="securityLink">
  227. <el-input v-model="subForm.securityLink" placeholder="请输入官网认证链接" />
  228. </el-form-item>
  229. </el-form>
  230. <div slot="footer">
  231. <el-button @click="addBrandSubmitCancel">取 消</el-button>
  232. <el-button type="primary" :loading="submitLoading" @click="handleSaveBrand">确 定</el-button>
  233. </div>
  234. </el-dialog>
  235. </div>
  236. </template>
  237. <script>
  238. import UploadFile from '@/components/UploadFile'
  239. import UploadImage from '@/components/UploadImage'
  240. import { mapGetters } from 'vuex'
  241. import { isMobile } from '@/utils/validate'
  242. import { fetchBrandList } from '@/api/brand'
  243. import { deepClone } from '@/utils'
  244. import { addSupplier, getSupplierById } from '@/api/supplier'
  245. import { Promise } from 'jszip/lib/external'
  246. let uuid = 0
  247. export default {
  248. components: { UploadImage, UploadFile },
  249. data() {
  250. const validMobile = (rule, value, callback) => {
  251. if (!isMobile(value)) {
  252. return callback(new Error('手机号格式不正确'))
  253. }
  254. return callback()
  255. }
  256. const validShopInfo = (rule, value, callback) => {
  257. console.log(value)
  258. if (value <= 0) {
  259. return callback(new Error('代理品牌不能为空'))
  260. }
  261. return callback()
  262. }
  263. return {
  264. id: '', // 供应商id
  265. editType: '',
  266. isLoading: false,
  267. submitLoading: false,
  268. dialogAddBrand: false,
  269. brandTagClickType: '', // 品牌表单点击类型
  270. selectedShopType: 1, // 当前选中的供应商类型
  271. currentBrand: {}, // 当前选中的品牌
  272. selectedBrandIds: [], // 代理商已添加的品牌id
  273. editBrandInfo: {},
  274. // 表单1
  275. submitForm: {
  276. shopType: 1, // 供应商类型
  277. shopName: '', // 供应商名称
  278. brandId: '', // 品牌id
  279. mobile: '', // 手机号
  280. linkMan: '', // 联系人
  281. countryId: 1, // 产地id
  282. brandAuthLogo: '', // 品牌logo
  283. securityLink: '', // 官网认证链接
  284. shopStatus: 1, // 供应商状态,
  285. shopInfo: '',
  286. wxAccountType: 0,
  287. appId: '',
  288. appSecret: '',
  289. qrCodeImage: '', // 微信公众号二维码
  290. logo: '' // 代理商logo
  291. },
  292. // 表单2
  293. subForm: {
  294. brandId: '', // 品牌id
  295. countryId: 1, // 产地id
  296. brandAuthLogo: '', // 品牌logo
  297. securityLink: '', // 官网认证链接
  298. statementType: 1, // 代理声明类型
  299. statementContent: '', // 声明内容
  300. statementFileId: null, // 声明文件id
  301. statementImage: '', // 声明图片
  302. statementLink: '' // 声明链接
  303. },
  304. supplierBrands: [],
  305. brandList: [],
  306. // 表单数据校验
  307. formDataRules: {
  308. shopType: { required: true, message: '供应商类型不能为空', tigger: 'change', type: 'number' },
  309. shopName: { required: true, message: '供应名称不能为空', tigger: 'change' },
  310. mobile: [
  311. { required: true, message: '手机号不能为空', tigger: 'change' },
  312. { validator: validMobile, tigger: 'change' }
  313. ],
  314. linkMan: { required: true, message: '联系人不能为空', tigger: 'blur' },
  315. countryId: { required: true, message: '产地不能为空', tigger: 'change', type: 'number' },
  316. brandAuthLogo: { required: true, message: '品牌logo不能为空', tigger: 'change' },
  317. shopInfo: [
  318. { required: true, message: '代理品牌不能为空', tigger: 'change', type: 'number' },
  319. { validator: validShopInfo, tigger: 'change' }
  320. ],
  321. brandId: { required: true, message: '品牌不能为空', tigger: 'change', type: 'number' },
  322. statementContent: { required: true, message: '声明内容不能为空', tigger: 'change' }, // 声明内容
  323. statementFileId: { required: true, message: '声明文件不能为空', tigger: 'change', type: 'number' }, // 声明文件id
  324. statementImage: { required: true, message: '声明图片不能为空', tigger: 'change' }, // 声明图片
  325. statementLink: { required: true, message: '声明链接不能为空', tigger: 'change' }, // 声明链接,
  326. logo: { required: true, message: '代理商logo不能为空', tigger: 'change' }
  327. },
  328. // 上传图片列表
  329. logoList: [],
  330. brandAuthLogoList: [],
  331. qrCodeImageList: [],
  332. // brandAuthLogoList:[],
  333. statementImageList: [],
  334. // 上传的文件列表
  335. statementFileList: [], // 文件
  336. statementFileName: '' // 声明文件名称 临时
  337. }
  338. },
  339. computed: {
  340. ...mapGetters(['countryList', 'authUserId']),
  341. // 去除重复的品牌后的列表
  342. otherBrandList() {
  343. if (this.brandTagClickType === 'add') {
  344. return this.brandList.filter((item) => this.selectedBrandIds.indexOf(item.id) === -1)
  345. }
  346. if (this.brandTagClickType === 'edit') {
  347. const exclude = this.selectedBrandIds.filter((id) => id !== this.editBrandInfo.brandId)
  348. return this.brandList.filter((item) => exclude.indexOf(item.id) === -1)
  349. }
  350. return this.brandList
  351. },
  352. // 文件上传参数
  353. uploadParams() {
  354. return {
  355. brandId: this.currentBrand.id,
  356. authUserId: this.id
  357. }
  358. },
  359. // 文案提示
  360. editTypeText() {
  361. return this.editType === 'edit' ? '修改' : '添加'
  362. },
  363. editBrandText() {
  364. return this.brandTagClickType === 'edit' ? '修改品牌' : '添加品牌'
  365. }
  366. },
  367. watch: {
  368. // 根据供应商类型变化获取品牌列表
  369. selectedShopType(nVal) {
  370. this.getBrandList(nVal)
  371. }
  372. },
  373. created() {
  374. this.editType = this.$route.query.type || 'add'
  375. this.id = parseInt(this.$route.query.id) || ''
  376. this.getBrandList(this.selectedShopType)
  377. this.fetchSupplierInfo()
  378. },
  379. methods: {
  380. /** 数据回显 */
  381. // 获取供应商信息
  382. fetchSupplierInfo() {
  383. if (!this.id) return
  384. getSupplierById({ authUserId: this.id }).then((res) => {
  385. this.initSupplierInfo(res.data)
  386. })
  387. },
  388. // 初始化供应商信息
  389. initSupplierInfo(info) {
  390. for (const key in this.submitForm) {
  391. if (Object.hasOwnProperty.call(info, key)) {
  392. this.submitForm[key] = info[key]
  393. }
  394. }
  395. this.selectedShopType = info.shopType
  396. if (this.selectedShopType === 1) {
  397. // 品牌方
  398. const shopInfo = info.shopInfo[0]
  399. this.submitForm.brandId = shopInfo.brandId
  400. this.submitForm.countryId = shopInfo.countryId
  401. this.submitForm.brandAuthLogo = shopInfo.brandAuthLogo
  402. this.submitForm.securityLink = shopInfo.securityLink
  403. this.submitForm.brandName = shopInfo.brandName
  404. if (shopInfo.brandAuthLogo) {
  405. this.brandAuthLogoList = [{ name: shopInfo.brandName, url: shopInfo.brandAuthLogo }]
  406. }
  407. } else {
  408. // 代理商
  409. this.supplierBrands = info.shopInfo.map((item) => {
  410. item.uuid = ++uuid
  411. this.selectedBrandIds.push(item.brandId)
  412. return item
  413. })
  414. // 代理商logo
  415. if (this.submitForm.logo) {
  416. this.logoList = [{ name: this.submitForm.brandName, url: this.submitForm.logo }]
  417. }
  418. this.submitForm.shopInfo = this.supplierBrands.length
  419. }
  420. // 微信公众号二维码
  421. if (this.submitForm.qrCodeImage) {
  422. this.qrCodeImageList = [{ name: '', url: this.submitForm.qrCodeImage }]
  423. }
  424. },
  425. /** 数据回显END */
  426. // 提交保存
  427. async submit() {
  428. try {
  429. await this.$refs.submitFormRef.validate()
  430. } catch (err) {
  431. return
  432. }
  433. this.isLoading = true
  434. let params = {}
  435. if (this.selectedShopType === 1) {
  436. params = this.getBrandParams()
  437. } else {
  438. params = this.getShopParams()
  439. }
  440. // 设置创建人
  441. params.createBy = this.authUserId
  442. params.authUserId = this.id
  443. console.log(params)
  444. addSupplier(params)
  445. .then((res) => {
  446. this.$message.success(`${this.editTypeText}供应商成功`)
  447. this.$store.dispatch('tagsView/delView', this.$route)
  448. this.$router.replace('/supplier/list')
  449. })
  450. .finally(() => {
  451. this.isLoading = false
  452. })
  453. },
  454. /** 封装请求参数 */
  455. // 代理商参数
  456. getShopParams() {
  457. const params = {
  458. shopType: 2, // 供应商类型
  459. shopName: '', // 供应商名称
  460. logo: '', // 代理商logo
  461. mobile: '', // 手机号
  462. linkMan: '', // 联系人
  463. securityLink: '', // 官网认证链接
  464. shopStatus: 1, // 供应商状态,
  465. wxAccountType: 2,
  466. appId: '',
  467. appSecret: '',
  468. qrCodeImage: '' // 微信公众号二维码
  469. }
  470. for (const key in params) {
  471. if (Object.hasOwnProperty.call(this.submitForm, key)) {
  472. params[key] = this.submitForm[key]
  473. }
  474. }
  475. params.shopInfo = deepClone(this.supplierBrands).map((item) => {
  476. delete item.statementFileName
  477. delete item.uuid
  478. return item
  479. })
  480. return params
  481. },
  482. // 品牌方参数
  483. getBrandParams() {
  484. const params = {
  485. shopType: 1, // 供应商类型
  486. mobile: '', // 手机号
  487. linkMan: '', // 联系人
  488. wxAccountType: 2,
  489. appId: '',
  490. appSecret: '',
  491. qrCodeImage: '', // 微信公众号二维码
  492. shopStatus: 1 // 供应商状态,
  493. }
  494. for (const key in params) {
  495. if (Object.hasOwnProperty.call(this.submitForm, key)) {
  496. params[key] = this.submitForm[key]
  497. }
  498. }
  499. params.shopName = this.currentBrand.name
  500. params.shopInfo = [
  501. {
  502. brandId: this.submitForm.brandId,
  503. countryId: this.submitForm.countryId,
  504. brandAuthLogo: this.submitForm.brandAuthLogo,
  505. securityLink: this.submitForm.securityLink,
  506. statementType: 1,
  507. statementContent: '',
  508. statementFileId: null,
  509. statementImage: '',
  510. statementLink: ''
  511. }
  512. ]
  513. return params
  514. },
  515. // 大理上添加
  516. /** 封装请求参数 end */
  517. // 品牌改变事件
  518. handleBrandChange(id) {
  519. console.log(id)
  520. this.currentBrand = this.brandList.find((item) => item.id === id)
  521. this.brandAuthLogoList = [{ name: this.currentBrand.name, url: this.currentBrand.authLogo }]
  522. this.submitForm.brandAuthLogo = this.currentBrand.authLogo
  523. this.subForm.brandAuthLogo = this.currentBrand.authLogo
  524. },
  525. /** 品牌标签操作 */
  526. // 添加品牌对话框
  527. handleAddBrand() {
  528. this.brandTagClickType = 'add'
  529. // 文件上传参数
  530. this.dialogAddBrand = true
  531. },
  532. // 修改品牌
  533. handleEditBrand(row) {
  534. this.brandTagClickType = 'edit'
  535. // 等待dialog表单渲染完成后再设置值
  536. this.$nextTick(() => {
  537. this.editBrandInfo = row
  538. // 设置选中品牌信息
  539. this.currentBrand.id = row.brandId
  540. this.currentBrand.name = row.brandName
  541. this.currentBrand.authLogo = row.brandAuthLogo
  542. this.statementFileName = row.statementFileName
  543. if (row.brandAuthLogo) {
  544. this.brandAuthLogoList = [{ name: row.brandName, url: row.brandAuthLogo }]
  545. }
  546. if (row.statementImage) {
  547. this.statementImageList = [{ name: row.brandName, url: row.statementImage }]
  548. }
  549. if (row.statementFileId) {
  550. this.statementFileList = [{ name: row.statementFileName }]
  551. }
  552. for (const key in this.subForm) {
  553. if (Object.hasOwnProperty.call(this.editBrandInfo, key)) {
  554. this.subForm[key] = this.editBrandInfo[key]
  555. }
  556. }
  557. console.log(this.subForm)
  558. })
  559. this.dialogAddBrand = true
  560. },
  561. // 移除品牌
  562. handleRemoveBrand(row) {
  563. // 从已选品牌id列表中移除
  564. this.selectedBrandIds.splice(this.selectedBrandIds.indexOf(row.brandId), 1)
  565. // 从已添加品牌列表中移除
  566. const findIndex = this.supplierBrands.findIndex((item) => item.uuid === row.uuid)
  567. this.supplierBrands.splice(findIndex, 1)
  568. this.submitForm.shopInfo = this.supplierBrands.length
  569. },
  570. // 保存品牌
  571. async handleSaveBrand() {
  572. if (this.subForm.statementType === 4) {
  573. console.log('有文件上传')
  574. if (!this.subForm.statementFileId || this.subForm.statementFileId === -1) {
  575. this.submitLoading = true
  576. this.$refs.fileUpload.$refs.fileUpload.submit()
  577. return
  578. }
  579. }
  580. try {
  581. await this.$refs.subFormRef.validate()
  582. this.handleSaveBrandAction()
  583. } catch (error) {
  584. console.log(error)
  585. }
  586. },
  587. // 取消保存品牌
  588. addBrandSubmitCancel() {
  589. // 取消上传文件
  590. if (this.$refs.fileUpload) {
  591. this.$refs.fileUpload.$refs.fileUpload.abort()
  592. this.$message.info('文件上传已取消')
  593. }
  594. this.dialogAddBrand = false
  595. },
  596. // 保存品牌操作
  597. handleSaveBrandAction() {
  598. // 深度克隆数据
  599. const brandInfo = deepClone(this.subForm)
  600. // 保存已添加品牌id
  601. this.selectedBrandIds.push(this.currentBrand.id)
  602. // 设置品牌名称(显示使用)
  603. brandInfo.brandName = this.currentBrand.name
  604. brandInfo.brandAuthLogo = this.currentBrand.authLogo
  605. brandInfo.statementFileName = this.statementFileName
  606. if (this.brandTagClickType === 'add') {
  607. // 设置唯一id
  608. brandInfo.uuid = ++uuid
  609. // 保存数据到代理商品牌列表
  610. this.supplierBrands.push(brandInfo)
  611. }
  612. if (this.brandTagClickType === 'edit') {
  613. // 使用新数据替换旧数据
  614. const findIndex = this.supplierBrands.findIndex((item) => item.uuid === this.editBrandInfo.uuid)
  615. this.supplierBrands.splice(findIndex, 1, brandInfo)
  616. }
  617. this.dialogAddBrand = false
  618. },
  619. // 添加品牌对话框关闭
  620. handleDialogAddBrandClosed() {
  621. this.subForm.securityLink = ''
  622. this.subForm.statementType = 1
  623. this.statementFileName = ''
  624. this.statementImageList = []
  625. this.statementFileList = []
  626. this.brandAuthLogoList = []
  627. this.currentBrand = {}
  628. this.submitForm.shopInfo = this.supplierBrands.length
  629. // 按钮loading结束
  630. this.submitLoading = false
  631. // 初始化表单
  632. this.$refs.subFormRef.resetFields()
  633. console.log(this.subForm)
  634. },
  635. // 声明类型切换
  636. handleStatementChange() {
  637. this.$refs.statement.clearValidate()
  638. },
  639. // 供应商类型改变事件
  640. handleTypeChange(type) {
  641. this.selectedShopType = type
  642. this.brandAuthLogoList = []
  643. this.statementImageList = []
  644. this.currentBrand = {}
  645. },
  646. // 获取品牌列表
  647. getBrandList(type) {
  648. fetchBrandList({ type }).then((res) => {
  649. if (res.code !== 0) {
  650. return
  651. }
  652. this.brandList = res.data
  653. })
  654. },
  655. /** 品牌标签操作END */
  656. // 输入框输入时
  657. handleMobileInput() {
  658. this.submitForm.mobile = this.submitForm.mobile.replace(/[^\w\.\/]/gi, '')
  659. },
  660. /** 图片上传 */
  661. // 代理商logo
  662. uploadLogoImageSuccess({ response, file, fileList }) {
  663. this.logoList = fileList
  664. this.submitForm.logo = response.data
  665. },
  666. handleLogoImageRemove({ file, fileList }) {
  667. this.logoList = fileList
  668. this.submitForm.logo = ''
  669. },
  670. // 品牌logo
  671. uploadBrandAuthSuccess({ response, file, fileList }) {
  672. this.brandAuthLogoList = fileList
  673. this.submitForm.brandAuthLogo = response.data
  674. this.subForm.brandAuthLogo = response.data
  675. },
  676. handleRemoveBrandAuthLogo({ file, fileList }) {
  677. this.brandAuthLogoList = fileList
  678. this.submitForm.brandAuthLogo = ''
  679. this.subForm.brandAuthLogo = ''
  680. },
  681. // 公众号二维码
  682. uploadQrCodeImageSuccess({ response, file, fileList }) {
  683. this.qrCodeImageList = fileList
  684. this.submitForm.qrCodeImage = response.data
  685. },
  686. handleRemoveQrCodeImage({ file, fileList }) {
  687. this.qrCodeImageList = fileList
  688. this.submitForm.qrCodeImage = ''
  689. },
  690. // 声明图片
  691. uploadStatementImageSuccess({ response, file, fileList }) {
  692. this.statementImageList = fileList
  693. this.subForm.statementImage = response.data
  694. },
  695. handleRemoveStatementImage({ file, fileList }) {
  696. this.statementImageList = fileList
  697. this.subForm.statementImage = ''
  698. },
  699. /** 文件上传 */
  700. uploadStatementFileSuccess({ response, file, fileList }) {
  701. this.statementFileList = fileList
  702. this.subForm.statementFileId = response.data.fileId
  703. this.statementFileName = response.data.fileName
  704. // 验证表单数据并保存
  705. this.$refs.subFormRef.validate((valide) => {
  706. if (!valide) return
  707. this.handleSaveBrandAction()
  708. })
  709. },
  710. removeStatementFile({ file, fileList }) {
  711. this.statementFileList = []
  712. this.subForm.statementFileId = null
  713. },
  714. changeStatementFile({ file, fileList }) {
  715. this.statementFileList = fileList
  716. this.subForm.statementFileId = -1
  717. },
  718. beforeUploadStatementFile(file) {
  719. const maxSize = 30
  720. if (file.size <= maxSize * 1024 * 1024) return true
  721. return this.$confirm(`您上传的文件大于${maxSize}MB,是否继续上传?文件上传过程中请您耐心等待!`, '文件上传提示', {
  722. confirmButtonText: '继续',
  723. cancelButtonText: '取消',
  724. type: 'warning'
  725. })
  726. .then(() => {
  727. return Promise.resolve()
  728. })
  729. .catch(() => {
  730. this.$message.info('已取消上传')
  731. this.submitLoading = false
  732. return Promise.reject()
  733. })
  734. }
  735. }
  736. }
  737. </script>
  738. <style lang="scss" scoped>
  739. .addSupplier {
  740. margin-bottom: 80px;
  741. }
  742. .addForm {
  743. width: 500px;
  744. margin: 0 auto;
  745. margin-top: 80px;
  746. .brand-list {
  747. .el-tag {
  748. margin-right: 5px;
  749. cursor: pointer;
  750. }
  751. }
  752. }
  753. .submit-btn {
  754. text-align: center;
  755. .el-button {
  756. width: 140px;
  757. }
  758. }
  759. .hiddenInput {
  760. display: none;
  761. }
  762. </style>