index.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. <template>
  2. <div class="app-container">
  3. <div class="tab-container clearfix">
  4. <div class="tab-list fl">
  5. <div class="item" :class="screenForm.type === '' ? 'current':''" @click="changeType('')">全部({{ goodsStateCount.total ? goodsStateCount.total : 0 }})</div>
  6. <div class="item" :class="screenForm.type === 'S' ? 'current':''" @click="changeType('S')">出售中({{ goodsStateCount.csz ? goodsStateCount.csz : 0 }})</div>
  7. <div class="item" :class="screenForm.type === 'O' ? 'current':''" @click="changeType('O')">已售罄({{ goodsStateCount.ysq ? goodsStateCount.ysq : 0 }})</div>
  8. <div class="item" :class="screenForm.type === 'W' ? 'current':''" @click="changeType('W')">仓库中({{ goodsStateCount.ckz ? goodsStateCount.ckz : 0 }})</div>
  9. <div class="item" :class="screenForm.type === 'A' ? 'current':''" @click="changeType('A')">活动中({{ goodsStateCount.hdz ? goodsStateCount.hdz : 0 }})</div>
  10. </div>
  11. <!-- <el-button type="primary" size="small" @click="addOrEdit('add')">添加商品</el-button> -->
  12. </div>
  13. <div class="screen2-container">
  14. <el-row :gutter="20">
  15. <el-col :xs="24" :sm="2" :lg="3" style="opacity: 0;">.</el-col>
  16. <el-col :xs="24" :sm="20" :lg="18">
  17. <el-form ref="form" :model="screenForm" label-width="80px">
  18. <div class="search">
  19. <el-input v-model="screenForm.keyword" placeholder="想快速搜索什么商品呢?输入商品名称,商品id,商品分类都可快速找到" class="input-with-select" clearable @change="getListByScreen">
  20. <el-button slot="append" icon="el-icon-search" @click="getListByScreen"></el-button>
  21. </el-input>
  22. </div>
  23. <div class="screen clearfix">
  24. <el-row :gutter="20">
  25. <el-col :xs="8" :sm="8" :lg="4">
  26. <el-form-item label-width="0">
  27. <el-cascader
  28. v-model="screenForm.classify"
  29. :options="classifyList"
  30. :props="{ label: 'name', value: 'categoryId' }"
  31. size="small"
  32. @change="getListByScreen">
  33. </el-cascader>
  34. <!-- <el-select v-model="screenForm.classify" placeholder="全部" size="small" @change="getListByScreen">
  35. <el-option label="商品分类" value=""></el-option>
  36. <el-option :label="item.name" :value="item.categoryId" v-for="item in classifyList" :key="item.categoryId"></el-option>
  37. </el-select> -->
  38. </el-form-item>
  39. </el-col>
  40. <el-col :xs="8" :sm="8" :lg="4">
  41. <el-form-item label-width="0">
  42. <el-select v-model="screenForm.status" placeholder="上下架状态" size="small" clearable @change="getListByScreen">
  43. <el-option :label="item.label" :value="item.value" v-for="(item, index) in select_status" :key="index"></el-option>
  44. </el-select>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :xs="8" :sm="8" :lg="4">
  48. <el-form-item label-width="0">
  49. <el-select v-model="screenForm.isTrade" placeholder="是否支持以旧换新" size="small" clearable @change="getListByScreen">
  50. <el-option label="支持以旧换新" value="YES"></el-option>
  51. <el-option label="不支持以旧换新" value="NO"></el-option>
  52. </el-select>
  53. </el-form-item>
  54. </el-col>
  55. <el-col :xs="12" :sm="12" :lg="6">
  56. <el-form-item label="销售价格" label-width="80px">
  57. <el-input v-model="screenForm.price1" size="small" @change="getListByScreen" clearable ></el-input>
  58. <span>至</span>
  59. <el-input v-model="screenForm.price2" size="small" @change="getListByScreen" clearable ></el-input>
  60. </el-form-item>
  61. </el-col>
  62. <el-col :xs="12" :sm="12" :lg="6">
  63. <el-form-item label="分销金额" label-width="80px">
  64. <el-input v-model="screenForm.amount1" size="small" @change="getListByScreen" clearable ></el-input>
  65. <span>至</span>
  66. <el-input v-model="screenForm.amount2" size="small" @change="getListByScreen" clearable ></el-input>
  67. </el-form-item>
  68. </el-col>
  69. </el-row>
  70. </div>
  71. </el-form>
  72. </el-col>
  73. <el-col :xs="24" :sm="2" :lg="3" style="opacity: 0;">.</el-col>
  74. </el-row>
  75. </div>
  76. <div class="mymain-container">
  77. <div class="btn-group clearfix">
  78. <div class="fl">
  79. <el-button v-if="$restrict('add')" type="primary" icon="el-icon-plus" size="small" @click="addOrEdit('add')">添加商品</el-button>
  80. <el-button v-if="$restrict('batchSet')" size="small" @click="batchOperation('module')">批量设置模块</el-button>
  81. <el-button v-if="$restrict('batchSetfreight')" size="small" @click="batchOperation('freight')">批量设置运费</el-button>
  82. <el-divider direction="vertical"></el-divider>
  83. <el-button v-if="$restrict('batchLaunch')" size="small" @click="batchOperation('status', 'on')">批量上架</el-button>
  84. <el-button v-if="$restrict('batchRemova')" size="small" @click="batchOperation('status', 'off')">批量下架</el-button>
  85. <el-divider direction="vertical"></el-divider>
  86. <el-button v-if="$restrict('batchTrade')" size="small" @click="batchOperation('isTrade', 'YES')">开启以旧换新</el-button>
  87. <el-button v-if="$restrict('batchTrade')" size="small" @click="batchOperation('isTrade', 'NO')">关闭以旧换新</el-button>
  88. </div>
  89. </div>
  90. <div class="table">
  91. <el-table v-loading="listLoading" :data="dataList" element-loading-text="Loading" border fit highlight-current-row stripe @selection-change="handleTableSelection">
  92. <el-table-column align="center" type="selection" width="55" fixed></el-table-column>
  93. <el-table-column align="center" label="商品图片" prop="imgUrl" width="85">
  94. <template slot-scope="scope">
  95. <el-image style="width: 60px; height: 60px; display: block;" :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]" fit="cover"></el-image>
  96. </template>
  97. </el-table-column>
  98. <el-table-column align="center" label="商品名称" prop="goodsName" min-width="200">
  99. <template slot-scope="scope">
  100. <!-- {{ scope.row.goodsName }} -->
  101. <span style="margin-right: 10px">{{ scope.row.goodsName }}</span>
  102. <i class="el-icon-edit pointer" @click="editData('goodsName', scope.row)"></i>
  103. </template>
  104. </el-table-column>
  105. <el-table-column align="center" label="状态" class-name="status-col">
  106. <template slot-scope="scope">
  107. <div style="display: flex; flex-wrap: wrap; align-items: center; justify-content: center;">
  108. <el-tag size="small" :type="scope.row.status ? 'success':'danger'">{{ scope.row.status ? '上架':'下架' }}</el-tag>
  109. <el-tag size="small" v-if="scope.row.promotionGroup" style="margin-top: 4px;">团购商品</el-tag>
  110. </div>
  111. </template>
  112. </el-table-column>
  113. <el-table-column align="center" label="销售价格" prop="goodsPrice" min-width="110" sortable>
  114. <template slot-scope="scope">
  115. <!-- ¥{{ scope.row.goodsPrice }} -->
  116. <span style="margin-right: 10px">¥{{ scope.row.goodsPrice }}</span>
  117. <i class="el-icon-edit pointer" @click="editData('price', scope.row)"></i>
  118. </template>
  119. </el-table-column>
  120. <el-table-column align="center" label="分销金额" prop="shareAmount" min-width="110" sortable>
  121. <template slot-scope="scope">
  122. <!-- ¥{{ scope.row.shareAmount }} -->
  123. <span style="margin-right: 10px">¥{{ scope.row.shareAmount }}</span>
  124. <i class="el-icon-edit pointer" @click="editData('shareAmount', scope.row)"></i>
  125. </template>
  126. </el-table-column>
  127. <el-table-column align="center" label="佣金比例" prop="sharePercent" min-width="110" sortable>
  128. <template slot-scope="scope">
  129. <!-- ¥{{ scope.row.sharePercent }} -->
  130. <span style="margin-right: 10px">{{ scope.row.sharePercent }}%</span>
  131. <i class="el-icon-edit pointer" @click="editData('sharePercent', scope.row)"></i>
  132. </template>
  133. </el-table-column>
  134. <el-table-column align="center" label="内部分销金额" prop="innerShareAmount" min-width="130" sortable>
  135. <template slot-scope="scope">
  136. <!-- ¥{{ scope.row.sharePercent }} -->
  137. <span style="margin-right: 10px">¥{{ scope.row.innerShareAmount }}</span>
  138. <i class="el-icon-edit pointer" @click="editData('innerShareAmount', scope.row)"></i>
  139. </template>
  140. </el-table-column>
  141. <el-table-column align="center" label="内部佣金比列" prop="innerSharePercent" min-width="130" sortable>
  142. <template slot-scope="scope">
  143. <!-- ¥{{ scope.row.sharePercent }} -->
  144. <span style="margin-right: 10px">{{ scope.row.innerSharePercent }}%</span>
  145. <i class="el-icon-edit pointer" @click="editData('innerSharePercent', scope.row)"></i>
  146. </template>
  147. </el-table-column>
  148. <el-table-column align="center" label="商品库存" prop="stockNum" min-width="110" sortable>
  149. <template slot-scope="scope">
  150. <!-- {{ scope.row.stockNum }} -->
  151. <span style="margin-right: 10px">{{ scope.row.stockNum }}</span>
  152. <i class="el-icon-edit pointer" @click="editData('stockNum', scope.row)"></i>
  153. </template>
  154. </el-table-column>
  155. <el-table-column align="center" label="仓库库存" prop="allStockNum" min-width="110" sortable>
  156. <template slot-scope="scope">
  157. <span style="margin-right: 10px">{{ scope.row.allStockNum || 0 }}</span>
  158. <i class="el-icon-s-data pointer" @click="editData('stockNum', scope.row)"></i>
  159. </template>
  160. </el-table-column>
  161. <el-table-column align="center" label="销量" prop="soldNum" min-width="110" sortable></el-table-column>
  162. <el-table-column align="center" label="是否支持以旧换新" prop="isTrade" min-width="130">
  163. <template slot-scope="scope">
  164. {{ {YES: '支持', NO: '不支持'}[scope.row.isTrade] }}
  165. </template>
  166. </el-table-column>
  167. <el-table-column align="center" label="排序" prop="sortNum" min-width="110" sortable>
  168. <template slot-scope="scope">
  169. <!-- {{ scope.row.sortNum }} -->
  170. <span style="margin-right: 10px">{{ scope.row.sortNum }}</span>
  171. <i class="el-icon-edit pointer" @click="editData('sortNum', scope.row)"></i>
  172. </template>
  173. </el-table-column>
  174. <el-table-column align="center" label="商户" prop="companyName" min-width="120"></el-table-column>
  175. <el-table-column align="center" label="操作" width="280" fixed="right">
  176. <template slot-scope="scope">
  177. <!-- <template>
  178. <el-popconfirm v-if="scope.row.status" style="margin-right: 10px;" title="确定冻结吗?" @confirm="changeMemberStatus(scope.row.goodsId, 0)" >
  179. <el-button slot="reference" type="text">冻结</el-button>
  180. </el-popconfirm>
  181. <el-popconfirm v-else style="margin-right: 10px;" title="确定恢复吗?" @confirm="changeMemberStatus(scope.row.goodsId, 1)" >
  182. <el-button slot="reference" type="text">恢复</el-button>
  183. </el-popconfirm>
  184. </template> -->
  185. <el-button v-if="$restrict('edit')" type="primary" size="mini" @click="addOrEdit('edit', scope.row.goodsId)">编辑</el-button>
  186. <el-popconfirm v-if="$restrict('clone')" style="margin-left: 10px; margin-right: 10px" title="确定克隆吗?" @confirm="clone(scope.row.goodsId)" >
  187. <el-button slot="reference" type="primary" size="mini">克隆</el-button>
  188. </el-popconfirm>
  189. <el-button v-if="$restrict('copyLink')" type="primary" size="mini" class="tag-read" @click="copy(scope.row.goodsId)" :data-clipboard-text="scope.row.goodsId">复制链接</el-button>
  190. <el-popconfirm v-if="$restrict('del')" style="margin-left: 10px;" title="确定删除吗?" @confirm="delItem(scope.row.goodsId, scope.row.goodsSpecId)" >
  191. <el-button slot="reference" size="mini">删除</el-button>
  192. </el-popconfirm>
  193. </template>
  194. </el-table-column>
  195. </el-table>
  196. </div>
  197. <div class="pagination clearfix">
  198. <div class="fr">
  199. <el-pagination
  200. @size-change="handleSizeChange"
  201. @current-change="handleCurrentChange"
  202. :current-page="currentPage"
  203. :page-sizes="[10, 20, 50, 100]"
  204. :page-size="10"
  205. layout="total, sizes, prev, pager, next, jumper"
  206. :total="listTotal">
  207. </el-pagination>
  208. </div>
  209. </div>
  210. </div>
  211. <!-- 编辑规格数据 -->
  212. <el-dialog title="编辑" :visible.sync="editSpecVisible" :show-close="false" width="60%" :close-on-click-modal="false">
  213. <el-table :data="editGoodsDetail.goodsSpecs" element-loading-text="Loading" border fit highlight-current-row stripe style="margin-bottom: 20px">
  214. <el-table-column align="center" label="规格名称" prop="name"></el-table-column>
  215. <el-table-column align="center" label="规格值" prop="specValue"></el-table-column>
  216. <el-table-column align="center" label="规格图片" prop="imgUrl">
  217. <template slot-scope="scope">
  218. <el-image style="width: 40px; height: 40px;" :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]" fit="cover"></el-image>
  219. </template>
  220. </el-table-column>
  221. <el-table-column align="center" label="成本价格" prop="costPrice"></el-table-column>
  222. <el-table-column align="center" label="销售价格" prop="price" min-width="120">
  223. <template slot-scope="scope">
  224. <el-input v-model="scope.row.price" :disabled="editType != 'price'"></el-input>
  225. </template>
  226. </el-table-column>
  227. <el-table-column align="center" label="分销金额" prop="shareAmount" min-width="120">
  228. <template slot-scope="scope">
  229. <el-input v-model="scope.row.shareAmount" :disabled="editType != 'shareAmount'"></el-input>
  230. </template>
  231. </el-table-column>
  232. <el-table-column align="center" label="佣金比例(%)" prop="sharePercent" min-width="120">
  233. <template slot-scope="scope">
  234. <el-input v-model="scope.row.sharePercent" :disabled="editType != 'sharePercent'"></el-input>
  235. </template>
  236. </el-table-column>
  237. <el-table-column align="center" label="内部分销金额" prop="innerShareAmount" min-width="120">
  238. <template slot-scope="scope">
  239. <el-input v-model="scope.row.innerShareAmount" :disabled="editType !== 'innerShareAmount'"></el-input>
  240. </template>
  241. </el-table-column>
  242. <el-table-column align="center" label="内部佣金比例(%)" prop="innerSharePercent" min-width="130">
  243. <template slot-scope="scope">
  244. <el-input v-model="scope.row.innerSharePercent" :disabled="editType !== 'innerSharePercent'"></el-input>
  245. </template>
  246. </el-table-column>
  247. <el-table-column align="center" label="商品库存" prop="stockNum" min-width="120">
  248. <template slot-scope="scope">
  249. <el-input v-model="scope.row.stockNum" :disabled="editType != 'stockNum'"></el-input>
  250. </template>
  251. </el-table-column>
  252. <el-table-column align="center" label="仓库库存" prop="goodsMaterialStock">
  253. <template slot-scope="scope">
  254. {{scope.row.goodsMaterialStock || 0}}
  255. </template>
  256. </el-table-column>
  257. <el-table-column align="center" label="物料编号" prop="goodsCode" min-width="120">
  258. <template slot-scope="scope">
  259. <el-input v-model="scope.row.goodsCode"></el-input>
  260. </template>
  261. </el-table-column>
  262. </el-table>
  263. <div slot="footer" class="dialog-footer">
  264. <el-button @click="cancelEditSpecForm">取 消</el-button>
  265. <el-button type="primary" @click="submitEditSpecForm">确 定</el-button>
  266. </div>
  267. </el-dialog>
  268. <!-- 批量设置模块 -->
  269. <el-dialog :title="'设置模块 (已选择' + tableSelection.length + '件商品)'" :visible.sync="setModuleVisible" :show-close="false" width="30%" :close-on-click-modal="false">
  270. <el-form ref="setModuleForm" :model="setModuleForm" :rules="setModuleFormRules" label-position="left" label-width="80px">
  271. <el-form-item label="说明模块" prop="module">
  272. <el-select v-model="setModuleForm.module" placeholder="请选择说明模块" style="width: 250px;">
  273. <el-option v-for="item in moduleList" :key="item.commonTemplateId" :label="item.name" :value="item.commonTemplateId">
  274. </el-option>
  275. </el-select>
  276. </el-form-item>
  277. </el-form>
  278. <div slot="footer" class="dialog-footer">
  279. <el-button @click="cancelSetModuleForm">取 消</el-button>
  280. <el-button type="primary" @click="submitSetModuleForm">确 定</el-button>
  281. </div>
  282. </el-dialog>
  283. <!-- 批量设置运费 -->
  284. <el-dialog :title="'设置运费 (已选择' + tableSelection.length + '件商品)'" :visible.sync="setFreightVisible" :show-close="false" width="30%" :close-on-click-modal="false">
  285. <el-form ref="setFreightForm" :model="setFreightForm" :rules="setFreightFormRules" label-position="left" label-width="80px">
  286. <el-form-item label="运费模版" prop="freight">
  287. <el-select v-model="setFreightForm.freight" placeholder="请选择运费模版" style="width: 250px;">
  288. <el-option v-for="item in freightList" :key="item.freightTemplateId" :label="item.name" :value="item.freightTemplateId">
  289. </el-option>
  290. </el-select>
  291. </el-form-item>
  292. </el-form>
  293. <div slot="footer" class="dialog-footer">
  294. <el-button @click="cancelSetFreightForm">取 消</el-button>
  295. <el-button type="primary" @click="submitSetFreightForm">确 定</el-button>
  296. </div>
  297. </el-dialog>
  298. </div>
  299. </template>
  300. <script>
  301. import { getGoodsList, deleteGoods, getClassifyList, getGoodsStateCount, cloneGoods, editGoods, goodsPutOn, goodsPutOff, checkSeckill, getGoodsDetail, getModuleList, setCommomModule, setFreight, getFreightList, batchTrade } from '@/api/goods'
  302. import Clipboard from 'clipboard'
  303. import { EventBus } from '@/utils/eventBus'
  304. export default {
  305. data() {
  306. return {
  307. dataList: null, // 列表数据
  308. listLoading: true, // 列表加载loading
  309. currentPage: 1, // 当前页码
  310. pageSize: 10, // 每页数量
  311. listTotal: 0, // 列表总数
  312. screenForm: {
  313. type: '',
  314. keyword: '',
  315. classify: '',
  316. status: '',
  317. isTrade: '',
  318. price1: '',
  319. price2: '',
  320. amount1: '',
  321. amount2: '',
  322. },
  323. select_status: [ // 筛选字段 - 状态
  324. { label: '上架', value: true },
  325. { label: '下架', value: false }
  326. ],
  327. classifyList: [],
  328. goodsStateCount: {
  329. total: 0,
  330. csz: 0,
  331. ysq: 0,
  332. ckz: 0,
  333. hdz: 0,
  334. },
  335. tableSelection: [],
  336. editSpecVisible: false,
  337. editGoodsDetail: {},
  338. editType: '',
  339. setModuleVisible: false,
  340. moduleList: [],
  341. setModuleForm: {
  342. module: '',
  343. },
  344. setModuleFormRules: {
  345. module: [
  346. { required: true, message: '请选择说明模块', trigger: 'change' }
  347. ],
  348. },
  349. setFreightVisible: false,
  350. freightList: [],
  351. setFreightForm: {
  352. freight: '',
  353. },
  354. setFreightFormRules: {
  355. freight: [
  356. { required: true, message: '请选择运费模块', trigger: 'change' }
  357. ],
  358. },
  359. }
  360. },
  361. created() {
  362. this.getList();
  363. this.getClassifyList();
  364. EventBus.$on("updateGoodsListPage",()=>{
  365. this.getList();
  366. })
  367. },
  368. methods: {
  369. getClassifyList() {
  370. let params = {
  371. name: '',
  372. status: true
  373. };
  374. getClassifyList(params).then(res => {
  375. res.data.unshift({
  376. name: '全部',
  377. categoryId: '',
  378. children: null,
  379. });
  380. this.classifyList = res.data;
  381. })
  382. },
  383. getList() {
  384. this.listLoading = true;
  385. let categoryId = '';
  386. if(this.screenForm.classify) {
  387. categoryId = this.screenForm.classify[1];
  388. }
  389. let params = {
  390. flag: this.screenForm.type,
  391. keyword: this.screenForm.keyword,
  392. categoryId: categoryId,
  393. status: this.screenForm.status,
  394. isTrade: this.screenForm.isTrade,
  395. startPrice: this.screenForm.price1,
  396. endPrice: this.screenForm.price2,
  397. startShare: this.screenForm.amount1,
  398. endShare: this.screenForm.amount2,
  399. pageNum: this.currentPage,
  400. pageSize: this.pageSize
  401. };
  402. getGoodsList(params).then(res => {
  403. console.log('-----------',res.data.records)
  404. this.dataList = res.data.records;
  405. this.listTotal = res.data.total;
  406. this.listLoading = false;
  407. })
  408. getGoodsStateCount({}).then(res => {
  409. this.goodsStateCount = res.data;
  410. })
  411. },
  412. // 更改每页数量
  413. handleSizeChange(val) {
  414. this.pageSize = val;
  415. this.currentPage = 1;
  416. this.getList();
  417. },
  418. // 更改当前页
  419. handleCurrentChange(val) {
  420. this.currentPage = val;
  421. this.getList();
  422. },
  423. // 筛选后重新获取列表
  424. getListByScreen() {
  425. this.currentPage = 1;
  426. this.getList();
  427. },
  428. // 切换类型
  429. changeType(type) {
  430. this.screenForm.type = type;
  431. this.getListByScreen();
  432. },
  433. // 删除商品
  434. delItem(goodsId, goodsSpecId) {
  435. deleteGoods({
  436. goodsId,
  437. goodsSpecId
  438. }).then(res => {
  439. this.getList();
  440. this.$successMsg();
  441. })
  442. },
  443. // 添加商品
  444. addOrEdit(type, id) {
  445. if(type == 'add') {
  446. this.$router.push({
  447. name: 'goods_add',
  448. query: {}
  449. })
  450. }else {
  451. this.$router.push({
  452. name: 'goods_add',
  453. query: {
  454. id
  455. }
  456. })
  457. }
  458. },
  459. // 克隆
  460. clone(id) {
  461. cloneGoods({
  462. goodsId: id
  463. }).then(res => {
  464. this.getList();
  465. })
  466. },
  467. copy() {
  468. const clipboard = new Clipboard('.tag-read');
  469. // clipboard.on('success', e => {
  470. // this.$successMsg('复制成功');
  471. // })
  472. clipboard.on('error', e =>{
  473. console.log('该浏览器不支持复制');
  474. return false;
  475. })
  476. this.$successMsg('复制成功');
  477. },
  478. // 编辑数据
  479. async editData(type, item) {
  480. const typeMap = {
  481. goodsName: '商品名称',
  482. price: '销售价格',
  483. shareAmount: '分销金额',
  484. sharePercent: '佣金比例',
  485. innerShareAmount: '内部分销金额',
  486. innerSharePercent: '内部佣金比例',
  487. stockNum: '商品库存',
  488. sortNum: '排序'
  489. }
  490. await getGoodsDetail({goodsId: item.goodsId}).then(res => {
  491. this.editGoodsDetail = res.data;
  492. })
  493. if(['sortNum', 'goodsName'].includes(type)) {
  494. let promptObj = {};
  495. if(['sortNum'].includes(type)) {
  496. promptObj = {
  497. inputType: 'number',
  498. inputValidator: function(value) {
  499. if(!value && value !== 0) return '请输入'+typeMap[type]
  500. if(value*1 < 0) return typeMap[type]+'不能小于0'
  501. },
  502. }
  503. }else {
  504. promptObj = {
  505. inputValidator: function(value) {
  506. if(!value) return '请输入'+typeMap[type]
  507. },
  508. }
  509. }
  510. this.$prompt('请输入'+typeMap[type], '编辑', {
  511. confirmButtonText: '确定',
  512. cancelButtonText: '取消',
  513. inputValue: this.editGoodsDetail[type],
  514. ...promptObj
  515. }).then(({ value }) => {
  516. let params = this.editGoodsDetail;
  517. params[type] = value;
  518. editGoods(params).then(res => {
  519. this.$successMsg('编辑成功');
  520. this.getList();
  521. })
  522. }).catch(() => {});
  523. }
  524. else {
  525. if(type == 'shareAmount' && item.sharePercent != 0) {
  526. return this.$errorMsg('佣金比例不为0的时候无法修改分销金额');
  527. }
  528. if(type === 'innerShareAmount' && item.innerSharePercent !== 0) {
  529. return this.$errorMsg('内部佣金比例不为0的时候无法修改内部分销金额');
  530. }
  531. this.editType = type;
  532. this.editSpecVisible = true;
  533. }
  534. },
  535. // 取消 编辑规格数据
  536. cancelEditSpecForm(){
  537. this.editSpecVisible = false;
  538. },
  539. // 提交 编辑规格数据
  540. submitEditSpecForm(){
  541. let specList = this.editGoodsDetail.goodsSpecs;
  542. for(let i=0; i<specList.length; i++) {
  543. if(specList[i].shareAmount / specList[i].price > 0.4) {
  544. this.formLoading = false;
  545. this.$errorMsg('单个规格的分销金额不能超过销售价的40%');
  546. return;
  547. }
  548. if(Number(specList[i].sharePercent) < 0 || Number(specList[i].sharePercent) > 40) {
  549. this.formLoading = false;
  550. this.$errorMsg('单个规格的佣金比例范围在0-40');
  551. return;
  552. }
  553. if(specList[i].innerShareAmount / specList[i].price > 0.4) {
  554. this.formLoading = false;
  555. this.$errorMsg('单个规格的内部分销金额不能超过销售价的40%');
  556. return;
  557. }
  558. if(Number(specList[i].innerSharePercent) < 0 || Number(specList[i].innerSharePercent) > 40) {
  559. this.formLoading = false;
  560. this.$errorMsg('单个规格的内部佣金比例范围在0-40');
  561. return;
  562. }
  563. }
  564. let allPrice = [];
  565. specList.forEach(item => {
  566. allPrice.push(item.price);
  567. })
  568. this.editGoodsDetail.goodsPrice = Math.min(...allPrice);
  569. let params = this.editGoodsDetail;
  570. editGoods(params).then(res => {
  571. this.editSpecVisible = false;
  572. this.$successMsg('编辑成功');
  573. this.getList();
  574. })
  575. },
  576. // 表格选择列
  577. handleTableSelection(val) {
  578. this.tableSelection = val;
  579. },
  580. // 批量操作
  581. batchOperation(type, status) {
  582. if(this.tableSelection.length < 1) {
  583. return this.$errorMsg('至少选择一个商品');
  584. }
  585. // 批量上架/批量下架
  586. if(type == 'status') {
  587. this.$confirm(`您确定要批量${{on: '上架', off: '下架'}[status]}选中商品吗?`, '提示', {
  588. confirmButtonText: '确定',
  589. cancelButtonText: '取消',
  590. type: 'warning'
  591. }).then(() => {
  592. let goodsIds = [];
  593. this.tableSelection.forEach(item => {
  594. goodsIds.push(item.goodsId);
  595. });
  596. // 批量上架
  597. if(status == 'on') {
  598. goodsPutOn(goodsIds).then(res => {
  599. this.$successMsg();
  600. this.getList();
  601. })
  602. }
  603. // 批量下架
  604. else if(status == 'off') {
  605. checkSeckill(goodsIds).then(res => {
  606. if(res.data && res.data.length > 0) {
  607. let goodsNames = [];
  608. res.data.forEach(item => {
  609. let index = this.$findElem(this.tableSelection, 'goodsId', item);
  610. goodsNames.push('【' + this.tableSelection[index].goodsName + '】');
  611. })
  612. this.$confirm('你所选中的商品'+goodsNames.join('、')+'正在参与秒杀活动,是否确定下架?', '提示', {
  613. confirmButtonText: '确定',
  614. cancelButtonText: '取消',
  615. type: 'warning'
  616. }).then(() => {
  617. goodsPutOff(goodsIds).then(res => {
  618. this.$successMsg();
  619. this.getList();
  620. })
  621. }).catch(() => {});
  622. }else {
  623. goodsPutOff(goodsIds).then(res => {
  624. this.$successMsg();
  625. this.getList();
  626. })
  627. }
  628. })
  629. }
  630. }).catch(() => {});
  631. }
  632. // 批量开启关闭以旧换新
  633. else if(type == 'isTrade') {
  634. this.$confirm(`您确定要批量${{YES: '开启', NO: '关闭'}[status]}以旧换新吗?`, '提示', {
  635. confirmButtonText: '确定',
  636. cancelButtonText: '取消',
  637. type: 'warning'
  638. }).then(() => {
  639. let goodsIds = [];
  640. this.tableSelection.forEach(item => {
  641. goodsIds.push(item.goodsId);
  642. });
  643. batchTrade({
  644. goodsIds: goodsIds.join(','),
  645. isTrade: status
  646. }).then(res => {
  647. this.$successMsg();
  648. this.getList();
  649. })
  650. }).catch(() => {});
  651. }
  652. // 批量设置模块
  653. else if(type == 'module') {
  654. this.getModuleList();
  655. this.setModuleVisible = true;
  656. }
  657. // 批量设置运费
  658. else if(type == 'freight') {
  659. this.getFreightList();
  660. this.setFreightVisible = true;
  661. }
  662. },
  663. // 获取模块列表
  664. getModuleList() {
  665. getModuleList({
  666. pageNum: 1,
  667. pageSize: 1000
  668. }).then(res => {
  669. this.moduleList = res.data.records;
  670. })
  671. },
  672. // 取消 设置模块
  673. cancelSetModuleForm(){
  674. this.setModuleVisible = false;
  675. this.$refs.setModuleForm.resetFields();
  676. },
  677. // 提交 设置模块
  678. submitSetModuleForm() {
  679. let goodsIds = [];
  680. this.tableSelection.forEach(item => {
  681. goodsIds.push(item.goodsId);
  682. });
  683. setCommomModule({
  684. goodsIdList: goodsIds,
  685. templateId: this.setModuleForm.module
  686. }).then(res => {
  687. this.cancelSetModuleForm();
  688. this.$successMsg();
  689. this.getList();
  690. })
  691. },
  692. // 获取运费模版列表
  693. getFreightList() {
  694. getFreightList({
  695. pageNum: 1,
  696. pageSize: 1000
  697. }).then(res => {
  698. this.freightList = res.data.records;
  699. })
  700. },
  701. // 取消 设置运费
  702. cancelSetFreightForm(){
  703. this.setFreightVisible = false;
  704. this.$refs.setFreightForm.resetFields();
  705. },
  706. // 提交 设置运费
  707. submitSetFreightForm() {
  708. let goodsIds = [];
  709. this.tableSelection.forEach(item => {
  710. goodsIds.push(item.goodsId);
  711. });
  712. setFreight({
  713. goodsIdList: goodsIds,
  714. freightTemplateId: this.setFreightForm.freight
  715. }).then(res => {
  716. this.cancelSetFreightForm();
  717. this.$successMsg();
  718. this.getList();
  719. })
  720. }
  721. }
  722. }
  723. </script>
  724. <style scoped lang="scss">
  725. .tab-container {
  726. .tab-list {
  727. .item {
  728. float: left;
  729. font-size: 14px;
  730. margin-right: 20px;
  731. cursor: pointer;
  732. line-height: 32px;
  733. &.current {
  734. color: #409EFF;
  735. }
  736. }
  737. }
  738. }
  739. .screen2-container {
  740. .search {
  741. margin-top: 30px;
  742. }
  743. .screen {
  744. margin-top: 20px;
  745. .el-input {
  746. width: 40%;
  747. }
  748. span {
  749. width: 20%;
  750. display: inline-block;
  751. text-align: center;
  752. color: #666666;
  753. }
  754. }
  755. }
  756. .pointer {
  757. cursor: pointer;
  758. color: #409EFF;
  759. }
  760. </style>
  761. <style lang="scss">
  762. .screen2-container {
  763. .el-form-item__label {
  764. line-height: 32px;
  765. }
  766. .el-form-item__content {
  767. line-height: 32px;
  768. }
  769. }
  770. .el-image-viewer__wrapper .el-icon-circle-close {
  771. color: #ffffff !important;
  772. font-size: 60px;
  773. }
  774. </style>