edit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <div class="app-container">
  3. <div v-if="editType === 'add'" class="filter-container">
  4. <div class="filter-control">
  5. <span style="color: red;">在本页面,对每三个月给超级会员自动发放的优惠券进行配置,配置完成后下一阶段才生效(最少配置1个,最多5个)。</span>
  6. <el-button type="primary" icon="el-icon-plus" size="mini" :disabled="disabled" @click="handleAddList">新增优惠券</el-button>
  7. </div>
  8. </div>
  9. <div v-else class="filter-container">
  10. <div class="filter-control">
  11. <span>优惠月份:</span>
  12. <el-input
  13. v-model="formParams.month"
  14. placeholder="开始月份"
  15. clearable
  16. suffix-icon="el-icon-date"
  17. :disabled="true"
  18. style="width:100px;"
  19. />
  20. -
  21. <el-input
  22. v-model="formParams.endMonth"
  23. placeholder="结束月份"
  24. clearable
  25. suffix-icon="el-icon-date"
  26. :disabled="true"
  27. style="width:100px;"
  28. />
  29. <el-button type="primary" icon="el-icon-plus" size="mini" :disabled="disabled" style="margin-left: 30px;" @click="handleAddList">新增优惠券</el-button>
  30. </div>
  31. </div>
  32. <el-form ref="couponFrom" :model="form" label-width="100px">
  33. <div v-for="(formItem,index) in form.formList" :key="formItem.key" class="form-cell" :data-key="formItem.key">
  34. <el-form-item :label="`优惠券${index+1}:`" style="margin-bottom: 10px;" :rules="rules.couponType">
  35. <el-radio-group v-model="formItem.couponType">
  36. <el-radio :label="0">活动券</el-radio>
  37. <el-radio :label="1">品类券</el-radio>
  38. <el-radio :label="3">店铺券</el-radio>
  39. </el-radio-group>
  40. </el-form-item>
  41. <el-form-item label="供应商" :prop="`formList.${index}.shopData`" :hidden="formItem.couponType === 3 ? false : true" :rules="rules.shopData">
  42. <template v-if="formItem.shopData && formItem.shopData.length === 0">
  43. <el-button type="primary" autofocussize="mini" size="mini" icon="el-icon-plus" @click="handleShopDialogVisible(index)">选择供应商</el-button>
  44. <el-checkbox-group v-show="false" v-model="formItem.shopData" />
  45. </template>
  46. <template v-else>
  47. <el-table :data="formItem.shopData" border width="1000">
  48. <el-table-column prop="name" label="供应商名称" align="center" width="300" />
  49. <el-table-column prop="sname" label="供应商简称" align="center" width="200" />
  50. <el-table-column prop="linkMan" label="联系人" align="center" width="100" />
  51. <el-table-column prop="contractMobile" label="手机号" align="center" width="150">
  52. <template slot-scope="{ row }">
  53. {{ row.contractMobile ? row.contractMobile : '---' }}
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="操作" align="center">
  57. <el-button type="text" @click="deleteShop(index)">删除</el-button>
  58. </el-table-column>
  59. </el-table>
  60. </template>
  61. </el-form-item>
  62. <el-form-item label="优惠券金额:" :prop="`formList.${index}.couponAmount`" :rules="rules.couponAmount">
  63. <el-input v-model="formItem.couponAmount" style="width: 150px" size="mini" />
  64. </el-form-item>
  65. <el-form-item label="优惠条件:" :prop="`formList.${index}.touchPrice`" :rules="rules.touchPrice">
  66. <el-input v-model="formItem.touchPrice" style="width: 220px" size="mini">
  67. <template slot="prepend" style="padding: 0 10px;">订单商品总额满:</template>
  68. </el-input>
  69. </el-form-item>
  70. <el-form-item label="优惠商品:" :hidden="formItem.couponType === 0 ? false : true" style="margin-bottom: 10px;" :rules="rules.productType">
  71. <el-radio-group v-model="formItem.productType">
  72. <el-radio :label="'1'">全商城商品</el-radio>
  73. <el-radio :label="'2'">指定商品</el-radio>
  74. </el-radio-group>
  75. </el-form-item>
  76. <template v-if="formItem.productType === '2'&& formItem.couponType === 0">
  77. <el-form-item label="商品信息" :prop="`formList.${index}.associateList`" :rules="rules.associateList">
  78. <el-button type="primary" icon="el-icon-sort" size="mini" :disabled="disabled3(formItem.associateList)" @click="handleOnInputBlur(formItem,index)">一键排序</el-button>
  79. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleGoodDialogVisible(index)">添加商品</el-button>
  80. <el-checkbox-group v-show="false" v-model="formItem.associateList" />
  81. <el-table v-show="formItem.associateList && formItem.associateList.length>0" :data="formItem.associateList" border>
  82. <el-table-column property="mainImage" label="商品图片" align="center" width="80">
  83. <template slot-scope="{ row }">
  84. <el-popover
  85. placement="top-start"
  86. title=""
  87. width="180"
  88. trigger="hover"
  89. >
  90. <img :src="row.mainImage" alt="" style="width:150px;height:150px;">
  91. <img slot="reference" :src="row.mainImage" alt="" style="width:30px;height:30px;">
  92. </el-popover>
  93. </template>
  94. </el-table-column>
  95. <el-table-column property="name" label="商品名称" align="center" />
  96. <el-table-column property="shopName" label="供应商" align="center" />
  97. <el-table-column label="网站状态" align="center" width="80">
  98. <template slot-scope="scope">
  99. <el-switch
  100. v-model="scope.row.pcStatus"
  101. active-color="#1890ff"
  102. inactive-color="#DCDFE6"
  103. active-value="1"
  104. inactive-value="0"
  105. />
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="小程序状态" align="center" width="100">
  109. <template slot-scope="scope">
  110. <el-switch
  111. v-model="scope.row.appletsStatus"
  112. active-color="#1890ff"
  113. inactive-color="#DCDFE6"
  114. active-value="1"
  115. inactive-value="0"
  116. />
  117. </template>
  118. </el-table-column>
  119. <el-table-column label="排序" align="center" width="100">
  120. <template slot-scope="{row}">
  121. <el-input v-model="row.sort" maxlength="4" minlength="1" />
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="操作" align="center">
  125. <template slot-scope="scope">
  126. <el-button type="text" @click="handleDeletePros(formItem,scope.$index)">删除</el-button>
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. </el-form-item>
  131. </template>
  132. <el-form-item label="优惠品类:" :hidden="formItem.couponType ===1 ? false : true" :rules="rules.categoryType">
  133. <el-radio-group v-model="formItem.categoryType">
  134. <el-radio :label="'1'">产品</el-radio>
  135. <el-radio :label="'2'">仪器</el-radio>
  136. </el-radio-group>
  137. </el-form-item>
  138. <el-button class="delete_label" :disabled="disabled1" icon="el-icon-delete" size="mini" type="danger" @click="handleDelete(formItem,index)">删除</el-button>
  139. </div>
  140. </el-form>
  141. <div class="el-dialog__footer">
  142. <el-button type="primary" @click="onSubmit('couponFrom')">保存</el-button>
  143. </div>
  144. <!-- 供应商弹框 -->
  145. <shop-dialog v-if="dialogShopVisible" ref="shopDialog" @cancel="handleShopCancel" @confirm="handleShopConfirm" />
  146. <!-- 商品弹框 -->
  147. <good-dialog v-if="dialogGoodVisible" ref="goodDialog" @cancel="handleGoodCancel" @confirm="handleGoodConfirm" />
  148. </div>
  149. </template>
  150. <script>
  151. import { svipCoupon, saveVipCoupon, delCoupon } from '@/api/member/member'
  152. import goodDialog from './components/good-dialog'
  153. import shopDialog from './components/shop-dialog'
  154. const defaultForm = () => {
  155. return {
  156. shopId: 0,
  157. shopData: [],
  158. couponType: 0,
  159. couponAmount: '',
  160. touchPrice: '',
  161. productType: '1',
  162. categoryType: '1',
  163. associateList: []// 指定商品信息
  164. }
  165. }
  166. export default {
  167. name: 'MemberEdit',
  168. components: { goodDialog, shopDialog },
  169. data() {
  170. return {
  171. form: {
  172. formList: []
  173. },
  174. formParams: {
  175. id: '',
  176. month: '',
  177. endMonth: '',
  178. status: '',
  179. configure: 1, // 专属优惠券配置 1是、0否
  180. coupons: []
  181. },
  182. doctorId: '',
  183. editType: 'add',
  184. time: '',
  185. dialogTableVisible: false,
  186. shopTotal: 0,
  187. rows: [],
  188. // 供应商列表
  189. shopTableData: [],
  190. // 商品列表
  191. dialogProductVisible: false,
  192. productTableData: [],
  193. productTotal: 0,
  194. addIndex: 0,
  195. dialogShopVisible: false,
  196. dialogGoodVisible: false,
  197. rules: {
  198. couponType: [{ required: true, message: '请选择优惠券类型', trigger: 'blur' }],
  199. shopId: [{ required: true, message: '请选择供应商', trigger: 'blur' }],
  200. productType: [{ required: true, message: '请选择优惠商品', trigger: 'blur' }],
  201. shopData: [{ required: true, type: 'array', message: '请添加一个供应商', trigger: ['change'] }],
  202. associateList: [{ required: true, type: 'array', message: '请至少添加一个商品', trigger: ['change'] }],
  203. categoryType: [{ required: true, message: '请选择优惠品类', trigger: 'blur' }],
  204. couponAmount: [{ required: true, message: '优惠券金额不能为空', trigger: 'blur' }],
  205. touchPrice: [{ required: true, message: '优惠条件不能为空', trigger: 'blur' }]
  206. },
  207. delFlag: false
  208. }
  209. },
  210. computed: {
  211. disabled() {
  212. return this.form.formList.length === 5
  213. },
  214. disabled1() {
  215. return this.form.formList.length === 1
  216. }
  217. },
  218. created() {
  219. this.editType = this.$route.query.type || 'edit'
  220. console.log('editType', this.editType)
  221. this.initForm(this.editType)
  222. },
  223. methods: {
  224. initForm(type) {
  225. if (type === 'add') {
  226. console.log('add')
  227. this.svipCoupon(type, 1, 0)
  228. } else {
  229. console.log('edit')
  230. this.svipCoupon(type, 0, this.$route.query.id)
  231. }
  232. },
  233. async svipCoupon(type, configure, id) {
  234. const res = await svipCoupon({ id: id, configure: configure })
  235. const data = res.data.svipcouponForm
  236. this.formParams = { ...this.formParams, ...data }
  237. if (data.coupons.length > 0) {
  238. this.delFlag = true
  239. this.form.formList = data.coupons.map((el) => {
  240. el.shopData = []
  241. if (el.shop) {
  242. el.shopData.push(el.shop)
  243. }
  244. return el
  245. })
  246. console.log('formList', this.form.formList)
  247. } else {
  248. for (let i = 0; i <= 2; i++) {
  249. this.form.formList.push(defaultForm())
  250. }
  251. }
  252. },
  253. handleShopDialogVisible(index) {
  254. // 显示选择供应商弹窗
  255. this.addIndex = index
  256. this.dialogShopVisible = true
  257. },
  258. handleGoodDialogVisible(index) {
  259. // 显示选择商品弹窗
  260. this.addIndex = index
  261. this.dialogGoodVisible = true
  262. },
  263. // 清除供应商
  264. deleteShop(index) {
  265. this.form.formList[index].shopData = []
  266. },
  267. handleShopConfirm(data) {
  268. // 确认选择供应商
  269. this.form.formList[this.addIndex].shopId = data.shopId
  270. this.form.formList[this.addIndex].shopData.push(data)
  271. console.log('formList', this.form.formList[this.addIndex])
  272. this.handleShopCancel()
  273. },
  274. handleGoodConfirm(data) {
  275. // 确认选择商品
  276. console.log('data', data)
  277. console.log('addIndex', this.addIndex)
  278. const from = this.form.formList[this.addIndex]
  279. from.associateList.push(data)
  280. console.log('from', this.form.formList)
  281. this.handleGoodCancel()
  282. },
  283. handleDeletePros(formItem, index) {
  284. // 删除商品
  285. this.$confirm('确定删除吗?', '提示', {
  286. confirmButtonText: '确定',
  287. cancelButtonText: '取消',
  288. type: 'warning'
  289. }).then(() => {
  290. formItem.associateList.splice(index, 1)
  291. })
  292. },
  293. onSubmit(formName) {
  294. this.$refs[formName].validate(valid => {
  295. if (valid) {
  296. this.handleFormParams()
  297. this.$confirm('是否提交数据', '提示', {
  298. confirmButtonText: '确定',
  299. cancelButtonText: '取消',
  300. type: 'warning'
  301. }).then(() => {
  302. console.log('formParams', this.formParams)
  303. if (this.editType === 'add') {
  304. this.formParams.configure = 1
  305. } else {
  306. this.formParams.configure = 0
  307. }
  308. this.saveVipCoupon(this.formParams)
  309. })
  310. } else {
  311. return false
  312. }
  313. })
  314. },
  315. handleFormParams() {
  316. // 处理参数
  317. this.formParams.coupons = this.form.formList.map((el) => {
  318. if (el.associateList && el.associateList.length > 0) {
  319. el.associateList = el.associateList.map((pro) => {
  320. return {
  321. sort: pro.sort,
  322. pcStatus: pro.pcStatus,
  323. appletsStatus: pro.appletsStatus,
  324. name: pro.name,
  325. shopName: pro.shopName,
  326. mainImage: pro.mainImage,
  327. productId: pro.productId
  328. }
  329. })
  330. }
  331. return el
  332. })
  333. },
  334. async saveVipCoupon(params) {
  335. // 保存超级会员优惠券
  336. await saveVipCoupon(params)
  337. this.$message.success('保存成功')
  338. setTimeout(() => {
  339. this.$router.push({ path: '/member/coupon/list' })
  340. }, 1000)
  341. },
  342. handleShopCancel() {
  343. // 取消选择供应商
  344. this.dialogShopVisible = false
  345. this.$refs.shopDialog.visible = false
  346. },
  347. handleGoodCancel() {
  348. // 取消编辑商品
  349. this.dialogGoodVisible = false
  350. this.$refs.goodDialog.visible = false
  351. },
  352. handleAddList() {
  353. // 新增优惠券
  354. this.form.formList.push(defaultForm())
  355. },
  356. handleDelete(item, index) {
  357. // 删除单挑优惠券
  358. if (this.delFlag) {
  359. this.delCoupon(item.id, index)
  360. } else {
  361. this.form.formList.splice(index, 1)
  362. }
  363. },
  364. async delCoupon(id, index) {
  365. // 保存超级会员优惠券
  366. await delCoupon(id)
  367. this.form.formList.splice(index, 1)
  368. },
  369. handleOnInputBlur(formItem) {
  370. // 商品排序
  371. formItem.associateList.sort(this.sortByEnent('sort'))
  372. },
  373. sortByEnent(i) {
  374. // 排序
  375. return function(a, b) {
  376. return a[i] - b[i] // a[i] - b[i]为正序,倒叙为 b[i] - a[i]
  377. }
  378. },
  379. handlePcStatusChange(row) {
  380. // PC状态开启关闭
  381. console.log('row', row)
  382. if (row.pcStatus === '0') {
  383. row.pcStatus = '1'
  384. } else {
  385. row.pcStatus = '0'
  386. }
  387. },
  388. handleAppStatusChange(row) {
  389. // 小程序状态开启关闭
  390. if (row.appletsStatus === '0') {
  391. row.appletsStatus = '1'
  392. } else {
  393. row.appletsStatus = '0'
  394. }
  395. },
  396. disabled3(array) {
  397. if (array && array.length >= 2) {
  398. return false
  399. } else {
  400. return true
  401. }
  402. }
  403. }
  404. }
  405. </script>
  406. <style>
  407. .form-cell{
  408. border: 1px solid #e1e1e1;
  409. border-radius: 8px;
  410. box-sizing: border-box;
  411. box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.07);
  412. padding: 20px;
  413. position: relative;
  414. margin-bottom: 20px;
  415. }
  416. .delete_label{
  417. position: absolute;
  418. right: 2%;
  419. top: 20px;
  420. }
  421. </style>