index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="10" class="mb8">
  4. <el-col :span="1.5">
  5. <el-button
  6. type="primary"
  7. icon="el-icon-plus"
  8. size="mini"
  9. @click="handleAdd"
  10. v-hasPermi="['store:shippingTemplates:add']"
  11. >新增</el-button>
  12. </el-col>
  13. <el-col :span="1.5">
  14. <el-button
  15. type="success"
  16. icon="el-icon-edit"
  17. size="mini"
  18. :disabled="single"
  19. @click="handleUpdate"
  20. v-hasPermi="['store:shippingTemplates:edit']"
  21. >修改</el-button>
  22. </el-col>
  23. <el-col :span="1.5">
  24. <el-button
  25. type="danger"
  26. icon="el-icon-delete"
  27. size="mini"
  28. :disabled="multiple"
  29. @click="handleDelete"
  30. v-hasPermi="['store:shippingTemplates:remove']"
  31. >删除</el-button>
  32. </el-col>
  33. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  34. </el-row>
  35. <el-table height="500" border v-loading="loading" :data="shippingTemplatesList" @selection-change="handleSelectionChange">
  36. <el-table-column type="selection" width="55" align="center" />
  37. <el-table-column label="模板ID" align="center" prop="id" />
  38. <el-table-column label="模板名称" align="center" prop="name" />
  39. <el-table-column label="计费方式" align="center" prop="type" >
  40. <template slot-scope="scope">
  41. <el-tag prop="type" v-for="(item, index) in typeOptions" v-if="scope.row.type==item.dictValue">{{item.dictLabel}}</el-tag>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="指定包邮开关" align="center" prop="appoint" >
  45. <template slot-scope="scope">
  46. <el-tag prop="type" v-for="(item, index) in appointOptions" v-if="scope.row.appoint==item.dictValue">{{item.dictLabel}}</el-tag>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="添加时间" align="center" prop="createTime" />
  50. <el-table-column label="排序" align="center" prop="sort" />
  51. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  52. <template slot-scope="scope">
  53. <el-button
  54. size="mini"
  55. type="text"
  56. icon="el-icon-edit"
  57. @click="handleUpdate(scope.row)"
  58. v-hasPermi="['store:shippingTemplates:edit']"
  59. >修改</el-button>
  60. <el-button
  61. size="mini"
  62. type="text"
  63. icon="el-icon-delete"
  64. @click="handleDelete(scope.row)"
  65. v-hasPermi="['store:shippingTemplates:remove']"
  66. >删除</el-button>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. <pagination
  71. v-show="total>0"
  72. :total="total"
  73. :page.sync="queryParams.pageNum"
  74. :limit.sync="queryParams.pageSize"
  75. @pagination="getList"
  76. />
  77. <!-- 添加或修改运费模板对话框 -->
  78. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  79. <el-form ref="form" :model="form" :rules="rules" label-width="130px">
  80. <el-form-item label="模板名称" prop="name">
  81. <el-input v-model="form.name" placeholder="请输入模板名称" />
  82. </el-form-item>
  83. <el-form-item label="计费方式" prop="type">
  84. <el-radio-group v-model="form.type" >
  85. <el-radio :label="item.dictValue" v-for="item in typeOptions" >{{item.dictLabel}}</el-radio>-radio>
  86. </el-radio-group>
  87. </el-form-item>
  88. <el-row :gutter="24" type="flex">
  89. <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
  90. <el-form-item class="label" label="配送区域及运费:" props="state">
  91. <el-table
  92. ref="table"
  93. :data="templateList"
  94. empty-text="暂无数据"
  95. border
  96. >
  97. <el-table-column prop="regionName" label="可配送区域" width="130" />
  98. <el-table-column prop="first" label="首件" width="120">
  99. <template slot="header" slot-scope="scope">
  100. <span v-if="form.type == 1">首件</span>
  101. <span v-else-if="form.type == 2">首件重量(KG)</span>
  102. <span v-else>首件体积(m³)</span>
  103. </template>
  104. <template slot-scope="scope">
  105. <span><el-input type="text" v-model="scope.row.first" /></span>
  106. </template>
  107. </el-table-column>
  108. <el-table-column prop="price" label="运费(元)" width="110">
  109. <template slot-scope="scope">
  110. <span><el-input type="text" v-model="scope.row.price"/></span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column prop="_continue" label="续件" width="120">
  114. <template slot="header" slot-scope="scope">
  115. <span v-if="form.type == 1">续件</span>
  116. <span v-else-if="form.type == 2">续件重量(KG)</span>
  117. <span v-else>续件体积(m³)</span>
  118. </template>
  119. <template slot-scope="scope">
  120. <span><el-input type="text" v-model="scope.row.continues"/></span>
  121. </template>
  122. </el-table-column>
  123. <el-table-column prop="continuePrice" label="续费(元)" width="110">
  124. <template slot-scope="scope">
  125. <span><el-input type="text" v-model="scope.row.continuePrice"/></span>
  126. </template>
  127. </el-table-column>
  128. <el-table-column label="操作">
  129. <template slot-scope="scope">
  130. <a @click="delCity(scope.$index,1)">删除</a>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. <el-row type="flex" class="addTop">
  135. <el-col>
  136. <el-button size="small" type="primary" icon="md-add" @click="addCity(1)">单独添加配送区域</el-button>
  137. </el-col>
  138. </el-row>
  139. </el-form-item>
  140. </el-col>
  141. </el-row>
  142. <el-row :gutter="24" type="flex">
  143. <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
  144. <el-form-item label="指定包邮:" prop="appoint">
  145. <el-radio-group v-model="form.appoint" >
  146. <el-radio :label="item.dictValue" v-for="item in appointOptions" >{{item.dictLabel}}</el-radio>-radio>
  147. </el-radio-group>
  148. <el-table
  149. ref="table"
  150. :data="appointList"
  151. empty-text="暂无数据"
  152. border
  153. v-if="form.appoint === '1'"
  154. >
  155. <el-table-column prop="placeName" label="选择地区" />
  156. <el-table-column prop="a_num" label="包邮件数" width="120" >
  157. <template slot="header" slot-scope="scope">
  158. <span v-if="form.type == 1">包邮件数</span>
  159. <span v-else-if="form.type == 2">包邮重量(KG)</span>
  160. <span v-else>包邮体积(m³)</span>
  161. </template>
  162. <template slot-scope="scope">
  163. <span><el-input type="text" v-model="scope.row.number"/></span>
  164. </template>
  165. </el-table-column>
  166. <el-table-column prop="price" label="包邮金额(元)" width="120">
  167. <template slot-scope="scope">
  168. <span><el-input type="text" v-model="scope.row.price"/></span>
  169. </template>
  170. </el-table-column>
  171. <el-table-column label="操作">
  172. <template slot-scope="scope">
  173. <a @click="delCity(scope.$index ,2)">删除</a>
  174. </template>
  175. </el-table-column>
  176. </el-table>
  177. <el-row type="flex" v-if="form.appoint === '1'">
  178. <el-col>
  179. <el-button size="small" type="primary" icon="md-add" @click="addCity(2)">单独指定包邮</el-button>
  180. </el-col>
  181. </el-row>
  182. </el-form-item>
  183. </el-col>
  184. </el-row>
  185. <el-form-item label="排序" prop="sort">
  186. <el-input-number :min="0" v-model="form.sort" placeholder="请输入排序" />
  187. </el-form-item>
  188. </el-form>
  189. <div slot="footer" class="dialog-footer">
  190. <el-button type="primary" @click="submitForm">确 定</el-button>
  191. <el-button @click="cancel">取 消</el-button>
  192. </div>
  193. </el-dialog>
  194. <CityZm ref="city" @selectCity="selectCity" :type="type"></CityZm>
  195. </div>
  196. </template>
  197. <script>
  198. import { listShippingTemplates, getShippingTemplates, delShippingTemplates, addShippingTemplates, updateShippingTemplates, exportShippingTemplates } from "@/api/hisStore/shippingTemplates";
  199. import CityZm from '@/components/City/indexZm'
  200. export default {
  201. name: "ShippingTemplates",
  202. components: {
  203. CityZm
  204. },
  205. data() {
  206. return {
  207. type:0,
  208. appointList:[],
  209. templateList:[],
  210. appointOptions:[],
  211. typeOptions:[],
  212. // 遮罩层
  213. loading: true,
  214. // 选中数组
  215. ids: [],
  216. // 非单个禁用
  217. single: true,
  218. // 非多个禁用
  219. multiple: true,
  220. // 显示搜索条件
  221. showSearch: true,
  222. // 总条数
  223. total: 0,
  224. // 运费模板表格数据
  225. shippingTemplatesList: [],
  226. // 弹出层标题
  227. title: "",
  228. // 是否显示弹出层
  229. open: false,
  230. // 查询参数
  231. queryParams: {
  232. pageNum: 1,
  233. pageSize: 10,
  234. name: null,
  235. type: null,
  236. regionInfo: null,
  237. appoint: null,
  238. appointInfo: null,
  239. isDel: null,
  240. sort: null
  241. },
  242. // 表单参数
  243. form: {},
  244. // 表单校验
  245. rules: {
  246. name: [
  247. { required: true, message: "名称不能为空", trigger: "blur" }
  248. ],
  249. }
  250. };
  251. },
  252. created() {
  253. this.getDicts("store_shipping_type").then((response) => {
  254. this.typeOptions = response.data;
  255. });
  256. this.getDicts("store_shipping_appoint").then((response) => {
  257. this.appointOptions = response.data;
  258. });
  259. this.getList();
  260. },
  261. methods: {
  262. delCity (index,type) {
  263. if (type === 1) {
  264. this.templateList.splice(index, 1);
  265. } else {
  266. this.appointList.splice(index, 1);
  267. }
  268. },
  269. selectCity: function (data, type) {
  270. let cityName = data.map(function (item) {
  271. return item.name;
  272. }).join(';');
  273. switch (type) {
  274. case 1:
  275. this.templateList.push({
  276. region: data,
  277. regionName: cityName,
  278. first: 1,
  279. price: 0,
  280. continues: 1,
  281. continuePrice: 0
  282. });
  283. break;
  284. case 2:
  285. this.appointList.push({
  286. place: data,
  287. placeName: cityName,
  288. number: 0,
  289. price: 0
  290. });
  291. break;
  292. }
  293. },
  294. // 单独添加配送区域
  295. addCity (type) {
  296. // 获取已选择的城市数据
  297. let selectedCities = [];
  298. if (type === 1) {
  299. // 配送区域
  300. this.templateList.forEach(item => {
  301. if (item.region && item.region.length > 0) {
  302. selectedCities = selectedCities.concat(item.region);
  303. }
  304. });
  305. } else {
  306. // 指定包邮
  307. this.appointList.forEach(item => {
  308. if (item.place && item.place.length > 0) {
  309. selectedCities = selectedCities.concat(item.place);
  310. }
  311. });
  312. }
  313. this.$refs.city.addressView = true;
  314. this.type = type;
  315. this.$refs.city.selectedCities = selectedCities;
  316. this.$refs.city.getCityList()
  317. },
  318. /** 查询运费模板列表 */
  319. getList() {
  320. this.loading = true;
  321. listShippingTemplates(this.queryParams).then(response => {
  322. this.shippingTemplatesList = response.rows;
  323. this.total = response.total;
  324. this.loading = false;
  325. });
  326. },
  327. // 取消按钮
  328. cancel() {
  329. this.open = false;
  330. this.reset();
  331. },
  332. // 表单重置
  333. reset() {
  334. this.form = {
  335. id: null,
  336. name: null,
  337. type: "1",
  338. appoint: "0",
  339. createTime: null,
  340. updateTime: null,
  341. isDel: null,
  342. sort: null
  343. };
  344. this.templateList = [
  345. {
  346. region: [
  347. {
  348. name: '默认全国',
  349. cityId: 0
  350. }
  351. ],
  352. regionName: '默认全国',
  353. first: 1,
  354. price: 0,
  355. continues: 1,
  356. continuePrice: 0
  357. }
  358. ];
  359. this.appointList=[],
  360. this.resetForm("form");
  361. },
  362. /** 搜索按钮操作 */
  363. handleQuery() {
  364. this.queryParams.pageNum = 1;
  365. this.getList();
  366. },
  367. /** 重置按钮操作 */
  368. resetQuery() {
  369. this.resetForm("queryForm");
  370. this.handleQuery();
  371. },
  372. // 多选框选中数据
  373. handleSelectionChange(selection) {
  374. this.ids = selection.map(item => item.id)
  375. this.single = selection.length!==1
  376. this.multiple = !selection.length
  377. },
  378. /** 新增按钮操作 */
  379. handleAdd() {
  380. this.reset();
  381. this.open = true;
  382. this.title = "添加运费模板";
  383. },
  384. /** 修改按钮操作 */
  385. handleUpdate(row) {
  386. this.reset();
  387. const id = row.id || this.ids
  388. getShippingTemplates(id).then(response => {
  389. this.form = response.data;
  390. this.form.type = response.data.type.toString();
  391. this.form.appoint = response.data.appoint.toString();
  392. this.appointList=JSON.parse(this.form.appointInfo)
  393. this.templateList=JSON.parse(this.form.regionInfo)
  394. this.open = true;
  395. this.title = "修改运费模板";
  396. });
  397. },
  398. /** 提交按钮 */
  399. submitForm() {
  400. this.$refs["form"].validate(valid => {
  401. if (valid) {
  402. this.form.regionInfo=this.templateList;
  403. this.form.appointInfo=this.appointList;
  404. if (this.form.id != null) {
  405. updateShippingTemplates(this.form).then(response => {
  406. if (response.code === 200) {
  407. this.msgSuccess("修改成功");
  408. this.open = false;
  409. this.getList();
  410. }
  411. });
  412. } else {
  413. addShippingTemplates(this.form).then(response => {
  414. if (response.code === 200) {
  415. this.msgSuccess("新增成功");
  416. this.open = false;
  417. this.getList();
  418. }
  419. });
  420. }
  421. }
  422. });
  423. },
  424. /** 删除按钮操作 */
  425. handleDelete(row) {
  426. const ids = row.id || this.ids;
  427. this.$confirm('是否确认删除运费模板编号为"' + ids + '"的数据项?', "警告", {
  428. confirmButtonText: "确定",
  429. cancelButtonText: "取消",
  430. type: "warning"
  431. }).then(function() {
  432. return delShippingTemplates(ids);
  433. }).then(() => {
  434. this.getList();
  435. this.msgSuccess("删除成功");
  436. }).catch(function() {});
  437. },
  438. /** 导出按钮操作 */
  439. handleExport() {
  440. const queryParams = this.queryParams;
  441. this.$confirm('是否确认导出所有运费模板数据项?', "警告", {
  442. confirmButtonText: "确定",
  443. cancelButtonText: "取消",
  444. type: "warning"
  445. }).then(function() {
  446. return exportShippingTemplates(queryParams);
  447. }).then(response => {
  448. this.download(response.msg);
  449. }).catch(function() {});
  450. }
  451. }
  452. };
  453. </script>